【FFmpeg】FFmpeg在Linux中的下载、编译、安装

全称参考:http://avdancedu.com/f3f66133/

版本1:通过源代码的方式安装FFmpeg(虽然麻烦,但是强推)

在Windows中下载源码包,并传到Linux中:

下载地址

(1)下载得到的压缩包名称:ffmpeg-snapshot.tar.bz2
(2)上传到云服务器
scp ffmpeg-snapshot.tar.bz2 root@129.211.91.3:/root/Study/FFmpeg/
(3)到云端解压缩
ssh root@129.211.91.3
找到文件夹
tar -jxvf ffmpeg-snapshot.tar.bz2
(4)进入解压后的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-opengl --enable-libspeex --enable-libopus --enable-libmp3lame --enable-videotoolbox --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --host-cflags= --host-ldflags= 

暂时不用:
–cc=clang 报错:C compiler test failed.

(4-1)报错1:

ERROR: libfdk_aac not found

解决:
在Windows下下载压缩包,下载地址
压缩包名称:fdk-aac-2.0.1.tar.gz

scp fdk-aac-2.0.1.tar.gz root@129.211.91.3:/root/Study/FFmpeg/
在云服务器中找到FFmpeg/文件夹
tar -zxvf fdk-aac-2.0.1.tar.gz
cd fdk-aac-2.0.1
./configure --enable-static --enable-shared --disable-asm --disable-avs
make && sudo make install
(4-2)报错2

重复执行configure命令,报错2如下:

ERROR: speex not found using pkg-config

解决:
参考
在Windows下下载压缩包,下载地址
压缩包名称:speex-1.2.0.tar.gz

scp speex-1.2.0.tar.gz root@129.211.91.3:/root/Study/FFmpeg/
在云服务器中找到FFmpeg/文件夹
tar -zxvf speex-1.2.0.tar.gz
cd speex-1.2.0
./configure --disable-oggtest
make && sudo make install
(4-3) 报错3

重复执行configure命令,仍然报错

ERROR: speex not found using pkg-config

参考

vi /etc/profile
在末尾添加:
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/bin/pkgconfig
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/ffmpeg/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
然后保存退出
执行以下命令使配置文件生效
source /etc/profile	
(4-4) 报错4

重复执行configure命令,报错:

ERROR: libx264 not found

参考

wget https://code.videolan.org/videolan/x264/-/archive/master/x264-master.tar.bz2
tar -jxvf x264-master.tar.bz2
cd x264-master
./configure --enable-static --enable-shared --disable-asm --disable-avs
make && sudo make install
(4-5) 报错5

重复执行configure命令,报错:

ERROR: x265 not found using pkg-config

参考

wget http://ftp.videolan.org/pub/videolan/x265/x265-2.7.tar.bz2
tar -jxvf x265-2.7.tar.bz2
cd multicoreware-x265-e41a9bf2bac4
cd build/linux
./make-Makefiles.bash
按c或g
make install
(4-6)报错6

重复执行configure命令,报错:

ERROR: libmp3lame >= 3.98.3 not found

解决:
参考
在Windows下下载压缩包,下载地址
压缩包名称:lame-3.100.tar.gz

scp lame-3.100.tar.gz root@129.211.91.3:/root/Study/FFmpeg/
在云服务器中找到FFmpeg/文件夹
tar -zxvf lame-3.100.tar.gz
cd lame-3.100
./configure
make && sudo make install
(4-7)报错7

重复执行configure命令,报错:

ERROR: opus not found using pkg-config

解决:
参考

在Windows下下载压缩包,下载地址
压缩包名称:opus-1.3.1.tar.gz

scp opus-1.3.1.tar.gz root@129.211.91.3:/root/Study/FFmpeg/
在云服务器中找到FFmpeg/文件夹
tar -zxvf opus-1.3.1.tar.gz
cd opus-1.3.1
./configure
make && sudo make install
(4-8)报错8

