音视频剪辑|剪辑神器FFMPEG的详细介绍和一些基本的参数介绍

FFmpeg的介绍

FFmpeg是一套可以用来记录、转换数字音频、视频,并能将其转化为流的开源计算机程序。它包括了目前领先的音/视频编码库libavcodec。 FFmpeg是在 Linux 下开发出来的,但它可以在包括 Windows 在内的大多数操作系统中编译。

这个项目最早由 Fabrice Bellard 发起,2004年至2015年间由 Michael Niedermayer 主 要负责维护。许多 FFmpeg 的开发人员都来自 MPlayer 项目,而且当前 FFmpeg 也是放在 MPlayer 项目组的服务器上。项目的名称来自 MPEG 视频编码标准 ,前面的 "FF" 代表 "Fast Forward" ,也就是快速转换。
FFMPEG的主要特点:

  1. 多种文件格式的支持:FFmpeg 是领先的多媒体框架,能够解码、编码、转码、混合、解密、流媒体、过滤和播放人类和机器创造的几乎所有东西。它支持最晦涩的古老格式,直到最尖端的格式。无论它们是由某个标准委员会、社区还是公司设计的;它还具有高度的便携性,易用性,FFmpeg 可以在 Linux、Mac OS X、Microsoft Windows、BSDs、Solaris 等各种构建环境、机器架构和配置下编译、运行,并通过测试基础设施 FATE,当然,某些加密格式暂时还无能为力,例如mflac格式的文件
  2. 各种文件格式之间自由的转换:ffmpeg 可以轻而易举的在不同媒体格式之间进行自由转换了。你只需要指明输入和输出文件名就行了, ffmpeg 会从后缀名猜测格式,这个方法同时适用于视频和音频以及图片文件。例如可以将摄录下的视频avi等转成现在主流的视频网站所采用的flv格式,可以快速将音视频分解为帧图片,也可以将一系列图片合成为音视频文件等等,这使得文件格式的转换十分自由,简单
  3. 应用广泛:可用于短视频剪辑;可用于配合人工智能框架深度开发,实现智能识图,特征搜寻等等;可进行各种音视频资源的翻录,项目的demo演示;直播领域的实时推拉流;图片和音视频素材库之间的转换等等应用
  4. 易于开发:含 libavcodec、libavutil、libavformat、libavfilter、libavdevice、libswscale 和 libswresample等程序集,可以被程序开发者调用使用,先进的 音频/视频编解码库 libavcodec,为了保证高可移植性和编解码质量, libavcodec 里很多 code 都是 从头开发的;还有 ffmpeg、ffplay 和 ffprobe等可执行程序,可以被用户直接使用,进行调试开发工作



开发库:

  • x264 编码H.264视频,编译参数--enable-gpl --enable-libx264
  • fdk-aac 编码AAC音频,编译参数--enable-libfdk-aac
  • libvpx VP8/VP9视频编码器,编译参数--enable-libvpx
  • libvorbis 编码Vorbis音频,需要libogg。编译参数--enable-libvorbis
  • libopus 编码Opus音频。
  • LAME 编码MP3音频,编译参数--enable-libmp3lame
  • libass 字幕渲染器,编译参数--enable-libass

主程序:

  • ffmpeg.exe:是一个处理媒体文件的命令行工具 (command line based) ,主要用于对音视频进行处理,比如说剪切、抽取视频、抽取音频、增加贴纸水印,抽帧,加帧等等,音视频编解码工具(类似爱剪辑 格式工厂),并且因为他是开源的,很多知名的工具如 VLC,YouTube, iTunes 等等,都是基于ffmpeg开发出来的。也有许多为他定制UI的视频编辑器Linux video editors。
  • ffplay.exe:ffplay主要用于播放视频,几乎支持所有的本地视频播放,还能支持流媒体等网络视频播放,甚至还能播放YUV视频,这点在开发过程中非常好用。Simple media player 简单媒体播放器
  • ffprobe.exe:ffprobe主要用于查看音视频文件格式,比如说你要将一个音视频文件的所有信息以JSON格式输出,ffprobe这个命令行就很便捷,而这一点结合人工智能分析,重构音视频是非常重要的



ffmpeg的参数介绍:

查询参数:

什么情况下,使用这些查询命令呢?比如你正在使用 ffmpeg 编码时,结果报错了,你首先需要使用这个命令查看一下当前 ffmpeg 是否支持目标编码器。这里你可能会问,ffmpeg没有统一的版本吗?为什么支持的编码器还不一样?官网正式的 ffmpeg 版本肯定是统一的,但是实际项目我们不可能使用所有的编码器、解码器、滤镜等组件,一般会进行裁剪,也就是源码编译,并且适当的裁剪会提高服务器的安全性

  • -buildconf

