Android make mp4 video file smaller

160 Views Asked by At

Is there a way to quickly implement a size reduction of an mp4 video file? 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! I can't believe there is no high level APIs to do this.

Here is an example how it is done in 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! Is there something similar to this in Android?

1

There are 1 best solutions below

1
ChrisBe On

At this time there is no higher abstraction level for what you want to achieve in the AOSP. If you don't want to experiment with MediaCodec etc. there are libraries you can use.

Transcoder for example looks like a promising project. 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