feat: 新增代码
This commit is contained in:
40
video_worker/app/utils/ffmpeg_utils.py
Normal file
40
video_worker/app/utils/ffmpeg_utils.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def run_cmd(cmd: list[str]) -> None:
|
||||
proc = subprocess.run(cmd, capture_output=True, text=True)
|
||||
if proc.returncode != 0:
|
||||
raise RuntimeError(f"Command failed: {' '.join(cmd)}\nSTDOUT: {proc.stdout}\nSTDERR: {proc.stderr}")
|
||||
|
||||
|
||||
def frames_to_video(frames_pattern: str, fps: int, output_video_path: Path) -> None:
|
||||
output_video_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
cmd = [
|
||||
"ffmpeg",
|
||||
"-y",
|
||||
"-framerate",
|
||||
str(fps),
|
||||
"-i",
|
||||
frames_pattern,
|
||||
"-pix_fmt",
|
||||
"yuv420p",
|
||||
str(output_video_path),
|
||||
]
|
||||
run_cmd(cmd)
|
||||
|
||||
|
||||
def extract_first_frame(video_path: Path, first_frame_path: Path) -> None:
|
||||
first_frame_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
cmd = [
|
||||
"ffmpeg",
|
||||
"-y",
|
||||
"-i",
|
||||
str(video_path),
|
||||
"-vf",
|
||||
"select=eq(n\\,0)",
|
||||
"-vframes",
|
||||
"1",
|
||||
str(first_frame_path),
|
||||
]
|
||||
run_cmd(cmd)
|
||||
Reference in New Issue
Block a user