相关前置库
openssl
仓库:https://github.com/openssl/openssl.git 编译方式参考INSTALL.md中的步骤
$ ./config
$ make && sudo make install
lame库
如果需要处理mp3相关,依赖lame库, 仓库:https://sourceforge.net/projects/lame/ mp3相关操作可以参考《ffmpeg转换mp3的实现》 编译方式
build_lame ( )
{
echo "Build lame"
if [ -f "${INSTALL_DIR} /lib/libmp3lame.a" ] ; then
echo "Use built static libmp3lame.a"
else
if [ -f "${THIRD_PARTY_DIR} /lame-3.100.tar.gz" ] ; then
echo "exist lame source in 3rd dir, use it"
tar -zxvf ${THIRD_PARTY_DIR} /lame-3.100.tar.gz -C $INSTALL_DIR
else
echo "do not have lame source, need download"
wget https://jaist.dl.sourceforge.net/project/lame/lame/3.100/lame-3.100.tar.gz -P ${THIRD_PARTY_DIR}
fi
pushd $INSTALL_DIR /lame*
os_type = $( uname )
if [ [ "$os_type " == "Darwin" ] ] ; then
XCRUN_SDK = ` echo macosx | tr '[:upper:]' '[:lower:]' `
CC = "xcrun -sdk $XCRUN_SDK clang -arch x86_64"
CFLAGS = "-arch x86_64 $SIMULATOR "
if ! xcodebuild -version | grep "Xcode [1-6]\."
then
CFLAGS = "$CFLAGS -fembed-bitcode"
fi
CXXFLAGS = "$CFLAGS "
LDFLAGS = "$CFLAGS "
CC = $CC ./configure --disable-shared --disable-frontend --host = x86_64-apple-darwin \
--prefix = $INSTALL_DIR CC = "$CC " CFLAGS = "$CFLAGS " LDFLAGS = "$LDFLAGS "
elif [ [ "$os_type " == "Linux" ] ] ; then
LDFLAGS = "-fPIC" ./configure --prefix = $INSTALL_DIR --build = BUILD --enable-static --enable-nasm --with-pic
else
echo "Unknown operating system"
fi
make -j
make install
popd
fi
}
x264库
如果需要x264,对应仓库:https://github.com/mirror/x264
build_x264 ( )
{
pushd $INSTALL_DIR
echo "Build x264"
if [ -d x264 ] ; then
echo "Use exists x264."
else
git clone -b master git@github.com:mirror/x264.git
fi
pushd x264
if [ -f "${INSTALL_DIR} /lib/libx264.a" ] ; then
echo "Use built static libx264.a"
else
./configure --prefix = $INSTALL_DIR \
--enable-static \
--enable-pic
fi
make -j
make install
popd
popd
}
x265库
如果需要x265,到官网下载https://www.x265.org/downloads/
build_x265 ( )
{
pushd $INSTALL_DIR
echo "Build x265"
if [ -d x265 ] ; then
echo "Use exists x265."
else
if [ -f "${THIRD_PARTY_DIR} /x265_v3.3.tar.gz" ] ; then
echo "exist x265 in 3rd dir, use it"
tar -zxvf $THIRD_PARTY_DIR /x265_v3.3.tar.gz -C $INSTALL_DIR
else
echo "download x265 source code from https://www.x265.org/downloads/ and save it to 3rd dir, for example: 3rd/x265_v3.3.tar.gz"
fi
fi
pushd x265_3.3
ln -sf $INSTALL_DIR /.. /scripts/x265_multilib.sh build/linux/x265_multilib.sh
if [ -f "${INSTALL_DIR} /lib/libx265.a" ] ; then
echo "Use built static libx265.a"
else
pushd build/linux
sh x265_multilib.sh $INSTALL_DIR
popd
fi
popd
popd
}
FFmpeg的编译
整理ffmpeg的编译相关build ffmpeg
build_ffmpeg ( )
{
if [ -f "${INSTALL_DIR} /lib/libavcodec.so" ] ; then
echo "Use built libavcodec.so"
else
pushd $ROOT_DIR
echo "check ffmpeg source"
if [ -d FFmpeg ] ; then
echo "Use exists ffmpeg."
else
git clone -b feature/support_hevc_base_rc4.4 git@github.com:yagerfgcs/FFmpeg.git
fi
pushd FFmpeg
export PKG_CONFIG_PATH = ${PKG_CONFIG_PATH} : $INSTALL_DIR /lib/pkgconfig
./configure --pkg-config= $( which pkg-config) \
--pkg-config-flags= "--static" \
--enable-static --enable-pic \
--prefix = ${INSTALL_DIR} \
--enable-openssl --enable-nonfree \
--enable-libmp3lame \
--disable-encoders --enable-encoder= aac --enable-encoder= libx264 --enable-gpl --enable-libx264 --enable-encoder= libx265 --enable-libx265 \
--disable-decoders --enable-decoder= aac --enable-decoder= h264 --enable-decoder= hevc \
--disable-demuxers --enable-demuxer= aac --enable-demuxer= mov --enable-demuxer= mpegts --enable-demuxer= flv --enable-demuxer= h264 --enable-demuxer= hevc --enable-demuxer= hls \
--disable-muxers --enable-muxer= h264 --enable-muxer= flv --enable-muxer= f4v --enable-muxer= mp4 \
--disable-doc --extra-cflags= "-I${INSTALL_DIR} /include -fno-stack-check" \
--extra-ldflags= "-L${INSTALL_DIR} /lib -ldl -lpthread"
make -j16
make install
popd
popd
fi
}
备注
自动编译脚本已经上传到github,参考:https://github.com/yagerfgcs/build_ffmpeg