ffmpeg库编译加文字_1.编译ffmpeg库
1.下載ffmpeg
#!/bin/bash
source="ffmpeg-4.1"
if [ ! -r $source ]
then
curl http://ffmpeg.org/releases/${source}.tar.bz2 | tar xj || exit 1
fi
curl 表示下載,后邊跟下載的地址。
tar表示解壓或者壓縮。 x表示解壓,j表示是否需要解壓bz2壓縮包(壓縮包格式類型有很多:zip、bz2等等)
2.查看ffmpeg編譯配置項
cd 到ffmpeg目錄下,
執行./configure --help
ffmpeg有很多配置項:
help options:幫助選項、
standard options:標準選項、
Licensing options:許可選項、
configuration options:配置選項、
external library support:外部庫支持、
toolchain options:工具鏈選項、
advanced options:高級選項、
developer options:開發者選項、
3.編譯ffmpeg
下邊分析:
1.定義一些字符串
VERSION="4.1" //版本號
SOURCE="ffmpeg-$VERSION" // 需要編譯的ffmpeg源文件
CACHEDIR="CACHEDIR" // 保存編譯生成的.o文件。
STATICDIR=`pwd`/"weixiao-ffmpeg" // 編譯生成的靜態庫.a的目錄
pwd表示獲取當前位置的命令。
2.添加ffmpeg的配置項
CONFIGURE_FLAGS="--enable-cross-compile --disable-debug \
--disable-programs --disable-doc --enable-pic"
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
FFmpeg一共九個庫,常用的(默認)編譯的是七個庫。 而我們一般用到的是3到4個庫,其中最重要的庫是用于編解碼的庫avcodec。
可以根據我們的需要進行編譯:
查看這些配置項使用上邊第二條講過的方式,./confifure --help
通過設置CONFIGURE_FLAGS 來配置這些庫是否需要,類似下邊:
CONFIGURE_FLAGS ="$CONFIGURE_FLAGS --enable-avdevice --enable-avcodec --enable-avformat --disable-postproc"
3.添加需要編譯的cpu平臺
ARCHS="arm64 armv7 x86_64 i386"
// 也可以動態的通過入參指定需要的cpu平臺
if [ "$*" ]
then
#存入輸入參數,也就說:外部指定需要編譯CPU架構類型
ARCHS ="$*"
fi
4.安裝匯編器yasm
if [ ! `which yasm` ]
then
echo "Yasm not found"
if [ ! `which brew` ]
then
echo "Homebrew not found"
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" || exit 1
fi
brew install yasm || exit 1
fi
ffmpeg編譯用到了匯編,所以需要匯編器yasm,注意不要寫錯。
5.gas-preprocessor.pl 腳本文件
if [ ! `which gas-preprocessor.pl` ]
then
echo "gas-preprocessor.pl not found"
(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
ffmpeg編譯需要gas-preprocessor.pl 文件,它是一個perl的腳本。
6.根據需要的cpu平臺循環編譯
CWD=`pwd`
for ARCH in $ARCHS
do
編譯代碼
done
7.for循環中的代碼一,首先設置platform平臺(7和下邊都是for遵循中執行的代碼)
echo "build $ARCH"
mkdir -p "$CACHEDIR/$ARCH"
cd "$CACHEDIR/$ARCH"
CFLAGS="-arch $ARCH"
if [ "$ARCH" = "i386" -o "$ARCH" = "x86_64" ]
then
PLATFORM="iPhoneSimulator"
CFLAGS="$CFLAGS -mios-simulator-version-min=$TARGET"
else
PLATFORM="iPhoneOS"
CFLAGS="$CFLAGS -mios-version-min=$TARGET -fembed-bitcode"
if [ "$ARCH" = "arm64" ]
then
EXPORT="GASPP_FIX_XCODE5=1"
fi
fi
根據需要編譯的cpu類型,設置 PLATFORM 是真機還是模擬器。
設置了編譯參數 CFLAGS,支持的最低iOS版本。
是否支持x264 和 acc
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
根據是否支持x264 和acc 繼續拼接編譯參數。
設置匯編器
XCRUN_SDK=`echo $PLATFORM | tr '[:upper:]' '[:lower:]'`
CC="xcrun -sdk $XCRUN_SDK clang"
if [ "$ARCH" = "arm64" ]
then
AS="gas-preprocessor.pl -arch aarch64 -- $CC"
else
AS="gas-preprocessor.pl -- $CC"
fi
設置了匯編參數 cc 和as
10.設置參數,并編譯
TMPDIR=${TMPDIR/%\/} $CWD/$SOURCE/configure \
--target-os=darwin \
--arch=$ARCH \
--cc="$CC" \
--as="$AS" \
$CONFIGURE_FLAGS \
--extra-cflags="$CFLAGS" \
--extra-ldflags="$LDFLAGS" \
--prefix="$STATICDIR/$ARCH" \
|| exit 1
make -j3 install $EXPORT || exit 1
cd $CWD
--prefix表示.a文件的輸出文件目錄
darwin 是Mac系統的意思
4.編譯ffmpeg遇到的問題匯總:
1.shell腳本的語法錯誤,`` 寫成了 '' ,斜著的兩個點表示shell命令,豎直的兩點表示字符串的意思。
`pwd` 表示獲取當前位置的命令, 'pwd'表示pwd字符串
2.shell腳本錯誤,=號和if判斷
name="jack" =號前不能有空格
if [ age == 18 ] []前后必須有空格
3.變量名和專有名詞寫錯
ffmpeg 需要的匯編器是 yasm 而不是ysam。 因為變量名寫的時候不報錯,所以很難檢查出來,要細心些。
4.編譯錯誤,我編譯的時候遇到了如下錯誤:
xcrun -sdk iphoneos clang is unable to create an executable file.
C compiler test failed.
解決方案是命令行執行如下語句:
sudo xcode-select --switch /Applications/Xcode.app
該問題的鏈接為:issues119 大意是說因為找不到Xcode的目錄。
5.完整腳本如下:
VERSION="4.1"
SOURCE="ffmpeg-$VERSION"
CACHEDIR="CACHEDIR"
STATICDIR=`pwd`/"weixiao-ffmpeg"
CONFIGURE_FLAGS="--enable-cross-compile --disable-debug --disable-programs --disable-doc --enable-pic"
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
ARCHS="arm64 armv7 x86_64 i386"
TARGET="10.0"
if [ ! `which yasm` ]
then
echo "Yasm not found"
if [ ! `which brew` ]
then
echo "Homebrew not found"
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" || exit 1
fi
brew install yasm || exit 1
fi
if [ ! `which gas-preprocessor.pl` ]
then
echo "gas-preprocessor.pl not found"
(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
CWD=`pwd`
for ARCH in $ARCHS
do
echo "build $ARCH"
mkdir -p "$CACHEDIR/$ARCH"
cd "$CACHEDIR/$ARCH"
CFLAGS="-arch $ARCH"
if [ "$ARCH" = "i386" -o "$ARCH" = "x86_64" ]
then
PLATFORM="iPhoneSimulator"
CFLAGS="$CFLAGS -mios-simulator-version-min=$TARGET"
else
PLATFORM="iPhoneOS"
CFLAGS="$CFLAGS -mios-version-min=$TARGET -fembed-bitcode"
if [ "$ARCH" = "arm64" ]
then
EXPORT="GASPP_FIX_XCODE5=1"
fi
fi
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
XCRUN_SDK=`echo $PLATFORM | tr '[:upper:]' '[:lower:]'`
CC="xcrun -sdk $XCRUN_SDK clang"
if [ "$ARCH" = "arm64" ]
then
AS="gas-preprocessor.pl -arch aarch64 -- $CC"
else
AS="gas-preprocessor.pl -- $CC"
fi
TMPDIR=${TMPDIR/%\/} $CWD/$SOURCE/configure \
--target-os=darwin \
--arch=$ARCH \
--cc="$CC" \
--as="$AS" \
$CONFIGURE_FLAGS \
--extra-cflags="$CFLAGS" \
--extra-ldflags="$LDFLAGS" \
--prefix="$STATICDIR/$ARCH" \
|| exit 1
make -j3 install $EXPORT || exit 1
cd $CWD
done
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的ffmpeg库编译加文字_1.编译ffmpeg库的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 电视如何选择液晶电视如何选择
- 下一篇: 怎样设置手机通话录音