Fatal Exception: android.media.MediaCodec$CodecException
Describe the bug
The app crashes with a MediaCodec$CodecException when attempting to start video encoding via MediaCodec. This occurs specifically when calling MediaCodec.start() inside the BaseDecoder.start() method of the Pedro Encoder library, leading to an unhandled fatal exception.
To Reproduce
Steps to reproduce the behavior:
- Go to Stream form Video
- Go to **Choose video **
- Click on Start Publish
- Attempt to start streaming a video file
- App crashes immediately when initializing the MediaCodec
Expected behavior
The video encoder should start successfully, allowing the video file to be streamed without any crashes.
Screenshots
N/A (since it’s a crash)
Smartphone (please complete the following information):
- Library version: com.github.pedroSG94.RootEncoder:library:2.5.9
- Device: Samsung Galaxy Tab A9+
- OS: Android 14
- Media server: srs, version 5.0
-
Class used:
GenericFromFile
Additional context
- Crash happens inside
BaseDecoder.start()atMediaCodec.start() - It seems the codec fails to start — possible reasons might include:
- Unsupported or invalid video format
- Codec being in an illegal state
- Missing codec or hardware encoder issue on device
- Might need to add a try-catch around
MediaCodec.start()or validate codec availability and state before starting - Stack trace indicates issue occurs in:
when starting file stream encoding.startPublish ()
Hello,
Can you share the video used to know video information and show the result of?:
CodecUtil.showAllCodecsInfo().forEach {
Log.e("Pedro", it)
}
This way we can know if the problem is related with a limitation of the device decoders
Hello,
Thank you for your message.
The crash is currently appearing in Firebase Crashlytics, so I don't have a specific video sample that triggered it directly on my device
Hello,
I added a commit for it that avoid the crash allow capture it using a callback:
genericFromFile.setDecoderErrorCallback(object: CodecErrorCallback {
override fun onCodecError(type: CodecUtil.CodecTypeError, e: MediaCodec.CodecException) {
}
})
This will be available in the next version
Thank you for the quick update and for adding the error callback support! That’s a great addition — looking forward to the next version with this included.