ffmpeg的下载、编译与安装

325 阅读3分钟

ffmpeg的下载、编译与安装

下载

zh@zh-lpc:~$ mkdir soft
zh@zh-lpc:~$ cd soft/
zh@zh-lpc:~/soft$ ls
zh@zh-lpc:~/soft$
zh@zh-lpc:~/soft$
zh@zh-lpc:~/soft$ git clone https://git.ffmpeg.org/ffmpeg.git
正克隆到 'ffmpeg'...
remote: Enumerating objects: 7535, done.
remote: Counting objects: 100% (7535/7535), done.
remote: Compressing objects: 100% (6563/6563), done.
remote: Total 634019 (delta 5120), reused 1190 (delta 967)
接收对象中: 100% (634019/634019), 155.59 MiB | 190.00 KiB/s, 完成.
处理 delta 中: 100% (509013/509013), 完成.
zh@zh-lpc:~/soft$
zh@zh-lpc:~/soft$
zh@zh-lpc:~/soft$ ls
ffmpeg
zh@zh-lpc:~/soft$
zh@zh-lpc:~/soft$
zh@zh-lpc:~/soft$ cd ffmpeg/
zh@zh-lpc:~/soft/ffmpeg$ ls
Changelog  CONTRIBUTING.md  COPYING.LGPLv2.1  doc      INSTALL.md   libavfilter  libpostproc    LICENSE.md   presets    tests
compat     COPYING.GPLv2    COPYING.LGPLv3    ffbuild  libavcodec   libavformat  libswresample  MAINTAINERS  README.md  tools
configure  COPYING.GPLv3    CREDITS           fftools  libavdevice  libavutil    libswscale     Makefile     RELEASE
zh@zh-lpc:~/soft/ffmpeg$

编译

 ./configure --prefix=/usr/local/ffmpeg --enable-gpl --enable-nonfree --enable-libfdk-aac --enable-libx264 --enable-libx265 --enable-filter=delogo --enable-debug --disable-optimizations --enable-libspeex  --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --cc=gcc --host-cflags= --host-ldflags= --disable-x86asm

出现问题

ERROR: libfdk_aac not found

下载:
udomain.dl.sourceforge.net/project/ope…

依次执行:

./configure
make
make install

ERROR: speex not found using pkg-config

下载:www.speex.org/downloads/
在这里插入图片描述

zh@zh-lpc:~$ ls ~/soft/speex-1.2.0.tar.gz
/home/zh/soft/speex-1.2.0.tar.gz
zh@zh-lpc:~$

依次执行:

./configure
make
make install

ERROR: libx264 not found

libx264官网:www.videolan.org/developers/…

zh@zh-lpc:~/soft$ git clone https://code.videolan.org/videolan/x264.git
正克隆到 'x264'...
remote: Enumerating objects: 22884, done.
remote: Counting objects: 100% (416/416), done.
remote: Compressing objects: 100% (279/279), done.
remote: Total 22884 (delta 202), reused 330 (delta 137), pack-reused 22468
接收对象中: 100% (22884/22884), 6.12 MiB | 1.78 MiB/s, 完成.
处理 delta 中: 100% (18842/18842), 完成.
zh@zh-lpc:~/soft$

zh@zh-lpc:~/soft/x264$ ./configure
Found no assembler
Minimum version is nasm-2.13
If you really want to compile without asm, configure with --disable-asm.
zh@zh-lpc:~/soft/x264$
zh@zh-lpc:~/soft/x264$ ./configure  --disable-asm
platform:       X86_64
byte order:     little-endian
system:         LINUX
cli:            yes
libx264:        internal
shared:         no
static:         no
bashcompletion: yes
asm:            no
interlaced:     yes
avs:            avxsynth
lavf:           no
ffms:           no
mp4:            no
gpl:            yes
thread:         posix
opencl:         yes
filters:        crop select_every
lto:            no
debug:          no
gprof:          no
strip:          no
PIC:            no
bit depth:      all
chroma format:  all

You can run 'make' or 'make fprofiled' now.
zh@zh-lpc:~/soft/x264$
make
make install

几个比较好的解决办法:

# libfdk-aac
sudo apt-get install libfdk-aac-dev
​
# speex
sudo apt-get install libspeex-dev
​
# x264
sudo apt-get install libx264-dev
​
# x265
sudo apt-get install libx265-dev libnuma-dev

Max OS:

brew install fdk-aac

出现类似如下内容说明成功了:
在这里插入图片描述

然后编译:

如果你的计算机够强的话,可以使用多线程编译

make -j8

安装:

sudo make install

查看安装的内容

一下就是所安装的所有东西:

