replacement of Filter

This commit is contained in:
2025-08-11 15:13:35 +02:00
parent 8d5b8894e6
commit 72509ce38b

View File

@@ -34,7 +34,7 @@ SVT_AV1_PARAMS = {
}
DENOISE_PARAMS = {
"badsad": 300
"sigma": 3
}
def check_tools():
@@ -98,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, badsad=300):
def convert_video(source_file_base, source_file_full, is_vfr, target_cfr_fps_for_handbrake, autocrop_filter=None, sigma=3):
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
@@ -154,7 +154,7 @@ def convert_video(source_file_base, source_file_full, is_vfr, target_cfr_fps_for
ut_video_full_path = os.path.abspath(ut_video_file)
# --- VapourSynth Script Creation ---
print(" - Creating VapourSynth script with built-in MVTools denoising...")
print(" - Creating VapourSynth script with BM3D denoising...")
vpy_script_content = f"""
import vapoursynth as vs
import os
@@ -164,16 +164,9 @@ core.num_threads = max(1, os.cpu_count() // 2)
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={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)
# --- BM3D Denoising ---
denoised = core.bm3d.Basic(clip, sigma=[{sigma}, 0])
final_clip = denoised
# --- End of Denoising ---
final_clip.set_output()
@@ -480,7 +473,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, badsad=None):
def main(no_downmix=False, autocrop=False, speed=None, quality=None, grain=None, sigma=None):
check_tools()
if speed is not None:
SVT_AV1_PARAMS['speed'] = speed
@@ -488,8 +481,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
if sigma is not None:
DENOISE_PARAMS['sigma'] = sigma
current_dir = Path(".")
files_to_process = sorted(
@@ -600,7 +593,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, badsad=DENOISE_PARAMS['badsad']
file_path.stem, str(input_file_abs), is_vfr, target_cfr_fps_for_handbrake, autocrop_filter=autocrop_filter, sigma=DENOISE_PARAMS['sigma']
)
print("--- Starting Audio Processing ---")
@@ -727,6 +720,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.")
parser.add_argument("--sigma", type=int, help="Set BM3D sigma 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, badsad=args.badsad)
main(no_downmix=args.no_downmix, autocrop=args.autocrop, speed=args.speed, quality=args.quality, grain=args.grain, sigma=args.sigma)