fix: fall back to format duration when audio stream reports zero#177
Open
seonghobae wants to merge 1 commit into
Open
fix: fall back to format duration when audio stream reports zero#177seonghobae wants to merge 1 commit into
seonghobae wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
probe_mediamis-parses a realistic, perfectly valid ffprobe payload. Some containers report a stream-level"duration": "0.000000"(or"0") while the true duration lives in theformatsection. 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
_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._first_floathelper — no contract change to the generic helper, no new abstraction.Tests
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.coverageonmedia_shrinker.py: 100%.interrogate: 100%.os.listxattrerrors are unchanged and pass on Linux).🤖 Generated with Claude Code