Compare commits

..

No commits in common. "3c4cc4b331948d2d39136e1d52143717255470f4" and "63cefacbfaee10e1e704be171a74d97c7cbd7d77" have entirely different histories.

23
encode_video.py Normal file → Executable file
View File

@ -16,19 +16,21 @@ def get_duration(file_path):
def encode(input_file, codec, remove_source=False, save_log=False):
if codec == "x265":
ffmpeg_codec = "hevc_nvenc"
cq = 32
ffmpeg_codec = "libx265"
crf = 26
folder = "h265"
extra_params = [
]
extra_params = ["-crf", str(crf)]
elif codec == "x265-amd":
ffmpeg_codec = "hevc_amf"
folder = "h265"
extra_params = ["-quality", "quality"]
elif codec == "av1":
ffmpeg_codec = "av1_nvenc"
cq = 32
folder = "av1"
extra_params = [
"-pix_fmt", "yuv420p",
]
extra_params = ["-pix_fmt", "yuv420p", "-preset", "p4", "-cq", str(cq), "-rc", "vbr", "-b:v", "0"]
else:
raise ValueError(f"Unsupported codec: {codec}")
@ -55,13 +57,8 @@ def encode(input_file, codec, remove_source=False, save_log=False):
"ffmpeg",
"-i", input_file,
"-map", "0",
"-cq", str(cq),
] + extra_params + [
"-c:v", ffmpeg_codec,
"-preset", "p4",
"-cq", str(cq),
"-rc", "vbr",
"-b:v", "0",
"-c:a", "copy",
"-c:s", "copy",
"-y", output_file
@ -127,7 +124,7 @@ def main():
parser = argparse.ArgumentParser(description="Encode video(s) to x265 or AV1.")
parser.add_argument("input", nargs="?", help="Path to input file")
parser.add_argument("-d", "--directory", help="Path to a directory for batch encoding")
parser.add_argument("--codec", choices=["x265", "av1"], default="x265", help="Codec to use")
parser.add_argument("--codec", choices=["x265", "x265-amd", "av1"], default="x265", help="Codec to use")
parser.add_argument("--remove-source", action="store_true", help="Remove the source file after successful encoding")
parser.add_argument("--save-log", action="store_true", help="Save ffmpeg logs to a .log file")
args = parser.parse_args()