Search code examples
androidopengl-esandroid-mediacodec

Saving video frame from GPU texture


I am attempting to use the GPU to do video processing. I have been so far successful in extracting the frames from a video, and processing them using the GPU. Please keep in mind that i'm a total OpenGL noob.

I have come across the following bottleneck however: getting the finished frame from the GPU and recording it into a video.

I am aware of this example, but it doesn't exactly suit my needs.

My openGL context is javax.microedition.khronos.egl.EGLContext, which prevents me from sharing textures between the one described by Bigflake's example and mine, which contains the texture i wish to write to the video.

Is there any way to feed the MediaCodec encoder data directly from the GPU? From my research it seems that one can only set a surface provided by the encoder itself as a source using this method.

Can I somehow draw my texture onto the surface provided by the encoder?

I will try to provide any additional details upon request.


Solution

  • I ended up replacing my EGL10 Context with an EGL14 one as @fadden suggested.

    I then shared this context with the one created by the CodecInputSurface like in this example.

    The most important step was rendering the shared texture to the surface defined by the second context. I did this with the help of this answer.

    I hope that this can be of help to anybody else, i will attempt to clarify if requested.

    Thanks again to fadden for his help :).