如何使用MediaCodec Android压缩mp4视频? [英] How to compress mp4 video using MediaCodec Android?
问题描述
在我的Android应用程式中,我想通过更改其分辨率,bitrate来压缩mp4视频。我不想使用FFmpeg(因为我不想使用NDK),所以我决定使用MediaCodec API。
这是我的逻辑步骤: / p>
- 使用MediaExtractor解压缩视频文件,然后解码数据。
- 使用我的新分辨率创建新编码器,比特率和编码数据。
- 使用MediaMuxer创建一个新的mp4文件。
是:我不知道如何建立解码器的输出和编码器的输入之间的连接。我可以将视频解码到Surface或从表面编码新视频。但我不明白如何连接它们。
我阅读这些链接: Android MediaCodec:减少mp4视频大小, Android上的视频压缩使用新的MediaCodec库和Bigflake中的示例: https://android.googlesource.com/platform/cts/+/jb-mr2-release/tests/tests/media/src /android/media/cts/DecodeEditEncodeTest.java
任何人都可以给我一个清楚的解释,我要做什么?
我使用这个方法来了解如何在Android中操作视频: https: //github.com/hoolrory/AndroidVideoSamples ,请检查 CommonVideoLibrary 中的%20'VideoResampler.java'> VideoResampler.java
。
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:
- Extract video file with MediaExtractor, then decode data.
- Create new encoder with my new resolution, bitrate and encode data.
- 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?
I have used this to see how to manipulate video in android: https://github.com/hoolrory/AndroidVideoSamples , check the VideoResampler.java
in the CommonVideoLibrary
.
这篇关于如何使用MediaCodec Android压缩mp4视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!