Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting Exception ava.lang.UnsupportedOperationException: The producer output buffer format 0x1 doesn't match the ImageReader's configured buffer format 0x4. #1

Open
dudesarun opened this issue Aug 20, 2016 · 21 comments

Comments

@dudesarun
Copy link

Process: com.jni.screenshotter, PID: 1511
java.lang.UnsupportedOperationException: The producer output buffer format 0x1 doesn't match the ImageReader's configured buffer format 0x4.
at android.media.ImageReader.nativeImageSetup(Native Method)
at android.media.ImageReader.acquireNextSurfaceImage(ImageReader.java:298)
at android.media.ImageReader.acquireNextImage(ImageReader.java:344)
at android.media.ImageReader.acquireLatestImage(ImageReader.java:248)
at in.omerjerk.libscreenshotter.Screenshotter.onImageAvailable(Screenshotter.java:107)
at android.media.ImageReader$ListenerHandler.handleMessage(ImageReader.java:548)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

@omerjerk
Copy link
Owner

omerjerk commented Sep 9, 2016

On what device are you facing this issue if I may know? :)

@p0lipo
Copy link

p0lipo commented Sep 16, 2016

I have the same Issue on a Samsung S4 mini GT-I9195, Android Version 6.0.1.

@Fishfield
Copy link

I also have the same crash on my Nexus 5x. If I use ARGB_8888 it doesn'T crash, but i get a black image. Would be nice if you could figure out what's wrong. I was investigating the last two days to get an image (bitmap) out of the current screen...

@moster67
Copy link

moster67 commented Oct 2, 2016

I changed as follows:
//mImageReader = ImageReader.newInstance(width, height, ImageFormat.RGB_565, 2);
mImageReader = ImageReader.newInstance(width, height, PixelFormat.RGBA_8888, 2);

Seems to work

@Fishfield
Copy link

@moster67 I also tried this one, but just got a black image on my Nexus 5x. Do you get a correct image?

@omerjerk
Copy link
Owner

omerjerk commented Oct 4, 2016

I'm really sorry. I realise that this issue is bugging a lot people.
In my opinion, the only solution is to avoid the ImageReader API altogether and use OpenGL APIs.
The only thing blocking me to implement it is just that it's too much of work and I don't have much motivation for that. :(

@moster67
Copy link

moster67 commented Oct 4, 2016

@Fishfield I tried on Nexus4 but I will this evening try on some other devices and then report back.

@moster67
Copy link

moster67 commented Oct 4, 2016

@omerjerk No worries. I still appreciate your work and that you shared it with us.

@Fishfield
Copy link

I searched around in the interenet a lot the last months and the solution with the ImageReader API was the most found answer. I am just curious why it worked for them although the solution was exactly the same as mine. @omerjerk did it ever work for you?

@Fishfield
Copy link

@omerjerk I am curious about how you implemented it in your screenshot application on the play store?

@Raphdeumax
Copy link

Hi,
When i try to screenshot a video on Youtube for example, i get a black bitmap in RGB format and if i change the format in ImageReader.newInstance to YUV i has the same error message.
Have you an idea ?

@omerjerk
Copy link
Owner

omerjerk commented Sep 1, 2017

Hi @Raphdeumax

If you are getting a black image while screenshotting youtube app, it might be possible that youtube has made it's display secure. You can read about secure display here - https://developer.android.com/reference/android/view/Display.html#FLAG_SECURE

@Raphdeumax
Copy link

@omerjerk, Thanks for your repsonse, i will investigate on the secure flag.
I has appreciate your work ;-)

@Raphdeumax
Copy link

For information, i has the same problem using OpenGL.

@Raphdeumax
Copy link

Hello,
After testing, the FLAG_SECURE has no link to the black screen when capturing video. Small question, what is the role of the mediaencoder when using MediaProjection?

thank you

@musictrek1964
Copy link

mImageReader = ImageReader.newInstance(width, height, PixelFormat.RGBA_8888, 2)

worked on my Samsung phone, but no save to media folder as of yet

@JmSeason
Copy link

JmSeason commented Mar 6, 2022

The producer output buffer format is 0x1 in some android emulator,and is 0x2 in some android emulator, I don't get the compatible idea

@JmSeason
Copy link

JmSeason commented Mar 6, 2022

I think what can we do is catch the exception and get the producer output format info, then recreate the ImageReader in the format

@Ronkiro
Copy link

Ronkiro commented Nov 5, 2024

I changed as follows: //mImageReader = ImageReader.newInstance(width, height, ImageFormat.RGB_565, 2); mImageReader = ImageReader.newInstance(width, height, PixelFormat.RGBA_8888, 2);

Seems to work

I got an error saying that PixelFormat.RGBA_8888 wasn't an accepted type. I just added @SuppressLint("WrongConstant") and it worked (hope it also does to everyone)

@jeffasd
Copy link

jeffasd commented Dec 4, 2024

For the Camera you get to pick one of two output formats (NV21 or YV12), so pick YV12. That's your raw YUV data. For screen capture Or Opengl es render the output will always be RGB or RGBA, so you need to pick RGBA_8888 (format 0x1) for your ImageReader, rather than YUV_420_888 (format 0x23). If you need YUV for that, you will have to do the conversion yourself. The ImageReader gives you a series of Plane objects, not a byte[], so you will need to adapt to that.

@jeffasd
Copy link

jeffasd commented Dec 4, 2024

change code to
ImageReader imageReader = ImageReader.newInstance(width, height, PixelFormat.RGBA_8888, 4);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants