Comments (4)
Is OpenGL even the right tool for the job? It feels like setting up a rendering context etc is a large overhead, especially because I am now working in RGB instead of YUV/PRIVATE.
It should be ok to use OpenGL for "image processing" and then draw the result into the input Surface
of a MediaCodec
or MediaRecoder
.
BUT It's not so efficient to retrieve 'RGB' values by calling glReadPixels
. glReadPixels
is a blocking operation, I recommend you use some other async approaches instead, e.g.
- create an
ImageReader
instance with its format set toRGB_888
- get the input
Surface
of thisImageReader
- draw the processed image into the input
Surface
- you'll get an
OnImageAvaiable
callback once thedraw
operation is completed
See androidx for more details.
Note: If you want to get YUV instead of RGB, here are two choices for you:
- OpenGL 2.0: do
RGB->YUV
conversion in your fragment shader that is used in step 3
(It's your responsibility to determine how YUV values are stored,RGB888
should always be the most suitable format ofImageReader
for this case) - OpenGL 3.0: use
GL_EXT_YUV_target
extension in your fragment shader that is used in step 3
(this extension ONLY supportsYUV444
, it is compatible withRGB888
the format ofImageReader
used in this case)
from grafika.
Thanks for your reply!
I'm currently going through an ImageReader -> ImageWriter setup (USAGE_GPU_SAMPLED_IMAGE
), here's the code for that: https://github.com/mrousavy/react-native-vision-camera/blob/e845dc8397d2f53804cd755b7f73e6747a916bbb/package/android/src/main/java/com/mrousavy/camera/core/VideoPipeline.kt#L84-L113
This seems a bit unstable and some devices had problems with that, but to confirm; that'd be the recommended approach to get access to the raw Camera frames before passing them along to a MediaRecorder, right?
from grafika.
Detaching an Image
from one BufferQueue
and then attaching the Image
to another BufferQueue
is the easiest way on Android to forward an Image
to other "consumers".
The underlying pixel format that is chosen for this special use case (PRIVATE format combined with USAGE_GPU_SAMPLED_IMAGE usage) is implementation-defined and depends on the contract between Gralloc and GL driver. In most cases, though, the pixel format should be YUV_420_888
, you still need to confirm it if you want to read pixels and then process them on CPU.
About the combination USAGE_GPU_SAMPLED_IMAGE | USAGE_CPU_READ_OFTEN
, I also don't know whether it is guaranteed to be supported by Qcom, MTK, and so on. Sorry :(
from grafika.
Well, that sucks. Is there no alternative to this? I guess it's just gonna work on some phones, and won't work on others?
from grafika.
Related Issues (20)
- Extend encode/decode test example with asynchronous API
- Sound not available in Video using CameraCaptureActivity HOT 1
- how can i remove shape HOT 1
- how can i add shapes in texture view using open gl
- glReadPixels returns a blank image on disabling blend
- Decoding four video streams simultaneous on Google Pixel 2 phone
- seconds of video in Continuous Capture mode becomes double after keeping it on for a while. HOT 3
- If you want to record mp4 with sound, use this one https://github.com/moo611/OpenCamera
- Memory leak of Texture2dProgram
- Continuous capture bug(Android5.1.1) HOT 1
- Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x38 in tid 9379, pid 9379
- Some OpenGL stuff doesn't work on some devices: eglMakeCurrent failed and glDrawArrays: glError 0x505 HOT 4
- How to show front and back camera simultaneously? HOT 5
- Can we play scene.json in grafika?
- Test HOT 1
- Doesn't build on Flamingo and Giraffe HOT 2
- fun fact HOT 1
- Camera2 Pass Images from ImageReader to MediaRecorder HOT 2
- Website
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grafika.