This is a follow up post of the previous blog How to Build FFmpeg for Android. You can read the previous tutorial first, or refer back to it when you feel necessary.
This blog covers how to build a simple Android app based on FFmpeg library. The app will detect the input video file’s resolution and codec information through interface provided by FFmpeg.
Blow is a screenshot of the app,
Figure 1. Screen shot of the sample android app based on FFmpeg
0. Create a new Android Project FFmpegTest.
When you’re asked to select targeted platform, select 2.2 as it’s the platform used in previous blog. But you’re free to change it.
Also create a folder named jni under the root directory “FFmpegTest” of this project.
1. Download the ffmpeg Source Code and Extract it to jni Folder
Follow the previous blog How to Build FFmpeg for Android to build the library.
2. Write the Native Code that use FFmpeg’s libavcodec library.
You can copy and paste the code below and save it as ffmpeg-test-jni.c under FFmpegTest/jni/ directory. Note that the code below is not completed, you can download the entire code at the end of the post.
If you’re not familiar with Java JNI, you may need to read about JNI first in order to understand the code. But this is not the focus of this tutorial hence not covered.
3. Build the Native Code.
Create a file named Android.mk under jni directory and copy paste the content below,
Create another file named Application.mk under jni directory and copy paste the content below,
For more information about what Android.mk and Application.mk do, you can refer to the documentation comes with android NDK.
Your folder structure should be something like below after you finish all steps above,
Figure 2. Folder structure of project FFmpegTest and jni
4. Call the Native Code from FFmpegTest Java Code.
You’ll need to load the libraries and declare the jni functions. The code below is extracted from the app source code, which is provided for download at the end of this tutorial.
5. You can Download the Entire Source Code from here.
Note: the code is tested on Ubuntu 10.04 and Android ndk-5b, but it should work on other platforms (except for Windows, which I’m not sure about.)