diff --git a/app/upscaler.py b/app/upscaler.py index 04a951a..a5d98e4 100644 --- a/app/upscaler.py +++ b/app/upscaler.py @@ -7,6 +7,19 @@ import time import threading from typing import Dict, Any, Callable +_ffmpeg_filters_cache = {} +def has_ffmpeg_filter(filter_name: str) -> bool: + global _ffmpeg_filters_cache + if filter_name in _ffmpeg_filters_cache: + return _ffmpeg_filters_cache[filter_name] + try: + p = subprocess.Popen(["ffmpeg", "-filters"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + stdout, _ = p.communicate(timeout=5) + _ffmpeg_filters_cache[filter_name] = filter_name in stdout + except Exception: + _ffmpeg_filters_cache[filter_name] = False + return _ffmpeg_filters_cache[filter_name] + # Paths config BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BIN_PATH = os.path.join(BASE_DIR, "realesrgan-bin", "realesrgan-ncnn-vulkan") @@ -623,13 +636,15 @@ def run_upscale_pipeline(job: UpscaleJob, on_progress_update: Callable[[str, Dic if job.preserve_audio: assemble_cmd.extend(["-map", "1:a:0?"]) - if getattr(job, "ai_audio_denoise", False): + if getattr(job, "ai_audio_denoise", False) and has_ffmpeg_filter("arnnoise"): acodec_denoise = "libvorbis" if transcode_fmt == "webm" else "aac" assemble_cmd.extend([ "-af", "arnnoise", "-c:a", acodec_denoise ]) else: + if getattr(job, "ai_audio_denoise", False): + print(f"Warning: ai_audio_denoise was requested but 'arnnoise' filter is not available in ffmpeg. Copying audio without denoise.") assemble_cmd.extend(["-c:a", acodec]) if getattr(job, "preserve_subtitles", True):