fix: don't reject low-bitrate sources that already fit the target#179
Open
seonghobae wants to merge 1 commit into
Open
fix: don't reject low-bitrate sources that already fit the target#179seonghobae wants to merge 1 commit into
seonghobae wants to merge 1 commit into
Conversation
calculate_audio_bitrate applied the OPUS_MIN_REASONABLE_BITRATE_BPS floor after clamping to the source bitrate. A source already encoded below the floor (e.g. a 12 kbps opus voice recording) that fits a generous target with huge margin was therefore rejected with a misleading "Target size requires 12000 bps" error, even though the target required no such thing -- the 12000 came entirely from the source. The floor guards target feasibility, so apply it to the target-driven fitting bitrate before the source cap. Low-bitrate sources now transcode at their own bitrate instead of raising. 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
calculate_audio_bitratecomputes the target-driven fitting bitrate, clamps it to the source bitrate, and only then applies theOPUS_MIN_REASONABLE_BITRATE_BPS(16 kbps) floor. Because the floor check ran after the source clamp, a source already encoded below the floor was rejected outright.Example: a 12 kbps opus voice recording with a generous 1.9 GB target fits with enormous margin (the target alone permits ~510 kbps). Yet the old code returned:
The target does not "require" 12000 bps — that value comes entirely from the source being low bitrate. The tool refused to shrink a file it could trivially handle, with a misleading message.
What
Apply the floor guard to the target-driven fitting bitrate (before the source cap). The floor exists to reject targets too small to fit at usable quality; it should not reject sources that are simply low bitrate. Low-bitrate sources now transcode at their own bitrate. The genuine "target too small" rejection (e.g. 1 byte over 10000 s) is unchanged.
Tests
test_low_bitrate_source_that_fits_target_is_not_rejected— fails on the old code (raises), passes now (returns 12000).media_shrinker.py, 100% interrogate docstrings, no new failures (only the 5 pre-existing macOSos.listxattrerrors).🤖 Generated with Claude Code