fix: bundle FFmpeg offline, fix NoneType write crash in windowed apps, fallback to system PATH

This commit is contained in:
joel
2026-07-30 08:46:51 +02:00
parent cdf6073cba
commit fca6637f50
3 changed files with 46 additions and 2 deletions
+24 -2
View File
@@ -16,14 +16,36 @@ import static_ffmpeg
from .metadata import apply_id3_tags
import sys
import io
import shutil
def _ensure_ffmpeg() -> tuple[str, str]:
"""Stellt sicher, dass ffmpeg und ffprobe verfügbar sind.
Returns:
(ffmpeg_path, ffprobe_path)
"""
ffmpeg_path, ffprobe_path = static_ffmpeg.run.get_or_fetch_platform_executables_else_raise()
return ffmpeg_path, ffprobe_path
# 1. Behebe NoneType 'write' Fehler, wenn App im windowed-Modus gestartet wurde
if sys.stdout is None:
sys.stdout = io.StringIO()
if sys.stderr is None:
sys.stderr = io.StringIO()
# 2. Versuch 1: static_ffmpeg (jetzt direkt in der App gebündelt)
try:
ffmpeg_path, ffprobe_path = static_ffmpeg.run.get_or_fetch_platform_executables_else_raise()
return ffmpeg_path, ffprobe_path
except Exception:
pass
# 3. Versuch 2: System-FFmpeg (z.B. über winget, apt, brew) als Fallback
sys_ffmpeg = shutil.which("ffmpeg")
sys_ffprobe = shutil.which("ffprobe")
if sys_ffmpeg and sys_ffprobe:
return sys_ffmpeg, sys_ffprobe
raise RuntimeError("FFmpeg konnte weder im Bundle noch im System gefunden werden.")
def get_duration(file_path: Path, ffprobe_path: str) -> float: