问题描述
在我的 Android 应用中,我想通过更改分辨率和比特率来压缩 mp4 视频.不想用FFmpeg(因为不想用NDK),所以决定用MediaCodec API.
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.
这是我的逻辑步骤:
- 使用 MediaExtractor 提取视频文件,然后解码数据.
- 使用我的新分辨率、比特率和编码数据创建新的编码器.
- 使用 MediaMuxer 创建新的 mp4 文件.
我的问题是:我不知道如何设置解码器输出和编码器输入之间的连接.我可以将视频解码到 Surface 或从 Surface 编码新视频.但我不明白如何连接它们.
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.
我阅读了这些链接:Android MediaCodec:减小 mp4 视频大小,使用新的 MediaCodec 库在 android 上压缩视频 和来自Bigflake:https://android.googlesource.com/platform/cts/+/jb-mr2-release/tests/tests/media/src/android/media/cts/DecodeEditEncodeTest.java
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?
推荐答案
我已经用这个来了解如何在 android 中操作视频:https://github.com/hoolrory/AndroidVideoSamples ,检查 VideoResampler.java
在 CommonVideoLibrary
中.
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 视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!