Ubuntu搭建FFMPEG开发环境
1.下载FFmpeg源码
wget http://ffmpeg.org/releases/ffmpeg-5.0.1.tar.xz
tar -xf ffmpeg-5.0.1.tar.xz
cd ffmpeg-5.0.1
2.安装依赖库
sudo apt-get -y install autoconf automake build-essential libass-dev libfreetype6-dev libsdl2-dev libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev pkg-config texinfo zlib1g-dev
3.安装汇编库
Yasm是一个完全重写的NASM(The Netwide Assembler)汇编;
NASM是一个为可移植性与模块化而设计的一个80x86的汇编器。
它支持相当多的目标文件格式,包括Linux,*BSD,a.out,ELF,COFF,
Mach−O,Microsoft 16−bit OBJ,Win32以及Win64,
同时也支持简单的二进制文件生成。
sudo apt-get -y install yasm
sudo apt-get -y install nasm
4.安装视频库
要支持X264等视频处理,就需要安装相应的库:
sudo apt-get -y install libx264-dev
sudo apt-get -y install libx265-dev
5.安装音频库
要支持常见的音频处理,需要安装:
sudo apt-get -y install libfdk-aac-dev
sudo apt-get -y install libmp3lame-dev
sudo apt-get -y install libopus-dev
6.配置
-
基础选项
./configure --enable-shared --prefix=/usr/local/ffmpeg -
额外增加H264支持
./configure --prefix=/usr/local/ffmpeg --enable-libx264 --disable-yasm --enable-nonfree --enable-libfdk-aac --enable-shared --enable-gpl --enable-libmp3lame --enable-libopus --exta-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib -
编译安装
sudo make sudo make install
7.建立软链接
sudo ln -s /usr/local/ffmpeg/bin/ffmpeg /usr/bin/ffmpeg
sudo ln -s /usr/local/ffmpeg/bin/ffprobe /usr/bin/ffprobe
8.配置FFmpeg依赖环境
sudo vim /etc/ld.so.conf
在其中添加路径:/usr/local/ffmpeg/lib
include /etc/ld.so.conf.d/*.conf
/usr/local/ffmpeg/lib
更新环境变量
sudo ldconfig
9.路径配置
为能随时使用FFmpeg,需要把对应目录添加到路径中。打开配置文件vi ~/.profile,添加:
FFMPEG=/usr/local/ffmpeg
PATH="$PATH:$FFMPEG/bin"
然后执行source ~/.profile,以使配置生效。
10.版本查看
$ ffmpeg
ffmpeg version 5.0.1 Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
configuration: --enable-shared --prefix=/usr/local/ffmpeg
libavutil 57. 17.100 / 57. 17.100
libavcodec 59. 18.100 / 59. 18.100
libavformat 59. 16.100 / 59. 16.100
libavdevice 59. 4.100 / 59. 4.100
libavfilter 8. 24.100 / 8. 24.100
libswscale 6. 4.100 / 6. 4.100
libswresample 4. 3.100 / 4. 3.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'
11.卸载
删除相应的软链接/usr/bin/ffmpeg和/usr/bin/ffprobe,编译目录/usr/local/ffmpeg。清空环境变量中修改的地方并更新。

浙公网安备 33010602011771号