使用ffprobe/ffmpeg以编码顺序提取单个帧和类型 [英] Using ffprobe/ffmpeg to extract individual frames and types in encode order

查看:777
本文介绍了使用ffprobe/ffmpeg以编码顺序提取单个帧和类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够使用ffmpeg提取关键帧.我一直在使用这样的东西:

I am able to extract keyframes using 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.

我想用它在python中加载以提取运动矢量,但它们都应遵循编码顺序.有帮助吗?

I want to use this to load in python to extract motion vectors but they should all follow the encoding sequence. Any help?

修改: 更改了回放以对序列(或顺序)进行编码.

Changed playback to encode sequence(or order).

推荐答案

使用最新版本的ffmpeg,您可以运行,

With a recent version of ffmpeg, you can run,

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

您应该按字母/词汇顺序对输出图像列表进行排序-即按编码/解码顺序的图像.如果需要,您可以将9位数字字段批量重命名为简单的序列索引.

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.

setpts=POS将帧的时间戳设置为文件中的字节偏移量,它将跟踪编码/解码顺序.

setpts=POS sets the frame's timestamp to its byte offset in the file, which will track the encode/decode order.

这篇关于使用ffprobe/ffmpeg以编码顺序提取单个帧和类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