Centos7安装FFmpeg

第一部分:基础知识简介

1. FFmpeg介绍

FFmpeg是一个完整的,跨平台的解决方案,用于记录,转换和流化音视频.其中FF代表Fast Forword

2. FFmpeg的组件

包含libavcodec,libavutil,libavformat,libavfilter,libavdevice,libscale和libswresample,以及ffmpeg,ffplay和ffprobe,如图所示

[lidengyin@ldy ~]$ ffmpeg --version
ffmpeg version 4.1 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-39)
  configuration: --prefix=/usr/local/ffmpeg --enable-libx264 --enable-gpl
  libavutil      56. 22.100 / 56. 22.100
  libavcodec     58. 35.100 / 58. 35.100
  libavformat    58. 20.100 / 58. 20.100
  libavdevice    58.  5.100 / 58.  5.100
  libavfilter     7. 40.101 /  7. 40.101
  libswscale      5.  3.100 /  5.  3.100
  libswresample   3.  3.100 /  3.  3.100
  libpostproc    55.  3.100 / 55.  3.100

在这里插入图片描述

3. 所支持的协议

从直播角度来说FFmpeg支持HTTP,RTSP,RTMP协议

4. 实例

  • To set the video bitrate of the output file to 64 kbit/s(要将输出文件的视频比特率设置为64 kbit / s):
ffmpeg -i input.avi -b:v 64k -bufsize 64k output.avi
  • To force the frame rate of the output file to 24 fps(要将输出文件的帧速率强制为24 fps,请执行以下操作):
ffmpeg -i input.avi -r 24 output.avi
  • To force the frame rate of the input file (valid for raw formats only) to 1 fps and the frame rate of the output file to 24fps(要将输入文件的帧速率(仅对原始格式有效)强制为1 fps,将输出文件的帧速率强制为24 fps):

ffmpeg -r 1 -i input.m2v -r 24 output.avi

转码流程如下:

在这里插入图片描述
ffmpeg调用libavformat库(包含解复用器)以读取输入文件并从中获取包含编码数据的数据包。当有多个输入文件时,请ffmpeg尝试通过跟踪任何活动输入流上的最低时间戳来使它们保持同步。

然后,已编码的数据包将传递到解码器(除非为流选择了流复制,否则请参见说明)。解码器产生未压缩的帧(原始视频/ PCM音频/ …),可以通过过滤进一步处理(请参阅下一节)。过滤后,将帧传递到编码器,由编码器对其进行编码并输出编码后的数据包。最后,这些被传递到复用器,该复用器将编码的数据包写入输出文件。

第二部分:安装部分

1. 下载

wget https://johnvansickle.com/ffmpeg/release-source/ffmpeg-4.1.tar.xz

2. 解压

sudo tar -Jxvf ffmpeg-4.1.tar.xz -C /usr/local/software/

3. 配置

sudo ./configure --prefix=/usr/local/ffmpeg
sudo make & make install

4. 添加ffmpeg到环境变量

sudo vim /etc/profile

找到文件尾部,插入

export FFMEPG=/usr/local/ffmpeg
export PATH=${FFMEPG}/bin:${PATH}

生效

source /etc/profile

5. ./configure出现的问题,安装yasm

If you think configure made a mistake, make sure you are using the latest
version from Git.  If the latest version fails, report the problem to the
ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file "config.log" produced by configure as this will help
solve the problem.
  • 压缩包
wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz 
  • 解压
tar zxvf yasm-1.3.0.tar.gz -c /usr/local/software/yasm
  • 配置,编译,安装
sudo ./configure

  • 编译
sudo make
  • 安装
sudo make install 

6. 修改文件/etc/ld.so.conf

sudo vim /etc/ld.so.conf

在最后加入

include ld.so.conf.d/*.conf
/usr/local/ffmpeg/lib/

7. 查看版本

ffmpeg -version
[lidengyin@ldy ~]$ ffmpeg --version
ffmpeg version 4.1 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-39)
  configuration: --prefix=/usr/local/ffmpeg --enable-libx264 --enable-gpl
  libavutil      56. 22.100 / 56. 22.100
  libavcodec     58. 35.100 / 58. 35.100
  libavformat    58. 20.100 / 58. 20.100
  libavdevice    58.  5.100 / 58.  5.100
  libavfilter     7. 40.101 /  7. 40.101
  libswscale      5.  3.100 /  5.  3.100
  libswresample   3.  3.100 /  3.  3.100
  libpostproc    55.  3.100 / 55.  3.100

8. libx264安装(这里开始必须切换root)

重新编译配置以及编译安装FFmepg,将新的libx264配置到FFmepg

./configure --prefix=/usr/local/ffmpeg --enable-libx264 --enable-gpl
#启用libx264,libx264需要gpl
#提示ERROR,libx264 not found, x264需要我们自己安装,而并不是FFmpeg所默认包含的库

因为X264会依赖NASM的汇编加速,因此这里先安装NASM.如果不安装NASM,会报错:

Minimun version is nasm-2.13

(1)安装NASM
在这里插入图片描述
(2)安装x264
在这里插入图片描述
(3)配置x264环境变量
在这里插入图片描述
(4)一定要用root,我在安装的时候大量报错,因为权限不足

要在CentOS7安装FFmpeg,可以按照以下步骤进行操作: 1. 首先,从FFmpeg官方网站(https://johnvansickle.com/ffmpeg/release-source/)下载Linux版的FFmpeg源码包。 2. 使用finalshell或其他SSH工具将下载的源码包(例如ffmpeg-4.1.tar.xz)上传到CentOS7主机上的某个目录(例如/soft/ffmpeg目录)。 3. 在CentOS7主机上打开终端,使用以下命令安装编译FFmpeg所需的依赖项: ``` sudo yum install epel-release sudo yum install autoconf automake cmake freetype-devel gcc gcc-c++ git libtool make mercurial nasm pkgconfig zlib-devel ``` 4. 解压源码包并切换到解压后的目录: ``` tar -xf ffmpeg-4.1.tar.xz cd ffmpeg-4.1 ``` 5. 使用以下命令配置编译选项: ``` ./configure --enable-shared --disable-static ``` 6. 运行以下命令编译并安装FFmpeg: ``` make sudo make install ``` 7. 安装完成后,可以使用以下命令检查FFmpeg是否成功安装: ``` ffmpeg -version ``` 如果成功安装,将显示FFmpeg的版本信息。 通过以上步骤,您可以在CentOS7上成功安装FFmpeg并开始使用其功能。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Centos7安装FFmpeg](https://blog.csdn.net/weixin_45344950/article/details/118700456)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [开发那些事儿:如何在CentOS7安装部署ffmpeg?](https://blog.csdn.net/TsingSee/article/details/125395349)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值