例如,下面这个是我的Linux编译参数,非常简单的编译

bash 复制代码
[root@centos10 ~]# ffmpeg -hide_banner -buildconf 

  configuration:
    --enable-gpl
    --enable-ffplay
  • -formats:列出支持的文件格式,该命令列出了ffmpeg所有支持的文件格式,音视频和图片都包括
  • -codecs:列出支持的编解码器。
bash 复制代码
[root@centos10 ~]# ffmpeg  -hide_banner -codecs
Codecs:
 D..... = Decoding supported ###只支持解码
 .E.... = Encoding supported ###只支持编码
 ..V... = Video codec  ###可支持视频编解码
 ..A... = Audio codec ###可支持音频编解码
 ..S... = Subtitle codec  ###字幕编解码
 ..D... = Data codec  ##数据解码器
 ..T... = Attachment codec  ###附件编解码器,没用过,也没了解
 ...I.. = Intra frame-only codec ###独立帧编码器,每一帧都可以单独编辑,没用过,也没了解
 ....L. = Lossy compression  ###有损压缩
 .....S = Lossless compression ###无损压缩
 -------
###
  • -decoders:列出支持的解码器。

Linux下:

bash 复制代码
[root@centos10 ~]# ffmpeg -hide_banner -decoders
Decoders:
 V..... = Video  #视频解码用
 A..... = Audio  #音频解码用
 S..... = Subtitle ##字幕解码用
 .F.... = Frame-level multithreading ##
 ..S... = Slice-level multithreading
 ...X.. = Codec is experimental
 ....B. = Supports draw_horiz_band
 .....D = Supports direct rendering method 1
 ------
 V....D 012v                 Uncompressed 4:2:2 10-bit
 V....D 4xm                  4X Movie
 V....D 8bps                 QuickTime 8BPS video
 V....D aasc                 Autodesk RLE

Windows下:

bash 复制代码
C:\Users\Administrator>ffmpeg -hide_banner -decoders|more
Decoders:
 V..... = Video
 A..... = Audio
 S..... = Subtitle
 .F.... = Frame-level multithreading
 ..S... = Slice-level multithreading
 ...X.. = Codec is experimental
 ....B. = Supports draw_horiz_band
 .....D = Supports direct rendering method 1 ##可抽帧???
 ------
 V....D 012v                 Uncompressed 4:2:2 10-bit
 V....D 4xm                  4X Movie
 V....D 8bps                 QuickTime 8BPS video
 V....D aasc                 Autodesk RLE
 V....D agm                  Amuse Graphics Movie
 VF...D aic                  Apple Intermediate Codec
 V....D alias_pix            Alias/Wavefront PIX image
 V....D amv                  AMV Video
 V....D anm                  Deluxe Paint Animation
 V....D ansi                 ASCII/ANSI art
 VF...D apng                 APNG (Animated Portable Network Graphics) image
 V....D arbc                 Gryphon's Anim Compressor
 V....D argo                 Argonaut Games Video
 V....D asv1                 ASUS V1
 V....D asv2                 ASUS V2
 V....D aura                 Auravision AURA
 V....D aura2                Auravision Aura 2
 V..... libdav1d             dav1d AV1 decoder by VideoLAN (codec av1)
 V....D libaom-av1           libaom AV1 (codec av1)
  • -encoders:列出支持的编码器。
  • -muxers:列出支持解复用的编码器
  • demuxers:列出支持复用的编码器
  • -protocols:列出支持的协议。

Linux下:tcp,rtmp,rtmps,rtmpt,ftp,hls 等等协议

bash 复制代码
[root@centos10 ~]# ffmpeg -hide_banner -protocols
Supported file protocols:
Input:
  async
  cache
  concat
  concatf
  crypto
  data
  fd
  ffrtmphttp
  file
  ftp
  gopher
  hls
  http
  httpproxy
  mmsh
  mmst
  pipe
  rtmp
  rtmpt
  rtp
  srtp
  subfile
  tcp
  udp
  udplite
  unix
Output:
  crypto
  fd
  ffrtmphttp
  file
  ftp
  gopher
  http
  httpproxy
  icecast
  md5
  pipe
  prompeg
  rtmp
  rtmpt
  rtp
  srtp
  tee
  tcp
  udp
  udplite
  unix

Windows下:可以看到tcp,rtmp,rtmps,rtmpt,ftp,hls 等等协议

