ffmpeg输出带有时间位置的图像文件名 [英] ffmpeg output images filename with time position
问题描述
我正在使用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输出带有时间位置的图像文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!