1.CentOS7编译安装FFmpeg-4.3

环境确认

查看操作系统及内核版本号:

1
2
3
4
5
$ cat /etc/redhat-release 
CentOS Linux release 7.9.2009 (Core)

$ uname -a
Linux VM-32-14-centos 3.10.0-1160.88.1.el7.x86_64 #1 SMP Tue Mar 7 15:41:52 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

基础依赖

RHEL/CentOS 安装企业版 Linux 附加软件包(EPEL)

安装 EPEL 附加软件包

1
2
3
4
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

yum clean all
yum makecache

升级操作系统及软件包版本:

1
yum update -y

安装基础依赖:

1
2
3
4
5
6
7
8
yum install -y \
autoconf automake \
bzip2 bzip2-devel \
cmake freetype-devel \
gcc gcc-c++ \
git libtool \
make pkgconfig \
zlib-devel

yasm-1.2.0

1
yum install yasm -y

nasm-2.15.05

1
2
3
4
5
6
7
8
9
10
11
cd /usr/local/src
curl -O -L https://www.nasm.us/pub/nasm/releasebuilds/2.15.05/nasm-2.15.05.tar.bz2
tar xjvf nasm-2.15.05.tar.bz2
cd nasm-2.15.05
./autogen.sh
./configure \
--prefix="$HOME/ffmpeg_build" \
--bindir="$HOME/bin"
make && make install


x264

1
2
3
4
5
6
7
8
9
10
cd /usr/local/src
git clone --branch stable --depth 1 https://code.videolan.org/videolan/x264.git
cd x264
PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \
--prefix="$HOME/ffmpeg_build" \
--bindir="$HOME/bin" \
--enable-static
make && make install


x265

1
2
3
4
5
6
7
cd /usr/local/src
git clone --branch stable --depth 2 https://bitbucket.org/multicoreware/x265_git
cd x265_git/
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED:bool=off source
make && make install


fdk-aac

1
2
3
4
5
6
7
8
9
10
cd /usr/local/src
git clone --depth 1 https://github.com/mstorsjo/fdk-aac
cd fdk-aac/
autoreconf -fiv
./configure \
--prefix="$HOME/ffmpeg_build" \
--disable-shared
make && make install


lame-3.100

1
2
3
4
5
6
7
8
9
10
11
12
cd /usr/local/src
curl -O -L https://downloads.sourceforge.net/project/lame/lame/3.100/lame-3.100.tar.gz
tar xzvf lame-3.100.tar.gz
cd lame-3.100
./configure \
--prefix="$HOME/ffmpeg_build" \
--bindir="$HOME/bin" \
--disable-shared \
--enable-nasm
make && make install


opus-1.3.1

1
2
3
4
5
6
7
8
9
10
cd /usr/local/src
curl -O -L https://archive.mozilla.org/pub/opus/opus-1.3.1.tar.gz
tar xzvf opus-1.3.1.tar.gz
cd opus-1.3.1
./configure \
--prefix="$HOME/ffmpeg_build" \
--disable-shared
make && make install


libvpx

1
2
3
4
5
6
7
8
9
10
11
12
13
cd /usr/local/src
git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git
chmod -R 0777 libvpx
cd libvpx
./configure \
--prefix="$HOME/ffmpeg_build" \
--disable-examples \
--disable-unit-tests \
--enable-vp9-highbitdepth \
--as=yasm
make && make install


编译安装 ffmpeg-4.3

这里需要先安装一遍 ffmpeg,我们选用的版本号为 4.3

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
cd /usr/local/src
wget https://ffmpeg.org/releases/ffmpeg-4.3.tar.bz2
tar xvf ffmpeg-4.3.tar.bz2
cd ffmpeg-4.3

PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \
--prefix="$HOME/ffmpeg_build" \
--pkg-config-flags="--static" \
--extra-cflags="-I$HOME/ffmpeg_build/include" \
--extra-ldflags="-L$HOME/ffmpeg_build/lib" \
--extra-libs=-lpthread \
--extra-libs=-lm \
--bindir="$HOME/bin" \
--enable-gpl \
--enable-libfdk_aac \
--enable-libfreetype \
--enable-libmp3lame \
--enable-libopus \
--enable-libvpx \
--enable-libx264 \
--enable-libx265 \
--enable-nonfree
make && make install


首次安装完成,确认版本号及编译参数:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ ~/bin/ffmpeg 
ffmpeg version 4.3 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-44)
configuration: --prefix=/root/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/root/ffmpeg_build/include --extra-ldflags=-L/root/ffmpeg_build/lib --extra-libs=-lpthread --extra-libs=-lm --bindir=/root/bin --enable-gpl --enable-libfdk_aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Use -h to get full help or, even better, run 'man ffmpeg'

创建软链接:

1
ln -s ~/bin/ffmpeg /usr/local/bin/