FFmpeg怎么区分识别视频是逐行扫描还是隔行扫描

最近遇到要识别隔行扫描的视频加以特殊转码处理的问题。google了一番以后找到两个解决的方式,记录一下。


方法一:使用隔行扫描检查滤镜idet区分隔行扫描和逐行扫描

ffmpeg -filter:v idet \
    -frames:v 100 \
    -an \
    -f rawvideo -y /dev/null \
    -i 351.mp4
# Example output (this is not interlaced):
# [Parsed_idet_0 @ 0x1bcf720] Single frame detection: TFF:0 BFF:0 Progressive:564 Undetermined:84
# [Parsed_idet_0 @ 0x1bcf720] Multi frame detection: TFF:0 BFF:0 Progressive:623 Undetermined:25

# flags:
# -an            = discard audio, we don't need it 
# -f rawvideo    = output raw video
# -y /dev/null   = discard the output
# -i ...         = the input file to check
# -frames:v 100  = extract the first 100 frames
# -filter:v idet = insert the "idet" filter, which will output whether it has detected interlaced frames
如果结果中TFF和BFF非常多的话,那就意味着视频是隔行扫描的, 如果都是 Progressive 的话就是逐行扫描的。




关于TFF、BFF、Progressive三个参数,FFmpeg的帮助文档里有相关的说明(这个正是方法二里面要用到的):

interlaced mode ("P" for "progressive", "T" for top field first, "B" for bottom field first)

TFF:top field first  上场(奇数场)优先

BFF:bottom field first 下场(偶数场)优先

具体可以参考这篇英文文章:

http://www.aktau.be/2013/09/22/detecting-interlaced-video-with-ffmpeg/

以及FFmpeg的官方文档关于idet滤镜的说明:
http://ffmpeg.org/ffmpeg-filters.html#idet

ffmpeg -filter:v idet -frames:v 1000 -an -f rawvideo -y /dev/null -i 1080p_nvenc_2m.mp4


frame= 1000 fps= 31 q=-0.0 Lsize= 3037500kB time=00:00:41.70 bitrate=596600.2kbits/s speed=1.28x    
video:3037500kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000%
[Parsed_idet_0 @ 0xa73ca0] Repeated Fields: Neither:  1000 Top:     0 Bottom:     1
[Parsed_idet_0 @ 0xa73ca0] Single frame detection: TFF:     1 BFF:     1 Progressive:   817 Undetermined:   182
[Parsed_idet_0 @ 0xa73ca0] Multi frame detection: TFF:     0 BFF:     0 Progressive:   896 Undetermined:   105

你可能感兴趣的:(音视频)