How to Build FFmpeg for Android
ffmpeg is an open-source platform for recording, converting, playing and streaming video and audio. It includes libavcodec, a popular video/audio codec.
Several popular Android applications are built based on FFmpeg, including RockPlayer, MoboPlayer, acrMedia, vitalPlayer, V-Cut Express etc. If you’re developing multimedia applications that needs a video/audio codec, ffmpeg is a good choice.
This blog covers how to compile ffmpeg for Android, and next blog will cover how to use ffmpeg to build a simple application.
The steps below are done on Ubuntu 10.10, android NDK r5b, and ffmpeg 0.8. It should work on other versions of Android NDK and ffmpeg, but it may require minor changes.
0. Download Android NDK r5b
You can download the NDK here. Once downloaded, simply extract the file, and you’ll have a folder named android-ndk-r5b. You’ll need the folder location for configurations later.
1. Download Source Code for FFmpeg
You can download the source code from here. If you want to get the latest code, you can use git or svn, the link has detailed instructions. But for this tutorial, the FFmpeg 0.8 “Love” release is downloaded.
After downloaded the source, extract it and you’ll have a folder named ffmpeg-0.8.
2. Build FFmpeg (The script is based on RockPlayer build script)
2.1 Copy and Paste the bash script from here to a text editor, and save it as build_android.sh under ffmpeg-0.8 folder.
Note that NDK location has to be changed according to your android-ndk-r5b folder location. In my machine, it’s at ~/Desktop/android/, so it’s set as
NDK=~/Desktop/android/android-ndk-r5b
PLATFORM=$NDK/platforms/android-8/arch-arm/
PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86
You may also need to adjust the PLATFORM based on which version of SDK you’re using, android-8 corresponds to android SDK 2.2.
The default configuration in the script disables a lot of stuff to speed up the build, you can change the configuration to suit your needs. Besides, you can compile for multiple hardware platforms, but here we only enable arm v7vfpv3 to speed up the build process.
2.2 Make sure the bash script is executable. Go to the ffmpeg-0.8 directory in terminal, then type the following command,
sudo chmod 755 build_android.sh
2.3 Then execute the script, by typing the following command,
./build_android.sh
The compilation will take a while (several minutes or above depends on your machine) to finish.
Update for NDK-r6:
For android NDK-r6, the build_android.sh script might not work. You can try the script here.
Note that you may need to create ./android/armv7-a/ folder in the ffmpeg directory yourself. (Thanks to mgg28831 for this).
If you encounter permission denied error, you can try sudo ./build_android.sh.
3. The Output of the Build
Once the script finishes execution, there’ll be a folder called android under ffmpeg-0.8 directory, which contains all the output of the build.
4. To be Continued
Once the library is compiled successfuly, the next step is to use it to build Android apps. This is covered in next blog, How to Build Android Apps Based on FFmpeg By an Example.
Reference:
RockPlayer open source component: http://rockplayer.freecoder.org/tech.html
113 comments on “How to Build FFmpeg for Android”
Leave a Reply Cancel reply
40% Discount on My Book — Android NDK Cookbook
Android NDK Cookbook ebook 40% discount with promotion code MREANC40 at Packt Publishing The promotion code is valid until 15th June.Categories
- Android Apps (18)
- Android Audio Editor (1)
- TS 2 (3)
- Video Converter Android (8)
- Video2Gif (1)
- Android Tutorial (26)
- Android Dev Tools (1)
- API illustrated (8)
- Multimedia API (3)
- ffmpeg on Android (4)
- NDK (6)
- UI (5)
- Animation (1)
- Code Snippet (2)
- Coding Beyond Technique (18)
- a word, a world (4)
- Bug Rectified (4)
- Programming Habit (1)
- Software as a Career (1)
- Software as User Experience (1)
- Compilers and Related (2)
- ELF (2)
- Computer Languages (31)
- C/C++ (13)
- Java (9)
- JavaScript (2)
- PHP (1)
- Python (8)
- Data Structure & Algorithms (29)
- Bits (1)
- Data Structure (5)
- Integers (10)
- BigInteger (1)
- Prime (4)
- Search (3)
- Sorting (5)
- Strings (5)
- Database (1)
- SQLite (1)
- Digital Signal Processing (33)
- Distributed Systems (17)
- Apache Cassandra (6)
- Apache Hadoop (8)
- Apache Avro (3)
- Apache Nutch (3)
- Apache Solr (1)
- Linux Study Notes (40)
- crontab (1)
- Linux Kernel Programming (8)
- Linux Programming (12)
- IPC (2)
- Linux Network Programming (5)
- Linux Signals (2)
- Linux Shell Scripting (1)
- ssh (3)
- Machinery (30)
- misc (1)
- My Ideas (1)
- My Project (3)
- Mobile Caching (1)
- Selective Decoding (2)
- My Publication (1)
- My Readings (1)
- Networking (15)
- Program for Performance (8)
- Uncategorized (1)
- Virtual Machine (2)
- Web Dev (8)
- web components (3)
- Android Apps (18)
Recent Comments
Archives
- May 2013 (1)
- April 2013 (1)
- March 2013 (4)
- December 2012 (2)
- November 2012 (6)
- October 2012 (6)
- September 2012 (3)
- August 2012 (13)
- July 2012 (15)
- June 2012 (3)
- May 2012 (8)
- April 2012 (4)
- March 2012 (13)
- February 2012 (19)
- January 2012 (9)
- December 2011 (11)
- November 2011 (12)
- October 2011 (4)
- September 2011 (12)
- August 2011 (16)
- July 2011 (15)
- June 2011 (6)
- May 2011 (10)
- April 2011 (13)
- March 2011 (20)
- February 2011 (4)
- November 2010 (2)
- May 2010 (1)
- April 2010 (1)
- February 2010 (1)





