diff --git a/__pycache__/main.cpython-313.pyc b/__pycache__/main.cpython-313.pyc index c57f872..5c73020 100644 Binary files a/__pycache__/main.cpython-313.pyc and b/__pycache__/main.cpython-313.pyc differ diff --git a/main.py b/main.py index 3daa972..1117a9b 100644 --- a/main.py +++ b/main.py @@ -2,6 +2,7 @@ from __future__ import annotations import asyncio import contextlib +import logging import os import shutil import tempfile @@ -13,6 +14,9 @@ from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import FileResponse from starlette.background import BackgroundTask +logger = logging.getLogger("ffmpeg-api") +logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(name)s: %(message)s") + FFMPEG_BINARY = os.getenv("FFMPEG_BINARY", "ffmpeg") ALLOWED_CODECS = {"libx264", "h264_nvenc"} @@ -119,6 +123,9 @@ async def run_ffmpeg_command(command: list[str], error_prefix: str) -> None: if process.returncode != 0: error_message = (stderr or stdout).decode("utf-8", errors="replace").strip() + logger.error( + "%s (ffmpeg rc=%s): %s", error_prefix, process.returncode, error_message or "unknown error" + ) raise HTTPException( status_code=500, detail=f"{error_prefix}: {error_message or 'unknown error'}", @@ -219,10 +226,12 @@ async def run_ffmpeg_compose( "error", ] + if codec == "h264_nvenc": + command.extend(["-init_hw_device", "cuda:0"]) + if kind == "image": - command.extend(["-loop", "1"]) + command.extend(["-framerate", str(fps), "-loop", "1"]) elif codec == "h264_nvenc": - # Keep CPU filters, but still ask FFmpeg to prefer CUDA decoding for video backgrounds. command.extend(["-hwaccel", "cuda"]) command.extend(