fix(android): prevent encoder & reverse-render crashes#140
Merged
Conversation
- Enable encoder fallback in main render path so Media3 falls back to supported settings instead of failing with a codec exception when the hardware encoder rejects the requested configuration (Qualcomm AVC). - applyBitrate: clamp bitrate into the codec's supported range instead of bailing out, and prefer VBR over CBR at high bitrates (high-bitrate CBR is frequently rejected by hardware encoders). - VideoReverser: configure the all-intra encoder with a clamped bitrate and progressive fallback to avoid MediaCodec.CodecException crashes. - VideoReverser: guard remuxReversed against OutOfMemoryError by checking the all-intra temp file size against available heap before loading frames.
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.
Summary
Fixes several crash sources in the Android render pipeline, including a
RENDER_ERRORcodec exception on Qualcomm AVC hardware encoders and potential crashes in the reverse-video pre-render path.The original failure:
Changes
Main render path
DefaultEncoderFactory.Builder.setEnableFallback(true)) so Media3 falls back to supported encoder settings instead of failing the whole render when the hardware encoder rejects the requested configuration.applyBitrateVideoReverser(reverse pre-render)preferred → w·h·4 → w·h·2), wrapped intry/catch, to avoid aMediaCodec.CodecExceptioncrashing the reverse thread (e.g. when an HEVC source bitrate is invalid for AVC).remuxReversedagainstOutOfMemoryError: the all-intra temp file is loaded fully into RAM, so its size is checked against available heap (with a 2× margin) before loading. Oversized segments throw a clear exception instead of killing the process.Both reverse-path exceptions are caught by the existing fallback in
preReverseClips, so the clip gracefully degrades to forward playback rather than failing the entire render.Testing