重复执行configure命令,报错:

ERROR: opengl not found.

解决:
下载https://www.khronos.org/opengl/wiki/Getting_Started#Downloading_OpenGL

参考1
参考2

安装依赖包:
yum list mesa* :查看mesa相关的包
yum install mesa*
yum install freeglut*
yum -y install gcc-c++  若没有c++编译器,还需要安装
(4-9)报错9(暂未解决)

重复执行configure命令,报错:

ERROR: videotoolbox requested, but not all dependencies are satisfied: corefoundation coremedia corevideo

参考
解决:

yum install alsa-lib-devel

在FFmpeg/文件夹下,下载并编译头文件:
git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git
cd nv-codec-headers
make
sudo make install

在FFmpeg/文件夹下,下载并编译SDL2:
wget http://www.libsdl.org/release/SDL2-2.0.12.tar.gz
tar -zxvf SDL2-2.0.12.tar.gz 
cd SDL2-2.0.12
./configure
make && sudo make install

还是报错,选择去掉–enable-videotoolbox。

重复执行configure命令,终于不报错了。

(5)编译与安装

在ffmpeg文件夹中执行:

make && make install

最终成功!!!

(6)在环境变量中添加ffmpeg的路径
vim /etc/profile

在文件末尾加上两句话:
export FFMPEG_HOME=/usr/local/ffmpeg 
export PATH=$FFMPEG_HOME/bin:$PATH

保存并关闭后使其生效:
source /etc/profile

直接执行ffmpeg,就可以看到版本和配置信息:

ffmpeg
ffmpeg version N-100131-g0639f5c Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-39)
  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
  libavutil      56. 61.100 / 56. 61.100
  libavcodec     58.114.100 / 58.114.100
  libavformat    58. 64.100 / 58. 64.100
  libavdevice    58. 11.103 / 58. 11.103
  libavfilter     7. 91.100 /  7. 91.100
  libswscale      5.  8.100 /  5.  8.100
  libswresample   3.  8.100 /  3.  8.100
  libpostproc    55.  8.100 / 55.  8.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'

查看版本 ffmpeg -version:

[root@VM_0_10_centos bin]#  ffmpeg -version
ffmpeg version N-100131-g0639f5c Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-39)
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
libavutil      56. 61.100 / 56. 61.100
libavcodec     58.114.100 / 58.114.100
libavformat    58. 64.100 / 58. 64.100
libavdevice    58. 11.103 / 58. 11.103
libavfilter     7. 91.100 /  7. 91.100
libswscale      5.  8.100 /  5.  8.100
libswresample   3.  8.100 /  3.  8.100
libpostproc    55.  8.100 / 55.  8.100

版本2:通过平台安装FFmpeg

refrence

(1)添加RPMfusion仓库

我的是CentOS 7 如果是其他版本 请参考:https://download1.rpmfusion.org/free/el/

sudo yum install https://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm
(2)安装SDL媒体库
sudo yum install http://rpmfind.net/linux/epel/7/x86_64/Packages/s/SDL2-2.0.10-1.el7.x86_64.rpm
(3)安装FFmpeg
sudo yum install ffmpeg

如果需要开发的同学 可以在安装开发库

sudo yum -y install ffmpeg-devel
(4)查看是否安装成功

rpm -qi ffmpeg

[root@iZuf69fe7vrj77jnaq5xn2Z pk]# rpm -qi ffmpeg
Name        : ffmpeg
Version     : 3.4.8
Release     : 1.el7
Architecture: x86_64
Install Date: 20201104日 星期三 150546秒
Group       : Unspecified
Size        : 2260881
License     : GPLv2+
Signature   : RSA/SHA1, 20200706日 星期一 203914, Key ID 758b3d18f5cf6c1e
Source RPM  : ffmpeg-3.4.8-1.el7.src.rpm
Build Date  : 20200705日 星期日 152754秒
Build Host  : ebb14babbee54b3dada2f07a2760bfe1
Relocations : (not relocatable)
Packager    : RPM Fusion
Vendor      : RPM Fusion
URL         : http://ffmpeg.org/
Summary     : Digital VCR and streaming server
Description :
FFmpeg is a complete and free Internet live audio and video
broadcasting solution for Linux/Unix. It also includes a digital
VCR. It can encode in real time in many formats including MPEG1 audio
and video, MPEG4, h263, ac3, asf, avi, real, mjpeg, and flash.

