Add Linux/Windows support
This commit is contained in:
@@ -21,7 +21,7 @@ def _encode_video(
|
|||||||
hentai_title: str,
|
hentai_title: str,
|
||||||
input_aspect: str = "16:9"
|
input_aspect: str = "16:9"
|
||||||
):
|
):
|
||||||
print(f'Encoding {preset['h']}p AV1')
|
print(f"Encoding {preset['h']}p AV1")
|
||||||
|
|
||||||
cmd = [
|
cmd = [
|
||||||
"ffmpeg",
|
"ffmpeg",
|
||||||
@@ -33,12 +33,12 @@ def _encode_video(
|
|||||||
"-map", "1:t?", # Attachments from source video (optional)
|
"-map", "1:t?", # Attachments from source video (optional)
|
||||||
"-map", "1:d?", # Other Data from source video (optional)
|
"-map", "1:d?", # Other Data from source video (optional)
|
||||||
"-disposition:v:0", "default", # Mark video as default in mkv container
|
"-disposition:v:0", "default", # Mark video as default in mkv container
|
||||||
"-metadata", f'Title=\"{hentai_title} [hstream.moe]\"',
|
"-metadata", f"Title={hentai_title} [hstream.moe]",
|
||||||
"-c:v", "libsvtav1",
|
"-c:v", "libsvtav1",
|
||||||
"-crf", preset['crf'],
|
"-crf", preset['crf'],
|
||||||
"-preset", "4",
|
"-preset", "4",
|
||||||
"-pix_fmt", "yuv420p10le", # 10bit
|
"-pix_fmt", "yuv420p10le",
|
||||||
"-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,
|
"-aspect", input_aspect,
|
||||||
"-c:a", "libopus",
|
"-c:a", "libopus",
|
||||||
"-b:a", "160k",
|
"-b:a", "160k",
|
||||||
@@ -46,10 +46,8 @@ def _encode_video(
|
|||||||
output_video
|
output_video
|
||||||
]
|
]
|
||||||
|
|
||||||
print(cmd)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subprocess.run(cmd, shell=True, check=True)
|
subprocess.run(cmd, check=True)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
print(f"\nffmpeg failed with error code {e.returncode}", file=sys.stderr)
|
print(f"\nffmpeg failed with error code {e.returncode}", file=sys.stderr)
|
||||||
sys.exit(e.returncode)
|
sys.exit(e.returncode)
|
||||||
|
|||||||
@@ -69,12 +69,11 @@ def _encode_720p_fallback(
|
|||||||
]
|
]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subprocess.run(cmd, shell=True, check=True)
|
subprocess.run(cmd, check=True)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
print(f"\nffmpeg failed with error code {e.returncode}", file=sys.stderr)
|
print(f"\nffmpeg failed with error code {e.returncode}", file=sys.stderr)
|
||||||
sys.exit(e.returncode)
|
sys.exit(e.returncode)
|
||||||
|
|
||||||
|
|
||||||
def _change_chunk_extension(
|
def _change_chunk_extension(
|
||||||
preset: dict[str, str],
|
preset: dict[str, str],
|
||||||
cdn_folder: str,
|
cdn_folder: str,
|
||||||
@@ -141,36 +140,36 @@ def _encode(
|
|||||||
"-map", "1:a:0", # Audio from Source
|
"-map", "1:a:0", # Audio from Source
|
||||||
"-c:v", preset['encoder'],
|
"-c:v", preset['encoder'],
|
||||||
"-preset", preset['preset'],
|
"-preset", preset['preset'],
|
||||||
"-crf", preset['crf'],
|
"-crf", str(preset['crf']),
|
||||||
"-pix_fmt", "yuv420p", # 8bit to increase decode performance
|
"-pix_fmt", "yuv420p", # 8bit to increase decode performance
|
||||||
"-vf", f"scale={preset['w']}:{preset['h']},setsar=1:1",
|
"-vf", f"scale={preset['w']}:{preset['h']},setsar=1:1",
|
||||||
"-aspect", aspect_ratio,
|
"-aspect", aspect_ratio,
|
||||||
]
|
]
|
||||||
|
|
||||||
if preset["encoder"] == "libx264":
|
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"]
|
cmd += ["-c:a", "aac", "-b:a", "160k"]
|
||||||
elif preset["encoder"] == "libsvtav1":
|
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"]
|
cmd += ["-c:a", "aac", "-b:a", "160k"]
|
||||||
|
|
||||||
|
output_path = os.path.join(cdn_folder, preset['out_folder'], 'manifest.mpd')
|
||||||
|
|
||||||
cmd += [
|
cmd += [
|
||||||
"-ac", "2",
|
"-ac", "2",
|
||||||
"-sn", # No subtitles
|
"-sn", # No subtitles
|
||||||
"-map_metadata", "-1", # Get rid of metadata which might be incorrect
|
"-map_metadata", "-1", # Get rid of metadata which might be incorrect
|
||||||
"-use_template", "1", # Don't list every segment url, use template instead
|
"-use_template", "1", # Don't list every segment url, use template instead
|
||||||
"-use_timeline", "1", # Make sure segment timing is always correct
|
"-use_timeline", "1", # Make sure segment timing is always correct
|
||||||
"-init_seg_name", "chunks/init-stream$RepresentationID$.webm", # Init segment
|
"-init_seg_name", "chunks/init-stream$RepresentationID$.webm",
|
||||||
"-media_seg_name", "chunks/chunk-stream$RepresentationID$-$Number%05d$.webm", # Media segments
|
"-media_seg_name", "chunks/chunk-stream$RepresentationID$-$Number%05d$.webm",
|
||||||
"-seg_duration", str(segment_duration), # DASH segment duration
|
"-seg_duration", str(segment_duration),
|
||||||
"-f", "dash",
|
"-f", "dash",
|
||||||
os.path.join(cdn_folder, preset['out_folder'], 'manifest.mpd')
|
output_path
|
||||||
]
|
]
|
||||||
|
|
||||||
print(cmd)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subprocess.run(cmd, shell=True, check=True)
|
subprocess.run(cmd, check=True)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
print(f"\nffmpeg failed with error code {e.returncode}", file=sys.stderr)
|
print(f"\nffmpeg failed with error code {e.returncode}", file=sys.stderr)
|
||||||
sys.exit(e.returncode)
|
sys.exit(e.returncode)
|
||||||
|
|||||||
@@ -40,20 +40,43 @@ def _interpolate(
|
|||||||
vapoursynth_file: str,
|
vapoursynth_file: str,
|
||||||
interpolate_output: str,
|
interpolate_output: str,
|
||||||
):
|
):
|
||||||
cmd = [
|
print('Started Interpolation')
|
||||||
"vspipe",
|
|
||||||
"-c", "y4m",
|
|
||||||
vapoursynth_file,
|
|
||||||
"-", "|",
|
|
||||||
"ffmpeg", "-v", "quiet", "-stats",
|
|
||||||
"-i", "-",
|
|
||||||
"-c:v", "hevc_nvenc",
|
|
||||||
"-qp", "5",
|
|
||||||
interpolate_output
|
|
||||||
]
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subprocess.run(cmd, shell=True, check=True)
|
# First process (vspipe)
|
||||||
|
vspipe = subprocess.Popen(
|
||||||
|
[
|
||||||
|
"vspipe",
|
||||||
|
"-c", "y4m",
|
||||||
|
vapoursynth_file,
|
||||||
|
"-"
|
||||||
|
],
|
||||||
|
stdout=subprocess.PIPE
|
||||||
|
)
|
||||||
|
|
||||||
|
# Second process (ffmpeg), reading from vspipe
|
||||||
|
ffmpeg = subprocess.Popen(
|
||||||
|
[
|
||||||
|
"ffmpeg",
|
||||||
|
"-v", "quiet", "-stats",
|
||||||
|
"-f", "yuv4mpegpipe",
|
||||||
|
"-i", "-",
|
||||||
|
"-c:v", "hevc_nvenc",
|
||||||
|
"-qp", "5",
|
||||||
|
interpolate_output
|
||||||
|
],
|
||||||
|
stdin=vspipe.stdout
|
||||||
|
)
|
||||||
|
|
||||||
|
# Important: allow vspipe to receive SIGPIPE if ffmpeg exits
|
||||||
|
vspipe.stdout.close()
|
||||||
|
|
||||||
|
ffmpeg.wait()
|
||||||
|
vspipe.wait()
|
||||||
|
|
||||||
|
if ffmpeg.returncode != 0:
|
||||||
|
raise subprocess.CalledProcessError(ffmpeg.returncode, "ffmpeg")
|
||||||
|
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
print(f"\nffmpeg failed with error code {e.returncode}", file=sys.stderr)
|
print(f"\nffmpeg failed with error code {e.returncode}", file=sys.stderr)
|
||||||
sys.exit(e.returncode)
|
sys.exit(e.returncode)
|
||||||
|
|||||||
@@ -20,12 +20,16 @@ def _re_encode(
|
|||||||
:type input_aspect: str
|
:type input_aspect: str
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
fps = get_framerate(source_video)
|
||||||
|
|
||||||
|
vf_filter = f"fps={fps},scale=-1:min({MAX_INPUT_WIDTH}\\,ih)"
|
||||||
|
|
||||||
cmd = [
|
cmd = [
|
||||||
"ffmpeg", "-v", "quiet", "-stats",
|
"ffmpeg", "-v", "quiet", "-stats",
|
||||||
"-i", source_video,
|
"-i", source_video,
|
||||||
"-c:v", "ffv1",
|
"-c:v", "ffv1",
|
||||||
"-level", "3",
|
"-level", "3",
|
||||||
"-vf", f"fps={get_framerate(source_video)},scale=-1:\'min({MAX_INPUT_WIDTH},ih)\'",
|
"-vf", vf_filter,
|
||||||
"-aspect", input_aspect,
|
"-aspect", input_aspect,
|
||||||
"-pix_fmt", "yuv420p",
|
"-pix_fmt", "yuv420p",
|
||||||
"-color_primaries", "1",
|
"-color_primaries", "1",
|
||||||
@@ -38,7 +42,7 @@ def _re_encode(
|
|||||||
]
|
]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subprocess.run(cmd, shell=True, check=True)
|
subprocess.run(cmd, check=True)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
print(f"\nffmpeg failed with error code {e.returncode} at _re_encode()", file=sys.stderr)
|
print(f"\nffmpeg failed with error code {e.returncode} at _re_encode()", file=sys.stderr)
|
||||||
sys.exit(e.returncode)
|
sys.exit(e.returncode)
|
||||||
@@ -51,23 +55,42 @@ def _upscale(
|
|||||||
|
|
||||||
vapoursynth_script = os.path.join('utils', 'vs-realesrgan.vpy')
|
vapoursynth_script = os.path.join('utils', 'vs-realesrgan.vpy')
|
||||||
|
|
||||||
cmd = [
|
|
||||||
"vspipe",
|
|
||||||
"-c", "y4m",
|
|
||||||
vapoursynth_script,
|
|
||||||
"-", # Video output to pipe
|
|
||||||
"|", # Pipe
|
|
||||||
"ffmpeg", "-v", "quiet", "-stats",
|
|
||||||
"-f", "yuv4mpegpipe",
|
|
||||||
"-i", "-", # Pipe Video Input
|
|
||||||
"-c:v", "hevc_nvenc",
|
|
||||||
"-qp", "5",
|
|
||||||
"-aspect", input_aspect,
|
|
||||||
upscale_output
|
|
||||||
]
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subprocess.run(cmd, shell=True, check=True)
|
# First process (vspipe)
|
||||||
|
vspipe = subprocess.Popen(
|
||||||
|
[
|
||||||
|
"vspipe",
|
||||||
|
"-c", "y4m",
|
||||||
|
vapoursynth_script,
|
||||||
|
"-"
|
||||||
|
],
|
||||||
|
stdout=subprocess.PIPE
|
||||||
|
)
|
||||||
|
|
||||||
|
# Second process (ffmpeg), reading from vspipe
|
||||||
|
ffmpeg = subprocess.Popen(
|
||||||
|
[
|
||||||
|
"ffmpeg",
|
||||||
|
"-v", "quiet", "-stats",
|
||||||
|
"-f", "yuv4mpegpipe",
|
||||||
|
"-i", "-",
|
||||||
|
"-c:v", "hevc_nvenc",
|
||||||
|
"-qp", "5",
|
||||||
|
"-aspect", input_aspect,
|
||||||
|
upscale_output
|
||||||
|
],
|
||||||
|
stdin=vspipe.stdout
|
||||||
|
)
|
||||||
|
|
||||||
|
# Important: allow vspipe to receive SIGPIPE if ffmpeg exits
|
||||||
|
vspipe.stdout.close()
|
||||||
|
|
||||||
|
ffmpeg.wait()
|
||||||
|
vspipe.wait()
|
||||||
|
|
||||||
|
if ffmpeg.returncode != 0:
|
||||||
|
raise subprocess.CalledProcessError(ffmpeg.returncode, "ffmpeg")
|
||||||
|
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
print(f"\nffmpeg failed with error code {e.returncode}", file=sys.stderr)
|
print(f"\nffmpeg failed with error code {e.returncode}", file=sys.stderr)
|
||||||
sys.exit(e.returncode)
|
sys.exit(e.returncode)
|
||||||
|
|||||||
Reference in New Issue
Block a user