bash 复制代码
C:\Users\Administrator>ffmpeg -hide_banner -protocols
Supported file protocols:
Input:
  async
  bluray
  cache
  concat
  concatf
  crypto
  data
  fd
  ffrtmpcrypt
  ffrtmphttp
  file
  ftp
  gopher
  gophers
  hls
  http
  httpproxy
  https
  mmsh
  mmst
  pipe
  rtmp
  rtmpe
  rtmps
  rtmpt
  rtmpte
  rtmpts
  rtp
  srtp
  subfile
  tcp
  tls
  udp
  udplite
  rist
  srt
  sftp
  zmq
  ipfs
  ipns
Output:
  crypto
  fd
  ffrtmpcrypt
  ffrtmphttp
  file
  ftp
  gopher
  gophers
  http
  httpproxy
  https
  icecast
  md5
  pipe
  prompeg
  rtmp
  rtmpe
  rtmps
  rtmpt
  rtmpte
  rtmpts
  rtp
  srtp
  tee
  tcp
  tls
  udp
  udplite
  rist
  srt
  sftp
  zmq
  • -bsfs:列出支持的比特流过滤器。

Linux:

bash 复制代码
[root@centos10 ~]# ffmpeg -hide_banner -bsfs|more
Bitstream filters:
aac_adtstoasc
av1_frame_merge
av1_frame_split
av1_metadata
chomp
dump_extra
dca_core
dts2pts
dv_error_marker
eac3_core
extract_extradata
filter_units
h264_metadata
h264_mp4toannexb
h264_redundant_pps
hapqa_extract
hevc_metadata
hevc_mp4toannexb
imxdump
media100_to_mjpegb
mjpeg2jpeg
mjpegadump
mp3decomp
mpeg2_metadata
mpeg4_unpack_bframes
mov2textsub
noise
null
opus_metadata
pcm_rechunk
pgs_frame_merge
prores_metadata
remove_extra
setts
text2movsub
trace_headers
truehd_core
vp9_metadata
vp9_raw_reorder
vp9_superframe
vp9_superframe_split
vvc_metadata
vvc_mp4toannexb
evc_frame_merge

Windows

bash 复制代码
C:\Users\Administrator>ffmpeg -hide_banner -bsfs|more
Bitstream filters:
aac_adtstoasc
av1_frame_merge
av1_frame_split
av1_metadata
chomp
dump_extra
dca_core
dts2pts
dv_error_marker
eac3_core
extract_extradata
filter_units
h264_metadata
h264_mp4toannexb
h264_redundant_pps
hapqa_extract
hevc_metadata
hevc_mp4toannexb
imxdump
media100_to_mjpegb
mjpeg2jpeg
mjpegadump
  • -filters:列出支持的滤镜,这个是常用的,在剪辑的时候

Linux:

bash 复制代码
[root@centos10 ~]# ffmpeg -hide_banner -filters |more
Filters:
  T.. = Timeline support
  .S. = Slice threading
  ..C = Command support
  A = Audio input/output
  V = Video input/output
  N = Dynamic number and/or type of input/output
  | = Source or sink filter
 ... abench            A->A       Benchmark part of a filtergraph.
 ..C acompressor       A->A       Audio compressor.
 ... acontrast         A->A       Simple audio dynamic range compression/expansion filter.
 ... acopy             A->A       Copy the input audio unchanged to the output.
 ... acue              A->A       Delay filtering to match a cue.
 ... acrossfade        AA->A      Cross fade two input audio streams.

Windows:

bash 复制代码
C:\Users\Administrator>ffmpeg -hide_banner -filters |more
Filters:
  T.. = Timeline support
  .S. = Slice threading
  ..C = Command support
  A = Audio input/output
  V = Video input/output
  N = Dynamic number and/or type of input/output
  | = Source or sink filter
 ... abench            A->A       Benchmark part of a filtergraph.
 ..C acompressor       A->A       Audio compressor.
 ... acontrast         A->A       Simple audio dynamic range compression/expansion filter.
 ... acopy             A->A       Copy the input audio unchanged to the output.
 ... acue              A->A       Delay filtering to match a cue.
 ... acrossfade        AA->A      Cross fade two input audio streams.
 .S. acrossover        A->N       Split audio into per-bands streams.
 T.C acrusher          A->A       Reduce audio bit resolution.
 TS. adeclick          A->A       Remove impulsive noise from input audio.
 TS. adeclip           A->A       Remove clipping from input audio.
 TS. adecorrelate      A->A       Apply decorrelation to input audio.
 T.C adelay            A->A       Delay one or more audio channels.
 TSC adenorm           A->A       Remedy denormals by adding extremely low-level noise.
 T.. aderivative       A->A       Compute derivative of input audio.
  • -pix_fmts:列出支持的图像采样格式。