或者
ffmpeg -version

[root@iZuf69fe7vrj77jnaq5xn2Z pk]# ffmpeg -version
ffmpeg version 3.4.8 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-39)
configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --docdir=/usr/share/doc/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic' --extra-ldflags='-Wl,-z,relro ' --extra-cflags=' ' --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-version3 --enable-bzlib --disable-crystalhd --enable-fontconfig --enable-gcrypt --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libcdio --enable-libdrm --enable-indev=jack --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libmp3lame --enable-nvenc --enable-openal --enable-opencl --enable-opengl --enable-libopenjpeg --enable-libopus --disable-encoder=libopus --enable-libpulse --enable-librsvg --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvidstab --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzvbi --enable-avfilter --enable-avresample --enable-libmodplug --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-libmfx --enable-runtime-cpudetect
libavutil      55. 78.100 / 55. 78.100
libavcodec     57.107.100 / 57.107.100
libavformat    57. 83.100 / 57. 83.100
libavdevice    57. 10.100 / 57. 10.100
libavfilter     6.107.100 /  6.107.100
libavresample   3.  7.  0 /  3.  7.  0
libswscale      4.  8.100 /  4.  8.100
libswresample   2.  9.100 /  2.  9.100
libpostproc    54.  7.100 / 54.  7.100

到这里就完成了,是不是很方便简单

版本3(无效,仅做记录,不要参考)

登录我的远程主机:

ssh root@129.211.91.3
回车后输入10位密码进入CentorOS环境

下载FFmpeg,这一步很费时间

git clone https://git.ffmpeg.org/ffmpeg.git

编译:

./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
make
make install
  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
编译 FFmpeg 的 ffplay 工具,你需要先获取 FFmpeg 的源代码,并在 Linux 环境下安装交叉编译工具链。以下是编译步骤的简要概述: 1. 获取 FFmpeg 源代码 你可以从 FFmpeg 的官方网站或 Git 仓库获取最新的源代码。 2. 安装交叉编译工具链 你需要安装适用于 arm64 架构的交叉编译工具链,例如 aarch64-linux-gnu-gcc。你可以从 Linux 发行版的软件仓库安装,或者从交叉编译工具链的官方网站下载。 3. 配置编译选项 进入 FFmpeg 源代码目录,运行以下命令进行配置: ``` ./configure --arch=arm64 --target-os=linux --enable-gpl --enable-nonfree --enable-shared --enable-pic --cross-prefix=aarch64-linux-gnu- --prefix=/usr/local/arm/ffmpeg --extra-cflags="-I/usr/local/arm/include" ``` 这个命令与之前提到的类似,指定了 arm64 架构和 Linux 系统,启用了 GPL 和非自由组件,以及共享库和位置无关代码编译选项。额外的 CFLAGS 选项指定了头文件搜索路径。 4. 编译安装 运行以下命令进行编译安装: ``` make make install ``` 这个命令将编译 FFmpeg 和 ffplay 工具,并将它们安装到指定的目录。如果编译过程出现错误,你可以查看编译日志和错误信息,然后尝试解决问题。 注意:编译 FFmpeg 需要一定的时间和系统资源,特别是在较慢的硬件上。你可以使用 make 命令的 -j 选项来指定并行编译任务的数量,以缩短编译时间。例如,make -j4 将使用 4 个并行任务编译代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值