作者:手机用户2602939883 | 来源:互联网 | 2023-07-11 15:59
1.下载ffmpeg4.3.1源码2.解压.configure--prefixusrlocal--enable-gpl--enable-nonfree--enable-liba
1.下载ffmpeg4.3.1源码
2.解压
./configure --prefix=/usr/local --enable-gpl --enable-nonfree --enable-libass\ --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus \ --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid
创建一个编译脚本vi mffmpeg.sh
chmod 777 mffmpeg.sh
#!/bin/sh# directories
FF_VERSION="4.3.1"
#FF_VERSION="snapshot-git"
if [[ $FFMPEG_VERSION != "" ]]; thenFF_VERSION=$FFMPEG_VERSION
fi
SOURCE="ffmpeg-$FF_VERSION"
FAT="FFmpeg-iOS"SCRATCH="scratch"
# must be an absolute path
THIN=`pwd`/"thin"# absolute path to x264 library
#X264=`pwd`/fat-x264#FDK_AAC=`pwd`/../fdk-aac-build-script-for-iOS/fdk-aac-iosCONFIGURE_FLAGS="--enable-cross-compile --disable-debug --disable-programs \--disable-doc --enable-pic"if [ "$X264" ]
thenCONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-gpl --enable-libx264"
fiif [ "$FDK_AAC" ]
thenCONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-libfdk-aac --enable-nonfree"
fi# avresample
#CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-avresample"ARCHS="arm64 armv7 x86_64 i386"COMPILE="y"
LIPO="y"DEPLOYMENT_TARGET="8.0"if [ "$*" ]
thenif [ "$*" = "lipo" ]then# skip compileCOMPILE=elseARCHS="$*"if [ $# -eq 1 ]then# skip lipoLIPO=fifi
fiif [ "$COMPILE" ]
thenif [ ! `which yasm` ]thenecho 'Yasm not found'if [ ! `which brew` ]thenecho 'Homebrew not found. Trying to install...'ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" \|| exit 1fiecho 'Trying to install Yasm...'brew install yasm || exit 1fiif [ ! `which gas-preprocessor.pl` ]thenecho '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 1fiif [ ! -r $SOURCE ]thenecho 'FFmpeg source not found. Trying to download...'curl http://www.ffmpeg.org/releases/$SOURCE.tar.bz2 | tar xj \|| exit 1fiCWD=`pwd`for ARCH in $ARCHSdoecho "building $ARCH..."mkdir -p "$SCRATCH/$ARCH"cd "$SCRATCH/$ARCH"CFLAGS="-arch $ARCH"if [ "$ARCH" = "i386" -o "$ARCH" = "x86_64" ]thenPLATFORM="iPhoneSimulator"CFLAGS="$CFLAGS -mios-simulator-version-min=$DEPLOYMENT_TARGET"elsePLATFORM="iPhoneOS"CFLAGS="$CFLAGS -mios-version-min=$DEPLOYMENT_TARGET -fembed-bitcode"if [ "$ARCH" = "arm64" ]thenEXPORT="GASPP_FIX_XCODE5=1"fifiXCRUN_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" ]thenAS="gas-preprocessor.pl -arch aarch64 -- $CC"elseAS="gas-preprocessor.pl -- $CC"fiCXXFLAGS="$CFLAGS"LDFLAGS="$CFLAGS"if [ "$X264" ]thenCFLAGS="$CFLAGS -I$X264/include"LDFLAGS="$LDFLAGS -L$X264/lib"fiif [ "$FDK_AAC" ]thenCFLAGS="$CFLAGS -I$FDK_AAC/include"LDFLAGS="$LDFLAGS -L$FDK_AAC/lib"fiTMPDIR=${TMPDIR/%\/} $CWD/$SOURCE/configure \--target-os=darwin \--arch=$ARCH \--cc="$CC" \--as="$AS" \$CONFIGURE_FLAGS \--extra-cflags="$CFLAGS" \--extra-ldflags="$LDFLAGS" \--prefix="$THIN/$ARCH" \|| exit 1make -j3 install $EXPORT || exit 1cd $CWDdone
fiif [ "$LIPO" ]
thenecho "building fat binaries..."mkdir -p $FAT/libset - $ARCHSCWD=`pwd`cd $THIN/$1/libfor LIB in *.adocd $CWDecho lipo -create `find $THIN -name $LIB` -output $FAT/lib/$LIB 1>&2lipo -create `find $THIN -name $LIB` -output $FAT/lib/$LIB || exit 1donecd $CWDcp -rf $THIN/$1/include $FAT
fiecho Done
编译ios:./mffmpeg.sh lipo
编译安卓:./mffmpeg.sh arm64 armv7 x86_64
生产库文件,接下来应用到Xcode工程
liuMacBook-Pro:Downloads liuoliver$ ls
FFmpeg-iOS ffmpeg-4.3.1 pucca-pseudoroom
arm64 mffmpeg.sh thin
liuMacBook-Pro:Downloads liuoliver$ cd thin
liuMacBook-Pro:thin liuoliver$ ls
arm64 armv7 x86_64 x86_64.zip
liuMacBook-Pro:thin liuoliver$