Add Linux/Windows support
This commit is contained in:
@@ -20,25 +20,29 @@ def _re_encode(
|
||||
:type input_aspect: str
|
||||
"""
|
||||
|
||||
fps = get_framerate(source_video)
|
||||
|
||||
vf_filter = f"fps={fps},scale=-1:min({MAX_INPUT_WIDTH}\\,ih)"
|
||||
|
||||
cmd = [
|
||||
"ffmpeg", "-v", "quiet", "-stats",
|
||||
"-i", source_video,
|
||||
"-c:v", "ffv1",
|
||||
"-level", "3",
|
||||
"-vf", f"fps={get_framerate(source_video)},scale=-1:\'min({MAX_INPUT_WIDTH},ih)\'",
|
||||
"-vf", vf_filter,
|
||||
"-aspect", input_aspect,
|
||||
"-pix_fmt", "yuv420p",
|
||||
"-color_primaries", "1",
|
||||
"-color_trc", "1",
|
||||
"-colorspace", "1",
|
||||
"-an",
|
||||
"-an",
|
||||
"-sn",
|
||||
"-map_metadata", "-1",
|
||||
temp_out_video
|
||||
]
|
||||
|
||||
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} at _re_encode()", file=sys.stderr)
|
||||
sys.exit(e.returncode)
|
||||
@@ -51,23 +55,42 @@ def _upscale(
|
||||
|
||||
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:
|
||||
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:
|
||||
print(f"\nffmpeg failed with error code {e.returncode}", file=sys.stderr)
|
||||
sys.exit(e.returncode)
|
||||
|
||||
Reference in New Issue
Block a user