问题描述
我正在使用 ffmpeg 通过以下命令以特定速率(每 5 秒一个屏幕截图)从我的视频中获取一些 jpg :
I am using ffmpeg to get some jpg from my video at a specific rate (one screenshot every 5 seconds) with this command :
ffmpeg -i source -f image2 -r 1/5 %d.jpg
这有效并给我连续的文件名:
This works and give me sequential filenames :
1.jpg
2.jpg
3.jpg
4.jpg
如果我需要知道这些屏幕截图的拍摄时间怎么办?类似于时间戳的东西:
What if I need to know at which time those screenshots have been taken ? Something like a timestamp :
00:00:00.0000.jpg
00:00:05.0000.jpg
00:00:10.0000.jpg
00:00:15.0000.jpg
或秒数:
0.jpg
5.jpg
10.jpg
15.jpg
我再次尝试使用新的 -frame_pts 选项:>
I tried again with the new -frame_pts option :
ffmpeg -i source -f image2 -r 1/5 -frame_pts 1 %d.jpg
我得到了类似的连续文件名,但现在它们从零开始:
I got similar sequential filenames, but now they are starting from zero :
0.jpg
1.jpg
2.jpg
3.jpg
推荐答案
使用
ffmpeg -i source -vf fps=1,select='not(mod(t,5))' -vsync 0 -frame_pts 1 z%d.jpg
frame_pts 将为图像名称分配一个序列号,其中数字表示根据输出时基的帧位置.所以计算出的时间位置是frame #
x timebase
.时基是输出帧率的倒数,例如对于 12 fps 流,时基为 1/12.所以输出文件image212
代表212
x 1/12
= 17.67s
frame_pts will assign a serial number to the image name, where the number represents the frame position as per the output timebase. So the calculated time position is frame #
x timebase
. The timebase is the reciprocal of the output framerate e.g. for a 12 fps stream, timebase is 1/12. So output file image212
represents a time of 212
x 1/12
= 17.67s
要表示秒,您需要生成一个 1 fps 的流,然后每 5 帧选取一次,以每 5 秒获取一个帧.添加了 vsync 0
以防止 ffmpeg 复制帧以生成恒定帧速率流.
To represent seconds, you need to generate a 1 fps stream and then pick every 5th frame, to get a frame from every 5th second. The vsync 0
is added to prevent ffmpeg from duplicating frames to generate a constant frame rate stream.
这篇关于ffmpeg 输出图像文件名与时间位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!