This commit is contained in:
2025-10-01 16:06:53 +02:00
commit 93c6b1c261
12 changed files with 874 additions and 0 deletions

52
utils/encodeDDL.py Normal file
View File

@@ -0,0 +1,52 @@
import os
import subprocess
def extract_subs(video_source, subtitle_out, vtt_out):
if os.path.exists(subtitle_out):
print('Skipped Sub Extract')
return
print('Extracting Sub')
subprocess.call(f'ffmpeg -v quiet -stats -i "{video_source}" -c copy "{subtitle_out}"', shell=True)
subprocess.call(f'ffmpeg -v quiet -stats -i "{subtitle_out}" "{vtt_out}"', shell=True)
def encode_video(video_source, input_file, output_file, mux_file, temp_name, input_aspect, width, height):
if os.path.exists(output_file):
print(f'Skipped {height}p HEVC Encode')
return
print(f'Encoding {height}p HEVC')
command = (f'ffmpeg -v quiet -stats -i "{input_file}" -i "{video_source}"'
' -map 0:v:0 -map 1:a:0 -map 1:s:0 -map 1:t? -map 1:d?'
f' -disposition:v:0 default -metadata Title="{temp_name} [hstream.moe]"'
' -metadata:s:v:0 title="Upscaled by hstream.moe"'
' -c:v hevc_nvenc -qp 18 -pix_fmt yuv420p10le'
f' -vf "scale=\'min({width},iw)\':-2,setsar=1:1" -aspect {input_aspect}'
' -c:a aac -b:a 160k -c:s copy'
f' "{output_file}"'
)
subprocess.call(command, shell=True)
subprocess.run(f'mkvmerge --output "{mux_file}" "{output_file}"', shell=True)
def EncodeDDL(video_source, cdn_folder, folder_name, temp_name, upscale_out, input_aspect, interpolate_out, INTERPOLATE_4K, interpolate_4k_output):
# Extract subtitles
out_ass = os.path.join(cdn_folder, 'eng.ass')
out_vtt = os.path.join(cdn_folder, 'eng.vtt')
extract_subs(video_source, out_ass, out_vtt)
# Encoding settings
resolutions = [
(1920, 1080, upscale_out, "[1080p-HEVC]"),
(1920, 1080, interpolate_out, "[1080p-HEVC][48fps]"),
(3840, 2160, upscale_out, "[2160p-HEVC]")
]
# Also encode 4k 48fps if enabled
if INTERPOLATE_4K:
resolutions.append((3840, 2160, interpolate_4k_output, "[2160p-HEVC][48fps]"))
for width, height, input_file, suffix in resolutions:
tmp_out = os.path.join('2-Out', folder_name, f"{temp_name} {suffix}[hstream.moe].mkv")
mux_out = os.path.join('2-Out', folder_name, 'Muxed', f"{temp_name} {suffix}[hstream.moe].mkv")
encode_video(video_source, input_file, tmp_out, mux_out, temp_name, input_aspect, width, height)