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
}

备注

相关推荐
MonkeyKing_sunyuhua14 小时前
FFmpeg将mp4的文件转化为m4a
ffmpeg
zanglengyu15 小时前
RK3568硬解码并与Qt界面融合显示深入探究
开发语言·qt·ffmpeg·rk3568硬解码rtsp
橘子味的茶二1 天前
ffmpeg内存模型
ffmpeg
TPCloud1 天前
windows 11编译安装ffmpeg(包含ffplay)
windows·ffmpeg·源码安装·mysys
runing_an_min2 天前
ffmpeg视频滤镜:缓入缓出-fade
ffmpeg·音视频·fade·缓出·缓入
ssslar3 天前
FFMPEG录屏(22)--- Linux 下基于X11枚举所有显示屏,并获取大小和截图等信息
linux·运维·ffmpeg
MonkeyKing_sunyuhua3 天前
FFmpeg 怎么裁剪m4a的音频,从一个时间点开始,裁剪15秒钟的视频
ffmpeg·音视频
DO_Community3 天前
教程:FFmpeg结合GPU实现720p至4K视频转换
ffmpeg·音视频
x66ccff3 天前
使用NVIDIA GPU加速FFmpeg视频压制:完全指南
ffmpeg·音视频
冷眼Σ(-᷅_-᷄๑)3 天前
如何使用ffmpeg命令行进行录屏
ffmpeg