feat: add ffprobe duration detection

This commit is contained in:
2025-11-30 17:43:35 -05:00
parent dd6b5c143a
commit 503e9f2662
2 changed files with 54 additions and 0 deletions

View File

@@ -1,3 +1,4 @@
import asyncio
import shlex
from pathlib import Path
@@ -99,3 +100,24 @@ def extract_output_path(args: list[str]) -> str | None:
return arg
i -= 1
return None
async def get_duration(input_path: str) -> float | None:
"""Get duration of media file using ffprobe."""
try:
process = await asyncio.create_subprocess_exec(
"ffprobe",
"-v", "error",
"-show_entries", "format=duration",
"-of", "default=noprint_wrappers=1:nokey=1",
input_path,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
stdout, _ = await process.communicate()
if process.returncode == 0:
return float(stdout.decode().strip())
except (ValueError, OSError):
pass
return None