Android: How to Solve Video Compression

Android Video Compression
Social sharing

A high quality recording by an Android phone for 30 seconds is around 40 to 45 MB in size; storage space is not a concern now-a-days! However, it is a concern for anyone while sharing the video through an app or mail. For example, sharing it in WhatsApp is a problem, as the app does not support videos more than 16 MB in size. This article will help you in Video Compression so that you can share it easily!

What is Video Compression?
Video compression uses modern coding techniques to reduce redundancy in video data. Most video compression algorithms and codecs combine spatial image compression and temporal motion compensation. Most video codecs also use audio compression techniques in parallel to compress the separate, but combined data streams as one package.

To implement the video compression in Android we need a video to be recorded with the surfaceView and a Media recorder. Therefore, before starting a video recording we need to set the required parameters to the Media recorder like the Video Frame Rate, Video Size, Video Encoder, and Video Encoding Bitrate.

Compressing a video of 20MB can reduce to 2 to 4 MB, helping users to a much faster sharing/uploading.

Here’s the code snippet for compressing a video file in the Android app.

mediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT); 
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mediaRecorder.setVideoEncodingBitRate(690000);
mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mediaRecorder.setVideoFrameRate(30);
mediaRecorder.setVideoSize(640, 480);

Conclusion

Compressed video files will take less time to Upload, Sync, Share while saving storage space. However, compressing a video file may reduce the video quality depending upon the settings that have been applied.

Sources: http://bit.ly/1WBuhEX, http://bit.ly/27w20CY

Your recently viewed posts:

    Contact Us

    We’d love to help & work with you




    When do you want to start ?


    Enter your email address to stay up to date with the latest news.
    Holler Box

    Orange Exit pop up

    Subscribe for the latest
    trends in web and
    mobile app development
    Holler Box

    Exit pop up

    Sad to see you leaving early...

    From "Aha" to "Oh shit" we are sharing everything on our journey.
    Enter your email address to stay up to date with the latest news.
    Holler Box