I am using ffmpeg library for video compression. I am using the sample code from ffmpeg4android_lib and the following command to compress the video.
String[] complexCommand = new String[]{ "ffmpeg", "-y", "-i",
"/sdcard/videokit/in.mp4", "-strict", "experimental",
"-vcodec", "mpeg4", "-b:v", "500k",
"-acodec", "aac", "-ar", "48000", "-ac", "1",
"-b:a", "96k", "-s", "480x360", "/sdcard/videokit/out.mp4" };
in.mp4 video file is recorded from camera which is originally 46 mb. It convert video file size to 1.7 mb with better quality. When I select another video from Whatsapp Gallery which is already compressed by Whatsapp like I have a Whatsapp video which is 6 min duration and 9.8 mb in size, when I select this video to compress with the same command, It's size becomes 26 mb which is larger than original. When I decrease the video bit rate from 500k to 150k then output file size becomes smaller but quality becomes poor which cannot be acceptable.
I have found people are using libx264 encoder to find better quality with minimum file size. I have changed my compress command to use this encoder.
String[] complexCommand = new String[]{ "ffmpeg", "-y", "-i",
"/sdcard/videokit/in.mp4", "-strict", "experimental",
"-vcodec", "libx264", "-preset", "medium", "-b:v", "500k",
"-crf", "26", "-acodec", "aac", "-ar", "48000", "-ac", "1",
"-b:a", "96k", "-s", "480x360", "/sdcard/videokit/out.mp4" };
But the above command is not working with ffmpeg library. I am getting the following issue which write log in vk.log file
Reading option '-vcodec' ... matched as option 'vcodec' (force video codec ('copy' to copy stream)) with argument 'libx264'.
Reading option '-preset' ...Unrecognized option 'preset'.
Error splitting the argument list: Option not found
ffmpeg4android: ffmpeg_parse_options not passed
exit_program: 1
I am trying to use the encoder libx264, but ffmpeg not compiled to support this encoder. How can I configure libx264 with ffmpeg ? I have found the following references to configure ffmpeg With libx264
1- ffmpeg on Heroku: unrecognized option 'preset'
2- http://blog.oneiroi.co.uk/linux/ffmpeg-install-with-libx264-h264/
3- http://writingminds.github.io/ffmpeg-android/
Should I have to download NDK and will have to configure It through libx264 commands as defined in above references. I am not getting how to configure it through commands because I have to configure it in Android Studio with ffmpeg and I am using windows not ubuntu or Linux. Please suggest me how can i achieve this ?