Render Bitmap frames to Surface for encoding

前端 未结 3 1677
清酒与你
清酒与你 2020-12-11 09:53

My goal is to take in a M4V video file, decode a segment of the video as PNG frames, modify these frames, and re-encode the trimmed video (also to M4V).

The workflow

3条回答
  •  北海茫月
    2020-12-11 10:25

    I was able to render bitmap frames to a surface for encoding. I used MediaCodec + MediaMuxer to encode bitmap frames using the InputSurface and rendering the bitmaps using OpenGL.

    Looks like all you are missing is open gl commands to render the texture

    To fix this issue I also added some additional open gl commands to render the texture using a vertex shader.

    See this project and util class for more details on rendering a texture using open gl https://github.com/rsri/Pic2Fro/blob/b4fe69b44343dab2515c3fd6e769f3370bf31312/app/src/main/java/com/pic2fro/pic2fro/util/Util.java

    Calling the renderTexture(..) with the texture handle and appropriate width and height after GLUtils.texImage2D(..) in your snippet will fix all bitmap rendering issues.

    See also my related answer here https://stackoverflow.com/a/49331295/7602598

提交回复
热议问题