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

来源:互联网 发布:java web 高并发框架 编辑:程序博客网 时间:2024/04/28 00:07

最近遇到要识别隔行扫描的视频加以特殊转码处理的问题。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



方法二:使用查看视频帧详细信息的showinfo滤镜区分隔行扫描和逐行扫描

ffmpeg -y -i 351.mp4 -vf showinfo -frames:v 2 -f flv /dev/null

[Parsed_showinfo_0 @ 0xf675c0] n:0 pts:0 pts_time:0 pos:324675 fmt:yuv420p sar:1/1 s:1280x720 i:P iskey:1 type:I checksum:A5217CD1 plane_checksum:[308C60A8 4FA1B85C A41363BE]
[Parsed_showinfo_0 @ 0xf675c0] n:1 pts:1200 pts_time:0.04 pos:370498 fmt:yuv420p sar:1/1 s:1280x720 i:P iskey:0 type:B checksum:CF15D48E plane_checksum:[CB69A1EF 637DBF49 5FAF7347]
[Parsed_showinfo_0 @ 0xf675c0] n:2 pts:2400 pts_time:0.08 pos:373819 fmt:yuv420p sar:1/1 s:1280x720 i:P iskey:0 type:B checksum:5974D3B6 plane_checksum:[53AAA123 0C00BF3F 976C7345]
[Parsed_showinfo_0 @ 0xf675c0] n:3 pts:3600 pts_time:0.12 pos:345089 fmt:yuv420p sar:1/1 s:1280x720 i:P iskey:0 type:P checksum:8D43B49A plane_checksum:[FBCBC61A AE12A284 E4DA4BED]
[Parsed_showinfo_0 @ 0xf675c0] n:4 pts:4800 pts_time:0.16 pos:414675 fmt:yuv420p sar:1/1 s:1280x720 i:P iskey:0 type:B checksum:6C5487AC plane_checksum:[22107838 FE5FB347 755C5C1E]
[Parsed_showinfo_0 @ 0xf675c0] n:5 pts:6000 pts_time:0.2 pos:430027 fmt:yuv420p sar:1/1 s:1280x720 i:P iskey:0 type:B checksum:AF33CE8C plane_checksum:[3C499702 6B0DC18A B51375F1]
[Parsed_showinfo_0 @ 0xf675c0] n:6 pts:7200 pts_time:0.24 pos:377169 fmt:yuv420p sar:1/1 s:1280x720 i:P iskey:0 type:P checksum:4606BBA6 plane_checksum:[BF20865F 7FECA5AB 614E8F8D]

这个滤镜会将视频每一帧的详细信息都输出,在做视频详细分析的时候很好用,这里用到的是i参数信息,具体的参数信息可以参考FFmpeg官方文档:

http://ffmpeg.org/ffmpeg-filters.html#showinfo

关于i的说明是这样的:

i

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

                   隔行扫描模式("P"代表逐行,“T”代表上场优先,“B”代表下场优先)

通过提取这个参数的信息即可区分出来视频是隔行还是逐行的。



0 0
原创粉丝点击