Centos7安装编译ffmpeg到指定目录
一、编译安装(太麻烦了)
1、官网下载tar包
https://ffmpeg.org/download.html
2、解压/usr/local目录
3、编译准备
cd ffmpeg-6.0 # 切换到ffmpeg-6.0目录
yum install gcc # 安装gcc编译器
yum install yasm # 安装yasm编译器
4、安装设置
./configure --enable-shared --prefix=/usr/local/ffmpeg # --prefix 指定安装目录
5、编译安装
make # 编译(需要等待)
make install # 安装
6、修改文件/etc/ld.so.conf
vim /etc/ld.so.conf
# 输入以下内容
include ld.so.conf.d/*.conf
/usr/local/ffmpeg/lib/
输入 ldconfig
使修改生效
7、查看ffmpeg版本
ffmpeg -version
8、配置系统变量
打开配置文件
vi /etc/profile
在export PATH之后添加:
# Set ffmpeg environment
PATH=$PATH:/usr/local/ffmpeg/ffmpeg/bin
二、静态安装
1、下载静态安装包
John Van Sickle - FFmpeg Static Builds
ffmpeg-release-amd64-static.tar.xz解压安装到:/usr/local/ffmpeg下
2、配置环境变量
打开配置文件
vi /etc/profile
在export PATH之后添加:
# Set ffmpeg environment
PATH=$PATH:/usr/local/ffmpeg
CentOS编译FFmpeg
libx264
H. 264视频编码器。有关更多信息和使用示例,请参阅H. 264编码指南。
要求将 ffmpeg 配置为 --enable-gpl
--enable-libx264.
git clone --branch stable --depth 1 https://code.videolan.org/videolan/x264.git
cd x264
./configure --enable-shared --enable-static
make && make install
libx265
H. 265/HEVC 视频编码器。有关更多信息和使用示例,请参阅H.265编码指南。
要求将 ffmpeg 配置为 --enable-gpl
--enable-libx265.
git clone --branch stable --depth 2 https://bitbucket.org/multicoreware/x265_git
cd x265
./configure --enable-shared --enable-static
make
make install
libfdk_aac
AAC 音频编码器。有关更多信息和使用示例,请参阅AAC 音频编码指南。
要求将 ffmpeg 配置为 --enable-libfdk_aac
(and --enable-nonfree
if you also included --enable-gpl
).
git clone --depth 1 https://github.com/mstorsjo/fdk-aac
cd fdk-aac
autoreconf -fiv
./configure --disable-shared
make
make install
libmp3lame
MP3音频编码器。
要求将 ffmpeg 配置为 --enable-libmp3lame
.
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 --disable-shared
make
make install
libopus
Opus音频解码器和编码器。
要求将 ffmpeg 配置为 --enable-libopus
.
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 --disable-shared
make
make install
libvpx
VP8/VP9视频编码器和解码器。更多信息和使用实例,请参见VP9视频编码指南。
要求将 ffmpeg 配置为 --enable-libvpx
.
git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git
cd libvpx
./configure --disable-examples --disable-unit-tests --enable-vp9-highbitdepth --as=yasm
make
make install
FFmpeg
wget http://www.ffmpeg.org/releases/ffmpeg-5.1.tar.gz
tar -zxvf ffmpeg-5.1.tar.gz
cd ffmpeg
./configure \
--prefix="/usr/local/ffmpeg" \
--pkg-config-flags="--static" \
--extra-libs=-lpthread \
--extra-libs=-lm \
--enable-gpl \
--enable-libfdk_aac \
--enable-libfreetype \
--enable-libmp3lame \
--enable-libopus \
--enable-libvpx \
--enable-libx264 \
--enable-libx265 \
--enable-nonfree
make
make install
参数详解:
用法:配置[选项] 选项:[描述后括号中的默认值]
--prefix="/usr/local/ffmpeg" 安装程序到指定目录 [/usr/local]
--pkg-config-flags="--static" 将附加标志传递给pkgconf []
--extra-cflags="-I/usr/local/include" 将"-I/usr/local/include" 添加到CFLAGS []
--extra-ldflags="-L/usr/local/lib" 将"-I/usr/local/include" 添加到LDFLAGS []
--extra-libs=-lpthread 添加 ELIBS []
--extra-libs=-lm 添加 ELIBS []
--enable-gpl 允许使用GPL代码,生成的库和二进制文件将在GPL下 [no]
--enable-libfreetype 启用libfreetype,drawtext过滤器需要 [no]
--enable-libx264 通过x264启用H.264编码 [no]
--enable-libx265 通过x265启用HEVC编码 [no]
--enable-nonfree 允许使用非自由代码,生成的库和二进制文件将是不可分发的 [no]
--extra-libs=-ldl 添加 ELIBS []
--enable-pic 构建与位置无关的代码
配置系统变量
# 新增动态库地址
echo "/usr/local/lib" >> /etc/ld.so.conf
ldconfig # 刷新动态库
# 在最后PATH添加环境变量
vi /etc/profile
export PATH=$PATH:/usr/local/ffmpeg/bin
# 设置生效
source /etc/profile
备注:ldconfig是一个动态链接库管理命令,此命令可以让动态链接库为系统所共享。 主要用途是在默认搜寻目录(/lib和/usr/lib)以及动态库配置文件(/etc/ld.so.conf)内所列的目录下,搜索出可共享的动态链接库(格式lib*.so*),并创建出动态装入程序(ld.so)所需的连接和缓存文件。
查看版本
[root@localhost ~]# ffmpeg -version
ffmpeg version 5.1 Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-44)
configuration: --prefix=/usr/local/ffmpeg --pkg-config-flags=--static --extra-libs=-lpthread --extra-libs=-lm --enable-gpl --enable-libfreetype --enable-libfdk_aac --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
libavutil 57. 28.100 / 57. 28.100
libavcodec 59. 37.100 / 59. 37.100
libavformat 59. 27.100 / 59. 27.100
libavdevice 59. 7.100 / 59. 7.100
libavfilter 8. 44.100 / 8. 44.100
libswscale 6. 7.100 / 6. 7.100
libswresample 4. 7.100 / 4. 7.100
libpostproc 56. 6.100 / 56. 6.100
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。