Android: How to Solve Video Compression by Jay May 17, 2016 < 1 Minute ReadA 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. [code language=”html”] 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); [/code] 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 Related Posts: What’s new in Android 4.4 ‘KitKat’ for Developers Various Resourceful Places to Find Amazing New Android Apps for Android Development Android’s Fragmentation – Still A Problem For Android Developers Tags: Android, Code Jayadev Das email@example.com Do what you do best in – that’s what I’ve always believed in and that’s what I preach. Over the past 25+ years (yup that’s my expertise ‘n’ experience in the Information Technology domain), I’ve been consulting to small, medium and large companies ‘bout Web Technologies, Mobile Future as well as on the good-and-bad of tech. Blogger, International Business Advisor, Web Technology Expert, Sales Guru, Startup Mentor, Insurance Sales Portal Expert & a Tennis Player. And top of all – a complete family man!