Repository navigation
fix(android): retry the export with a software encoder when the hardware encoder fails - #14
Merged
thangdevalone merged 1 commit intoOct 15, 2026
Conversation
…are encoder fails
Some hardware encoders reject an export after opening fine: a Samsung
SM-A526B (OMX.qcom.video.encoder.avc) answers the first surface frame of
some clips with OMX_ErrorHardware, which Media3 reports as
ERROR_CODE_ENCODING_FAILED. runTransform now runs once more with an
EncoderSelector limited to non-hardware encoders when the failure comes
from the video encoder, and ProcessingFailed carries Media3's error code
name plus the MediaCodec.CodecException details for every attempt.
MediaResult gains an optional `encoder` ("<attempt>:<codec>") on Android
video exports. The transmux flag is gone: both branches configured the
same H.264 path and the retry needs an encoder factory everywhere.
Closes thangdevalone#11
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.
Closes #11.
What
On Android, when the video encoder fails, the export runs once more with a software encoder before the library gives up, and errors carry Media3's details.
runTransformtries Media3's default encoder, then, if theExportExceptionhas a video encodercodecInfo(init failure orERROR_CODE_ENCODING_FAILEDmid-export), retries with aDefaultEncoderFactorywhoseEncoderSelectoronly returns non-hardware-accelerated encoders. Any other error stops immediately.ProcessingFailednow readsTransform failed: default: ERROR_CODE_ENCODING_FAILED | <message> | CodecException(errorCode=…, transient=…, recoverable=…, diagnostic=…): … || software_encoder: …instead ofTransform failed: Codec exception. The same text goes to logcat under tagVideoProcessor, plusExport used <attempt>:<codec>on success.MediaResult.encoder?: string,"<default|software_encoder>:<ExportResult.videoEncoderName>", set on Android video exports so apps can see which encoder produced a file. iOS leaves it unset.nitrogen/regenerated withyarn codegen.transmuxflag onrunTransformis removed. Both branches already configured the same H.264 encoder path (Media3 transcodes a clipped item regardless), and the retry needs an encoder factory on every path.trimVideo,cropVideoandprocessVideokeep their current behaviour: no bitrate request for the first two, 4 Mbps for the last.encoderonMediaResultand a note on the fallback.Why
A Samsung SM-A526B (Snapdragon 750G, Android 14, legacy
OMX.qcom.video.encoder.avc) rejects some clips on the first surface frame:Output size (1616x726, 1684x756, 1616x720), portrait vs landscape encoding, colour tags, and Media3's
operating-rate/priorityhints were each ruled out on the device.c2.android.avc.encoderencodes the same clip at the same size and frame rate in about 7 s for a 10 s range, so the retry turns a hard failure into a slower export. Other clips on the same device still take the hardware path on the first attempt.Testing
yarn typecheckpasses.yarn lintreports the same 278 pre-existing prettier errors asmain; none are on changed lines.swiftc -parse.encoder = "software_encoder:c2.android.avc.encoder"and the logcat line lists the hardware attempt's error; unaffected clips reportdefault:OMX.qcom.video.encoder.avc. Running in production (Relive) as a patch on 2.4.0.VideoProcessor.ktand the Nitro spec; both apply cleanly onmainand I can rebase whichever lands second.