[英]Using ffprobe/ffmpeg to extract individual frames and types in encode order
I am able to extract keyframes using ffmpeg. 我能够使用ffmpeg提取关键帧。 Something like this that I have been using:
我一直在使用这样的东西:
ffmpeg -i input.mp4 -vf "select='eq(pict_type\,I)" -vsync vfr -qscale:v 2 I-thumbnails-%02d.png -vf "select='eq(pict_type\,B)" -vsync vfr -qscale:v 2 B-thumbnails-%02d.png -vf "select='eq(pict_type\,P)" -vsync vfr -qscale:v 2 P-thumbnails-%02d.png
Now the issue is, I would like these extracted frames to be in encode order, if possible, the way they are extracted should have a timestamp or any way to know that they start in a certain sequence, example, from start to end: 现在的问题是,我希望这些提取的帧按编码顺序排列,如果可能的话,它们的提取方式应有时间戳记或以某种方式知道它们以特定顺序开始的任何方式,例如从头到尾:
IBBBIPPB......BI
IBBBIPPB ...... BI
but in a way that I can sort the frames in the encode sequence. 但我可以按照编码顺序对帧进行排序
I want to use this to load in python to extract motion vectors but they should all follow the encoding sequence. 我想用它来加载python以提取运动矢量,但它们都应遵循编码顺序。 Any help?
有什么帮助吗?
Edit: Changed playback to encode sequence(or order). 编辑:更改播放以编码序列(或顺序)。
With a recent version of ffmpeg, you can run, 使用最新版本的ffmpeg,您可以运行,
ffmpeg -i input.mp4
-vf "select='eq(pict_type\,I)" -vsync 0 -frame_pts 1 thumbnails-%02d-I.png
-vf "select='eq(pict_type\,B)" -vsync 0 -frame_pts 1 thumbnails-%02d-B.png
-vf "select='eq(pict_type\,P)" -vsync 0 -frame_pts 1 thumbnails-%02d-P.png
The image serial numbers will correspond to their index position (display-wise) in the video, and the suffix will indicate the frame type. 图像序列号将与其在视频中的索引位置(按显示方式)相对应,后缀将指示帧类型。
To get frames in encode/decode order, run 要以编码/解码顺序获取帧,请运行
ffmpeg -i input.mp4
-vf "setpts=POS,select='eq(pict_type\,I)" -vsync 0 -frame_pts 1 thumbnails-%09d-I.png
-vf "setpts=POS,select='eq(pict_type\,B)" -vsync 0 -frame_pts 1 thumbnails-%09d-B.png
-vf "setpts=POS,select='eq(pict_type\,P)" -vsync 0 -frame_pts 1 thumbnails-%09d-P.png
You should sort the output image listing in alphabetical/lexical order - that's the images in encode/decode order. 您应该按字母/词汇顺序对输出图像列表进行排序-即按编码/解码顺序的图像。 You can batch rename the 9-digit field to a simple serial index, if wanted.
如果需要,可以将9位数字字段批量重命名为简单的序列索引。
setpts=POS
sets the frame's timestamp to its byte offset in the file, which will track the encode/decode order. setpts=POS
将帧的时间戳设置为其在文件中的字节偏移量,它将跟踪编码/解码顺序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.