Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building FFmpeg for Android to use command line arguments

I am trying to build the FFmpeg library to use in my android app with the NDK. The reason for this is because I am using the native video capture feature in android because I really don't want to write my own video recorder. However, the native video capture only allows for either high-quality encoding, or low quality encoding. I want something in between, and I believe that the solution is to use the FFmpeg library to re-encode the high quality video to be lighter.

So far I have been able to build the FFmpeg library according to this guide: http://www.roman10.net/how-to-build-ffmpeg-for-android/ and which a few tweaks I have been able to get it to work.

However, everything that I've found seems to be about writing your own encoder, which seems like overkill to me. All that I really want to do is send a string in command line format to the main() function of FFmpeg and re-encode my video. However, I can't seem to figure out how I build FFmpeg to give me access to the main method. I found this post: Compile ffmpeg.c and call its main() via JNI which links to a project doing what I want more of less, but for the life of me I cannot figure out what is going on. It also seems like he is compiling more than I want, and I would really like to keep my application as light weight as possible.

Some additional direction would be extremely helpful. Thank you.

like image 357
Zargoon Avatar asked Nov 13 '22 04:11

Zargoon


1 Answers

In Android NDK there is no main() in your application in the typical sense, so you are unable to do what you want to directly. However, you can still call the main() of FFmpeg yourself and provide all necessary parameters to it. Here are 2 possibilities to get the parameters:

  1. Android Activity receives an Intent after creation. You can pass the parameters through the intent while starting your activity and then extract it like this:

    Intent CommandLine = this.getIntent();
    Uri uri = CommandLine.getData();
    
  2. You can read parameters from file you create somewhere on a SD-card and pass the to FFmpeg.

like image 191
Sergey K. Avatar answered Nov 16 '22 03:11

Sergey K.