logging
This commit is contained in:
Binary file not shown.
@@ -2,6 +2,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import contextlib
|
import contextlib
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
@@ -13,6 +14,9 @@ from fastapi.middleware.cors import CORSMiddleware
|
|||||||
from fastapi.responses import FileResponse
|
from fastapi.responses import FileResponse
|
||||||
from starlette.background import BackgroundTask
|
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")
|
FFMPEG_BINARY = os.getenv("FFMPEG_BINARY", "ffmpeg")
|
||||||
ALLOWED_CODECS = {"libx264", "h264_nvenc"}
|
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:
|
if process.returncode != 0:
|
||||||
error_message = (stderr or stdout).decode("utf-8", errors="replace").strip()
|
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(
|
raise HTTPException(
|
||||||
status_code=500,
|
status_code=500,
|
||||||
detail=f"{error_prefix}: {error_message or 'unknown error'}",
|
detail=f"{error_prefix}: {error_message or 'unknown error'}",
|
||||||
@@ -219,10 +226,12 @@ async def run_ffmpeg_compose(
|
|||||||
"error",
|
"error",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if codec == "h264_nvenc":
|
||||||
|
command.extend(["-init_hw_device", "cuda:0"])
|
||||||
|
|
||||||
if kind == "image":
|
if kind == "image":
|
||||||
command.extend(["-loop", "1"])
|
command.extend(["-framerate", str(fps), "-loop", "1"])
|
||||||
elif codec == "h264_nvenc":
|
elif codec == "h264_nvenc":
|
||||||
# Keep CPU filters, but still ask FFmpeg to prefer CUDA decoding for video backgrounds.
|
|
||||||
command.extend(["-hwaccel", "cuda"])
|
command.extend(["-hwaccel", "cuda"])
|
||||||
|
|
||||||
command.extend(
|
command.extend(
|
||||||
|
|||||||
Reference in New Issue
Block a user