Skip to content

Instantly share code, notes, and snippets.

@dturner
Last active June 14, 2022 07:03
Show Gist options
  • Save dturner/11fe5c8e420c2a73e15537274aafbd3a to your computer and use it in GitHub Desktop.
Save dturner/11fe5c8e420c2a73e15537274aafbd3a to your computer and use it in GitHub Desktop.
FFmpeg configure options
#!/bin/bash
if [ -z "$ANDROID_NDK" ]; then
echo "Please set ANDROID_NDK to the Android NDK folder"
exit 1
fi
#Change to your local machine's architecture
HOST_OS_ARCH=darwin-x86_64
function configure_ffmpeg {
ABI=$1
PLATFORM_VERSION=$2
TOOLCHAIN_PATH=$ANDROID_NDK/toolchains/llvm/prebuilt/${HOST_OS_ARCH}/bin
local STRIP_COMMAND
# Determine the architecture specific options to use
case ${ABI} in
armeabi-v7a)
TOOLCHAIN_PREFIX=armv7a-linux-androideabi
STRIP_COMMAND=arm-linux-androideabi-strip
ARCH=armv7-a
;;
arm64-v8a)
TOOLCHAIN_PREFIX=aarch64-linux-android
ARCH=aarch64
;;
x86)
TOOLCHAIN_PREFIX=i686-linux-android
ARCH=x86
EXTRA_CONFIG="--disable-asm"
;;
x86_64)
TOOLCHAIN_PREFIX=x86_64-linux-android
ARCH=x86_64
EXTRA_CONFIG="--disable-asm"
;;
esac
if [ -z ${STRIP_COMMAND} ]; then
STRIP_COMMAND=${TOOLCHAIN_PREFIX}-strip
fi
echo "Configuring FFmpeg build for ${ABI}"
echo "Toolchain path ${TOOLCHAIN_PATH}"
echo "Command prefix ${TOOLCHAIN_PREFIX}"
echo "Strip command ${STRIP_COMMAND}"
./configure \
--prefix=build/${ABI} \ # The path where the resulting libraries and headers will be installed after `make install` is run. The resulting directory structure is "build/{armeabi-v7a,arm64-v8a,x86,x86_64}/{include, lib}".
--target-os=android \ # Target operating system name.
--arch=${ARCH} \ # Target CPU architecture e.g. armv7-a.
--enable-cross-compile \ # We are compiling for a different target architecture than the host.
--cc=${TOOLCHAIN_PATH}/${TOOLCHAIN_PREFIX}${PLATFORM_VERSION}-clang \ # Path to the C compiler. In our case we're using clang.
--strip=${TOOLCHAIN_PATH}/${STRIP_COMMAND} \ # Path to the strip binary for our target architecture.
--enable-small \ # Optimize for size instead of speed.
--disable-programs \ # Do not build command line programs. We don't need them as our app will be interacting with the FFmpeg API.
--disable-doc \ # Do not build documentation.
--enable-shared \ # Build shared libraries. We'll keep the FFmpeg .so files separate from our main shared library.
--disable-static \ # Do not build static libraries.
${EXTRA_CONFIG} \
--disable-everything \ # Disable all modules. To keep the library size to a minimum we will explicitly specify the modules to be built below.
--enable-decoder=mp3 \ # Enable the MP3 decoder. For a list of supported decoders type ./configure --help.
--enable-demuxer=mp3 # Enable the MP3 demuxer. For a list of supported demuxers type ./configure --help.
return $?
}
function build_ffmpeg {
configure_ffmpeg $1 $2
if [ $? -eq 0 ]
then
make clean
make -j12
make install
else
echo "FFmpeg configuration failed, please check the error log."
fi
}
build_ffmpeg armeabi-v7a 16
build_ffmpeg arm64-v8a 21
build_ffmpeg x86 16
build_ffmpeg x86_64 21
@harthorst
Copy link

harthorst commented Jul 27, 2020

Hi Don. Thank you for this file. I use ffmpeg in my app and it helped me a lot. But I'm a bit concerned about getting into trouble since my app has in app payment and ffmpeg is licensed under LGPL. As far I understood I have to provide information about how my app can be updated with newer versions of ffmpeg.

So I thought about writing a little howto about how to unzip the apk, building ffmpeg, exchange the ffmpeg so files and zipping it all together. Do you think that would do it? Maybe you have a reference or some experience about that.

Kind regards,
Thomas

@dturner
Copy link
Author

dturner commented Jul 27, 2020

Hey Thomas, glad it was useful. I'll be honest I was not aware of any requirement to allow the FFmpeg libraries to be upgraded inside an APK. This requirement seems quite strange as any API changes would require that your app also be updated. Where did you read this?

@harthorst
Copy link

harthorst commented Jul 27, 2020

Hi Don. Here is a blog article: https://xebia.com/blog/the-lgpl-on-android/ - see d1. There are also some discussions, for instance here: https://stackoverflow.com/questions/4916512/using-lgpl-library-in-paid-android-app

@prashant-prajapati
Copy link

Hi Don, I'm getting the following error while executing bash.

./ffmpeg-build.sh: line 59: unexpected EOF while looking for matching `''
./ffmpeg-build.sh: line 87: syntax error: unexpected end of file

@dturner
Copy link
Author

dturner commented Aug 4, 2020

@prashan-prajapati Did you edit the script? If so, it could be that you have a \ in the wrong place.

@dturner
Copy link
Author

dturner commented Aug 6, 2020

@harthorst That article is referring to LGPL 3.0 whereas FFmpeg is licensed with LGPL 2.1 which does not contain the clause (section 4.1.b) about providing an update mechanism.

@harthorst
Copy link

@dturner thanks. I did not see that

@jakkubu
Copy link

jakkubu commented Nov 20, 2020

Hi Don, I'm getting the following error while executing bash.

./ffmpeg-build.sh: line 59: unexpected EOF while looking for matching `''
./ffmpeg-build.sh: line 87: syntax error: unexpected end of file

I had the same problem. Solution: delete all comments from lines 50 - 64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment