Cria novos components

This commit is contained in:
LeoMortari
2025-10-20 17:56:36 -03:00
parent 2b99d2ad78
commit b090f7c2cb
38 changed files with 1391 additions and 1024 deletions

54
video_render/ffmpeg.py Normal file
View File

@@ -0,0 +1,54 @@
from __future__ import annotations
import logging
import shlex
import subprocess
from pathlib import Path
from typing import Sequence
logger = logging.getLogger(__name__)
def _run_ffmpeg(args: Sequence[str]) -> None:
cmd = ["ffmpeg", "-hide_banner", "-loglevel", "error", *args]
logger.debug("Executando ffmpeg: %s", " ".join(shlex.quote(part) for part in cmd))
completed = subprocess.run(cmd, check=False)
if completed.returncode != 0:
raise RuntimeError(f"ffmpeg falhou com exit code {completed.returncode}")
def extract_audio_to_wav(input_video: Path, output_wav: Path) -> Path:
_run_ffmpeg(
[
"-y",
"-i",
str(input_video),
"-ac",
"1",
"-ar",
"16000",
"-vn",
str(output_wav),
]
)
return output_wav
def create_video_segment(input_video: Path, start: float, end: float, output_path: Path) -> Path:
duration = max(0.01, end - start)
_run_ffmpeg(
[
"-y",
"-i",
str(input_video),
"-ss",
f"{start:.3f}",
"-t",
f"{duration:.3f}",
"-c",
"copy",
str(output_path),
]
)
return output_path