CMD list handled differently when shell=True
This commit is contained in:
@@ -24,9 +24,9 @@ def _encode_video(
|
|||||||
print(f'Encoding {preset['h']}p AV1')
|
print(f'Encoding {preset['h']}p AV1')
|
||||||
|
|
||||||
cmd = [
|
cmd = [
|
||||||
"ffmpeg",
|
"ffmpeg", "-v", "quiet", "-stats",
|
||||||
"-i", preset['input_video'],
|
"-i", f'"{preset['input_video']}"',
|
||||||
"-i", source_video,
|
"-i", f'"{source_video}"',
|
||||||
"-map", "0:v:0", # Video from upscale or interpolated file
|
"-map", "0:v:0", # Video from upscale or interpolated file
|
||||||
"-map", "1:a:0", # Audio from source video
|
"-map", "1:a:0", # Audio from source video
|
||||||
"-map", "1:s:0", # Subtitle from source video
|
"-map", "1:s:0", # Subtitle from source video
|
||||||
@@ -38,15 +38,16 @@ def _encode_video(
|
|||||||
"-crf", preset['crf'],
|
"-crf", preset['crf'],
|
||||||
"-preset", "4",
|
"-preset", "4",
|
||||||
"-pix_fmt", "yuv420p10le", # 10bit
|
"-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,
|
"-aspect", input_aspect,
|
||||||
"-c:a", "libopus",
|
"-c:a", "libopus",
|
||||||
"-b:a", "160k",
|
"-b:a", "160k",
|
||||||
"-c:s", "copy",
|
"-c:s", "copy",
|
||||||
output_video
|
f'"{output_video}"'
|
||||||
]
|
]
|
||||||
|
|
||||||
print(cmd)
|
if sys.platform == 'linux':
|
||||||
|
cmd = ' '.join(cmd)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subprocess.run(cmd, shell=True, check=True)
|
subprocess.run(cmd, shell=True, check=True)
|
||||||
|
|||||||
@@ -52,8 +52,8 @@ def _encode_720p_fallback(
|
|||||||
|
|
||||||
cmd = [
|
cmd = [
|
||||||
"ffmpeg", "-v", "quiet", "-stats",
|
"ffmpeg", "-v", "quiet", "-stats",
|
||||||
"-i", upscale_output,
|
"-i", f'"{upscale_output}"',
|
||||||
"-i", video_source,
|
"-i", f'"{video_source}"',
|
||||||
"-map", "0:v:0",
|
"-map", "0:v:0",
|
||||||
"-map", "1:a:0",
|
"-map", "1:a:0",
|
||||||
"-c:v", "libx264",
|
"-c:v", "libx264",
|
||||||
@@ -65,9 +65,12 @@ def _encode_720p_fallback(
|
|||||||
"-sn",
|
"-sn",
|
||||||
"-map_metadata", "-1",
|
"-map_metadata", "-1",
|
||||||
"-movflags", "+faststart",
|
"-movflags", "+faststart",
|
||||||
output
|
f'"{output}"'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if sys.platform == 'linux':
|
||||||
|
cmd = ' '.join(cmd)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subprocess.run(cmd, shell=True, check=True)
|
subprocess.run(cmd, shell=True, check=True)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
@@ -135,8 +138,8 @@ def _encode(
|
|||||||
|
|
||||||
cmd = [
|
cmd = [
|
||||||
"ffmpeg", "-v", "quiet", "-stats",
|
"ffmpeg", "-v", "quiet", "-stats",
|
||||||
"-i", preset['input_video'],
|
"-i", f'"{preset['input_video']}"',
|
||||||
"-i", source_video,
|
"-i", f'"{source_video}"',
|
||||||
"-map", "0:v:0", # Video from Upscale
|
"-map", "0:v:0", # Video from Upscale
|
||||||
"-map", "1:a:0", # Audio from Source
|
"-map", "1:a:0", # Audio from Source
|
||||||
"-c:v", preset['encoder'],
|
"-c:v", preset['encoder'],
|
||||||
@@ -164,10 +167,11 @@ def _encode(
|
|||||||
"-media_seg_name", "chunks/chunk-stream$RepresentationID$-$Number%05d$.webm", # Media segments
|
"-media_seg_name", "chunks/chunk-stream$RepresentationID$-$Number%05d$.webm", # Media segments
|
||||||
"-seg_duration", str(segment_duration), # DASH segment duration
|
"-seg_duration", str(segment_duration), # DASH segment duration
|
||||||
"-f", "dash",
|
"-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:
|
try:
|
||||||
subprocess.run(cmd, shell=True, check=True)
|
subprocess.run(cmd, shell=True, check=True)
|
||||||
|
|||||||
@@ -43,15 +43,18 @@ def _interpolate(
|
|||||||
cmd = [
|
cmd = [
|
||||||
"vspipe",
|
"vspipe",
|
||||||
"-c", "y4m",
|
"-c", "y4m",
|
||||||
vapoursynth_file,
|
f'"{vapoursynth_file}"',
|
||||||
"-", "|",
|
"-", "|",
|
||||||
"ffmpeg", "-v", "quiet", "-stats",
|
"ffmpeg", "-v", "quiet", "-stats",
|
||||||
"-i", "-",
|
"-i", "-",
|
||||||
"-c:v", "hevc_nvenc",
|
"-c:v", "hevc_nvenc",
|
||||||
"-qp", "5",
|
"-qp", "5",
|
||||||
interpolate_output
|
f'"{interpolate_output}"'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if sys.platform == 'linux':
|
||||||
|
cmd = ' '.join(cmd)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subprocess.run(cmd, shell=True, check=True)
|
subprocess.run(cmd, shell=True, check=True)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
|
|||||||
190
utils/upcale.py
190
utils/upcale.py
@@ -1,92 +1,98 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from utils.mediainfo import get_framerate
|
from utils.mediainfo import get_framerate
|
||||||
|
|
||||||
MAX_INPUT_WIDTH = '720'
|
MAX_INPUT_WIDTH = '720'
|
||||||
|
|
||||||
def _re_encode(
|
def _re_encode(
|
||||||
source_video: str,
|
source_video: str,
|
||||||
temp_out_video: str,
|
temp_out_video: str,
|
||||||
input_aspect: str = "16:9"
|
input_aspect: str = "16:9"
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Re-Encodes the source video to avoid nasty video bugs
|
Re-Encodes the source video to avoid nasty video bugs
|
||||||
|
|
||||||
:param source_video: Video Input
|
:param source_video: Video Input
|
||||||
:type source_video: str
|
:type source_video: str
|
||||||
:param input_aspect: Aspect Ratio of Video
|
:param input_aspect: Aspect Ratio of Video
|
||||||
:type input_aspect: str
|
:type input_aspect: str
|
||||||
"""
|
"""
|
||||||
|
|
||||||
cmd = [
|
cmd = [
|
||||||
"ffmpeg", "-v", "quiet", "-stats",
|
"ffmpeg", "-v", "quiet", "-stats",
|
||||||
"-i", source_video,
|
"-i", f'"{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", f"\"fps={get_framerate(source_video)},scale=-1:\'min({MAX_INPUT_WIDTH},ih)\'\"",
|
||||||
"-aspect", input_aspect,
|
"-aspect", input_aspect,
|
||||||
"-pix_fmt", "yuv420p",
|
"-pix_fmt", "yuv420p",
|
||||||
"-color_primaries", "1",
|
"-color_primaries", "1",
|
||||||
"-color_trc", "1",
|
"-color_trc", "1",
|
||||||
"-colorspace", "1",
|
"-colorspace", "1",
|
||||||
"-an",
|
"-an",
|
||||||
"-sn",
|
"-sn",
|
||||||
"-map_metadata", "-1",
|
"-map_metadata", "-1",
|
||||||
temp_out_video
|
f'"{temp_out_video}"'
|
||||||
]
|
]
|
||||||
|
|
||||||
try:
|
if sys.platform == 'linux':
|
||||||
subprocess.run(cmd, shell=True, check=True)
|
cmd = ' '.join(cmd)
|
||||||
except subprocess.CalledProcessError as e:
|
|
||||||
print(f"\nffmpeg failed with error code {e.returncode} at _re_encode()", file=sys.stderr)
|
try:
|
||||||
sys.exit(e.returncode)
|
subprocess.run(cmd, shell=True, check=True)
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
def _upscale(
|
print(f"\nffmpeg failed with error code {e.returncode} at _re_encode()", file=sys.stderr)
|
||||||
upscale_output: str,
|
sys.exit(e.returncode)
|
||||||
input_aspect: str = "16:9"
|
|
||||||
):
|
def _upscale(
|
||||||
print('Started Upscale')
|
upscale_output: str,
|
||||||
|
input_aspect: str = "16:9"
|
||||||
vapoursynth_script = os.path.join('utils', 'vs-realesrgan.vpy')
|
):
|
||||||
|
print('Started Upscale')
|
||||||
cmd = [
|
|
||||||
"vspipe",
|
vapoursynth_script = os.path.join('utils', 'vs-realesrgan.vpy')
|
||||||
"-c", "y4m",
|
|
||||||
vapoursynth_script,
|
cmd = [
|
||||||
"-", # Video output to pipe
|
"vspipe",
|
||||||
"|", # Pipe
|
"-c", "y4m",
|
||||||
"ffmpeg", "-v", "quiet", "-stats",
|
f"\"{vapoursynth_script}\"",
|
||||||
"-f", "yuv4mpegpipe",
|
"-", # Video output to pipe
|
||||||
"-i", "-", # Pipe Video Input
|
"|", # Pipe
|
||||||
"-c:v", "hevc_nvenc",
|
"ffmpeg", "-v", "quiet", "-stats",
|
||||||
"-qp", "5",
|
"-f", "yuv4mpegpipe",
|
||||||
"-aspect", input_aspect,
|
"-i", "-", # Pipe Video Input
|
||||||
upscale_output
|
"-c:v", "hevc_nvenc",
|
||||||
]
|
"-qp", "5",
|
||||||
|
"-aspect", input_aspect,
|
||||||
try:
|
f"\"{upscale_output}\""
|
||||||
subprocess.run(cmd, shell=True, check=True)
|
]
|
||||||
except subprocess.CalledProcessError as e:
|
|
||||||
print(f"\nffmpeg failed with error code {e.returncode}", file=sys.stderr)
|
if sys.platform == 'linux':
|
||||||
sys.exit(e.returncode)
|
cmd = ' '.join(cmd)
|
||||||
|
|
||||||
|
try:
|
||||||
def upscale(
|
subprocess.run(cmd, shell=True, check=True)
|
||||||
source_video: str,
|
except subprocess.CalledProcessError as e:
|
||||||
upscaled_video_output: str,
|
print(f"\nffmpeg failed with error code {e.returncode}", file=sys.stderr)
|
||||||
input_aspect: str,
|
sys.exit(e.returncode)
|
||||||
):
|
|
||||||
if os.path.exists(upscaled_video_output):
|
|
||||||
print('Skipped Upscale')
|
def upscale(
|
||||||
return
|
source_video: str,
|
||||||
|
upscaled_video_output: str,
|
||||||
temp_out_video = os.path.join('1-Temp', 'source.mkv')
|
input_aspect: str,
|
||||||
|
):
|
||||||
_re_encode(source_video, temp_out_video, input_aspect)
|
if os.path.exists(upscaled_video_output):
|
||||||
_upscale(upscaled_video_output, input_aspect)
|
print('Skipped Upscale')
|
||||||
|
return
|
||||||
# Remove Temp Files
|
|
||||||
os.remove(temp_out_video)
|
temp_out_video = os.path.join('1-Temp', 'source.mkv')
|
||||||
os.remove(f'{temp_out_video}.ffindex')
|
|
||||||
|
_re_encode(source_video, temp_out_video, input_aspect)
|
||||||
|
_upscale(upscaled_video_output, input_aspect)
|
||||||
|
|
||||||
|
# Remove Temp Files
|
||||||
|
os.remove(temp_out_video)
|
||||||
|
os.remove(f'{temp_out_video}.ffindex')
|
||||||
|
|||||||
Reference in New Issue
Block a user