Compare commits
2 Commits
63cefacbfa
...
3c4cc4b331
Author | SHA1 | Date | |
---|---|---|---|
3c4cc4b331 | |||
c9fd7c319a |
23
encode_video.py
Executable file → Normal file
23
encode_video.py
Executable file → Normal file
@ -16,21 +16,19 @@ def get_duration(file_path):
|
|||||||
|
|
||||||
def encode(input_file, codec, remove_source=False, save_log=False):
|
def encode(input_file, codec, remove_source=False, save_log=False):
|
||||||
if codec == "x265":
|
if codec == "x265":
|
||||||
ffmpeg_codec = "libx265"
|
ffmpeg_codec = "hevc_nvenc"
|
||||||
crf = 26
|
cq = 32
|
||||||
folder = "h265"
|
folder = "h265"
|
||||||
extra_params = ["-crf", str(crf)]
|
extra_params = [
|
||||||
|
]
|
||||||
elif codec == "x265-amd":
|
|
||||||
ffmpeg_codec = "hevc_amf"
|
|
||||||
folder = "h265"
|
|
||||||
extra_params = ["-quality", "quality"]
|
|
||||||
|
|
||||||
elif codec == "av1":
|
elif codec == "av1":
|
||||||
ffmpeg_codec = "av1_nvenc"
|
ffmpeg_codec = "av1_nvenc"
|
||||||
cq = 32
|
cq = 32
|
||||||
folder = "av1"
|
folder = "av1"
|
||||||
extra_params = ["-pix_fmt", "yuv420p", "-preset", "p4", "-cq", str(cq), "-rc", "vbr", "-b:v", "0"]
|
extra_params = [
|
||||||
|
"-pix_fmt", "yuv420p",
|
||||||
|
]
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"Unsupported codec: {codec}")
|
raise ValueError(f"Unsupported codec: {codec}")
|
||||||
@ -57,8 +55,13 @@ def encode(input_file, codec, remove_source=False, save_log=False):
|
|||||||
"ffmpeg",
|
"ffmpeg",
|
||||||
"-i", input_file,
|
"-i", input_file,
|
||||||
"-map", "0",
|
"-map", "0",
|
||||||
|
"-cq", str(cq),
|
||||||
] + extra_params + [
|
] + extra_params + [
|
||||||
"-c:v", ffmpeg_codec,
|
"-c:v", ffmpeg_codec,
|
||||||
|
"-preset", "p4",
|
||||||
|
"-cq", str(cq),
|
||||||
|
"-rc", "vbr",
|
||||||
|
"-b:v", "0",
|
||||||
"-c:a", "copy",
|
"-c:a", "copy",
|
||||||
"-c:s", "copy",
|
"-c:s", "copy",
|
||||||
"-y", output_file
|
"-y", output_file
|
||||||
@ -124,7 +127,7 @@ def main():
|
|||||||
parser = argparse.ArgumentParser(description="Encode video(s) to x265 or AV1.")
|
parser = argparse.ArgumentParser(description="Encode video(s) to x265 or AV1.")
|
||||||
parser.add_argument("input", nargs="?", help="Path to input file")
|
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("-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("--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")
|
parser.add_argument("--save-log", action="store_true", help="Save ffmpeg logs to a .log file")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user