第一部分:基础知识简介
1. FFmpeg介绍
FFmpeg是一个完整的,跨平台的解决方案,用于记录,转换和流化音视频.其中FF表明Fast Forwordnode
2. FFmpeg的组件
包含libavcodec,libavutil,libavformat,libavfilter,libavdevice,libscale和libswresample,以及ffmpeg,ffplay和ffprobe,如图所示vim
[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协议bash
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
转码流程以下:ide
ffmpeg调用libavformat库(包含解复用器)以读取输入文件并从中获取包含编码数据的数据包。当有多个输入文件时,请ffmpeg尝试经过跟踪任何活动输入流上的最低时间戳来使它们保持同步。
post
而后,已编码的数据包将传递到解码器(除非为流选择了流复制,不然请参见说明)。解码器产生未压缩的帧(原始视频/ PCM音频/ …),能够经过过滤进一步处理(请参阅下一节)。过滤后,将帧传递到编码器,由编码器对其进行编码并输出编码后的数据包。最后,这些被传递到复用器,该复用器将编码的数据包写入输出文件。ui
第二部分:安装部分
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
找到文件尾部,插入this
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
在最后加入spa
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.net
./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,我在安装的时候大量报错,由于权限不足