ffmpeg linux 编译

linux 编译 ffmpeg

  1. 下载源码
    下载ffmpeg源码 或者通过git clone源码:

    git clone [email protected]:FFmpeg/FFmpeg.git
    
  2. 进入源码根目录,执行./configure 出现如下错误:

    nasm/yasm not found
    

    需要下载yasm汇编器

  3. 下载yasm汇编器

    wget https://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
    

    解压安装 :

    tar -zxvf yasm-1.3.0.tar.gz
    

    进入解压后目录

    cd yasm-1.3.0
    
    ./configure
    # 接着 
    make 
    sudo make install
    

    接着返回 ffmpeg目录,执行命令

    small@small:~/FFmpeg$
    ./configure --prefix="/usr/local/ffmpeg/" --enable-libx264 --enable-gpl --enable-nonfree --enable-libfdk-aac
    

    出现如下显示就代表成功了:

    small@small:~/FFmpeg$ ./configure
    install prefix            /usr/local
    source path               .
    C compiler                gcc
    C library                 glibc
    ARCH                      x86 (generic)
    big-endian                no
    runtime cpu detection     yes
    standalone assembly       yes
    x86 assembler             yasm
    MMX enabled               yes
    MMXEXT enabled            yes
    3DNow! enabled            yes
    3DNow! extended enabled   yes
    SSE enabled               yes
    SSSE3 enabled             yes
    AESNI enabled             yes
    AVX enabled               yes
    AVX2 enabled              yes
    AVX-512 enabled           yes
    XOP enabled               yes
    ...
    

启用第三方模块支持:libfdk_aac和libx264,需要单独下载编译

出现如下错误

1. ERROR: libfdk_aac not found

small@small:~/FFmpeg$ ./configure --enable-libx264 --enable-libfdk-aac --enable-gpl --enable-nonfree
ERROR: libfdk_aac not found

If you think configure made a mistake, make sure you are using the latest
version from Git.  If the latest version fails, report the problem to the
[email protected] mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file "ffbuild/config.log" produced by configure as this will help
solve the problem.

下载libfdk_aac库:
https://sourceforge.net/projects/opencore-amr/files/fdk-aac/

./configure  # 配置
make  # 编译
make install # 编译安装

2. ERROR: libx264 not found

small@small:~/FFmpeg$ ./configure --enable-libx264 --enable-libfdk-aac --
ERROR: libx264 not found

If you think configure made a mistake, make sure you are using the latest
version from Git.  If the latest version fails, report the problem to the
[email protected] mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file "ffbuild/config.log" produced by configure as this will help
solve the problem.

下载libx264 :https://www.videolan.org/developers/x264.html

代码库:git clone https://code.videolan.org/videolan/x264.git
下载完继续:

./configure  --enable-shared
make  
make install

3. 还没完,又出现新的错误了:

small@small:~/x264$ ./configure
Found no assembler
Minimum version is nasm-2.13
If you really want to compile without asm, configure with --disable-asm.

下载nasm目前最新版 :https://www.nasm.us/pub/nasm/releasebuilds/2.15/
继续编译安装:

./configure  
make  
make install

4. 回到上一步,继续编译x264:

./configure  --enable-shared # --enable-shared 这里很重要
make  
make install

5. 最终回到ffmpeg继续编译:

small@small:~/FFmpeg$ ./configure --enable-libx264 --enable-libfdk-aac --
small@small:~/FFmpeg$ make
small@small:~/FFmpeg$ make install

6. make: Nothing to be done for 'all'.

有时候需要重新编译,会遇到这个错误,需要 clean

make clean

7. 最后还有个问题就是找不到.so 库的问题

small@small:/usr/lib$ ffmpeg
ffmpeg: error while loading shared libraries: libx264.so.161: cannot open shared object file: No such file or directory

这个问题一看就是没找到动态库,libx264默认安装路径是 /usr/local/lib 目录,解决这个问题的方法就是建个软连接或者直接把库移动到 /usr/lib 目录:

small@small:/usr/local/lib$ sudo ln -s /usr/local/lib/libx264.so.161 /usr/lib/libx264.so.161

大功告成,没有报错;

8. 接下来试试看是否正常:

small@small:~$ ffmpeg -i YOLOv3.mp4 YO.flv
ffmpeg version 4.3.git Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.3.0-17ubuntu1~20.04)
  configuration: --enable-libx264 --enable-libfdk-aac --enable-gpl --enable-nonfree
  libavutil      56. 66.100 / 56. 66.100
  libavcodec     58.125.101 / 58.125.101
  libavformat    58. 68.100 / 58. 68.100
  libavdevice    58. 12.100 / 58. 12.100
  libavfilter     7.107.100 /  7.107.100
  libswscale      5.  8.100 /  5.  8.100
  libswresample   3.  8.100 /  3.  8.100
  libpostproc    55.  8.100 / 55.  8.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'YOLOv3.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2018-10-29T06:43:27.000000Z
  Duration: 00:03:45.70, start: 0.000000, bitrate: 2072 kb/s
  Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 1942 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc (default)
  ...

9. 看一下转换结果,没有问题~

small@small:~$ ls
FFmpeg      fdk-aac-2.0.1         log.txt              nasm-2.15.tar.gz  x264
YO.flv      fdk-aac-2.0.1.tar.gz  nasm-2.13.03.tar.gz  python            
YOLOv3.mp4  go                    nasm-2.15            test.go           yasm-1.3.0.tar.gz

收工

你可能感兴趣的:(ffmpeg linux 编译)