-
Notifications
You must be signed in to change notification settings - Fork 29
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
Speedup in Java code #4
Comments
Thanks. The original code barely achieved 4FPS in the emulator. |
Ancient bump... but: Swapping for this code gives me an ArrayOutOfBounds Exception on this line:
It seems like the pixel array isn't large enough to play this 1920x1080 video. Any thoughts? |
@dylanatkeylogic |
@alsaleem00 I see! This may be a very ignorant question, but if I'm using the library via jitpack/gradle implementation, where would I find the C++ file in question to edit? I can't seem to find it within the file structure. |
it is here . in the C++ code, change AV_PIX_FMT_RGB to AV_PIX_FMT_ARGB (3 places) |
Interesting - still having the same issue with the OutOfBoundsException. My pixels[] has a cap of 1,555,200, while the area of a 1080p video is 2073600 So my buffer is exactly .75 of the area of my screen - could I still have a pixel formatting issues after changing AV_PIX_FMT_RGB24 to AV_PIC_FMT_ARGB? |
1,555,200 = 4 x 1080 x 360, try debug: `
} |
Ch 3, w 1920, h 1080, all 6220800 On that java side, intBuf.remaining is: 1555200. Then an ArrayIndexOutOfBoundsException at
Thank you so much for helping by the way - I'm learning a lot here :) |
Update: In the actual callback call in native-lib.cpp, I upped the channel to 4
Now I do have an image but I'm maybe 2fps and it crashes after about 10 seconds with no error. |
The crash is because of that many frames stacking up before jave handles the request. Memory gets full. `
} |
Still no luck. Very weird! Any chance you could attach your native-lib.cpp? |
`
} |
#define UPDATE_TIME_MS (150) |
Instead of the for loop to create the bitmap in the java code, use this:
IntBuffer intBuf = ByteBuffer.wrap(frame).order(ByteOrder.BIG_ENDIAN).asIntBuffer(); int[] pixels = new int[intBuf.remaining()]; intBuf.get(pixels); bmp = Bitmap.createBitmap(pixels, width, height, Bitmap.Config.ARGB_8888); ivPreview.setImageBitmap(bmp);
It makes the code an order of magnitude faster!
Also, in the C++ code, change AV_PIX_FMT_RGB to AV_PIX_FMT_ARGB.
The text was updated successfully, but these errors were encountered: