39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
import os
|
|
import subprocess
|
|
|
|
from utils.mediainfo import get_framerate
|
|
|
|
def re_encode(input_file, upscale_out, temp_out, max_width, input_aspect):
|
|
if os.path.exists(upscale_out):
|
|
print('Skipped Pre-Encode')
|
|
return
|
|
|
|
command = (
|
|
f'ffmpeg -v quiet -stats -i "{input_file}" '
|
|
'-c:v ffv1 -level 3 '
|
|
f'-vf "fps={get_framerate(input_file)},scale=-1:\'min({max_width},ih)\'" -aspect {input_aspect} '
|
|
'-pix_fmt yuv420p -color_primaries 1 -color_trc 1 -colorspace 1 '
|
|
'-an -sn -map_metadata -1 '
|
|
f'"{temp_out}"'
|
|
)
|
|
|
|
subprocess.call(command, shell=True)
|
|
|
|
def upscale(input_file, upscale_out, max_width, input_aspect):
|
|
temp_out = os.path.join('1-Temp', 'source.mkv')
|
|
vsgan = os.path.join('utils', 'vs-realesrgan.vpy')
|
|
|
|
# Re-Encode to fix issues
|
|
re_encode(input_file, upscale_out, temp_out, max_width, input_aspect)
|
|
|
|
if os.path.exists(upscale_out):
|
|
print('Skipped Upscale')
|
|
return
|
|
|
|
print('Started Upscale')
|
|
subprocess.call(f'vspipe -c y4m {vsgan} - | ffmpeg -v quiet -stats -f yuv4mpegpipe -i - -c:v hevc_nvenc -qp 5 -aspect {input_aspect} "{upscale_out}"', shell=True)
|
|
|
|
# Remove Temp Files
|
|
os.remove(temp_out)
|
|
os.remove(temp_out + '.ffindex')
|