zh@zh-lpc:~/soft/ffmpeg$ cd /usr/local/ffmpeg/
zh@zh-lpc:/usr/local/ffmpeg$ ls
bin  include  lib  share
zh@zh-lpc:/usr/local/ffmpeg$
zh@zh-lpc:/usr/local/ffmpeg$
zh@zh-lpc:/usr/local/ffmpeg$ tree
.
├── bin
│   ├── ffmpeg
│   └── ffprobe
├── include
│   ├── libavcodec
│   │   ├── ac3_parser.h
│   │   ├── adts_parser.h
│   │   ├── avcodec.h
│   │   ├── avdct.h
│   │   ├── avfft.h
│   │   ├── bsf.h
│   │   ├── codec_desc.h
│   │   ├── codec.h
│   │   ├── codec_id.h
│   │   ├── codec_par.h
│   │   ├── d3d11va.h
│   │   ├── defs.h
│   │   ├── dirac.h
│   │   ├── dv_profile.h
│   │   ├── dxva2.h
│   │   ├── jni.h
│   │   ├── mediacodec.h
│   │   ├── packet.h
│   │   ├── qsv.h
│   │   ├── vdpau.h
│   │   ├── version.h
│   │   ├── videotoolbox.h
│   │   ├── vorbis_parser.h
│   │   └── xvmc.h
│   ├── libavdevice
│   │   ├── avdevice.h
│   │   └── version.h
│   ├── libavfilter
│   │   ├── avfilter.h
│   │   ├── buffersink.h
│   │   ├── buffersrc.h
│   │   └── version.h
│   ├── libavformat
│   │   ├── avformat.h
│   │   ├── avio.h
│   │   └── version.h
│   ├── libavutil
│   │   ├── adler32.h
│   │   ├── aes_ctr.h
│   │   ├── aes.h
│   │   ├── attributes.h
│   │   ├── audio_fifo.h
│   │   ├── avassert.h
│   │   ├── avconfig.h
│   │   ├── avstring.h
│   │   ├── avutil.h
│   │   ├── base64.h
│   │   ├── blowfish.h
│   │   ├── bprint.h
│   │   ├── bswap.h
│   │   ├── buffer.h
│   │   ├── camellia.h
│   │   ├── cast5.h
│   │   ├── channel_layout.h
│   │   ├── common.h
│   │   ├── cpu.h
│   │   ├── crc.h
│   │   ├── des.h
│   │   ├── detection_bbox.h
│   │   ├── dict.h
│   │   ├── display.h
│   │   ├── dovi_meta.h
│   │   ├── downmix_info.h
│   │   ├── encryption_info.h
│   │   ├── error.h
│   │   ├── eval.h
│   │   ├── ffversion.h
│   │   ├── fifo.h
│   │   ├── file.h
│   │   ├── film_grain_params.h
│   │   ├── frame.h
│   │   ├── hash.h
│   │   ├── hdr_dynamic_metadata.h
│   │   ├── hmac.h
│   │   ├── hwcontext_cuda.h
│   │   ├── hwcontext_d3d11va.h
│   │   ├── hwcontext_drm.h
│   │   ├── hwcontext_dxva2.h
│   │   ├── hwcontext.h
│   │   ├── hwcontext_mediacodec.h
│   │   ├── hwcontext_opencl.h
│   │   ├── hwcontext_qsv.h
│   │   ├── hwcontext_vaapi.h
│   │   ├── hwcontext_vdpau.h
│   │   ├── hwcontext_videotoolbox.h
│   │   ├── hwcontext_vulkan.h
│   │   ├── imgutils.h
│   │   ├── intfloat.h
│   │   ├── intreadwrite.h
│   │   ├── lfg.h
│   │   ├── log.h
│   │   ├── lzo.h
│   │   ├── macros.h
│   │   ├── mastering_display_metadata.h
│   │   ├── mathematics.h
│   │   ├── md5.h
│   │   ├── mem.h
│   │   ├── motion_vector.h
│   │   ├── murmur3.h
│   │   ├── opt.h
│   │   ├── parseutils.h
│   │   ├── pixdesc.h
│   │   ├── pixelutils.h
│   │   ├── pixfmt.h
│   │   ├── random_seed.h
│   │   ├── rational.h
│   │   ├── rc4.h
│   │   ├── replaygain.h
│   │   ├── ripemd.h
│   │   ├── samplefmt.h
│   │   ├── sha512.h
│   │   ├── sha.h
│   │   ├── spherical.h
│   │   ├── stereo3d.h
│   │   ├── tea.h
│   │   ├── threadmessage.h
│   │   ├── timecode.h
│   │   ├── time.h
│   │   ├── timestamp.h
│   │   ├── tree.h
│   │   ├── twofish.h
│   │   ├── tx.h
│   │   ├── version.h
│   │   ├── video_enc_params.h
│   │   └── xtea.h
│   ├── libpostproc
│   │   ├── postprocess.h
│   │   └── version.h
│   ├── libswresample
│   │   ├── swresample.h
│   │   └── version.h
│   └── libswscale
│       ├── swscale.h
│       └── version.h
├── lib
│   ├── libavcodec.a
│   ├── libavcodec.so -> libavcodec.so.59.7.102
│   ├── libavcodec.so.59 -> libavcodec.so.59.7.102
│   ├── libavcodec.so.59.7.102
│   ├── libavdevice.a
│   ├── libavdevice.so -> libavdevice.so.59.0.101
│   ├── libavdevice.so.59 -> libavdevice.so.59.0.101
│   ├── libavdevice.so.59.0.101
│   ├── libavfilter.a
│   ├── libavfilter.so -> libavfilter.so.8.7.101
│   ├── libavfilter.so.8 -> libavfilter.so.8.7.101
│   ├── libavfilter.so.8.7.101
│   ├── libavformat.a
│   ├── libavformat.so -> libavformat.so.59.5.100
│   ├── libavformat.so.59 -> libavformat.so.59.5.100
│   ├── libavformat.so.59.5.100
│   ├── libavutil.a
│   ├── libavutil.so -> libavutil.so.57.4.101
│   ├── libavutil.so.57 -> libavutil.so.57.4.101
│   ├── libavutil.so.57.4.101
│   ├── libpostproc.a
│   ├── libpostproc.so -> libpostproc.so.56.0.100
│   ├── libpostproc.so.56 -> libpostproc.so.56.0.100
│   ├── libpostproc.so.56.0.100
│   ├── libswresample.a
│   ├── libswresample.so -> libswresample.so.4.0.100
│   ├── libswresample.so.4 -> libswresample.so.4.0.100
│   ├── libswresample.so.4.0.100
│   ├── libswscale.a
│   ├── libswscale.so -> libswscale.so.6.1.100
│   ├── libswscale.so.6 -> libswscale.so.6.1.100
│   ├── libswscale.so.6.1.100
│   └── pkgconfig
│       ├── libavcodec.pc
│       ├── libavdevice.pc
│       ├── libavfilter.pc
│       ├── libavformat.pc
│       ├── libavutil.pc
│       ├── libpostproc.pc
│       ├── libswresample.pc
│       └── libswscale.pc
└── share
    ├── ffmpeg
    │   ├── examples
    │   │   ├── avio_list_dir.c
    │   │   ├── avio_reading.c
    │   │   ├── decode_audio.c
    │   │   ├── decode_video.c
    │   │   ├── demuxing_decoding.c
    │   │   ├── encode_audio.c
    │   │   ├── encode_video.c
    │   │   ├── extract_mvs.c
    │   │   ├── filter_audio.c
    │   │   ├── filtering_audio.c
    │   │   ├── filtering_video.c
    │   │   ├── http_multiclient.c
    │   │   ├── hw_decode.c
    │   │   ├── Makefile
    │   │   ├── metadata.c
    │   │   ├── muxing.c
    │   │   ├── qsvdec.c
    │   │   ├── README
    │   │   ├── remuxing.c
    │   │   ├── resampling_audio.c
    │   │   ├── scaling_video.c
    │   │   ├── transcode_aac.c
    │   │   ├── transcoding.c
    │   │   ├── vaapi_encode.c
    │   │   └── vaapi_transcode.c
    │   ├── ffprobe.xsd
    │   ├── libvpx-1080p50_60.ffpreset
    │   ├── libvpx-1080p.ffpreset
    │   ├── libvpx-360p.ffpreset
    │   ├── libvpx-720p50_60.ffpreset
    │   └── libvpx-720p.ffpreset
    └── man
        ├── man1
        │   ├── ffmpeg.1
        │   ├── ffmpeg-all.1
        │   ├── ffmpeg-bitstream-filters.1
        │   ├── ffmpeg-codecs.1
        │   ├── ffmpeg-devices.1
        │   ├── ffmpeg-filters.1
        │   ├── ffmpeg-formats.1
        │   ├── ffmpeg-protocols.1
        │   ├── ffmpeg-resampler.1
        │   ├── ffmpeg-scaler.1
        │   ├── ffmpeg-utils.1
        │   ├── ffprobe.1
        │   └── ffprobe-all.1
        └── man3
            ├── libavcodec.3
            ├── libavdevice.3
            ├── libavfilter.3
            ├── libavformat.3
            ├── libavutil.3
            ├── libswresample.3
            └── libswscale.3

18 directories, 220 files
zh@zh-lpc:/usr/local/ffmpeg$

测试是否成功

zh@zh-lpc:/usr/local/ffmpeg$ cd bin/
zh@zh-lpc:/usr/local/ffmpeg/bin$ ls
ffmpeg  ffprobe
zh@zh-lpc:/usr/local/ffmpeg/bin$
zh@zh-lpc:/usr/local/ffmpeg/bin$ ./ffmpeg -version
./ffmpeg: error while loading shared libraries: libavdevice.so.59: cannot open shared object file: No such file or directory
zh@zh-lpc:/usr/local/ffmpeg/bin$

配置动态库:

sudo vim /etc/ld.so.conf.d/libc.conf

把自己的安装目录下的lib目录写进去

zh@zh-lpc:/usr/local/ffmpeg$ cat /etc/ld.so.conf.d/libc.conf
# libc default configuration
/usr/local/lib
/usr/local/ffmpeg/lib

然后加载一下:

sudo ldconfig

配置环境变量

vim ~/.bashrc

尾部新增:

#FFMPEG
export PATH=$PATH:/usr/local/ffmpeg/bin

立即生效:

source ~/.bashrc

随后就可以执行了:


zh@zh-lpc:~$ ffmpeg -h
ffmpeg version N-103553-g5e7e2e5031 Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.3.0-17ubuntu1~20.04)
  configuration: --prefix=/usr/local/ffmpeg --enable-gpl --enable-nonfree --enable-libfdk-aac --enable-libx264 --enable-libx265 --enable-filter=delogo --enable-debug --disable-optimizations --enable-libspeex --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --cc=gcc --host-cflags= --host-ldflags= --disable-x86asm
  libavutil      57.  4.101 / 57.  4.101
  libavcodec     59.  7.102 / 59.  7.102
  libavformat    59.  5.100 / 59.  5.100
  libavdevice    59.  0.101 / 59.  0.101
  libavfilter     8.  7.101 /  8.  7.101
  libswscale      6.  1.100 /  6.  1.100
  libswresample   4.  0.100 /  4.  0.100
  libpostproc    56.  0.100 / 56.  0.100

