RootEncoder icon indicating copy to clipboard operation
RootEncoder copied to clipboard

Fatal Exception: android.media.MediaCodec$CodecException

Open bhavinatharva opened this issue 9 months ago • 4 comments

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:

  1. Go to Stream form Video
  2. Go to **Choose video **
  3. Click on Start Publish
  4. Attempt to start streaming a video file
  5. 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() at MediaCodec.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:
    startPublish ()
    
    when starting file stream encoding.

bhavinatharva avatar Apr 17 '25 06:04 bhavinatharva

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

pedroSG94 avatar Apr 17 '25 10:04 pedroSG94

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

Image

bhavinatharva avatar Apr 17 '25 10:04 bhavinatharva

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

pedroSG94 avatar Apr 21 '25 15:04 pedroSG94

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.

bhavinatharva avatar Apr 22 '25 05:04 bhavinatharva