Android的媒体codeC:减少MP4视频大小 [英] Android MediaCodec: Reduce mp4 video size

查看:1133
本文介绍了Android的媒体codeC:减少MP4视频大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找一种方式来COM preSS的mp4视频。要做到这一点,我想降低视频的分辨率和/或降低FPS。

I am looking for a way to "compress" an mp4 video. To achieve this, I want to reduce the resolution of the video and / or reduce FPS.

长期的研究后,我认为这样做是利用媒体codeC和相关API如下的方式:

After long research, I think the way to do it is to use MediaCodec and related APIs as follows :

- > MediaExtractor从一个MP4文件中提取连接codeD介质的数据。 - >媒体codeC(德codeR):德code每一帧进行后续处理。 - >媒体codeC(恩codeR):在这一点上,我想这就是我们要建立MediaFormat参数,如视频分辨率,这将有助于我们减少了MP4文件的最终大小。 - > MediaMuxer的生成MP4文件(MinSDK 18,这可能是一个问题,但现在...... OK)

-> MediaExtractor to extract encoded media data from a mp4 file. -> MediaCodec (Decoder): Decode each frame for later processing. -> MediaCodec (Encoder): At this point, I guess that's where we should establish MediaFormat parameters such as video resolution, which should help us to reduce the final size of the mp4 file. -> MediaMuxer for generate mp4 file (MinSDK 18, this might be a problem, but for now... ok) .

我不希望使用SurfaceView / TextureView。 至于声音,我不想对其进行处理,以降低质量。

I don't want to use a SurfaceView/TextureView. Regarding the audio, I don't want to process it to reduce quality.

我一直期待在这里所有的例子: http://bigflake.com/media$c$cc/

I've been looking at all the examples here: http://bigflake.com/mediacodec/

我也看到了CTS源$ C ​​$ C模块。

I've also seen CTS source code modules.

和我一直在看的几个项目,如这些: <一href="https://github.com/vecio/Media$c$ccDemo/blob/master/src/io/vec/demo/media$c$cc/De$c$cActivity.java">https://github.com/vecio/Media$c$ccDemo/blob/master/src/io/vec/demo/media$c$cc/De$c$cActivity.java

And I've been looking at several projects like these: https://github.com/vecio/MediaCodecDemo/blob/master/src/io/vec/demo/mediacodec/DecodeActivity.java

当然,我看过几十个职位的计算器。

And of course I have read dozens of posts on stackoverflow.

现在的问题是,我还没有发现很适合这个porpuse任何code例子。我试图采取各种件code,并把它们放在一起在一个项目上,但并没有真正的工作。

The problem is that I have not yet found any code example that works well for this porpuse. I tried to take various pieces of code and put them together on a project, but does not really work.

感谢。

推荐答案

最接近你想要的可能是的德codeEditEn codeTEST 上bigflake。你不需要 SurfaceView TextureView ,因为你不是要显示视频,但您需要使用表面纹理

The closest thing to what you want is probably the DecodeEditEncodeTest on bigflake. You don't need SurfaceView or TextureView, since you're not trying to display the video, but you will need to use a SurfaceTexture.

测试code生成一个视频,然后去codeS /编辑/ EN codeS,然后测试连接codeD输出。你想要去code-编辑-CN code部分。在创建连接codeR,给它任何你想要的大小。它创建的输入表面将大小以匹配。该比例由GPU完成,因为它呈现GL纹理(从表面纹理)到EN codeR的输入表面。你必须决定是否GLES线性滤波提供优质的,你需要的水平。

The test code generates a video, then decodes / edits / encodes, then tests the encoded output. You want the decode-edit-encode part. When creating the encoder, give it whatever size you want. The input surface it creates will be sized to match. The scaling is performed by the GPU as it renders the GL texture (from the SurfaceTexture) onto the encoder's input surface. You'll have to decide whether GLES linear filtering provides the level of quality you need.

(你可以看到在 ExtractMpegFramesTest 相似,这一切都扩展到640×480的它做的提取。在这种情况下,它转换帧为PNG而不是将它们送入一间codeR,所以它不是适用于您的情况。)

(You can see something similar in ExtractMpegFramesTest, which scales everything to 640x480 as it's doing the extraction. In this case it's converting the frames to PNG rather than feeding them into an encoder, so it's not as applicable to your situation.)

丢帧在理论上是很简单:就是不提交给EN codeR。实际上这是一个有点困难,如果输入具有不规则隔开的帧。如果输入的是帧1帧2 ......暂停......窗口4 frame5,而你放下帧2,你最终会暂停在帧1,这可能看起来怪怪的。您可以使用presentation时间戳弄清楚的时机。

Dropping frames is theoretically easy: just don't submit it to the encoder. In practice it's a bit harder if the input has irregularly-spaced frames. If the input is "frame1 frame2 ... pause ... frame4 frame5", and you drop frame2, you'll end up paused on frame1, which might look weird. You can use the presentation time stamps to figure out the timing.

面输入和 MediaMuxer (需要保存H.264为.MP4​​)要求API 18+。对于老版本的Andr​​oid,你可能需要使用第三方库如的ffmpeg

Surface input and MediaMuxer (required for saving H.264 as .mp4) require API 18+. For older versions of Android you'll probably want to use a third-party library like ffmpeg.

这篇关于Android的媒体codeC:减少MP4视频大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