INNER CODE UNIT · Python

probe_video

unitedrhino/things · scripts/generate-energy-demo-svg.py:32

def probe_video(source: Path) -> tuple[float, int, int]:
    """probe_video 返回视频时长、宽度和高度,并在探测失败时终止生成。"""

    command = [
        "ffprobe",
        "-v",
        "error",
        "-show_entries",
        "format=duration:stream=width,height",
        "-of",
        "json",
        str(source),
    ]
    result = subprocess.run(command, check=True, capture_output=True, text=True)
    metadata = json.loads(result.stdout)
    video_stream = next(stream for stream in metadata["streams"] if "width" in stream)
    return float(metadata["format"]["duration"]), int(video_stream["width"]), int(video_stream["height"])

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…