Compare commits

...

4 Commits

Author SHA1 Message Date
w33b c1d5b62c9b Fix Display Aspect Ratio by forcing resolution 2026-04-18 19:21:54 +02:00
w33b a8670adbd3 Slightly decrease quality of AV1 streams 2026-04-18 19:20:54 +02:00
w33b ce5aa5da24 Use x265 for downloads 2026-04-18 19:20:40 +02:00
w33b 3ad22d86b1 Add linux start script 2026-04-18 19:20:00 +02:00
5 changed files with 56 additions and 22 deletions
+21
View File
@@ -0,0 +1,21 @@
#!/bin/bash
SCRIPT_DIR="$(dirname "$(realpath "$0")")"
# Change the directory to where the script is
cd "$SCRIPT_DIR"
# Path to your virtual environment
VENV_PATH="$SCRIPT_DIR/.venv"
source "$VENV_PATH/bin/activate"
# Path to your Python script
SCRIPT_PATH="$SCRIPT_DIR/Start.py"
# Run the Python script
python "$SCRIPT_PATH"
# Deactivate the virtual environment
deactivate
read -p "Press Enter to exit..."
+9 -9
View File
@@ -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 x265")
cmd = [ cmd = [
"ffmpeg", "-v", "quiet", "-stats", "ffmpeg", "-v", "quiet", "-stats",
@@ -34,14 +34,14 @@ def _encode_video(
"-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", "libx265",
"-crf", preset['crf'], "-crf", preset['crf'],
"-preset", "4", "-preset", "slow",
"-pix_fmt", "yuv420p10le", "-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", "128k",
"-c:s", "copy", "-c:s", "copy",
output_video output_video
] ]
@@ -62,13 +62,13 @@ def encode_downloads(
input_aspect: str = "16:9" input_aspect: str = "16:9"
): ):
presets = [ presets = [
{"w": "1920", "h": "1080", "crf": "24", "name": "[1080p-AV1]", "input_video": upscaled_video}, {"w": "1920", "h": "1080", "crf": "22", "name": "[1080p-x265]", "input_video": upscaled_video},
{"w": "1920", "h": "1080", "crf": "24", "name": "[1080p-AV1][48fps]", "input_video": interpolated_video}, {"w": "1920", "h": "1080", "crf": "22", "name": "[1080p-x265][48fps]", "input_video": interpolated_video},
{"w": "3840", "h": "2160", "crf": "26", "name": "[2160p-AV1]", "input_video": upscaled_video}, {"w": "3840", "h": "2160", "crf": "24", "name": "[2160p-x265]", "input_video": upscaled_video},
] ]
if interpolated_uhd_video is not None: if interpolated_uhd_video is not None:
presets.append({"w": "3840", "h": "2160", "crf": "26", "name": "[2160p-AV1][48fps]", "input_video": interpolated_uhd_video}) presets.append({"w": "3840", "h": "2160", "crf": "24", "name": "[2160p-x265][48fps]", "input_video": interpolated_uhd_video})
for preset in presets: for preset in presets:
file_name = f"{hentai_title} {preset['name']}[hstream.moe].mkv" file_name = f"{hentai_title} {preset['name']}[hstream.moe].mkv"
@@ -76,7 +76,7 @@ def encode_downloads(
mux_out = os.path.join('2-Out', folder_name, 'Muxed', file_name) mux_out = os.path.join('2-Out', folder_name, 'Muxed', file_name)
if os.path.exists(mux_out): if os.path.exists(mux_out):
print(f'Skipped {preset['h']}p AV1 Encode') print(f'Skipped {preset['h']}p x265 Encode')
continue continue
_encode_video(preset, source_video, tmp_out, hentai_title, input_aspect) _encode_video(preset, source_video, tmp_out, hentai_title, input_aspect)
+4 -4
View File
@@ -184,14 +184,14 @@ def encode_streams(
): ):
presets = [ presets = [
{"name": "720p", "w": "1280", "h": "720", "encoder": "libx264", "preset": "medium", "crf": "22", "input_video": upscaled_video, "out_folder": '720'}, {"name": "720p", "w": "1280", "h": "720", "encoder": "libx264", "preset": "medium", "crf": "22", "input_video": upscaled_video, "out_folder": '720'},
{"name": "1080p", "w": "1920", "h": "1080", "encoder": "libsvtav1", "preset": "6", "crf": "26", "input_video": upscaled_video, "out_folder": '1080'}, {"name": "1080p", "w": "1920", "h": "1080", "encoder": "libsvtav1", "preset": "6", "crf": "28", "input_video": upscaled_video, "out_folder": '1080'},
{"name": "1080p48", "w": "1920", "h": "1080", "encoder": "libsvtav1", "preset": "6", "crf": "26", "input_video": interpolated_video, "out_folder": '1080i'}, {"name": "1080p48", "w": "1920", "h": "1080", "encoder": "libsvtav1", "preset": "6", "crf": "28", "input_video": interpolated_video, "out_folder": '1080i'},
{"name": "2160", "w": "3840", "h": "2160", "encoder": "libsvtav1", "preset": "6", "crf": "28", "input_video": upscaled_video, "out_folder": '2160'}, {"name": "2160", "w": "3840", "h": "2160", "encoder": "libsvtav1", "preset": "6", "crf": "32", "input_video": upscaled_video, "out_folder": '2160'},
] ]
# Optional UHD Interpolate encode # Optional UHD Interpolate encode
if interpolated_uhd_video is not None: if interpolated_uhd_video is not None:
presets.append({"name": "2160p48", "w": "3840", "h": "2160", "encoder": "libsvtav1", "preset": "6", "crf": "28", "input_video": interpolated_uhd_video, "out_folder": '2160i'}) presets.append({"name": "2160p48", "w": "3840", "h": "2160", "encoder": "libsvtav1", "preset": "6", "crf": "32", "input_video": interpolated_uhd_video, "out_folder": '2160i'})
for preset in presets: for preset in presets:
# Skip already encoded streams # Skip already encoded streams
+6
View File
@@ -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]
+16 -9
View File
@@ -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)
scale = "720:480"
vf_filter = f"fps={fps},scale=-1:min({MAX_INPUT_WIDTH}\\,ih)" 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)