I want to upload video to server, when I catch video from gallery or record from camera , the server response to me that error but when I upload video with size 2 MB , it is uploading successfully. How can I compress the video to reduce the size? I uploaded the video from face book , the size of video on my mobile is 140 MB , but face book make a process on the video and reduce it's size to 1.35 MB
2 Answers
You have two way to do that:
Encode it to a lower bit rate and/or lower resolution. Have a look here: Is it possible to compress video on Android?.
Try to zip/compress it. Have a look here: http://www.jondev.net/articles/Zipping_Files_with_Android_%28Programmatically%29
Unfortunately I never tried to do that with a 140MB video. This is why I suggested to you the first library (FFmpeg 4 Android).
By the way, try to increase also your UPLOAD_LIMIT on your server. But this is not the problem, even if you increase it to 10MB you still have to compress it. Do not try to increase the UPLOAD_LIMIT to 140MB, it will cause for sure an HTTP timeout.
Otherwise you need to enable a chunked upload.
Have a look on this discussion:
Android: OutOfMemoryError while uploading video - how best to chunk?
-
thanks i have been used the first solution to compress video in size 140 MB to 1.63 MB but the facebook compress to 1.34 with higher resolution than my video , but thank You gave me the starting pointز – mostafa hashim Mar 26 '15 at 15:17
-
probably they use different algorithm. You can try to zip it, for sure it will be reduced more. – erlangb Mar 26 '15 at 16:01
-
Please can you explain this command cammand = "ffmpeg -y -i " + demoVideoPath + "-strict experimental -s 338x426 -r 29 -vcodec mpeg4 -b 150k -ab 48000 -ac 2 -ar 22050 " + outpath; – mostafa hashim Mar 26 '15 at 17:10
-
I know that the 338x426 is the resolution and r 29 is the frames/second – mostafa hashim Mar 26 '15 at 17:15
-
but what is the other ? I try to enhance the quality of my compressed video – mostafa hashim Mar 26 '15 at 17:16
-
@mostafa ..Hello Can u share any links or demo to use ffmeg for video compression ? – Yyy Sep 24 '16 at 13:45
-
@NancyY check this link may help you https://github.com/WritingMinds/ffmpeg-android-java if failed to deal with it , you can contact me on mostafa.hashim90@gmail.com , so I can share my code with you – mostafa hashim Sep 25 '16 at 09:30
-
2nd link is dead ! – King of Masses Aug 23 '17 at 09:17
-
@MashukKhan maybe is too old :( – erlangb Sep 13 '17 at 12:39
You can try using ffmpeg to reencode it with a lower bitrate, e.g.:
If you are trying to convert 140 MB to 1MB then
Calculate the bitrate you need by dividing your target size (in bits) by the video length (in seconds). For example for a target size of 1MB which is 8000000bits and 300 seconds of video, use a bitrate of approx 26 667 bit/s(i.e 27kbit/s):
ffmpeg -i input.mp4 -b 27k output.mp4
Other options that might be worth by setting Constant Rate Factor, which lowers the average bit rate, but retains better quality. Vary the CRF between around 18 and 24.
ffmpeg -i input.mp4 -vcodec libx264 -crf 20 output.mp4
Happy coding :)

- 1,451
- 3
- 19
- 26