Skip to content

fix(android): prevent encoder & reverse-render crashes#140

Merged
hm21 merged 2 commits into
stablefrom
fix/android-render
May 29, 2026
Merged

fix(android): prevent encoder & reverse-render crashes#140
hm21 merged 2 commits into
stablefrom
fix/android-render

Conversation

@hm21
Copy link
Copy Markdown
Owner

@hm21 hm21 commented May 29, 2026

Summary

Fixes several crash sources in the Android render pipeline, including a RENDER_ERROR codec exception on Qualcomm AVC hardware encoders and potential crashes in the reverse-video pre-render path.

The original failure:

PlatformException(RENDER_ERROR, Codec exception: CodecInfo{type=VideoEncoder, ...
mime=video/avc, bitrate=8739850, bitrate-mode=1, profile=8, level=16384, ...
name=c2.qti.avc.encoder}, ...)

Changes

Main render path

  • Enable encoder fallback (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.

applyBitrate

  • Clamp the requested bitrate into the codec's supported range instead of bailing out (which previously left the encoder on its very high default bitrate — one of the configurations Qualcomm encoders reject).
  • Prefer VBR over CBR when the bitrate sits in the upper portion of the supported range, since high-bitrate CBR is the combination most frequently rejected by hardware encoders.

VideoReverser (reverse pre-render)

  • Configure the all-intra encoder with a clamped bitrate and progressive fallback (preferred → w·h·4 → w·h·2), wrapped in try/catch, to avoid a MediaCodec.CodecException crashing the reverse thread (e.g. when an HEVC source bitrate is invalid for AVC).
  • Guard remuxReversed against OutOfMemoryError: 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

  • Android render verified to compile (no analyzer errors).
  • Recommend testing render + reverse render on a Qualcomm/Snapdragon device with high-bitrate 1080p and long/4K clips.

hm21 added 2 commits May 29, 2026 21:49
- 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.
@hm21 hm21 merged commit a69e22f into stable May 29, 2026
1 check passed
@hm21 hm21 deleted the fix/android-render branch May 29, 2026 15:00
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