FFmpeg编译

这里写自定义目录标题

FFmpeg的编译

  • 整理ffmpeg的编译相关

相关前置库

openssl

bash 复制代码
 # Unix / Linux / macOS
 $ ./config
 $ make && sudo make install

lame库

bash 复制代码
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库

bash 复制代码
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库

bash 复制代码
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
}

build ffmpeg

bash 复制代码
# for debug, add --enable-debug --disable-stripping
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
        # configure
        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
        make -j16
        make install
        popd
        popd
    fi
}

备注

相关推荐
Fre丸子_2 小时前
ffmpeg之播放一个yuv视频
ffmpeg·音视频
yinqinggong4 小时前
从源码编译支持FFmpeg的OpenCV
opencv·ffmpeg
冰山一脚20135 小时前
ffmpeg添加sps,pps
ffmpeg
嘟嘟实验室1 天前
微信小程序xr-frame透明视频实现
微信小程序·ffmpeg·音视频·xr
泰勒朗斯1 天前
如何编译Opencv +ffmpeg linux 明明安装了ffmpeg但是opencv就是找不到
linux·opencv·ffmpeg
-Mr_X-2 天前
windows下srs流媒体服务器使用ffmpeg推流
ffmpeg
dvlinker2 天前
C++开源项目 VLC 源代码的交叉编译以及库的裁剪方法详解
ffmpeg·mingw-w64·msys2·cygwin·开源vlc·vlc编译·vlc裁剪
因我你好久不见2 天前
springboot java ffmpeg 视频压缩、提取视频帧图片、获取视频分辨率
java·spring boot·ffmpeg
cuijiecheng20183 天前
音视频入门基础:MPEG2-TS专题(21)——FFmpeg源码中,获取TS流的视频信息的实现
ffmpeg·音视频
cuijiecheng20183 天前
音视频入门基础:AAC专题(13)——FFmpeg源码中,获取ADTS格式的AAC裸流音频信息的实现
ffmpeg·音视频·aac