• 下载ffmpeg源码

      1. git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
    • 切换分支

    查看远程分支,切换release版本最新的分支到本地,为了稳定,编译少bug,选择release版本的

    1. git branch -a
    2. git checkout -b remotes/origin/release/5.0
    • 安装环境

      1. sudo apt-get update -qq && sudo apt-get -y install \
      2. autoconf \
      3. automake \
      4. build-essential \
      5. cmake \
      6. git-core \
      7. libass-dev \
      8. libfreetype6-dev \
      9. libsdl2-dev \
      10. libtool \
      11. libva-dev \
      12. libvdpau-dev \
      13. libvorbis-dev \
      14. libxcb1-dev \
      15. libxcb-shm0-dev \
      16. libxcb-xfixes0-dev \
      17. pkg-config \
      18. texinfo \
      19. wget \
      20. zlib1g-dev
      1. sudo apt-get install nasm
      2. sudo apt-get install yasm
      • 安装libx264
        H.264 video encoder
        启用需要 configured 配置 —enable-gpl —enable-libx264

        1. sudo apt-get install libx264-dev -y
      • 安装libx265
        H.265/HEVC video encoder

        1. sudo apt-get install libx265-dev libnuma-dev -y
      • 安装libvpx
        VP8/VP9 video encoder/decoder
        启用需要 configured 配置 —enable-libvpx

        1. sudo apt-get install libvpx-dev -y
      • libfdk-aac
        AAC audio encoder.
        Requires ffmpeg to be configured with —enable-libfdk-aac (and —enable-nonfree if you also included —enable-gpl)

        1. sudo apt-get install libfdk-aac-dev -y
      • libmp3lame
        MP3 audio encoder.
        Requires ffmpeg to be configured with —enable-libmp3lame

        1. sudo apt-get install libmp3lame-dev -y
      • libopus
        Opus audio decoder and encoder.
        Requires ffmpeg to be configured with —enable-libopus

        1. sudo apt-get install libopus-dev -y
      • libaom
        AV1 video encoder/decoder:
        手动安装在ffmpeg_build文件夹下,也可以收到下载release版本编译安装

        1. git -C aom pull 2> /dev/null || git clone --depth 1 https://aomedia.googlesource.com/aom && \
        2. mkdir aom_build && \
        3. cd aom_build && \
        4. PATH="$HOME/bin:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED=off -DENABLE_NASM=on ../aom && \
        5. PATH="$HOME/bin:$PATH" make && \
        6. make install
    • 配置configure
      生成静态库,动态库, 安装到相对目录./bin文件下

      1. ./configure --prefix=./bin --enable-static --enable-shared

      配置&&编译&&安装

      1. PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \
      2. --prefix="$HOME/ffmpeg_build" \
      3. --pkg-config-flags="--static" \
      4. --extra-cflags="-I$HOME/ffmpeg_build/include" \
      5. --extra-ldflags="-L$HOME/ffmpeg_build/lib" \
      6. --extra-libs="-lpthread -lm" \
      7. --bindir="$HOME/bin" \
      8. --enable-gpl \
      9. --disable-libaom \
      10. --enable-libass \
      11. --enable-libfdk-aac \
      12. --enable-libfreetype \
      13. --enable-libmp3lame \
      14. --enable-libopus \
      15. --enable-libvorbis \
      16. --enable-libvpx \
      17. --enable-libx264 \
      18. --enable-libx265 \
      19. --enable-shared \
      20. --enable-nonfree && \
      21. PATH="$HOME/bin:$PATH" make -j 8 && \
      22. make install && \
      23. hash -r

    最终可执行文件安装到了bin目录下,库文件安装到了ffmpeg_build下

    • 使用时需要配置的环境变量
      1. #export PATH=/usr/local/ffmpeg/bin:$PATH # 指定可执行程序路径
      2. export LD_LIBRARY_PATH=/root/ffmpeg_build/lib:$LD_LIBRARY_PATH # 指定程序链接时查找的路径
      3. export LIBRARY_PATH=/root/ffmpeg_build/lib:$LIBRARY_PATH # 程序编译时查找的路径
      4. export C_INCLUDE_PATH=$C_INCLUDE_PATH:/root/ffmpeg_build/include # 指定 gcc 头文件查找路径
      5. export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/root/ffmpeg_build/include # 指定 g++ 头文件查找路径