"""Shared video helpers used by the /playback endpoint and the pretranscode celery task. The actual ffmpeg/ffprobe work is sync (subprocess.run); FastAPI handlers wrap calls in asyncio.to_thread, celery just calls them directly. Keeping a single sync implementation avoids drift between the request-time fallback and the background pre-transcode.""" from __future__ import annotations import logging import os import subprocess from pathlib import Path from typing import Optional logger = logging.getLogger(__name__) # On-disk cache of browser-playable transcodes. Backed by /data which is # the persistent volume in mulita-backend / mulita-worker-light. VIDEO_CACHE_DIR = Path('/data/video-cache') VIDEO_CACHE_DIR.mkdir(parents=True, exist_ok=True) # Codecs the browser can play in