1 安装支持库
sudo apt-get install -y autoconf automake build-essential git libass-dev libfreetype6-dev libsdl2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev pkg-config texinfo wget zlib1g-dev
还有
apt install libavformat-dev
apt install libavcodec-dev
apt install libswresample-dev
apt install libswscale-dev
apt install libavutil-dev
apt install libsdl1.2-dev
sudo apt install yasm libsdl2-dev libx264-dev libx265-dev libfdk-aac-dev5
全都需要安上,不然编译会报错
2 下载ffmpeg
git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg
也可直接去官网下载,只要能下载下来包就行了
3 编译
进入包,执行指令
./configure --enable-shared --prefix=/usr/local/ffmpeg --enable-gpl --enable-libx264 --enable-libx265
继续执行
make
make install
增加安装目录的动态链接库
export LD_LIBRARY_PATH=/usr/local/ffmpeg/lib:$LD_LIBRARY_PATH
查看依赖库
ldd ffmpeg
5 查看版本号
ffmpeg –version
这里可能会报一个错
The program 'ffmpeg' is currently not installed. You can install it by typing:
sudo apt install ffmpeg
此时把编译后文件中/usr/local/ffmpeg/bin/ffmpeg文件复制到/usr/ bin当中
就可以成功查看版本号了,会得到一个类似以下输出
ffmpeg version N-99925-g96443ab Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 5.5.0 (Ubuntu 5.5.0-12ubuntu1~16.04) 20171010
configuration: --enable-shared --prefix=/usr/local/ffmpeg --enable-gpl --enable-libx264 --enable-libx265
libavutil 56. 60.100 / 56. 60.100
libavcodec 58.112.103 / 58.112.103
libavformat 58. 64.100 / 58. 64.100
libavdevice 58. 11.102 / 58. 11.102
libavfilter 7. 90.100 / 7. 90.100
libswscale 5. 8.100 / 5. 8.100
libswresample 3. 8.100 / 3. 8.100
libpostproc 55. 8.100 / 55. 8.100
报错:
ffmpeg: error while loading shared libraries: libavdevice.so.58: cannot open
解决:
sudo gedit /etc/ld.so.conf
在文件中添加路径:
/usr/local/ffmpeg/lib
#usr/local/ffmpeg 目录是ffmpeg的安装目录,根据个人不同安装目录修改。
更新环境变量
sudo ldconfig
参考:
https://blog.csdn.net/u014470361/article/details/90705336
https://blog.csdn.net/weixin_37897683/article/details/90317616