question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

com.google.android.exoplayer2.mediacodec.MediaCodecRenderer$DecoderInitializationException: Decoder init failed:

See original GitHub issue

Caused by: com.google.android.exoplayer2.mediacodec.MediaCodecRenderer$DecoderInitializationException: Decoder init failed: OMX.Exynos.avc.dec, Format(1, null, null, video/avc, avc1.4D402A, -1, null, [1920, 1080, 60.000004], [-1, -1])

Every Time generate this issue

  1. Play video in our app -> works fine
  2. Run other video application
  3. Start video in other video application
  4. Minimize other video application
  5. Go back to our app
  6. Try to play video -> fail DecoderInitializationException
  7. Kill other video application
  8. Go back to our app
  9. Try to play video -> works fine

And Also show black screen on playerview

2021-07-27 16:51:10.097 10029-10904/com.oneintro.intromaker E/ExoPlayerImplInternal: Playback error
      com.google.android.exoplayer2.ExoPlaybackException: MediaCodecVideoRenderer error, index=0, format=Format(1, null, null, video/avc, avc1.4D402A, -1, null, [1920, 1080, 60.000004], [-1, -1]), format_supported=YES
        at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:555)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:164)
        at android.os.HandlerThread.run(HandlerThread.java:65)
     Caused by: com.google.android.exoplayer2.mediacodec.MediaCodecRenderer$DecoderInitializationException: Decoder init failed: OMX.Exynos.avc.dec, Format(1, null, null, video/avc, avc1.4D402A, -1, null, [1920, 1080, 60.000004], [-1, -1])
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.maybeInitCodecWithFallback(MediaCodecRenderer.java:1051)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.maybeInitCodecOrBypass(MediaCodecRenderer.java:606)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.onInputFormatChanged(MediaCodecRenderer.java:1465)
        at com.google.android.exoplayer2.video.MediaCodecVideoRenderer.onInputFormatChanged(MediaCodecVideoRenderer.java:713)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.readSourceOmittingSampleData(MediaCodecRenderer.java:998)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.render(MediaCodecRenderer.java:830)
        at com.google.android.exoplayer2.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:945)
        at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:478)
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.os.HandlerThread.run(HandlerThread.java:65) 
     Caused by: android.media.MediaCodec$CodecException: Error 0xffffec77
        at android.media.MediaCodec.native_configure(Native Method)
        at android.media.MediaCodec.configure(MediaCodec.java:1943)
        at android.media.MediaCodec.configure(MediaCodec.java:1872)
        at com.google.android.exoplayer2.mediacodec.SynchronousMediaCodecAdapter$Factory.createAdapter(SynchronousMediaCodecAdapter.java:50)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.initCodec(MediaCodecRenderer.java:1137)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.maybeInitCodecWithFallback(MediaCodecRenderer.java:1044)

Is there any way to release programmatically codec resources which are used by another app? This is quite a significant problem for us.

I can not find any solution so if you have any solution please help me out.

I have wasted 3 days in this issue but have not yet found a solution. Please give solution.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:10
  • Comments:27 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
christostscommented, Aug 4, 2021

How to know the hardware decoder fails?

The player will raise an error on the AnalyticsListener.onPlayerError callback and the passed ExoPlaybackException will contain a MediaCodecRenderer.DecoderInitializationException. You can see that in the first stack trace you posted on the issue description. In your app, you should add an AnalyticsListener to the player and if onPlayerError is raised, you can inspect if it was the decoder that failed as follows:

@Override
  public void onPlayerError(EventTime eventTime, ExoPlaybackException e) {
    if (e.getRendererException() instanceof MediaCodecRenderer.DecoderInitializationException) {
      MediaCodecRenderer.DecoderInitializationException decoderInitializationException = (MediaCodecRenderer.DecoderInitializationException) e.getRendererException();
      MediaCodecInfo codecInfo = decoderInitializationException.codecInfo;
      Log.d("EXO_V2", "Decoder failed to initialize: " + codecInfo.name);
      Log.d("EXO_V2", "Hardware? " + codecInfo.hardwareAccelerated);
      Log.d("EXO_V2", "Mime type? " + codecInfo.mimeType);
      Log.d("EXO_V2", "Is H264? " + MimeTypes.VIDEO_H264.equals(codecInfo.mimeType));
    }
  }

I’ve added some extra statements to show you some of the information you can obtain the exception’s MediaCodecInfo, such as the MIME type (from which you can tell if it’s an H264 decoder), the specific decoder name and if it’s a hardware one.

Unfortunately, if you wait until the player fails and then try out with a different decoder, your app will need extra time until it starts playing the video. Please try if DefaultRenderersFactory. setEnableDecoderFallback(true) solves your problem before you try this solution.

DefaultRenderersFactory always returns software decoder?

By default, the DefaultRenderersFactory will prefer a hardware decoder if one exists. This comes down to the device capabilities, and the player will query the device to find out what decoders are available for the specific video. If for a certain video format there is a hardware and a software decoder, the player’s default behavior is to prefer to hardware. But if the device only has one decoder for a certain video format, the player will pick that decoder nevertheless.

