feat: 新增代码

This commit is contained in:
Daniel
2026-04-07 00:37:39 +08:00
commit 8d0b729f2f
29 changed files with 1768 additions and 0 deletions

View 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)