Skip to content

Instantly share code, notes, and snippets.

@antheawu
Last active May 3, 2018 00:26
Show Gist options
  • Save antheawu/6cabec814aadb2db603ce2ddcff6c615 to your computer and use it in GitHub Desktop.
Save antheawu/6cabec814aadb2db603ce2ddcff6c615 to your computer and use it in GitHub Desktop.
ffmpeg library compilation
#!/bin/sh
# directories
FF_VERSION="3.4.1"
if [[ $FFMPEG_VERSION != "" ]]; then
FF_VERSION=$FFMPEG_VERSION
fi
SOURCE="ffmpeg"
FAT="FFmpeg-iOS"
SCRATCH="scratch"
# must be an absolute path
THIN=`pwd`/"thin"
# absolute path to x264 library
X264=`pwd`/"x264-iOS"
#FDK_AAC=`pwd`/../fdk-aac-build-script-for-iOS/fdk-aac-ios
CONFIGURE_FLAGS="--enable-cross-compile --disable-debug --disable-programs \
--disable-doc --enable-pic --disable-videotoolbox"
if [ "$X264" ]
then
CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-gpl --enable-libx264"
fi
if [ "$FDK_AAC" ]
then
CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-libfdk-aac --enable-nonfree"
fi
# avresample
#CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-avresample"
ARCHS="arm64 armv7s armv7 x86_64"
COMPILE="y"
LIPO="y"
DEPLOYMENT_TARGET="8.0"
if [ "$*" ]
then
if [ "$*" = "lipo" ]
then
# skip compile
COMPILE=
else
ARCHS="$*"
if [ $# -eq 1 ]
then
# skip lipo
LIPO=
fi
fi
fi
if [ "$COMPILE" ]
then
if [ ! `which yasm` ]
then
echo 'Yasm not found'
if [ ! `which brew` ]
then
echo 'Homebrew not found. Trying to install...'
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" \
|| exit 1
fi
echo 'Trying to install Yasm...'
brew install yasm || exit 1
fi
if [ ! `which gas-preprocessor.pl` ]
then
echo 'gas-preprocessor.pl not found. Trying to install...'
(curl -L https://github.com/libav/gas-preprocessor/raw/master/gas-preprocessor.pl \
-o /usr/local/bin/gas-preprocessor.pl \
&& chmod +x /usr/local/bin/gas-preprocessor.pl) \
|| exit 1
fi
if [ ! -r $SOURCE ]
then
echo 'FFmpeg source not found. Trying to download...'
curl http://www.ffmpeg.org/releases/$SOURCE.tar.bz2 | tar xj \
|| exit 1
fi
CWD=`pwd`
for ARCH in $ARCHS
do
echo "building $ARCH..."
mkdir -p "$SCRATCH/$ARCH"
cd "$SCRATCH/$ARCH"
CFLAGS="-arch $ARCH"
if [ "$ARCH" = "i386" -o "$ARCH" = "x86_64" ]
then
PLATFORM="iPhoneSimulator"
CFLAGS="$CFLAGS -mios-simulator-version-min=$DEPLOYMENT_TARGET"
else
PLATFORM="iPhoneOS"
CFLAGS="$CFLAGS -fembed-bitcode -mios-version-min=$DEPLOYMENT_TARGET"
if [ "$ARCH" = "arm64" ]
then
EXPORT="GASPP_FIX_XCODE5=1"
fi
fi
XCRUN_SDK=`echo $PLATFORM | tr '[:upper:]' '[:lower:]'`
CC="xcrun -sdk $XCRUN_SDK clang"
# force "configure" to use "gas-preprocessor.pl" (FFmpeg 3.3)
if [ "$ARCH" = "arm64" ]
then
AS="gas-preprocessor.pl -arch aarch64 -- $CC"
# CONFIGURE_FLAGS="$CONFIGURE_FLAGS --disable-asm"
else
AS="$CC"
fi
CXXFLAGS="$CFLAGS"
LDFLAGS="$CFLAGS"
if [ "$X264" ]
then
CFLAGS="$CFLAGS -I$X264/include"
LDFLAGS="$LDFLAGS -L$X264/lib"
fi
if [ "$FDK_AAC" ]
then
CFLAGS="$CFLAGS -I$FDK_AAC/include"
LDFLAGS="$LDFLAGS -L$FDK_AAC/lib"
fi
TMPDIR=${TMPDIR/%\/} $CWD/$SOURCE/configure \
--target-os=darwin \
--arch=$ARCH \
--cc="$CC" \
--as="$AS" \
--logfile="0124.log" \
$CONFIGURE_FLAGS \
--extra-cflags="$CFLAGS" \
--extra-ldflags="$LDFLAGS" \
--prefix="$THIN/$ARCH" \
|| exit 1
make -j3 install $EXPORT || exit 1
cd $CWD
done
fi
if [ "$LIPO" ]
then
echo "building fat binaries..."
mkdir -p $FAT/lib
set - $ARCHS
CWD=`pwd`
cd $THIN/$1/lib
for LIB in *.a
do
cd $CWD
echo lipo -create `find $THIN -name $LIB` -output $FAT/lib/$LIB 1>&2
lipo -create `find $THIN -name $LIB` -output $FAT/lib/$LIB || exit 1
done
cd $CWD
cp -rf $THIN/$1/include $FAT
fi
echo Done
#!/bin/sh
CONFIGURE_FLAGS="--enable-static --enable-pic --disable-cli"
ARCHS="arm64 x86_64 armv7 armv7s"
# directories
SOURCE="x264"
FAT="x264-iOS"
SCRATCH="scratch-x264"
# must be an absolute path
THIN=`pwd`/"thin-x264"
COMPILE="y"
LIPO="y"
FRAMEWORK="y"
if [ "$*" ]
then
if [ "$*" = "lipo" ]
then
# skip compile
COMPILE=
else
ARCHS="$*"
if [ $# -eq 1 ]
then
# skip lipo
LIPO=
fi
fi
fi
if [ "$COMPILE" ]
then
if [ ! -r $SOURCE ]
then
echo 'x264 source not found. Trying to download...'
git clone http://git.videolan.org/git/x264.git
fi
CWD=`pwd`
for ARCH in $ARCHS
do
echo "building $ARCH..."
mkdir -p "$SCRATCH/$ARCH"
cd "$SCRATCH/$ARCH"
CFLAGS="-arch $ARCH"
ASFLAGS=
if [ "$ARCH" = "i386" -o "$ARCH" = "x86_64" ]
then
PLATFORM="iPhoneSimulator"
CPU=
if [ "$ARCH" = "x86_64" ]
then
CFLAGS="$CFLAGS -mios-simulator-version-min=8.0"
CONFIGURE_FLAGS="--enable-static --enable-pic --disable-cli --disable-asm"
HOST=
else
CFLAGS="$CFLAGS -mios-simulator-version-min=8.0"
HOST="--host=i386-apple-darwin"
fi
else
PLATFORM="iPhoneOS"
if [ $ARCH = "arm64" ]
then
HOST="--host=aarch64-apple-darwin"
XARCH="-arch aarch64"
else
HOST="--host=arm-apple-darwin"
XARCH="-arch arm"
fi
CFLAGS="$CFLAGS -fembed-bitcode -mios-version-min=8.0"
ASFLAGS="$CFLAGS"
fi
XCRUN_SDK=`echo $PLATFORM | tr '[:upper:]' '[:lower:]'`
CC="xcrun -sdk $XCRUN_SDK clang"
if [ $PLATFORM = "iPhoneOS" ]
then
export AS="/usr/local/bin/gas-preprocessor.pl $XARCH -- $CC"
else
export -n AS
fi
CXXFLAGS="$CFLAGS"
LDFLAGS="$CFLAGS"
CC=$CC $CWD/$SOURCE/configure \
$CONFIGURE_FLAGS \
$HOST \
--extra-cflags="$CFLAGS" \
--extra-asflags="$ASFLAGS" \
--extra-ldflags="$LDFLAGS" \
--prefix="$THIN/$ARCH" || exit 1
make -j3 install || exit 1
cd $CWD
done
fi
if [ "$LIPO" ]
then
echo "building fat binaries..."
mkdir -p $FAT/lib
set - $ARCHS
CWD=`pwd`
cd $THIN/$1/lib
for LIB in *.a
do
cd $CWD
lipo -create `find $THIN -name $LIB` -output $FAT/lib/$LIB
done
cd $CWD
cp -rf $THIN/$1/include $FAT
fi
FFmpeg-iOS-build
- build-ffmpeg.sh
- build-x264.sh
+ ffmpeg(src)
+ x264(src)
//
brew install x264
brew install fdk-aac
brew install lame
//
./configure --disable-programs --disable-doc --enable-static --enable-shared --prefix=/Users/***/Documents/Working/libavcodec --enable-libfdk-aac --enable-libx264 --enable-gpl --enable-nonfree
./configure --disable-programs --disable-doc --enable-static --enable-shared --target-os=darwin --arch=arm64 -mios-version-min=8.0 -fembed-bitcode --prefix=/Users/***/Documents/Working/libavcodec_iOS --enable-libfdk-aac --enable-libx264 --enable-gpl --enable-nonfree
//
./configure --enable-cross-compile --disable-programs --disable-doc --enable-static --target-os=darwin --arch=x86_64 --sysroot="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk" --cc="xcrun -sdk iphonesimulator clang" --extra-cflags="-arch x86_64 -mios-simulator-version-min=8.0 -I/Users/***/Documents/Working/FFmpeg/x264-iOS/include" --extra-ldflags="-arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk -L/Users/***/Documents/Working/FFmpeg/x264-iOS/lib -mios-simulator-version-min=8.0" --prefix=/Users/***/Documents/Working/libavcodec_iOSs --enable-libx264 --enable-gpl --enable-nonfree
Ref: https://github.com/kewlbear/FFmpeg-iOS-build-script
https://forums.developer.apple.com/thread/83067
https://github.com/leozimmerman/ofxAudioAnalyzer/blob/master/AlgorithmsReference.md
./configure \
--target-os=darwin \
--cc="xcrun -sdk iphoneos clang" \
--arch=arm64 \
--as="gas-preprocessor.pl -arch aarch64 -- xcrun -sdk iphoneos clang" \
--enable-cross-compile --disable-programs --disable-doc --enable-static --disable-shared --enable-gpl --enable-libx264 \
--logfile=0124.log \
--extra-cflags="-arch arm64 -mios-version-min=8.0 -fembed-bitcode -I/Users/***/Documents/Working/FFmpeg-iOS-build/x264-iOS/include" \
--extra-ldflags="-arch arm64 -mios-version-min=8.0 -L/Users/***/Documents/Working/FFmpeg-iOS-build/x264-iOS/lib" \
--prefix="/Users/***/Documents/Working/FFmpeg-iOS-build/testArm" \
./configure \
--target-os=darwin \
--cc="xcrun -sdk iphoneos clang" \
--arch=armv7s \
--as="xcrun -sdk iphoneos clang" \
--enable-cross-compile --disable-programs --disable-doc --enable-static --disable-shared --enable-gpl --enable-libx264 \
--logfile=0124.log \
--extra-cflags="-arch arm64 -mios-version-min=8.0 -I/Users/***/Documents/Working/FFmpeg-iOS-build/x264-iOS/include" \
--extra-ldflags="-arch arm64 -mios-version-min=8.0 -L/Users/***/Documents/Working/FFmpeg-iOS-build/x264-iOS/lib" \
--prefix="/Users/***/Documents/Working/FFmpeg-iOS-build/armv7s" \
Toolchain options:
--arch=ARCH select architecture []
--cpu=CPU select the minimum required CPU (affects
instruction selection, may crash on older CPUs)
--cross-prefix=PREFIX use PREFIX for compilation tools []
--progs-suffix=SUFFIX program name suffix []
--enable-cross-compile assume a cross-compiler is used
--sysroot=PATH root of cross-build tree
--sysinclude=PATH location of cross-build system headers
--target-os=OS compiler targets OS []
--target-exec=CMD command to run executables on target
--target-path=DIR path to view of build directory on target
--target-samples=DIR path to samples directory on target
--tempprefix=PATH force fixed dir/prefix instead of mktemp for checks
--toolchain=NAME set tool defaults according to NAME
--nm=NM use nm tool NM [nm -g]
--ar=AR use archive tool AR [ar]
--as=AS use assembler AS []
--ln_s=LN_S use symbolic link tool LN_S [ln -s -f]
--strip=STRIP use strip tool STRIP [strip]
--windres=WINDRES use windows resource compiler WINDRES [windres]
--x86asmexe=EXE use nasm-compatible assembler EXE [nasm]
--cc=CC use C compiler CC [gcc]
--cxx=CXX use C compiler CXX [g++]
--objcc=OCC use ObjC compiler OCC [gcc]
--dep-cc=DEPCC use dependency generator DEPCC [gcc]
--nvcc=NVCC use Nvidia CUDA compiler NVCC [nvcc]
--ld=LD use linker LD []
--pkg-config=PKGCONFIG use pkg-config tool PKGCONFIG [pkg-config]
--pkg-config-flags=FLAGS pass additional flags to pkgconf []
--ranlib=RANLIB use ranlib RANLIB [ranlib]
--doxygen=DOXYGEN use DOXYGEN to generate API doc [doxygen]
--host-cc=HOSTCC use host C compiler HOSTCC
--host-cflags=HCFLAGS use HCFLAGS when compiling for host
--host-cppflags=HCPPFLAGS use HCPPFLAGS when compiling for host
--host-ld=HOSTLD use host linker HOSTLD
--host-ldflags=HLDFLAGS use HLDFLAGS when linking for host
--host-libs=HLIBS use libs HLIBS when linking for host
--host-os=OS compiler host OS []
--extra-cflags=ECFLAGS add ECFLAGS to CFLAGS []
--extra-cxxflags=ECFLAGS add ECFLAGS to CXXFLAGS []
--extra-objcflags=FLAGS add FLAGS to OBJCFLAGS []
--extra-ldflags=ELDFLAGS add ELDFLAGS to LDFLAGS []
--extra-ldexeflags=ELDFLAGS add ELDFLAGS to LDEXEFLAGS []
--extra-ldsoflags=ELDFLAGS add ELDFLAGS to LDSOFLAGS []
--extra-libs=ELIBS add ELIBS []
--extra-version=STRING version string suffix []
--optflags=OPTFLAGS override optimization-related compiler flags
--nvccflags=NVCCFLAGS override nvcc flags [-gencode arch=compute_30,code=sm_30 -O2]
--build-suffix=SUFFIX library name suffix []
--enable-pic build position-independent code
--enable-thumb compile for Thumb instruction set
--enable-lto use link-time optimization
--env="ENV=override" override the environment variables
//。commercial-dist
As a FFmpeg developer, I would expect you to follow the considerations mentioned on our website:
1. Compile FFmpeg without "--enable-gpl" and without "--enable-nonfree".
2. Use dynamic linking (on windows, this means linking to dlls) for linking with FFmpeg libraries.
3. Distribute the source code of FFmpeg, no matter if you modified it or not.
4. Make sure the source code corresponds exactly to the library binaries you are distributing.
5. Run the command "git diff > changes.diff" in the root directory of the FFmpeg source code to create a file with only the changes.
6. Explain how you compiled FFmpeg, for example the configure line, in a text file added to the root directory of the source code.
7. Use tarball or a zip file for distributing the source code.
8. Host the FFmpeg source code on the same webserver as the binary you are distributing.
9. Add "This software uses code of FFmpeg licensed under the LGPLv2.1 and its source can be downloaded here [where here is a link to the source code]" to every page in your website where there is a download link to your application.
10. Mention "This software uses libraries from the FFmpeg project under the LGPLv2.1" in your program "about box".
Mention in your EULA that your program uses FFmpeg under the LGPLv2.1.
11. If your EULA claims ownership over the code, you have to explicitly mention that you do not own FFmpeg, and where the relevant owners can be found.
12. Remove any prohibition of reverse engineering from your EULA.
13. Apply the same changes to all translations of your EULA.
Do not misspell FFmpeg (two capitals F and lowercase "mpeg").
14. Do not rename FFmpeg dlls to some obfuscated name, but adding a suffix or prefix is fine (renaming "avcodec.dll" to "MyProgDec.dll" is not fine, but to "avcodec-MyProg.dll" is).
15. Go through all the items again for any LGPL external library you compiled into FFmpeg (for example LAME).
16. Make sure your program is not using any GPL libraries (notably libx264).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment