Safely fallback if FFmpeg does not support the arnnoise audio filter
This commit is contained in:
+16
-1
@@ -7,6 +7,19 @@ import time
|
|||||||
import threading
|
import threading
|
||||||
from typing import Dict, Any, Callable
|
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
|
# Paths config
|
||||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
BIN_PATH = os.path.join(BASE_DIR, "realesrgan-bin", "realesrgan-ncnn-vulkan")
|
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:
|
if job.preserve_audio:
|
||||||
assemble_cmd.extend(["-map", "1:a:0?"])
|
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"
|
acodec_denoise = "libvorbis" if transcode_fmt == "webm" else "aac"
|
||||||
assemble_cmd.extend([
|
assemble_cmd.extend([
|
||||||
"-af", "arnnoise",
|
"-af", "arnnoise",
|
||||||
"-c:a", acodec_denoise
|
"-c:a", acodec_denoise
|
||||||
])
|
])
|
||||||
else:
|
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])
|
assemble_cmd.extend(["-c:a", acodec])
|
||||||
|
|
||||||
if getattr(job, "preserve_subtitles", True):
|
if getattr(job, "preserve_subtitles", True):
|
||||||
|
|||||||
Reference in New Issue
Block a user