Skip to content

fix: don't reject low-bitrate sources that already fit the target#179

Open
seonghobae wants to merge 1 commit into
mainfrom
fix/bitrate-edgecases
Open

fix: don't reject low-bitrate sources that already fit the target#179
seonghobae wants to merge 1 commit into
mainfrom
fix/bitrate-edgecases

Conversation

@seonghobae

Copy link
Copy Markdown
Contributor

Why

calculate_audio_bitrate computes the target-driven fitting bitrate, clamps it to the source bitrate, and only then applies the OPUS_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:

MediaShrinkerError: Target size requires 12000 bps, below the safe floor of 16000 bps

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

  • Added test_low_bitrate_source_that_fits_target_is_not_rejected — fails on the old code (raises), passes now (returns 12000).
  • Full suite: 100% coverage on media_shrinker.py, 100% interrogate docstrings, no new failures (only the 5 pre-existing macOS os.listxattr errors).

🤖 Generated with Claude Code

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
@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