Fix Display Aspect Ratio by forcing resolution
This commit is contained in:
@@ -7,6 +7,12 @@ def get_aspect_ratio(video_input: str) -> str:
|
|||||||
print('Detected Aspect Ratio : ' + aspect_ratio[0])
|
print('Detected Aspect Ratio : ' + aspect_ratio[0])
|
||||||
return aspect_ratio[0]
|
return aspect_ratio[0]
|
||||||
|
|
||||||
|
def get_video_resolution(video_input: str) -> tuple[int, int]:
|
||||||
|
media_info = MediaInfo.parse(video_input)
|
||||||
|
video_track = media_info.video_tracks[0]
|
||||||
|
print('Detected Resolution : ' + str(video_track.width) + 'x' + str(video_track.height))
|
||||||
|
return (video_track.width, video_track.height)
|
||||||
|
|
||||||
def get_framerate(video_input: str) -> str:
|
def get_framerate(video_input: str) -> str:
|
||||||
media_info = MediaInfo.parse(video_input)
|
media_info = MediaInfo.parse(video_input)
|
||||||
video_track = media_info.video_tracks[0]
|
video_track = media_info.video_tracks[0]
|
||||||
|
|||||||
@@ -2,9 +2,8 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from utils.mediainfo import get_framerate
|
from utils.mediainfo import get_framerate, get_video_resolution
|
||||||
|
|
||||||
MAX_INPUT_WIDTH = '720'
|
|
||||||
|
|
||||||
def _re_encode(
|
def _re_encode(
|
||||||
source_video: str,
|
source_video: str,
|
||||||
@@ -21,8 +20,20 @@ def _re_encode(
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
fps = get_framerate(source_video)
|
fps = get_framerate(source_video)
|
||||||
|
resolution = get_video_resolution(source_video)
|
||||||
|
|
||||||
vf_filter = f"fps={fps},scale=-1:min({MAX_INPUT_WIDTH}\\,ih)"
|
scale = "720:480"
|
||||||
|
|
||||||
|
if input_aspect == "16:9" and resolution[1] == 480:
|
||||||
|
scale = "854:480"
|
||||||
|
elif input_aspect == "16:9" and resolution[1] == 540:
|
||||||
|
scale = "960:540"
|
||||||
|
elif input_aspect == "16:9" and resolution[1] >= 720:
|
||||||
|
scale = "1280:720"
|
||||||
|
|
||||||
|
print(f"Scaling at : {scale}")
|
||||||
|
|
||||||
|
vf_filter = f"fps={fps},scale={scale},setsar=1"
|
||||||
|
|
||||||
cmd = [
|
cmd = [
|
||||||
"ffmpeg", "-v", "quiet", "-stats",
|
"ffmpeg", "-v", "quiet", "-stats",
|
||||||
@@ -47,10 +58,7 @@ def _re_encode(
|
|||||||
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)
|
||||||
|
|
||||||
def _upscale(
|
def _upscale(upscale_output: str):
|
||||||
upscale_output: str,
|
|
||||||
input_aspect: str = "16:9"
|
|
||||||
):
|
|
||||||
print('Started Upscale')
|
print('Started Upscale')
|
||||||
|
|
||||||
vapoursynth_script = os.path.join('utils', 'vs-realesrgan.vpy')
|
vapoursynth_script = os.path.join('utils', 'vs-realesrgan.vpy')
|
||||||
@@ -76,7 +84,6 @@ def _upscale(
|
|||||||
"-i", "-",
|
"-i", "-",
|
||||||
"-c:v", "hevc_nvenc",
|
"-c:v", "hevc_nvenc",
|
||||||
"-qp", "5",
|
"-qp", "5",
|
||||||
"-aspect", input_aspect,
|
|
||||||
upscale_output
|
upscale_output
|
||||||
],
|
],
|
||||||
stdin=vspipe.stdout
|
stdin=vspipe.stdout
|
||||||
@@ -108,7 +115,7 @@ def upscale(
|
|||||||
temp_out_video = os.path.join('1-Temp', 'source.mkv')
|
temp_out_video = os.path.join('1-Temp', 'source.mkv')
|
||||||
|
|
||||||
_re_encode(source_video, temp_out_video, input_aspect)
|
_re_encode(source_video, temp_out_video, input_aspect)
|
||||||
_upscale(upscaled_video_output, input_aspect)
|
_upscale(upscaled_video_output)
|
||||||
|
|
||||||
# Remove Temp Files
|
# Remove Temp Files
|
||||||
os.remove(temp_out_video)
|
os.remove(temp_out_video)
|
||||||
|
|||||||
Reference in New Issue
Block a user