Compare commits

3 Commits

Author SHA1 Message Date
630ac6dd2d Fix running out of vram on linux 2026-03-05 23:07:44 +01:00
8fd85322ca Escape "$" on linux for DASH encode 2026-03-05 23:05:58 +01:00
15e19fa056 CMD list handled differently when shell=True 2026-03-05 23:03:59 +01:00
4 changed files with 333 additions and 309 deletions

View File

@@ -24,9 +24,9 @@ def _encode_video(
print(f'Encoding {preset['h']}p AV1')
cmd = [
"ffmpeg",
"-i", preset['input_video'],
"-i", source_video,
"ffmpeg", "-v", "quiet", "-stats",
"-i", f'"{preset['input_video']}"',
"-i", f'"{source_video}"',
"-map", "0:v:0", # Video from upscale or interpolated file
"-map", "1:a:0", # Audio from source video
"-map", "1:s:0", # Subtitle from source video
@@ -38,15 +38,16 @@ def _encode_video(
"-crf", preset['crf'],
"-preset", "4",
"-pix_fmt", "yuv420p10le", # 10bit
"-vf", f"scale=\'min({preset['w']},iw)\':-2,setsar=1:1",
"-vf", f"\"scale=\'min({preset['w']},iw)\':-2,setsar=1:1\"",
"-aspect", input_aspect,
"-c:a", "libopus",
"-b:a", "160k",
"-c:s", "copy",
output_video
f'"{output_video}"'
]
print(cmd)
if sys.platform == 'linux':
cmd = ' '.join(cmd)
try:
subprocess.run(cmd, shell=True, check=True)

View File

@@ -52,8 +52,8 @@ def _encode_720p_fallback(
cmd = [
"ffmpeg", "-v", "quiet", "-stats",
"-i", upscale_output,
"-i", video_source,
"-i", f'"{upscale_output}"',
"-i", f'"{video_source}"',
"-map", "0:v:0",
"-map", "1:a:0",
"-c:v", "libx264",
@@ -65,9 +65,12 @@ def _encode_720p_fallback(
"-sn",
"-map_metadata", "-1",
"-movflags", "+faststart",
output
f'"{output}"'
]
if sys.platform == 'linux':
cmd = ' '.join(cmd)
try:
subprocess.run(cmd, shell=True, check=True)
except subprocess.CalledProcessError as e:
@@ -135,8 +138,8 @@ def _encode(
cmd = [
"ffmpeg", "-v", "quiet", "-stats",
"-i", preset['input_video'],
"-i", source_video,
"-i", f'"{preset['input_video']}"',
"-i", f'"{source_video}"',
"-map", "0:v:0", # Video from Upscale
"-map", "1:a:0", # Audio from Source
"-c:v", preset['encoder'],
@@ -154,20 +157,28 @@ def _encode(
cmd += ["-svtav1-params", f"keyint={keyframe_interval}s,fast-decode=1,tune=0"]
cmd += ["-c:a", "libopus", "-b:a", "128k"]
init_seg_name = "chunks/init-stream$RepresentationID$.webm"
media_seg_name = "chunks/chunk-stream$RepresentationID$-$Number%05d$.webm"
if sys.platform == 'linux':
init_seg_name = "chunks/init-stream\$RepresentationID\$.webm"
media_seg_name = "chunks/chunk-stream\$RepresentationID\$-\$Number%05d\$.webm"
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
"-init_seg_name", init_seg_name, # Init segment
"-media_seg_name", media_seg_name, # Media segments
"-seg_duration", str(segment_duration), # DASH segment duration
"-f", "dash",
os.path.join(cdn_folder, preset['out_folder'], 'manifest.mpd')
f'"{os.path.join(cdn_folder, preset['out_folder'], 'manifest.mpd')}"'
]
print(cmd)
if sys.platform == 'linux':
cmd = ' '.join(cmd)
try:
subprocess.run(cmd, shell=True, check=True)

View File

@@ -26,6 +26,9 @@ def _create_vsrife_script(
script = [
'import vapoursynth as vs',
'from vsrife import rife',
# this isn't a real fix, as this SHOULDN'T FIX IT
# however for some reason it does
'vs.core.max_cache_size=8192',
f'clip = vs.core.ffms2.Source(source="./{hentai_name} [4k][HEVC].mkv")',
f'clip = vs.core.resize.Bicubic(clip, width={video_width}, height=2160, format=vs.RGBS, matrix_in_s="709")',
'clip = rife(clip=clip, model="4.25.lite", factor_num=2, factor_den=1)',
@@ -43,15 +46,18 @@ def _interpolate(
cmd = [
"vspipe",
"-c", "y4m",
vapoursynth_file,
f'"{vapoursynth_file}"',
"-", "|",
"ffmpeg", "-v", "quiet", "-stats",
"-i", "-",
"-c:v", "hevc_nvenc",
"-qp", "5",
interpolate_output
f'"{interpolate_output}"'
]
if sys.platform == 'linux':
cmd = ' '.join(cmd)
try:
subprocess.run(cmd, shell=True, check=True)
except subprocess.CalledProcessError as e:

View File

@@ -22,10 +22,10 @@ def _re_encode(
cmd = [
"ffmpeg", "-v", "quiet", "-stats",
"-i", source_video,
"-i", f'"{source_video}"',
"-c:v", "ffv1",
"-level", "3",
"-vf", f"fps={get_framerate(source_video)},scale=-1:\'min({MAX_INPUT_WIDTH},ih)\'",
"-vf", f"\"fps={get_framerate(source_video)},scale=-1:\'min({MAX_INPUT_WIDTH},ih)\'\"",
"-aspect", input_aspect,
"-pix_fmt", "yuv420p",
"-color_primaries", "1",
@@ -34,9 +34,12 @@ def _re_encode(
"-an",
"-sn",
"-map_metadata", "-1",
temp_out_video
f'"{temp_out_video}"'
]
if sys.platform == 'linux':
cmd = ' '.join(cmd)
try:
subprocess.run(cmd, shell=True, check=True)
except subprocess.CalledProcessError as e:
@@ -54,7 +57,7 @@ def _upscale(
cmd = [
"vspipe",
"-c", "y4m",
vapoursynth_script,
f"\"{vapoursynth_script}\"",
"-", # Video output to pipe
"|", # Pipe
"ffmpeg", "-v", "quiet", "-stats",
@@ -63,9 +66,12 @@ def _upscale(
"-c:v", "hevc_nvenc",
"-qp", "5",
"-aspect", input_aspect,
upscale_output
f"\"{upscale_output}\""
]
if sys.platform == 'linux':
cmd = ' '.join(cmd)
try:
subprocess.run(cmd, shell=True, check=True)
except subprocess.CalledProcessError as e: