Add Linux/Windows support

This commit is contained in:
2026-03-19 18:16:12 +01:00
parent 479ac49796
commit 14bb4ac95f
4 changed files with 95 additions and 52 deletions

View File

@@ -69,12 +69,11 @@ def _encode_720p_fallback(
]
try:
subprocess.run(cmd, shell=True, check=True)
subprocess.run(cmd, check=True)
except subprocess.CalledProcessError as e:
print(f"\nffmpeg failed with error code {e.returncode}", file=sys.stderr)
sys.exit(e.returncode)
def _change_chunk_extension(
preset: dict[str, str],
cdn_folder: str,
@@ -141,36 +140,36 @@ def _encode(
"-map", "1:a:0", # Audio from Source
"-c:v", preset['encoder'],
"-preset", preset['preset'],
"-crf", preset['crf'],
"-crf", str(preset['crf']),
"-pix_fmt", "yuv420p", # 8bit to increase decode performance
"-vf", f"scale={preset['w']}:{preset['h']},setsar=1:1",
"-aspect", aspect_ratio,
]
if preset["encoder"] == "libx264":
cmd += ["-x264-params", f"keyint=24:min-keyint=24:scenecut=0"]
cmd += ["-x264-params", "keyint=24:min-keyint=24:scenecut=0"]
cmd += ["-c:a", "aac", "-b:a", "160k"]
elif preset["encoder"] == "libsvtav1":
cmd += ["-svtav1-params", f"keyint={keyframe_interval}s,fast-decode=1,tune=0"]
cmd += ["-svtav1-params", f"keyint={keyframe_interval}s:fast-decode=1:tune=0"]
cmd += ["-c:a", "aac", "-b:a", "160k"]
output_path = os.path.join(cdn_folder, preset['out_folder'], 'manifest.mpd')
cmd += [
"-ac", "2",
"-sn", # No subtitles
"-map_metadata", "-1", # Get rid of metadata which might be incorrect
"-use_template", "1", # Don't list every segment url, use template instead
"-use_timeline", "1", # Make sure segment timing is always correct
"-init_seg_name", "chunks/init-stream$RepresentationID$.webm", # Init segment
"-media_seg_name", "chunks/chunk-stream$RepresentationID$-$Number%05d$.webm", # Media segments
"-seg_duration", str(segment_duration), # DASH segment duration
"-f", "dash",
os.path.join(cdn_folder, preset['out_folder'], 'manifest.mpd')
"-init_seg_name", "chunks/init-stream$RepresentationID$.webm",
"-media_seg_name", "chunks/chunk-stream$RepresentationID$-$Number%05d$.webm",
"-seg_duration", str(segment_duration),
"-f", "dash",
output_path
]
print(cmd)
try:
subprocess.run(cmd, shell=True, check=True)
subprocess.run(cmd, check=True)
except subprocess.CalledProcessError as e:
print(f"\nffmpeg failed with error code {e.returncode}", file=sys.stderr)
sys.exit(e.returncode)