Compiling ffmpeg for Android

ffmpeg has threading errors on android

I've wrote a configure script to compile ffmpeg to be single threaded and static. This is a workaround to an intermittent segmentation fault inside ff_h264_remove_all_refs. Note that this error affected few devices and was intermittent. The only device I experienced it on was the Samsung Galaxy Note 3, but several users said they experienced this error consistently.

Shoutout to Roman who's blog post helped me configure ffmpeg for android in the first place.

Download ffmpeg v2.7.4 from github

git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg
cd ffmpeg
git checkout 5e99df019a850e9ffa96d73e72b8a47a93a61de8

Compile ffmpeg

NDK=/Volumes/LUCID_DREAMS/android-ndk-r9b \ 
OUTPUT_DIR=/Users/jason/Desktop/ffmpegcompiled \
sh build_android.sh `# build_android.sh is included below

In your OUTPUT_DIR, there will be bin, include, lib and share. If you are adding ffmpeg to your application statically (like me), you only need the contents of lib and include in your app.

build_android.sh

#!/bin/bash
# Set NDK to your android ndk base, and set OUTPUT_DIR

./configure --target-os=linux --prefix=$OUTPUT_DIR --enable-cross-compile \
--disable-pthreads \
--disable-w32threads \
--disable-os2threads \
--extra-libs="-lgcc" \
--arch=arm \
--cc=$TOOLCHAIN/bin/arm-linux-androideabi-gcc \
--cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
--nm=$TOOLCHAIN/bin/arm-linux-androideabi-nm \
--sysroot=$SYSROOT \
--disable-shared \
--enable-static \
--enable-runtime-cpudetect \
--pkg-config-flags="--static" \
--extra-ldflags="-Wl,-rpath-link=$SYSROOT/usr/lib -L$SYSROOT/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-decoder=rawvideo \
--enable-decoder=mjpeg \
--enable-decoder=h263 \
--enable-decoder=mpeg4 \
--enable-decoder=h264 \
--enable-parser=h264 \
--disable-network \
--disable-avfilter \
--disable-avdevice \
--extra-cflags=" -O3 -fpic -DANDROID -DHAVE_SYS_UIO_H=1 -Dipv6mr_interface=ipv6mr_ifindex -fasm -Wno-psabi -fno-short-enums -fno-strict-aliasing -finline-limit=300 --static $OPTIMIZE_CFLAGS " \
--pkg-config-flags="--static" \
--disable-doc \

make clean
make -j8
make -j8 install
In Tags ,