Linux:

bash 复制代码
[root@centos10 ~]# ffmpeg -hide_banner -pix_fmts
Pixel formats:
I.... = Supported Input  format for conversion
.O... = Supported Output format for conversion
..H.. = Hardware accelerated format ##硬编码
...P. = Paletted format
....B = Bitstream format
FLAGS NAME            NB_COMPONENTS BITS_PER_PIXEL BIT_DEPTHS
-----
IO... yuv420p                3             12      8-8-8
IO... yuyv422                3             16      8-8-8
IO... rgb24                  3             24      8-8-8
IO... bgr24                  3             24      8-8-8
IO... yuv422p                3             16      8-8-8
IO... yuv444p                3             24      8-8-8

Windows:

bash 复制代码
C:\Users\Administrator>ffmpeg -hide_banner -pix_fmts|more
Pixel formats:
I.... = Supported Input  format for conversion
.O... = Supported Output format for conversion
..H.. = Hardware accelerated format
...P. = Paletted format
....B = Bitstream format
FLAGS NAME            NB_COMPONENTS BITS_PER_PIXEL BIT_DEPTHS
-----
IO... yuv420p                3             12      8-8-8
IO... yuyv422                3             16      8-8-8
IO... rgb24                  3             24      8-8-8
IO... bgr24                  3             24      8-8-8
IO... yuv422p                3             16      8-8-8
IO... yuv444p                3             24      8-8-8
IO... yuv410p                3              9      8-8-8
IO... yuv411p                3             12      8-8-8
IO... gray                   1              8      8
IO..B monow                  1              1      1
IO..B monob                  1              1      1
I..P. pal8                   1              8      8
IO... yuvj420p               3             12      8-8-8
IO... yuvj422p               3             16      8-8-8
IO... yuvj444p               3             24      8-8-8
IO... uyvy422                3             16      8-8-8
  • -sample_fmts:列出支持的声音采样格式

Linux下:

bash 复制代码
[root@centos10 ~]# ffmpeg -hide_banner -sample_fmts
name   depth
u8        8 
s16      16 
s32      32 
flt      32 
dbl      64 
u8p       8 
s16p     16 
s32p     32 
fltp     32 
dblp     64 
s64      64 
s64p     64 
  • -devices 列出现有支持的,可用的输入输出设备

Linux下的:

bash 复制代码
[root@centos10 ~]# ffmpeg -devices -hide_banner
Devices:
 D. = Demuxing supported
 .E = Muxing supported
 --
 DE alsa            ALSA audio output
 DE fbdev           Linux framebuffer
 D  lavfi           Libavfilter virtual input device
 DE oss             OSS (Open Sound System) playback
  E sdl,sdl2        SDL2 output device
 DE video4linux2,v4l2 Video4Linux2 output device
 D  x11grab         X11 screen capture, using XCB ###这个好像也是录屏用的驱动类

Windows下的:

bash 复制代码
C:\Users\Administrator>ffmpeg -devices -hide_banner
Devices:
 D. = Demuxing supported
 .E = Muxing supported
 --
  E caca            caca (color ASCII art) output device
 D  dshow           DirectShow capture  ###录屏用的设备驱动
 D  gdigrab         GDI API Windows frame grabber
 D  lavfi           Libavfilter virtual input device
 D  libcdio
  E sdl,sdl2        SDL2 output device
 D  vfwcap          VfW video capture


设备 D dshow DirectShow capture 指的是录制相关 , 摄像头录制 , 麦克风录制等 ;

 设备 D lavfi Libavfilter virtual input device 是虚拟的输入设备 , 用于测试 ;

 设备 E sdl,sdl2 SDL2 output device 输出设备 , 播放视频时 , 使用该模块作为输出 ;

 设备 D vfwcap VfW video capture 摄像头采集设备 ;



术语介绍:

媒体流

媒体流 ( Stream ) : 时间上的一段连续数据 , 一段声音数据 称为 音频流 , 一段视频数据 称为 视频流 , 一段字幕数据 称为 字幕流 ;

这些媒体流数据 可以压缩 , 也可以不压缩 , 如视频流以 H.264 格式进行压缩 , 将视频帧编码成 关键帧 , 非关键帧 , 音频流一般是 AAC 编码格式进行压缩 ;

媒体流如果是压缩的 , 在播放时 , 先使用解码器解码 , 然后再播放 ; 生成文件时需要使用编码器 , 编码后存储到文件中 ;

数据帧

数据帧 ( Data Frame ) : 媒体流 由 若干 数据帧构成 ; 压缩格式中 , 数据帧是最小的处理单元 ;

在容器中如果有多个数据流 , 那么 视频帧 , 音频帧 , 字幕信息 , 交错存储 , 以保证实时性 ;

数据帧是未压缩的原始数据 , 如 : 视频帧每一帧都是一张完整的 YUV 图片 , 音频帧是 PCM 格式的 ;

数据包

数据包 ( Data Packet ) : 将 数据帧 压缩后就是 数据包 , 数据帧是未压缩的原始数据 , 数据包时压缩后的数据 ;

生成容器文件时 , 压缩数据 , 将数据帧 编码压缩 成 数据包 ;

播放容器文件时 , 解压数据 , 将数据包 解码展开 成 数据帧 ;

视频编码过程 : YUV 格式的图像 -> H.264 编码器编码 -> H.264 视频帧 视频解码过程 : H.264 视频帧 -> H.264 解码器解码 -> YUV 格式的图像

音频数据编码过程 : PCM 音频数据 -> ACC 编码器编码 -> AAC 音频帧 音频数据解码过程 : AAC 音频帧 -> AAC 解码器解码 -> PCM 音频数据

编解码器

编解码器 ( Codec ) : 数据帧 ( 原始数据 ) 与 数据包 ( 压缩数据 ) 之间的转换工具 ;

数据帧 ( 原始数据 ) -> 编解码器 ( 编码 ) -> 数据包 ( 压缩数据 )

数据包 ( 压缩数据 ) -> 编解码器 ( 解码 ) -> 数据帧 ( 原始数据 )

复用

复用 ( Mux ) : 将不同的 媒体流流 , 按照一定规则放入容器 ;

音频流 , 视频流 , 字幕流 , 按照一定规则 封装到 容器 ( 视频文件 ) 中 ;

复用的关键工具时 复用器 ( Muxer ) ;

解复用

解复用 ( Demux ) : 从容器中解析不同的流出来 ;

从 容器 ( 视频文件 ) 中 , 按照一定规则 拆分出 音频流 , 视频流 , 字幕流 ,

解复用的关键工具时 解复用器 ( Demuxer ) ;

码率与帧率


帧率 : 帧频率 , 视频中每秒钟含有视频帧的帧数 , 一秒钟刷新多少张图像 , 连续移动的图像至少每秒15帧 , 才能形成肉眼观察的连续播放效果 , 低于这个帧率 , 画面有卡顿感 ;

码率 : 比特率 , 数据率 ; 每秒处理的位数 ; 码率的单位是 bps , 表示每秒处理的位数 , 除以8

就是每秒的字节数 ; 该参数决定了音视频文件的播放质量 , 码率越大 , 视频质量越高 ;视频文件 中 码率 和 帧率 决定了视频的质量 ;根据 码率 和 时长 可以计算出视频文件的字节大小 ;

相关推荐
LN花开富贵1 小时前
stm32g431rbt6芯片中VREF+是什么?在电路中怎么设计?
笔记·stm32·单片机·嵌入式硬件·学习
CV金科1 小时前
蓝桥杯—STM32G431RBT6按键的多方式使用(包含软件消抖方法精讲)从原理层面到实际应用(一)
stm32·单片机·嵌入式硬件·蓝桥杯
luckyluckypolar1 小时前
STM32——输入捕获
stm32·单片机·嵌入式硬件·物联网
hai405871 小时前
单片机(Microcontroller)原理及应用
单片机·嵌入式硬件
Jerry 二河小鱼1 小时前
在Linux中安装FFmpeg
linux·运维·服务器·ffmpeg
Projectsauron3 小时前
STM32 芯片启动过程
stm32·单片机·芯片启动过程
CDialog3 小时前
arduino ide开发esp32-wroom-32E
单片机·嵌入式硬件
梅双单片机13 小时前
【源代码+仿真+原理图+技术文档+演示录屏+软件】基于单片机的厨房监控系统的设计与实现
单片机·嵌入式硬件
三菱-Liu16 小时前
三菱变频器以模拟量电流进行频率设定(电流输入)
驱动开发·单片机·嵌入式硬件·硬件工程·制造
MGT_979620 小时前
基于51单片机的GPS定位系统(仿真)
单片机·嵌入式硬件·51单片机