Repository navigation
fix(android): keep bitrate-targeted exports at the requested bitrate - #16
Merged
thangdevalone merged 2 commits intoNov 19, 2026
Merged
Conversation
Encode in CBR and tone-map HDR input to SDR when a target bitrate is set. In VBR, Android asks encoders for a minimum quality that overrides the bitrate, and HDR input kept as HDR switches the requested H.264 to a 10-bit HEVC encoder that can ignore the bitrate altogether. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keeps PR thangdevalone#16's behaviour (CBR + HDR-to-SDR tone-mapping for bitrate-targeted exports) on devices that support it, and stops it from failing exports on devices that don't: - Tone-mapping is tried with OpenGL (API 29+), then in the decoder (API 31+), then the pre-thangdevalone#16 behaviour (keep HDR, VBR) when the error is one a different HDR/bitrate mode can avoid. - CBR is requested only when the encoder DefaultEncoderFactory would pick supports it, since Media3 drops every encoder without the requested mode. - Whether HDR is tone-mapped is an explicit runTransform flag instead of being inferred from targetBitrate; compressVideo and processVideo set it, so their behaviour is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
What
On Android, exports with a target bitrate (
compressVideo, and the edit path that passes 4 Mbps) now:BITRATE_MODE_CBR) instead of the default VBR;Composition.HDR_MODE_TONE_MAP_HDR_TO_SDR_USING_OPEN_GL, API 29+) instead of keeping HDR.Exports without a target bitrate are unchanged.
export()now starts a one-itemCompositionto set the HDR mode.Why
compressVideocan produce a file many times larger thantargetSizeInMB. Two separate causes:setVideoMimeType(MimeTypes.VIDEO_H264)can't carry HDR, so Media3 keeps HDR by moving to a 10-bit HEVC encoder. On a Pixel 7 Pro,c2.exynos.hevc.encoderignores the requested bitrate: a 10 s 4K60 HLG clip comes out at ~49 Mbps whether 4.2 Mbps or 1 Mbps is requested.VQApply: minquality: codec claims to implement minquality=1in logcat), which overrides low bitrate requests. Even after tone-mapping to H.264, the same 4K60 clip doesn't go below ~5.6 Mbps. CBR is outside that behaviour.Testing
A standalone app built against Media3 1.10.1 ran this
export()setup unchanged: H.264 requested,Presentationto 1292×726, 10 s clipped, audio removed. Only the bitrate mode and HDR mode varied. Device: Pixel 7 Pro, Android 17. Clips are synthetic and noisy, a worst case for encoders. Each cell shows the average video bitrate in Mbps for requests of 4.2 / 1.0 Mbps.Tone-mapped output is H.264 High, 8-bit, BT.709, and the colours look right. The changed statements compile against Media3 1.10.1, and the APIs used are also in 1.5.1, the version
android/build.gradledeclares. This ships in Relive as a patch on 2.4.3.🤖 Generated with Claude Code