Compare commits

...

2 Commits

23
encode_video.py Executable file → Normal file
View File

@ -16,21 +16,19 @@ def get_duration(file_path):
def encode(input_file, codec, remove_source=False, save_log=False):
if codec == "x265":
ffmpeg_codec = "libx265"
crf = 26
ffmpeg_codec = "hevc_nvenc"
cq = 32
folder = "h265"
extra_params = ["-crf", str(crf)]
elif codec == "x265-amd":
ffmpeg_codec = "hevc_amf"
folder = "h265"
extra_params = ["-quality", "quality"]
extra_params = [
]
elif codec == "av1":
ffmpeg_codec = "av1_nvenc"
cq = 32
folder = "av1"
extra_params = ["-pix_fmt", "yuv420p", "-preset", "p4", "-cq", str(cq), "-rc", "vbr", "-b:v", "0"]
extra_params = [
"-pix_fmt", "yuv420p",
]
else:
raise ValueError(f"Unsupported codec: {codec}")
@ -57,8 +55,13 @@ 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
@ -124,7 +127,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", "x265-amd", "av1"], default="x265", help="Codec to use")
parser.add_argument("--codec", choices=["x265", "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()