added a new param for filtering the output

This commit is contained in:
2025-08-11 12:38:19 +02:00
parent 3223aa1c9e
commit deced80524

View File

@@ -33,6 +33,10 @@ SVT_AV1_PARAMS = {
"progress": 2, # Detailed progress output
}
DENOISE_PARAMS = {
"badsad": 300
}
def check_tools():
for tool in REQUIRED_TOOLS:
if shutil.which(tool) is None:
@@ -94,7 +98,7 @@ def convert_audio_track(index, ch, lang, audio_temp_dir, source_file, should_dow
])
return final_opus
def convert_video(source_file_base, source_file_full, is_vfr, target_cfr_fps_for_handbrake, autocrop_filter=None):
def convert_video(source_file_base, source_file_full, is_vfr, target_cfr_fps_for_handbrake, autocrop_filter=None, badsad=300):
print(" --- Starting Video Processing ---")
ut_video_file = Path(f"{source_file_base}.ut.mkv")
vpy_file = Path(f"{source_file_base}.vpy") # Path for the VapourSynth script
@@ -158,16 +162,16 @@ import os
core = vs.core
core.num_threads = max(1, os.cpu_count() // 2)
clip = core.lsmas.LWLibavSource(source=r'''{ut_video_full_path}''')
clip = core.lsmas.LWLibavSource(source=r'{ut_video_full_path}')
# --- MCTemporalDenoise 'high' setting equivalent using raw MVTools ---
clip_16bit = core.resize.Point(clip, format=vs.YUV420P16, matrix_in_s="709")
super_clip = core.mv.Super(clip_16bit, pel=2, sharp=1)
# CORRECTED: Use 'badsad' for the Sum of Absolute Differences threshold
vectors_backward = core.mv.Analyse(super_clip, isb=True, delta=1, badsad=250, blksize=16)
vectors_forward = core.mv.Analyse(super_clip, isb=False, delta=1, badsad=250, blksize=16)
vectors_backward2 = core.mv.Analyse(super_clip, isb=True, delta=2, badsad=250, blksize=16)
vectors_forward2 = core.mv.Analyse(super_clip, isb=False, delta=2, badsad=250, blksize=16)
vectors_backward = core.mv.Analyse(super_clip, isb=True, delta=1, badsad={badsad}, blksize=16)
vectors_forward = core.mv.Analyse(super_clip, isb=False, delta=1, badsad={badsad}, blksize=16)
vectors_backward2 = core.mv.Analyse(super_clip, isb=True, delta=2, badsad={badsad}, blksize=16)
vectors_forward2 = core.mv.Analyse(super_clip, isb=False, delta=2, badsad={badsad}, blksize=16)
denoised_clip = core.mv.Degrain2(clip_16bit, super_clip, vectors_backward, vectors_forward, vectors_backward2, vectors_forward2)
final_clip = core.resize.Point(denoised_clip, format=vs.YUV420P10)
# --- End of Denoising ---
@@ -237,7 +241,7 @@ final_clip.set_output()
raise RuntimeError(f"SvtAv1EncApp failed with exit code {svt_proc.returncode}")
print(" --- Finished Video Processing ---")
return encoded_video_file, handbrake_cfr_intermediate_file, None
return encoded_video_file, handbrake_cfr_intermediate_for_cleanup, None
def is_ffmpeg_decodable(file_path):
try:
@@ -476,7 +480,7 @@ def detect_autocrop_filter(input_file, significant_crop_threshold=5.0, min_crop=
return _analyze_video_cropdetect(input_file, duration, width, height, max(1, os.cpu_count() // 2), significant_crop_threshold, min_crop, debug)
# --- Main Processing Loop (denoise flag removed) ---
def main(no_downmix=False, autocrop=False, speed=None, quality=None, grain=None):
def main(no_downmix=False, autocrop=False, speed=None, quality=None, grain=None, badsad=None):
check_tools()
if speed is not None:
SVT_AV1_PARAMS['speed'] = speed
@@ -484,6 +488,8 @@ def main(no_downmix=False, autocrop=False, speed=None, quality=None, grain=None)
SVT_AV1_PARAMS['quality'] = quality
if grain is not None:
SVT_AV1_PARAMS['film-grain'] = grain
if badsad is not None:
DENOISE_PARAMS['badsad'] = badsad
current_dir = Path(".")
files_to_process = sorted(
@@ -594,7 +600,7 @@ def main(no_downmix=False, autocrop=False, speed=None, quality=None, grain=None)
print(" - No crop needed or detected.")
encoded_video_file, handbrake_intermediate_for_cleanup, _ = convert_video(
file_path.stem, str(input_file_abs), is_vfr, target_cfr_fps_for_handbrake, autocrop_filter=autocrop_filter
file_path.stem, str(input_file_abs), is_vfr, target_cfr_fps_for_handbrake, autocrop_filter=autocrop_filter, badsad=DENOISE_PARAMS['badsad']
)
print("--- Starting Audio Processing ---")
@@ -721,5 +727,6 @@ if __name__ == "__main__":
parser.add_argument("--speed", type=str, help="Set SvtAv1EncApp speed preset (e.g., 'slower', 'slow', 'medium').")
parser.add_argument("--quality", type=str, help="Set SvtAv1EncApp quality preset (e.g., 'low', 'medium', 'high').")
parser.add_argument("--grain", type=int, help="Set SvtAv1EncApp film-grain value.")
parser.add_argument("--badsad", type=int, help="Set MVTools badsad value for denoising.")
args = parser.parse_args()
main(no_downmix=args.no_downmix, autocrop=args.autocrop, speed=args.speed, quality=args.quality, grain=args.grain)
main(no_downmix=args.no_downmix, autocrop=args.autocrop, speed=args.speed, quality=args.quality, grain=args.grain, badsad=args.badsad)