简体   繁体   中英

Encoding a video with MediaCodec on Android

currently, I am playing a video on a GLSurfaceView using OpenGL ES 2.0. Now, I am searching for a way to encode this video played on the surface view into a MP4 video using MediaCodec.

Therefore, I found the bigflake example, which seems to solve my issue perfectly ( http://bigflake.com/mediacodec/EncodeAndMuxTest.java.txt ).

However, it seems that I am too stupid to set the input source right. This example uses mEncoder.createInputSurface() to create the input source, however I have a GLSurfaceView where the video is actually played. So how do I set my own surface as input source for the encoder?

Since you are using GLSurfaceView, you need to insert intercepting code in onDrawFrame(), while allocating surface in onSurfaceCreated(). Input surface can be created as usual after setting up encoder parameters. Interceptor can be done in a form of copying egl scene into frame buffer via copying shader. And then do swapbuffer to encode frame. Try look at tutorial for arbitrary elg scene capturing at https://software.intel.com/en-us/articles/intel-inde-media-pack-for-android-tutorials-video-capturing-for-opengl-applications

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM