Failed to initialize decoder when using ImageReader, whereas same video can be successfully played back
See original GitHub issueI’m trying to extract a single frame from a video by using ImageReader.
However, my target device keeps failing to initialize its decoder: this is strange, because when I’m trying to playback the same video with the same source code, it plays back without issues.
Here is my minimal example with 100% reproducability rate:
Layout:
<com.google.android.exoplayer2.ui.StyledPlayerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/myplayer"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Application:
public class MainActivity extends AppCompatActivity {
private static String TAG = "SimpleExo";
private SimpleExoPlayer player;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
protected void onResume() {
super.onResume();
player = new SimpleExoPlayer.Builder(this)
.setTrackSelector(new DefaultTrackSelector(this)).build();
boolean extractFrames = true;
if (extractFrames) {
ImageReader imgReader = ImageReader.newInstance(1600, 900, ImageFormat.YUV_420_888, 5);
imgReader.setOnImageAvailableListener(new ImageReader.OnImageAvailableListener() {
@Override
public void onImageAvailable(ImageReader imageReader) {
Image i = imageReader.acquireLatestImage();
Image.Plane[] planes = i.getPlanes();
Log.d(TAG, "onImageAvailable! planes=" + planes.length);
i.close();
}
}, null);
player.setVideoSurface(imgReader.getSurface());
}
else {
StyledPlayerView view = findViewById(R.id.myplayer);
view.setPlayer(player);
}
// Build the media item.
MediaItem mediaItem = MediaItem.fromUri("file:/android_asset/test2.mp4");
String playerInfo = Util.getUserAgent(getApplicationContext(), "ExoPlayerInfo");
DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(
getApplicationContext(), playerInfo
);
ProgressiveMediaSource mediaSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
.createMediaSource(mediaItem);
player.setMediaSource(mediaSource);
player.prepare();
player.setPlayWhenReady(true);
}
@Override
protected void onPause() {
super.onPause();
player.stop();
player.release();
}
}
Android version is currently 11. ExoPlayer is the latest (2.13.3). Phone is a Qualcomm-based Samsung.
If I set extractFrames
to false
, the video is played back correctly on the screen. However when I’m setting it to true
, I got the below error:
2021-05-08 23:12:20.546 16145-16145/? I/com.simpleexo: Late-enabling -Xcheck:jni
2021-05-08 23:12:21.076 16145-16145/com.simpleexo I/Perf: Connecting to perf service.
2021-05-08 23:12:21.152 16145-16145/com.simpleexo W/com.simpleexo: Accessing hidden method Landroid/graphics/drawable/Drawable;->getOpticalInsets()Landroid/graphics/Insets; (light greylist, linking)
2021-05-08 23:12:21.152 16145-16145/com.simpleexo W/com.simpleexo: Accessing hidden field Landroid/graphics/Insets;->left:I (light greylist, linking)
2021-05-08 23:12:21.152 16145-16145/com.simpleexo W/com.simpleexo: Accessing hidden field Landroid/graphics/Insets;->right:I (light greylist, linking)
2021-05-08 23:12:21.152 16145-16145/com.simpleexo W/com.simpleexo: Accessing hidden field Landroid/graphics/Insets;->top:I (light greylist, linking)
2021-05-08 23:12:21.152 16145-16145/com.simpleexo W/com.simpleexo: Accessing hidden field Landroid/graphics/Insets;->bottom:I (light greylist, linking)
2021-05-08 23:12:21.185 16145-16145/com.simpleexo W/com.simpleexo: Accessing hidden field Landroid/view/WindowInsets;->CONSUMED:Landroid/view/WindowInsets; (light greylist, reflection)
2021-05-08 23:12:21.191 16145-16145/com.simpleexo W/com.simpleexo: Accessing hidden method Landroid/view/View;->getAccessibilityDelegate()Landroid/view/View$AccessibilityDelegate; (light greylist, linking)
2021-05-08 23:12:21.222 16145-16145/com.simpleexo W/com.simpleexo: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection)
2021-05-08 23:12:21.223 16145-16145/com.simpleexo W/com.simpleexo: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection)
2021-05-08 23:12:21.292 16145-16145/com.simpleexo W/com.simpleexo: Accessing hidden method Landroid/text/SpannableStringInternal;->length()I (light greylist, linking)
2021-05-08 23:12:21.309 16145-16145/com.simpleexo D/OpenGLRenderer: Skia GL Pipeline
2021-05-08 23:12:21.338 16145-16145/com.simpleexo W/com.simpleexo: Accessing hidden method Landroid/graphics/FontFamily;-><init>()V (light greylist, reflection)
2021-05-08 23:12:21.338 16145-16145/com.simpleexo W/com.simpleexo: Accessing hidden method Landroid/graphics/FontFamily;->addFontFromAssetManager(Landroid/content/res/AssetManager;Ljava/lang/String;IZIII[Landroid/graphics/fonts/FontVariationAxis;)Z (light greylist, reflection)
2021-05-08 23:12:21.338 16145-16145/com.simpleexo W/com.simpleexo: Accessing hidden method Landroid/graphics/FontFamily;->addFontFromBuffer(Ljava/nio/ByteBuffer;I[Landroid/graphics/fonts/FontVariationAxis;II)Z (light greylist, reflection)
2021-05-08 23:12:21.338 16145-16145/com.simpleexo W/com.simpleexo: Accessing hidden method Landroid/graphics/FontFamily;->freeze()Z (light greylist, reflection)
2021-05-08 23:12:21.338 16145-16145/com.simpleexo W/com.simpleexo: Accessing hidden method Landroid/graphics/FontFamily;->abortCreation()V (light greylist, reflection)
2021-05-08 23:12:21.338 16145-16145/com.simpleexo W/com.simpleexo: Accessing hidden method Landroid/graphics/Typeface;->createFromFamiliesWithDefault([Landroid/graphics/FontFamily;Ljava/lang/String;II)Landroid/graphics/Typeface; (light greylist, reflection)
2021-05-08 23:12:21.571 16145-16145/com.simpleexo W/com.simpleexo: Accessing hidden method Landroid/media/AudioTrack;->getLatency()I (light greylist, reflection)
2021-05-08 23:12:21.584 16145-16145/com.simpleexo I/ExoPlayerImpl: Init 824dbe0 [ExoPlayerLib/2.13.3] [G8441, G8441, Sony, 28]
2021-05-08 23:12:21.676 16145-16145/com.simpleexo W/com.simpleexo: Accessing hidden method Landroid/graphics/Insets;->of(IIII)Landroid/graphics/Insets; (light greylist, linking)
2021-05-08 23:12:21.694 16145-16219/com.simpleexo I/Adreno: QUALCOMM build : 7ae04e7, Ia74c9b5270
Build Date : 09/20/18
OpenGL ES Shader Compiler Version: EV031.25.03.00
Local Branch :
Remote Branch : refs/tags/AU_LINUX_ANDROID_LA.UM.7.4.R1.09.00.00.453.030
Remote Branch : NONE
Reconstruct Branch : NOTHING
2021-05-08 23:12:21.694 16145-16219/com.simpleexo I/Adreno: Build Config : S L 6.0.7 AArch64
2021-05-08 23:12:21.697 16145-16219/com.simpleexo I/Adreno: PFP: 0x005ff112, ME: 0x005ff066
2021-05-08 23:12:21.683 16145-16145/com.simpleexo W/RenderThread: type=1400 audit(0.0:2241): avc: denied { search } for name="proc" dev="debugfs" ino=18698 scontext=u:r:untrusted_app:s0:c46,c257,c512,c768 tcontext=u:object_r:qti_debugfs:s0 tclass=dir permissive=0 ppid=789 pcomm="main" pgid=16145 pgcomm="com.simpleexo"
2021-05-08 23:12:21.700 16145-16219/com.simpleexo I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
2021-05-08 23:12:21.700 16145-16219/com.simpleexo I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
2021-05-08 23:12:21.704 16145-16219/com.simpleexo I/OpenGLRenderer: Initialized EGL, version 1.4
2021-05-08 23:12:21.705 16145-16219/com.simpleexo D/OpenGLRenderer: Swap behavior 2
2021-05-08 23:12:21.721 16145-16217/com.simpleexo W/VideoCapabilities: Unrecognized profile 2130706433 for video/avc
2021-05-08 23:12:21.721 16145-16217/com.simpleexo W/VideoCapabilities: Unrecognized profile 2130706434 for video/avc
2021-05-08 23:12:21.723 16145-16217/com.simpleexo W/VideoCapabilities: Unrecognized profile 2130706433 for video/avc
2021-05-08 23:12:21.723 16145-16217/com.simpleexo W/VideoCapabilities: Unrecognized profile 2130706434 for video/avc
2021-05-08 23:12:21.735 16145-16217/com.simpleexo W/VideoCapabilities: Unrecognized profile 4 for video/hevc
2021-05-08 23:12:21.750 16145-16217/com.simpleexo W/VideoCapabilities: Unrecognized profile 2130706433 for video/avc
2021-05-08 23:12:21.750 16145-16217/com.simpleexo W/VideoCapabilities: Unrecognized profile 2130706434 for video/avc
2021-05-08 23:12:21.762 16145-16217/com.simpleexo I/VideoCapabilities: Unsupported profile 4 for video/mp4v-es
2021-05-08 23:12:21.798 16145-16229/com.simpleexo I/OMXClient: IOmx service obtained
2021-05-08 23:12:21.835 16145-16228/com.simpleexo D/SurfaceUtils: connecting to surface 0x760d467010, reason connectToSurface
2021-05-08 23:12:21.835 16145-16228/com.simpleexo I/MediaCodec: [OMX.qcom.video.decoder.avc] setting surface generation to 16532481
2021-05-08 23:12:21.835 16145-16228/com.simpleexo D/SurfaceUtils: disconnecting from surface 0x760d467010, reason connectToSurface(reconnect)
2021-05-08 23:12:21.835 16145-16228/com.simpleexo D/SurfaceUtils: connecting to surface 0x760d467010, reason connectToSurface(reconnect)
2021-05-08 23:12:21.836 16145-16229/com.simpleexo I/ExtendedACodec: setupVideoDecoder()
2021-05-08 23:12:21.842 16145-16229/com.simpleexo I/ExtendedACodec: Decoder will be in frame by frame mode
2021-05-08 23:12:21.872 16145-16229/com.simpleexo E/BufferQueueProducer: [ImageReader-1600x900f23m5-16145-0] query: BufferQueue has been abandoned
2021-05-08 23:12:21.872 16145-16229/com.simpleexo W/SurfaceUtils: failed to get consumer usage bits. ignoring
2021-05-08 23:12:21.872 16145-16229/com.simpleexo D/SurfaceUtils: set up nativeWindow 0x760d467010 for 1600x900, color 0x7fa30c06, rotation 0, usage 0x20002900
2021-05-08 23:12:21.872 16145-16229/com.simpleexo E/BufferQueueProducer: [ImageReader-1600x900f23m5-16145-0] query: BufferQueue has been abandoned
2021-05-08 23:12:21.872 16145-16229/com.simpleexo E/ACodec: NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS query failed: No such device (19)
2021-05-08 23:12:21.872 16145-16229/com.simpleexo E/ACodec: Failed to allocate buffers after transitioning to IDLE state (error 0xffffffed)
2021-05-08 23:12:21.872 16145-16229/com.simpleexo E/ACodec: signalError(omxError 0x80001001, internalError -19)
2021-05-08 23:12:21.872 16145-16228/com.simpleexo E/MediaCodec: Codec reported err 0xffffffed, actionCode 0, while in state 5
2021-05-08 23:12:21.863 16145-16145/com.simpleexo W/MediaCodec_loop: type=1400 audit(0.0:2242): avc: denied { read } for name="u:object_r:display_color_prop:s0" dev="tmpfs" ino=19468 scontext=u:r:untrusted_app:s0:c46,c257,c512,c768 tcontext=u:object_r:display_color_prop:s0 tclass=file permissive=0 ppid=789 pcomm="main" pgid=16145 pgcomm="com.simpleexo"
2021-05-08 23:12:21.873 16145-16228/com.simpleexo E/libc: Access denied finding property "persist.sys.colorgamut.mode"
2021-05-08 23:12:21.874 16145-16229/com.simpleexo E/ACodec: [OMX.qcom.video.decoder.avc] ERROR(0x80001012)
2021-05-08 23:12:21.874 16145-16229/com.simpleexo E/ACodec: signalError(omxError 0x80001012, internalError -2147483648)
2021-05-08 23:12:21.874 16145-16229/com.simpleexo E/ACodec: [OMX.qcom.video.decoder.avc] ERROR(0x8000101c)
2021-05-08 23:12:21.874 16145-16229/com.simpleexo E/ACodec: signalError(omxError 0x8000101c, internalError -2147483648)
2021-05-08 23:12:21.874 16145-16229/com.simpleexo E/ACodec: [OMX.qcom.video.decoder.avc] ERROR(0x8000101c)
2021-05-08 23:12:21.874 16145-16229/com.simpleexo E/ACodec: signalError(omxError 0x8000101c, internalError -2147483648)
2021-05-08 23:12:21.874 16145-16229/com.simpleexo E/ACodec: [OMX.qcom.video.decoder.avc] ERROR(0x8000101c)
2021-05-08 23:12:21.874 16145-16229/com.simpleexo E/ACodec: signalError(omxError 0x8000101c, internalError -2147483648)
2021-05-08 23:12:21.874 16145-16229/com.simpleexo E/ACodec: [OMX.qcom.video.decoder.avc] ERROR(0x8000101c)
2021-05-08 23:12:21.874 16145-16229/com.simpleexo E/ACodec: signalError(omxError 0x8000101c, internalError -2147483648)
2021-05-08 23:12:21.874 16145-16228/com.simpleexo D/SurfaceUtils: disconnecting from surface 0x760d467010, reason disconnectFromSurface
2021-05-08 23:12:21.876 16145-16228/com.simpleexo E/MediaCodec: Codec reported err 0x80001012, actionCode 0, while in state 0
2021-05-08 23:12:21.890 16145-16228/com.simpleexo E/MediaCodec: Codec reported err 0x8000101c, actionCode 0, while in state 0
2021-05-08 23:12:21.925 16145-16228/com.simpleexo E/MediaCodec: Codec reported err 0x8000101c, actionCode 0, while in state 0
2021-05-08 23:12:21.943 16145-16228/com.simpleexo E/MediaCodec: Codec reported err 0x8000101c, actionCode 0, while in state 0
2021-05-08 23:12:21.973 16145-16228/com.simpleexo E/MediaCodec: Codec reported err 0x8000101c, actionCode 0, while in state 0
2021-05-08 23:12:22.043 16145-16145/com.simpleexo W/ExoPlayer:Playb: type=1400 audit(0.0:2243): avc: denied { read } for name="u:object_r:display_color_prop:s0" dev="tmpfs" ino=19468 scontext=u:r:untrusted_app:s0:c46,c257,c512,c768 tcontext=u:object_r:display_color_prop:s0 tclass=file permissive=0 ppid=789 pcomm="main" pgid=16145 pgcomm="com.simpleexo"
2021-05-08 23:12:22.061 16145-16217/com.simpleexo E/libc: Access denied finding property "persist.sys.colorgamut.mode"
2021-05-08 23:12:22.066 16145-16217/com.simpleexo W/MediaCodecRenderer: Failed to initialize decoder: OMX.qcom.video.decoder.avc
android.media.MediaCodec$CodecException: start failed
at android.media.MediaCodec.native_start(Native Method)
at android.media.MediaCodec.start(MediaCodec.java:2068)
at com.google.android.exoplayer2.mediacodec.SynchronousMediaCodecAdapter.start(SynchronousMediaCodecAdapter.java:66)
at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.initCodec(MediaCodecRenderer.java:1113)
at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.maybeInitCodecWithFallback(MediaCodecRenderer.java:1011)
at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.maybeInitCodecOrBypass(MediaCodecRenderer.java:578)
at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.onInputFormatChanged(MediaCodecRenderer.java:1420)
at com.google.android.exoplayer2.video.MediaCodecVideoRenderer.onInputFormatChanged(MediaCodecVideoRenderer.java:694)
at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.readToFlagsOnlyBuffer(MediaCodecRenderer.java:965)
at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.render(MediaCodecRenderer.java:811)
at com.google.android.exoplayer2.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:948)
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:280)
at android.os.HandlerThread.run(HandlerThread.java:65)
2021-05-08 23:12:22.070 16145-16217/com.simpleexo E/ExoPlayerImplInternal: Playback error
com.google.android.exoplayer2.ExoPlaybackException: MediaCodecVideoRenderer error, index=0, format=Format(1, null, null, video/avc, avc1.4D4028, -1, null, [1600, 900, 50.021015], [-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:280)
at android.os.HandlerThread.run(HandlerThread.java:65)
Caused by: com.google.android.exoplayer2.mediacodec.MediaCodecRenderer$DecoderInitializationException: Decoder init failed: OMX.qcom.video.decoder.avc, Format(1, null, null, video/avc, avc1.4D4028, -1, null, [1600, 900, 50.021015], [-1, -1])
at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.maybeInitCodecWithFallback(MediaCodecRenderer.java:1018)
at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.maybeInitCodecOrBypass(MediaCodecRenderer.java:578)
at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.onInputFormatChanged(MediaCodecRenderer.java:1420)
at com.google.android.exoplayer2.video.MediaCodecVideoRenderer.onInputFormatChanged(MediaCodecVideoRenderer.java:694)
at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.readToFlagsOnlyBuffer(MediaCodecRenderer.java:965)
at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.render(MediaCodecRenderer.java:811)
at com.google.android.exoplayer2.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:948)
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:280)
at android.os.HandlerThread.run(HandlerThread.java:65)
Caused by: android.media.MediaCodec$CodecException: start failed
at android.media.MediaCodec.native_start(Native Method)
at android.media.MediaCodec.start(MediaCodec.java:2068)
at com.google.android.exoplayer2.mediacodec.SynchronousMediaCodecAdapter.start(SynchronousMediaCodecAdapter.java:66)
at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.initCodec(MediaCodecRenderer.java:1113)
at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.maybeInitCodecWithFallback(MediaCodecRenderer.java:1011)
at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.maybeInitCodecOrBypass(MediaCodecRenderer.java:578)
at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.onInputFormatChanged(MediaCodecRenderer.java:1420)
at com.google.android.exoplayer2.video.MediaCodecVideoRenderer.onInputFormatChanged(MediaCodecVideoRenderer.java:694)
at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.readToFlagsOnlyBuffer(MediaCodecRenderer.java:965)
at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.render(MediaCodecRenderer.java:811)
at com.google.android.exoplayer2.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:948)
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:280)
at android.os.HandlerThread.run(HandlerThread.java:65)
I would happily share the test video too, how can I do that to keep its format, encoding and all parameters?
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
MediaCodec - Android Developers
You normally cannot access the raw video data when using a Surface, but you can use the ImageReader class to access unsecured decoded...
Read more >Camera2 ImageReader hangs after a while with "Failed to ...
I've create a capture request and added an ImageReader as a target. Then on the OnImageAvailableListener, i'm getting the image, transforming it ...
Read more >Common uploading errors - YouTube Help
If you're having problems uploading your video, select the error message you're seeing and follow the troubleshooting steps to solve your issue.
Read more >MediaPlayer | Android Developers
MediaPlayer class can be used to control playback of audio/video files and ... the MediaPlayer objects created using new is in the Idle...
Read more >US5329104A - Automatically identifying decode apparatus - Google ...
one of the decoders successfully decoding the digital data outputs decoded data ... In this case, a decode failure signal F1 is output...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’d guess that this is the default color format for whatever hardware codec is selected for the device you are testing on, and that overriding the color format in the codec configuration MediaFormat might fix the issue.
The reason the emulator works is probably that it’s using a software decoder that outputs to a more “standard” color format. If you were to override the renderer’s
MediaCodecSelector
to pick one of the software decoders I expect you’d see the same behavior on emulator and real device (but this is inefficient compared to using hardware decoding, so it’s worth trying to get that to work before resorting to using a software decoder).Good to know. Thanks for trying this!
I’d just not call through to
super.buildVideoRenderers
if the goal is always to useMyVeryOwnMediaCodecVideoRenderer
(then you don’t need to worry about clearing). See the implementation ofDefaultRenderersFactory.createRenderers
to understand how it works.