简体   繁体   English

在Android上使用MediaCodec编码视频

[英]Encoding a video with MediaCodec on Android

currently, I am playing a video on a GLSurfaceView using OpenGL ES 2.0. 目前,我正在使用OpenGL ES 2.0在GLSurfaceView上播放视频。 Now, I am searching for a way to encode this video played on the surface view into a MP4 video using MediaCodec. 现在,我正在寻找一种使用MediaCodec将表面视图上播放的视频编码为MP4视频的方法。

Therefore, I found the bigflake example, which seems to solve my issue perfectly ( http://bigflake.com/mediacodec/EncodeAndMuxTest.java.txt ). 因此,我找到了bigflake示例,它似乎可以完美地解决我的问题( 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. 本示例使用mEncoder.createInputSurface()创建输入源,但是我有一个实际播放视频的GLSurfaceView。 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(). 由于使用的是GLSurfaceView,因此需要在onDrawFrame()中插入拦截代码,同时在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. 拦截器可以通过复制着色器将egl场景复制到帧缓冲区中的形式来完成。 And then do swapbuffer to encode frame. 然后做swapbuffer编码帧。 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 尝试在https://software.intel.com/zh-cn/articles/intel-inde-media-pack-for-android-tutorials-video-capturing-for-opengl-applications上查看任意Elg场景捕获的教程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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