Skip to content

fix: fall back to format duration when audio stream reports zero#177

Open
seonghobae wants to merge 1 commit into
mainfrom
feat/probe-robustness
Open

fix: fall back to format duration when audio stream reports zero#177
seonghobae wants to merge 1 commit into
mainfrom
feat/probe-robustness

Conversation

@seonghobae

Copy link
Copy Markdown
Contributor

Why

probe_media mis-parses a realistic, perfectly valid ffprobe payload. Some containers report a stream-level "duration": "0.000000" (or "0") while the true duration lives in the format section. The helper _first_float(audio_stream.duration, format.duration) returns the first parseable value — 0.0 — and never consults the format fallback. The next check then wrongly raises "<file> has no usable duration", so a valid file fails to convert.

What

  • In _parse_probe_payload, read the audio stream duration first; when it is non-positive (unusable), fall back to the format duration before deciding the file has no duration.
  • Minimal, surgical change reusing the existing _first_float helper — no contract change to the generic helper, no new abstraction.

Tests

  • Added test_parse_probe_payload_falls_back_to_format_duration_when_stream_is_zero, which reproduces the real payload (audio stream "0.000000", format "123.5") and fails against the old code.
  • coverage on media_shrinker.py: 100%.
  • interrogate: 100%.
  • Full suite: no new failures (the 5 pre-existing macOS-only os.listxattr errors are unchanged and pass on Linux).

🤖 Generated with Claude Code

probe_media mis-parsed valid media whose audio stream carries
"duration": "0.000000" (or "0") while the true duration lives in the
format section. _first_float stopped at the first parseable value (0.0)
and never consulted the format fallback, so the file wrongly raised
"has no usable duration".

Parse the stream duration first and, when it is non-positive (unusable),
fall back to the format duration before deciding the file has no
duration. Adds a regression test reproducing the real ffprobe payload.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CJRVbDrp1vGYkJgNHMGPpG
@seonghobae seonghobae enabled auto-merge (squash) July 6, 2026 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant