通过ffmpeg -i命令查看视频基本信息
ffmpeg version 6.1-essentials_build-www.gyan.dev Copyright (c) 2000-2023 the FFmpeg developers
built with gcc 12.2.0 (Rev10, Built by MSYS2 project)
configuration: --enable-gpl --enable-version3 --enable-static --pkg-config=pkgconf --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-dxva2 --enable-d3d11va --enable-libvpl --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband
libavutil 58. 29.100 / 58. 29.100
libavcodec 60. 31.102 / 60. 31.102
libavformat 60. 16.100 / 60. 16.100
libavdevice 60. 3.100 / 60. 3.100
libavfilter 9. 12.100 / 9. 12.100
libswscale 7. 5.100 / 7. 5.100
libswresample 4. 12.100 / 4. 12.100
libpostproc 57. 3.100 / 57. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf60.16.100
Duration: 00:07:49.52, start: 0.000000, bitrate: 20142 kb/s
Stream #0:0[0x1](eng): Video: h264 (High 4:2:2) (avc1 / 0x31637661), yuv422p10le(tv, bt709, progressive), 1920x2160, 20007 kb/s, 25 fps, 25 tbr, 12800 tbn (default)
Metadata:
handler_name : VideoHandler
vendor_id : [0][0][0][0]
encoder : Lavc60.31.102 libx264
timecode : 00:32:38:24
Stream #0:1[0x2](eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
vendor_id : [0][0][0][0]
Stream #0:2[0x3](eng): Data: none (tmcd / 0x64636D74)
Metadata:
handler_name : TimeCodeHandler
timecode : 00:32:38:24
At least one output file must be specified
?
ffmpeg -i input.mp4 -af silencedetect=noise=-30dB:d=0.5 -vn -sn -dn -f null /dev/null
-af:silencedetect 的作用是获取音频的最大音量、平均音量以及音量直方图。它只支持 AV_SAMPLE_FMT_S16
?、?AV_SAMPLE_FMT_S32
?、?AV_SAMPLE_FMT_FLT
?和?AV_SAMPLE_FMT_DBL
?这四种格式——如果不是当然 FFmpeg 能够自动转换。
多大音量认为是静音由参数?noise
?确定,默认是?-60dB
?或?0.001
;多长的连续时长认为是静音由参数?duration
?确定,默认是?2
?秒。参数?mono
?为非?0
?表示各个声道分别检测,默认是合并在一起检测。
合并在一起检测:比如认为 2 秒连续无声(或小声)认为是静音,那么其中一个声道达标,另一个声道在该时段内不达标也不认为是静音。
-vn
、?-sn
?和?-dn
?告知 FFmpeg 忽略非音频流。能够在分析时避免不必要的操作从而更快速.
注意:在 Windows 中使用需将?/dev/null
?替换为?NUL
对于多声道音频,可以指定各个声道分别检测:
ffmpeg -i input.mp3 -af "silencedetect=mono=1" -vn -sn -dn -f null /dev/null
ffmpeg version 6.1-essentials_build-www.gyan.dev Copyright (c) 2000-2023 the FFmpeg developers
built with gcc 12.2.0 (Rev10, Built by MSYS2 project)
configuration: --enable-gpl --enable-version3 --enable-static --pkg-config=pkgconf --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-libfreetype --enable-libfribidi --enable-libharfbuzz --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-dxva2 --enable-d3d11va --enable-libvpl --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband
libavutil 58. 29.100 / 58. 29.100
libavcodec 60. 31.102 / 60. 31.102
libavformat 60. 16.100 / 60. 16.100
libavdevice 60. 3.100 / 60. 3.100
libavfilter 9. 12.100 / 9. 12.100
libswscale 7. 5.100 / 7. 5.100
libswresample 4. 12.100 / 4. 12.100
libpostproc 57. 3.100 / 57. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf60.16.100
Duration: 00:07:49.52, start: 0.000000, bitrate: 20142 kb/s
Stream #0:0[0x1](eng): Video: h264 (High 4:2:2) (avc1 / 0x31637661), yuv422p10le(tv, bt709, progressive), 1920x2160, 20007 kb/s, 25 fps, 25 tbr, 12800 tbn (default)
Metadata:
handler_name : VideoHandler
vendor_id : [0][0][0][0]
encoder : Lavc60.31.102 libx264
timecode : 00:32:38:24
Stream #0:1[0x2](eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
vendor_id : [0][0][0][0]
Stream #0:2[0x3](eng): Data: none (tmcd / 0x64636D74)
Metadata:
handler_name : TimeCodeHandler
timecode : 00:32:38:24
Stream mapping:
Stream #0:1 -> #0:0 (aac (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
Output #0, null, to 'nul':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf60.16.100
Stream #0:0(eng): Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s (default)
Metadata:
handler_name : SoundHandler
vendor_id : [0][0][0][0]
encoder : Lavc60.31.102 pcm_s16le
[silencedetect @ 000001ee5a9cb5c0] silence_start: 0 0x
[silencedetect @ 000001ee5a9cb5c0] silence_end: 13.238 | silence_duration: 13.238
[silencedetect @ 000001ee5a9cb5c0] silence_start: 17.0503
[silencedetect @ 000001ee5a9cb5c0] silence_end: 17.5835 | silence_duration: 0.53325
[silencedetect @ 000001ee5a9cb5c0] silence_start: 30.0168
[silencedetect @ 000001ee5a9cb5c0] silence_end: 30.5313 | silence_duration: 0.514437
[silencedetect @ 000001ee5a9cb5c0] silence_start: 35.2619
[silencedetect @ 000001ee5a9cb5c0] silence_end: 35.9293 | silence_duration: 0.667375
[silencedetect @ 000001ee5a9cb5c0] silence_start: 50.3024
[silencedetect @ 000001ee5a9cb5c0] silence_end: 50.909 | silence_duration: 0.606563
[silencedetect @ 000001ee5a9cb5c0] silence_start: 56.8453
[silencedetect @ 000001ee5a9cb5c0] silence_end: 57.9748 | silence_duration: 1.12958
[silencedetect @ 000001ee5a9cb5c0] silence_start: 76.3573
[silencedetect @ 000001ee5a9cb5c0] silence_end: 76.8851 | silence_duration: 0.527792
[silencedetect @ 000001ee5a9cb5c0] silence_start: 83.8969
[silencedetect @ 000001ee5a9cb5c0] silence_end: 84.6447 | silence_duration: 0.747771
[silencedetect @ 000001ee5a9cb5c0] silence_start: 97.7624
[silencedetect @ 000001ee5a9cb5c0] silence_end: 98.294 | silence_duration: 0.531604
[silencedetect @ 000001ee5a9cb5c0] silence_start: 99.3107
[silencedetect @ 000001ee5a9cb5c0] silence_end: 99.8335 | silence_duration: 0.522792
[silencedetect @ 000001ee5a9cb5c0] silence_start: 108.826
[silencedetect @ 000001ee5a9cb5c0] silence_end: 109.517 | silence_duration: 0.690979
[silencedetect @ 000001ee5a9cb5c0] silence_start: 126.216
[silencedetect @ 000001ee5a9cb5c0] silence_end: 126.837 | silence_duration: 0.621333
[silencedetect @ 000001ee5a9cb5c0] silence_start: 126.837
[silencedetect @ 000001ee5a9cb5c0] silence_end: 127.59 | silence_duration: 0.752958
[silencedetect @ 000001ee5a9cb5c0] silence_start: 172.294
[silencedetect @ 000001ee5a9cb5c0] silence_end: 172.929 | silence_duration: 0.634542
[silencedetect @ 000001ee5a9cb5c0] silence_start: 198.802
[silencedetect @ 000001ee5a9cb5c0] silence_end: 199.375 | silence_duration: 0.572875
[silencedetect @ 000001ee5a9cb5c0] silence_start: 203.289
[silencedetect @ 000001ee5a9cb5c0] silence_end: 203.968 | silence_duration: 0.678875
[silencedetect @ 000001ee5a9cb5c0] silence_start: 229.058
[silencedetect @ 000001ee5a9cb5c0] silence_end: 229.595 | silence_duration: 0.537167
[silencedetect @ 000001ee5a9cb5c0] silence_start: 230.641
[silencedetect @ 000001ee5a9cb5c0] silence_end: 231.178 | silence_duration: 0.536604
[silencedetect @ 000001ee5a9cb5c0] silence_start: 240.758
[silencedetect @ 000001ee5a9cb5c0] silence_end: 241.555 | silence_duration: 0.796854
[silencedetect @ 000001ee5a9cb5c0] silence_start: 314.606
[silencedetect @ 000001ee5a9cb5c0] silence_end: 315.126 | silence_duration: 0.519979
[silencedetect @ 000001ee5a9cb5c0] silence_start: 356.308
[silencedetect @ 000001ee5a9cb5c0] silence_end: 356.832 | silence_duration: 0.524271
[silencedetect @ 000001ee5a9cb5c0] silence_start: 358.494
[silencedetect @ 000001ee5a9cb5c0] silence_end: 359.071 | silence_duration: 0.576917
[silencedetect @ 000001ee5a9cb5c0] silence_start: 374.441
[silencedetect @ 000001ee5a9cb5c0] silence_end: 375.158 | silence_duration: 0.717313
[silencedetect @ 000001ee5a9cb5c0] silence_start: 375.999
[silencedetect @ 000001ee5a9cb5c0] silence_end: 376.772 | silence_duration: 0.772271
[silencedetect @ 000001ee5a9cb5c0] silence_start: 389.417
[silencedetect @ 000001ee5a9cb5c0] silence_end: 389.947 | silence_duration: 0.529458
[silencedetect @ 000001ee5a9cb5c0] silence_start: 419.457
[silencedetect @ 000001ee5a9cb5c0] silence_end: 420.038 | silence_duration: 0.581125
[silencedetect @ 000001ee5a9cb5c0] silence_start: 447.481
[silencedetect @ 000001ee5a9cb5c0] silence_end: 447.991 | silence_duration: 0.510146
[silencedetect @ 000001ee5a9cb5c0] silence_start: 454.29
[out#0/null @ 000001ee590392c0] video:0kB audio:88020kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
size=N/A time=00:07:49.41 bitrate=N/A speed= 957x
[silencedetect @ 000001ee5a9cb5c0] silence_end: 469.44 | silence_duration: 15.1504
?
FFmpeg项目由 Fabrice Bellard在2000年创立。到目前为止,FFmpeg项目的开发者仍然与VLC、MPV、dav1d、x264等多媒体开源项目有着广泛的重叠。Ffmpeg(FastForward Mpeg)是一款遵循GPL的开源软件,在音视频处理方面表现十分优秀,几乎囊括了现存所有的视音频格式的编码,解码、转码、混合、过滤及播放。作为最受欢迎的视频和图像处理软件,它被来自各行各业的不同公司所广泛使用。同时也是一款跨平台的软件,完美兼容Linux、Windows、Mac OSX等平台。其实它由3大部件组成,号称音视频处理工具三剑客:
Ffmpeg 应该是 FFmpeg 工具集中最核心的利器,支持多种多样的编码器、解码器、封装格式、滤镜功能。FFmpeg框架的基本组成包含AVFormat、AVCodec、AVFilter、AVDevice、AVUtil等模块库,结构图如下:
AVFormat中实现了目前多媒体领域中的绝大多数媒体封装格式,包括封装和解封装,如MP4、FLV、KV、TS等文件封装格式,RTMP、RTSP、MMS、HLS等网络协议封装格式。FFmpeg是否支持某种媒体封装格式,取决于编译时是否包含了该格式的封装库。根据实际需求,可进行媒体封装格式的扩展,增加自己定制的封装格式,即在AVFormat中增加自己的封装处理模块。
AVCodec中实现了目前多媒体领域绝大多数常用的编解码格式,即支持编码,也支持解码。AVCodec除了支持MPEG4、AAC、MJPEG等自带的媒体编解码格式之外,还支持第三方的编解码器,如H.264(AVC)编码,需要使用x264编码器;H.265(HEVC)编码,需要使用x264编码器;MP3(mp3lame)编码,需要使用libmp3lame编码器。如果希望增加自己的编码格式,或者硬件编解码,则需要在AVCodec中增加相应的编解码模块。
AVFilter库提供了一个通用的音频、视频、字幕等滤镜处理框架。在AVFilter中,滤镜框架可以有多个输入和多个输出。
swresample模块提供了高级别的音频重采样API。例如允许操作音频采样、音频通道布局转换与布局调整。
swscale模块提供了高级别的图像转换API,例如它允许进行图像缩放和像素格式转换,常见于将图像从1080p转换成720p或者480p等的缩放,或者将图像数据从YUV420p转换成YUYV,或者YUV转RGB等图像格式转换。
对于输入,以下选项通常是自动识别的,但也可以强制设定。
FFMPEG的某些选项可以对一个特定的媒体流起作用,这种情况下需要在选项后面增加一个流标识。流标识允许以下几种格式:
假如要设定第二个音频流为copy,则需要指定-codec:a:1 copy
-filter_simple 添加简单滤镜
-filter_complex FILTER 添加复杂滤镜
简单的说,ffprobe 是一个多媒体流分析工具。它从多媒体流中收集信息,并且以人类和机器可读的形式打印出来。它可以用来检测多媒体流的容器类型,以及每一个多媒体流的格式和类型。它可以作为一个独立的应用来使用,也可以结合文本过滤器执行更复杂的处理。