0

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 ?

Community
  • 1
  • 1
Nooruddin Lakhani
  • 4,098
  • 2
  • 14
  • 32
  • if you want to run ffmpeg.x264 on android then you will need to find android.ndk config & build includes libx264. If you want to run ffmpeg on the server then you can just install any ffmpeg binary on heroku and downscale your videos there. – Robert Rowntree Oct 18 '16 at 13:12
  • I want to run ffmpeg .x264 on android. I have downloaded android-ndk-r13 latest version and set it's path on Android Studio in Android NDK Location which the path in local.properties like "sdk.dir=C\:\\Local\\Android\\Sdk" and also set environment variable for NDK but I still getting the same issue. What should I do more ? – Nooruddin Lakhani Oct 18 '16 at 13:46
  • http://stackoverflow.com/questions/28988007/ffmpeg-android-ndk-on-windows or something like that for windows builds ( im on linux so can not help with cygwin/ffmpeg/ndk stuff) IMO you need a VM if ur gonna attempt all this on windows. – Robert Rowntree Oct 18 '16 at 13:54
  • is there a way to achieve better quality result with minimum file size using mpeg4 codec ? Currently I am getting issue with the videos which are already compressed so the command using the mpeg4 codec increases the converted video file size larger than original and I cannot find the selected video is already compressed or not. – Nooruddin Lakhani Oct 18 '16 at 14:58

0 Answers0