Wednesday, February 4, 2015

Video Compression on android application Using Java .

After a long period of time did R&D on Video Compression finally got good solution using java without using JNI (c,c++ ).

Here there is library called FFmpeg 4Android using this library u can compress video.

Download the ffmpeg4android_demo full source code from here:

Download the FFmpeg4Android Library from here:

Download above both of folders & import both in eclipse.i.e both should be import from same folder
like  ffmpegFloder folder
                     >> FFMPEGAndroidDemo
                    >> FFMPEFAndroidLib

Video Compress:

// simple regular commad
ffmpeg -y -i /sdcard/videokit/in.mp4 -strict experimental -s 160x120 -r 25 -vcodec mpeg4 -b 150k -ab 48000 -ac 2 -ar 22050 /sdcard/videokit/out.mp4

// compress with h264 (to support chrome)

ffmpeg -y -i /sdcard/videokit/in.mp4 -strict experimental -vcodec libx264 -preset ultrafast -crf 24 -acodec aac -ar 44100 -ac 2 -b:a 96k -s 320x240 -aspect 4:3 /sdcard/videokit/out3.mp4

// As complex command, don't forget to use setCommandComplex(complexCommand)

// Use this format to support files that contains spaces and special characters

String[] complexCommand = {"ffmpeg","-y" ,"-i", "/sdcard/video kit/in.mp4","-strict","experimental","-s", "160x120","-r","25", "-vcodec", "mpeg4", "-b", "150k", "-ab","48000", "-ac", "2", "-ar", "22050", "/sdcard/video kit/out.mp4"};

Adding FFMpeg support to your app (FFmpeg4Android  as Library):

Remove ffmpeg4android app from your device (if you have it installed) and remove the /sdcard/videokit folder.
Add the FFMpeg4Android project library (source code) as a new Android project. 
Download the demo client source which use the FFMpeg4Android library, both are ADT projects.
Run the demo client to your device, you should be able to run the FFMpeg command and rotate the video in.mp4, the output video is /sdcard/videokit/vid_trans.mp4

Full installation document for FFmpeg4Android library and the demo client project.