简体   繁体   English

Android 使mp4视频文件更小

[英]Android make mp4 video file smaller

Is there a way to quickly implement a size reduction of an mp4 video file?有没有办法快速实现 mp4 视频文件的大小缩减? Say, I have a full-HD video recorded on the device camera and I need to transfer it over the network so I need to make the video size smaller.比如说,我在设备摄像头上录制了一个全高清视频,我需要通过网络传输它,所以我需要使视频尺寸更小。

I have read a bunch of docs about MediaCodec , MediaExtractor , MediaMuxer , etc, however all the examples were like several hundred lines of code.我已经阅读了一堆关于MediaCodecMediaExtractorMediaMuxer等的文档,但是所有的例子都像是几百行代码。 I can't believe there is no high level APIs to do this.我不敢相信没有高级 API 可以做到这一点。

Here is an example how it is done in iOS:这是一个在 iOS 中如何完成的示例:

    let urlAsset = AVURLAsset(url: inputURL, options: nil)
    exportSession = AVAssetExportSession(asset: urlAsset, presetName: AVAssetExportPresetMediumQuality)
    exportSession.outputURL = outputURL
    exportSession.outputFileType = AVFileType.mp4
    exportSession.shouldOptimizeForNetworkUse = true
    exportSession.exportAsynchronously { // DONE! }

That's it, 6 lines of code!就是这样,6行代码! Is there something similar to this in Android? Android中是否有类似的东西?

At this time there is no higher abstraction level for what you want to achieve in the AOSP.此时,您想要在 AOSP 中实现的目标没有更高的抽象级别。 If you don't want to experiment with MediaCodec etc. there are libraries you can use.如果您不想尝试使用MediaCodec等,可以使用一些库。

Transcoder for example looks like a promising project.例如, Transcoder看起来是一个很有前途的项目。 It uses strategies i have used myself.它使用我自己使用的策略。 Like letting the codec fail instead of assuming what will happen beforehand.就像让编解码器失败而不是事先假设会发生什么。 It also offers a lot of non standard operations.它还提供了许多非标准操作。

I'm not affiliated with the project nor have i used it myself我不隶属于该项目,我自己也没有使用它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM