5

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.

4
  • I am interested in the same thing, but for audio capture instead of video. Similar principals apply, so I am adding a bounty to your question.
    – Brad
    Commented Sep 11, 2012 at 4:07
  • @Brad, Can you give some clarifications: You have been able to build ffmpg usingthe above guide but you want to figure out how to actually use the built library by calling it from java code and pass some parameters to it for purpose of encoding. Is that understanding right?
    – av501
    Commented Sep 11, 2012 at 15:06
  • @av501, I was hoping to use FFMPEG's Alsa input to capture audio from the microphone on an Android device. I believe this is along the lines of what Zargoon is wanting to do with capturing video from the camera. However, this is Zargoon's question, so if those two things are truly different, please answer along the lines of video capture specifically.
    – Brad
    Commented Sep 11, 2012 at 17:17
  • Refer to this link for calling ffmpeg's main directly via JNI .... [Here][1] [1]: stackoverflow.com/questions/2401764/… Commented Jun 28, 2013 at 19:06

1 Answer 1

1
+50

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.

2
  • hey. i also want to run ffmpeg commands in android. how can i achieve it. can you please guide? Commented Sep 25, 2012 at 12:58
  • 1
    By this how we can call the main() method which is situated in the FFMPEG folder in jni and pass our command in our native C file. Can you please share your knowledge so that it can also help us... Commented Jul 3, 2013 at 5:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.