没有ffplay的解决办法

可以看下生成的配置:

有一个!符号

zh@zh-lpc:~/soft/ffmpeg$ cat ffbuild/config.mak |grep "CONFIG_FFPLAY"
!CONFIG_FFPLAY=yes
zh@zh-lpc:~/soft/ffmpeg$

而且也没有编译成ffplay可执行程序

zh@zh-lpc:/usr/local/ffmpeg$ tree
.
├── bin
│   ├── ffmpeg
│   └── ffprobe

下载SDL2:

www.libsdl.org/download-2.…

在这里插入图片描述

然后解压并安装

./configure
make
make install

然后重新执行:

 ./configure --prefix=/usr/local/ffmpeg --enable-gpl --enable-nonfree --enable-libfdk-aac --enable-libx264 --enable-libx265 --enable-filter=delogo --enable-debug --disable-optimizations --enable-libspeex  --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --cc=gcc --host-cflags= --host-ldflags= --disable-x86asm

重新执行后发现!号没了:

zh@zh-lpc:~/soft/ffmpeg$ cat ffbuild/config.mak |grep "CONFIG_FFPLAY"
CONFIG_FFPLAY=yes
zh@zh-lpc:~/soft/ffmpeg$

然后进行编译安装:

make -j8

在这里插入图片描述

然后安装:

sudo make install

可以看到已经安装好了,也可以执行:

zh@zh-lpc:~$ ls /usr/local/ffmpeg/bin/
ffmpeg  ffplay  ffprobe
zh@zh-lpc:~$

zh@zh-lpc:~$
zh@zh-lpc:~$ ffplay
ffplay version N-103553-g5e7e2e5031 Copyright (c) 2003-2021 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.3.0-17ubuntu1~20.04)
  configuration: --prefix=/usr/local/ffmpeg --enable-gpl --enable-nonfree --enable-libfdk-aac --enable-libx264 --enable-libx265 --enable-filter=delogo --enable-debug --disable-optimizations --enable-libspeex --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --cc=gcc --host-cflags= --host-ldflags= --disable-x86asm
  libavutil      57.  4.101 / 57.  4.101
  libavcodec     59.  7.102 / 59.  7.102
  libavformat    59.  5.100 / 59.  5.100
  libavdevice    59.  0.101 / 59.  0.101
  libavfilter     8.  7.101 /  8.  7.101
  libswscale      6.  1.100 /  6.  1.100
  libswresample   4.  0.100 /  4.  0.100
  libpostproc    56.  0.100 / 56.  0.100
Simple media player
usage: ffplay [options] input_file