from __future__ import annotations import json from pathlib import Path from video_metadata_analyzer.probe import probe_video_metadata def test_probe_video_metadata_parses_primary_streams(tmp_path: Path) -> None: sample = tmp_path / "sample.mp4" sample.write_bytes(b"x" * 4096) captured_command: list[str] = [] def fake_runner(command: list[str]) -> str: captured_command[:] = command return json.dumps( { "format": { "filename": str(sample), "format_name": "mov,mp4,m4a,3gp,3g2,mj2", "duration": "12.500000", "bit_rate": "2621440", "size": "4096", }, "streams": [ { "codec_type": "video", "codec_name": "h264", "width": 1920, "height": 1080, "avg_frame_rate": "30000/1001", }, { "codec_type": "audio", "codec_name": "aac", }, ], } ) result = probe_video_metadata(sample, runner=fake_runner) assert captured_command[:4] == ["ffprobe", "-v", "quiet", "-print_format"] assert result.path == sample assert result.size_bytes == 4096 assert result.duration_seconds == 12.5 assert result.format_name == "mov,mp4,m4a,3gp,3g2,mj2" assert result.bit_rate == 2621440 assert result.video_codec == "h264" assert result.audio_codec == "aac" assert result.width == 1920 assert result.height == 1080 assert result.frame_rate == 30000 / 1001 assert result.video_stream_count == 1 assert result.audio_stream_count == 1 assert result.subtitle_stream_count == 0