How to compress mp4 video using MediaCodec Android?

不羁岁月 提交于 2019-11-27 20:19:48

问题


In my Android app, I want to compress mp4 video by changing its resolution, bitrate. I don't want to use FFmpeg (because I don't want to use NDK), so I decided to use MediaCodec API.

Here are my logical steps:

  1. Extract video file with MediaExtractor, then decode data.
  2. Create new encoder with my new resolution, bitrate and encode data.
  3. Using MediaMuxer to create a new mp4 file.

My problem is: I don't know how to setup the connection between output of decoder and input of encoder. I can decode the video to a Surface or encode a new video from a surface. But I don't understand how to connect them.

I read these links: Android MediaCodec: Reduce mp4 video size, Video compression on android using new MediaCodec Library and the example from Bigflake: https://android.googlesource.com/platform/cts/+/jb-mr2-release/tests/tests/media/src/android/media/cts/DecodeEditEncodeTest.java

Can anybody give me a clear explanation what I have to do?


回答1:


I have used this to see how to manipulate video in android: https://github.com/hoolrory/AndroidVideoSamples , check the VideoResampler.java in the CommonVideoLibrary .



来源:https://stackoverflow.com/questions/30842668/how-to-compress-mp4-video-using-mediacodec-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!