Please Explain this condition.

if (MimeTypes.VIDEO_H264.equals(mimeType)) {

This checks is the video format is H264. Media formats are defined by a MIME type. You can check the player’s MimeTypes class. For the snippet of code I shared above, this condition changes the default codec selection only for H264 (you’d want the default behavior for other codecs). Feel free to change the condition if you find more issues with decoders not being available.

I am not getting that which setExtensionRendererMode have to use when?

This is a setting used by the demo app, and works if you want to use the DefaultRenderersFactory with ExoPlayer extensions (feel free to ignore if you don’t use extensions).

Please let me know if I can assist further, otherwise I will close tis issue now.

2reactions
christostscommented, Aug 2, 2021

Please explain to me how to use a decoder. You tell me how to know the decoder of video. and how to change the video decoder.

I can think of two options

  1. If you control the generation of content, you choose an encoding other than H264, e.g. use HEVC or VP9 video. The majority of devices support this encoding. 2.Try enabling decoder fallback on the ExoPlayer by calling DefaultRenderersFactory. setEnableDecoderFallback(true). For example, in the demo app’s DemoUtil.java you can do
return new DefaultRenderersFactory(context.getApplicationContext())
        .setExtensionRendererMode(extensionRendererMode).setEnableDecoderFallback(true);
  1. Otherwise, following this answer, you can pass a custom MediaCodecSelector to the player which will have your custom logic to select an H264 decoder (if the video format is H264, you have to pick an H264 decoder). On an Android platform, you typically find a hardware and software decoder for H264. By default, ExoPlayer uses MediaCodecSelector.DEFAULT which prefers the hardware decoder. You may create a custom MediaCodecSelector that returns a list of decoders, with the software decoder for H264 on the top of the list instead of the hardware decoder. An easy way to achieve that is to wrap MediaCodecSelector.DEFAULT and re-order its returned results. For example, in the demo app, you can do something like this
return new DefaultRenderersFactory(context.getApplicationContext())
        .setExtensionRendererMode(extensionRendererMode).setMediaCodecSelector(
            new MediaCodecSelector() {
              @Override
              public List<MediaCodecInfo> getDecoderInfos(String mimeType,
                  boolean requiresSecureDecoder, boolean requiresTunnelingDecoder)
                  throws MediaCodecUtil.DecoderQueryException {
                List<MediaCodecInfo> decoderInfos = MediaCodecSelector.DEFAULT
                    .getDecoderInfos(mimeType, requiresSecureDecoder, requiresTunnelingDecoder);
                if (MimeTypes.VIDEO_H264.equals(mimeType)) {
                  // copy the list because MediaCodecSelector.DEFAULT returns an unmodifiable list
                  decoderInfos = new ArrayList<>(decoderInfos);
                  Collections.reverse(decoderInfos);
                }
                return decoderInfos;
              }
            });
  }

Please note the following for option 3:

  • I would not advice to always pick the software decoder (on the basis that it might fail) because using the software decoder is not as performant as the hardware (battery usage, frame drops etc)
  • the error you see on the specific devices does not happen on any device I have tested. What I believe is happening on your devices is that H264 decoders are acquired and not released when you put the particular video editing apps in the background. However, it’s up to the device capabilities on how many different instances of a certain decoder to create and share between processes.
  • The errors you see on your devices, may not happen on other devices
  • Therefore, you should first attempt to play videos with the hardware decoder and only if it fails, you should fallback to the software decoder.

Overall, I believe the issue you are seeing so far is not with ExoPlayer but with the video editing apps that seem to not release their resources when put them in the background. I have not managed to reproduce using Pixel devices and a Samsung S9. My guess is that the specific devices you are testing (Samsung J5/J7) may not have the ability to share resources. That said, I am not sure how else we have help you with the issue you are facing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - Video codec error com.google.android.exoplayer2 ...
Video codec error com.google.android.exoplayer2.mediacodec.MediaCodecRenderer$DecoderInitializationException: Decoder init failed: Android ...
Read more >
Class MediaCodecRenderer.DecoderInitializationException
com.google.android.exoplayer2.mediacodec.MediaCodecRenderer. ... The MediaCodecInfo of the decoder that failed to initialize. String, diagnosticInfo.
Read more >
ExoPlayer Error - Google Groups
com.google.android.exoplayer2.mediacodec.MediaCodecRenderer$DecoderInitializationException: Decoder init failed: OMX.
Read more >
MediaCodecRenderer (library API) - javadoc.io
An abstract renderer that uses MediaCodec to decode samples for rendering. ... Fields inherited from interface com.google.android.exoplayer2.
Read more >
com.google.android.exoplayer2.mediacodec ... - Tabnine
public DecoderInitializationException(Format format, Throwable cause, boolean secureDecoderRequired, String decoderName) { this( "Decoder init failed: " + ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found