1
import subprocess
from pathlib import Path
input_folders = [
Path(r"E:\Staging1"),
Path(r"E:\Staging2"),
Path(r"J:\Staging3")
]
output_folder = Path(r"Y:\Encodes")
ffmpeg_path = Path(r"C:\Programs\FFMPEG\bin\ffmpeg.exe")
output_folder.mkdir(parents=True, exist_ok=True)
x265_params = "preset=slow:limit-sao:bframes=8:psy-rd=1.5:psy-rdoq=2:aq-mode=3"
crf_value = 19
for current_input_folder in input_folders:
print(f"\n[Processing Folder] {current_input_folder}\n")
for input_file in current_input_folder.glob("*.mkv"):
filename = input_file.stem
output_file = output_folder / f"{filename}.mkv"
if output_file.exists():
print(f"[Skip] {filename} already encoded. Skipping.\n")
continue
print(f"[Start] {filename}")
cmd = [
str(ffmpeg_path),
"-hide_banner",
"-loglevel", "fatal",
"-stats",
"-i", str(input_file),
"-vf", "scale=w=-1:h=720:flags=lanczos+accurate_rnd",
"-map", "0:v:0",
"-c:v", "libx265",
"-crf", str(crf_value),
"-pix_fmt", "yuv420p10le",
"-x265-params", x265_params,
"-profile:v", "main10",
"-map", "0:a",
"-c:a", "libopus",
"-b:a", "160k",
"-ar", "48000",
"-map", "0:s?",
"-c:s", "copy",
"-y", str(output_file)
]
try:
subprocess.run(cmd, check=True)
print(f"[Finish] {filename}")
print(f"Output: {output_file}\n")
except subprocess.CalledProcessError as e:
print(f"[Error] Failed to encode: {input_file}")
print(f"Reason: {e}\n")
print("All encodes complete!")
For immediate assistance, please email our customer support: [email protected]