When I launch my app on emulator, I obtain always the same error:
“E/AndroidRuntime(576): Caused by: java.lang.UnsatisfiedLinkError: Couldn’t load ffmpeg”
Why i modify it to fit with my machine, it can run but at the end it report that:
INSTALL libavformat/libavformat.a
INSTALL libswscale/libswscale.a
INSTALL libavcodec/libavcodec.a
install: cannot stat `libswscale/libswscale.a’: No such file or directory
install: cannot stat `libavcodec/libavcodec.a’: No such file or directory
I don’t know why, could you help me please?
Thanks
Calrk
Hi,
I tried to compile ffmpeg using ubundu 12.04 and android-ndk-r8.
I got the following error while compiling build_android.sh
./configure: 1660: ./configure: uname: not found
./configure: 1664: ./configure: uname: not found
./configure: 306: ./configure: tr: not found
./configure: 314: ./configure: sed: not found
./configure: 314: ./configure: sed: not found
./configure: 314: ./configure: sed: not found
./configure: 314: ./configure: sed: not found
./configure: 314: ./configure: sed: not found
./configure: 314: ./configure: sed: not found
./configure: 314: ./configure: sed: not found
./configure: 314: ./configure: sed: not found
./configure: 314: ./configure: sed: not found
./configure: 314: ./configure: sed: not found
./configure: 314: ./configure: sed: not found
./configure: 314: ./configure: sed: not found
./configure: 314: ./configure: sed: not found
./configure: 314: ./configure: sed: not found
./configure: 314: ./configure: sed: not found
./configure: 314: ./configure: sed: not found
./configure: 314: ./configure: sed: not found
./configure: 314: ./configure: sed: not found
./configure: 314: ./configure: sed: not found
./configure: 314: ./configure: sed: not found
./configure: 314: ./configure: sed: not found
./configure: 314: ./configure: sed: not found
./configure: 314: ./configure: sed: not found
./configure: 314: ./configure: sed: not found
./configure: 314: ./configure: sed: not found
./configure: 314: ./configure: sed: not found
./configure: 314: ./configure: sed: not found
./configure: 314: ./configure: sed: not found
./configure: 314: ./configure: sed: not found
./configure: 314: ./configure: sed: not found
./configure: 1740: ./configure: sed: not found
./configure: 1740: ./configure: sed: not found
./configure: 1740: ./configure: sed: not found
./configure: 1740: ./configure: sed: not found
./configure: 1740: ./configure: sed: not found
./configure: 1740: ./configure: sed: not found
./configure: 1740: ./configure: sed: not found
./configure: 1740: ./configure: sed: not found
./configure: 1740: ./configure: sed: not found
./configure: 1740: ./configure: sed: not found
./configure: 1740: ./configure: sed: not found
./configure: 1756: ./configure: ./configure: 1756: ./configure: grep: not foundls: not found
./configure: 1756: ./configure: ./configure: 1756: ./configure: ls: not found
grep: not found
./configure: 1756: ./configure: ls: not found
./configure: 1756: ./configure: grep: not found
./configure: 1756: ./configure: ./configure: 1756: ./configure: grep: not found
ls: not found
./configure: 1756: ./configure: ./configure: 1756: ./configure: grep: not found
ls: not found
./configure: 302: ./configure: tr: not found
./configure: 302: ./configure: tr: not found
./configure: 302: ./configure: tr: not found
./configure: 302: ./configure: tr: not found
./configure: 302: ./configure: tr: not found
./configure: 302: ./configure: tr: not found
./configure: 302: ./configure: tr: not found
./configure: 302: ./configure: tr: not found
./configure: 302: ./configure: tr: not found
./configure: 302: ./configure: tr: not found
./configure: 302: ./configure: tr: not found
./configure: 1831: ./configure: sed: not found
Unknown option “–target-os=linux”.
See ./configure –help for available options.
./build_android.sh: line 54: make: command not found
./build_android.sh: line 55: make: command not found
./build_android.sh: line 56: /home/sakthi/Desktop/android/android-ndk-r5b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ar: No such file or directory
./build_android.sh: line 57: /home/sakthi/Desktop/android/android-ndk-r5b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ld: No such file or directory
Please help me.
hi, I want to use ffmpeg in android.. and i have windows os.. i cant run these sudo command… can you provide me command for windows??
Sorry, I never tried it on Windows.
Use Virtual Machine Luck
i am developing an app that requires video broadcasting from android device to web browser. I am using window 7 and tried to build ffmpegg for android. any suggestions
ffmpeg library support RTP, you can see if it fit your needs. For building on Windows 7, I never tried before.
when I’m trying type: ./build_android.sh. I get an alert: command not found. Please help me.
Can you modify this to worl with the ndk-r8b please ? Or just give us any hint on how to do it.
Thanks in advance
Hi,
I am using the ffmpeg library and want to use the ffmpeg encoder and decoder both to create a video from images.
I have compiled the ffmpeg-8.0 and now want to use the encoder. However when i call try to fetch the h264 encoder through the following code :
codec = avcodec_find_encoder(CODEC_ID_H264);
I am not able toget the codec.
I have changed my build_android.sh as follows
–disable-shared \
–enable-static \
–extra-ldflags=”-Wl,-rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -nostdlib -lc -lm -ldl -llog” \
–disable-everything \
–enable-demuxer=mov \
–enable-demuxer=h264 \
–disable-ffplay \
–enable-protocol=file \
–enable-avformat \
–enable-avcodec \
–enable-gpl \
–enable-encoder=h264 \
–enable-decoder=rawvideo \
–enable-decoder=mjpeg \
–enable-decoder=h263 \
–enable-decoder=mpeg4 \
–enable-decoder=h264 \
–enable-parser=h264 \
–disable-network \
–enable-zlib \
–disable-avfilter \
–disable-avdevice \
Please help,
Thanks in advance