Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Compress video file in android

I want to compress video file before uploading to server.I gone through this link How to compress a video to maximum level android, but i did not get an answer. Can anyone help me ??

like image 841
Divya Avatar asked Jun 20 '14 10:06

Divya


People also ask

How do I reduce the size of a video on Android?

Switching to the HD resolution or FHD resolution video resolution will reduce the file size by a huge margin. You should know that reducing the resolution will also reduce the overall quality of the video. So, to keep a balance between the quality and file size, we recommend using FHD resolution.


2 Answers

Give this a try

mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));     
mediaRecorder.setVideoEncodingBitRate(690000 );
like image 162
Badrul Avatar answered Oct 01 '22 21:10

Badrul


We can compress video using ffmpeg in android.

For integrating FFmpeg in android we can use precompiled libraries like ffmpeg-android.

You can use below command to compress video

String[] command = {"-y", "-i", inputFileAbsolutePath, "-s", "160x120", "-r", "25", "-vcodec", "mpeg4", "-b:v", "150k", "-b:a", "48000", "-ac", "2", "-ar", "22050", outputFileAbsolutePath};

Here,

-y

Overwrite output files without asking.

-i

ffmpeg reads from an arbitrary number of input “files” specified by the -i option

-s

video output size

-r

Set frame rate

-vcodec

Set the video codec.

-b:v

Set the video bitrate

-b:a

Set the audio bitrate

-ac

Set the number of audio channels.

-ar

sets the sampling rate for audio streams if encoded

For detailed explanation and code on using ffmpeg in android to edit videos,check out below ffmpeg video editor tutorial link on my blog which includes compressing video using ffmpeg-

https://androidlearnersite.wordpress.com/2017/03/17/ffmpeg-video-editor/

like image 21
Android Developer Avatar answered Oct 01 '22 22:10

Android Developer