使用ffmpeg同步文件时间戳 [英] Sync files timestamp with ffmpeg

查看:95
本文介绍了使用ffmpeg同步文件时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过捕获卡捕获4个与HDMI连接的摄像机的视频.我正在使用ffmpeg将来自摄像机的视频馈送保存到多个jpeg文件(每个摄像机每秒30 jpeg).

I'm capturing video from 4 cameras connected with HDMI through a capture card. I'm using ffmpeg to save the video feed from the cameras to multiples jpeg files (30 jpeg per second per camera).

我希望能够随拍摄时间一起保存图像.目前,我正在为一台相机使用此命令:

I want to be able to save the images with the capture time. Currently I'm using this command for one camera:

ffmpeg -f video4linux2 -pixel_format yuv420p -timestamps abs -I/dev/video0 -c:a jpeg -t 60 -ts_from_file 2 camera0-%5d.jpeg

ffmpeg -f video4linux2 -pixel_format yuv420p -timestamps abs -I /dev/video0 -c:a jpeg -t 60 -ts_from_file 2 camera0-%5d.jpeg

它保存我的文件,名称为camera0-00001.jpg,camera0-00002.jpg等.

It saves my file with the names camera0-00001.jpg, camera0-00002.jpg, etc.

然后根据文件的修改时间,使用camera0-HH-mm-ss-(1-30).jpeg重命名我的文件.

Then I rename my file with camera0-HH-mm-ss-(1-30).jpeg based on the modified time of the file.

所以最终我有4个文件,它们具有相同的时间和相同的帧,如下所示:相机0-12-00-00-1.jpegcamera1-12-00-00-1.jpegcamera2-12-00-00-1.jpegcamera3-12-00-00-1.jpeg

So in the end I have 4 files with the same time and same frame like this: camera0-12-00-00-1.jpeg camera1-12-00-00-1.jpeg camera2-12-00-00-1.jpeg camera3-12-00-00-1.jpeg

我的问题是文件可能从一帧偏移到两帧.它们可能具有相同的名称,但有时一两个摄像机可能会显示不同的帧.

My issue is that the file may be offset from one to two frame. They may have the same name but sometime one or two camera may show different frame.

是否有办法确保捕获帧具有捕获的实际时间而不是文件创建的时间?

Is there a way to be sure that the capture frames has the actual time of the capture and not the time of the creation of the file?

推荐答案

您可以使用mkvtimestamp_v2多路复用器

You can use the mkvtimestamp_v2 muxer

ffmpeg -f video4linux2 -pixel_format yuv420p -timestamps abs -copyts -i /dev/video0 \
       -vf setpts=PTS-STARTPTS -vsync 0 -vframes 1800 camera0-%5d.jpeg \
       -c copy -vsync 0 -vframes 1800 -f mkvtimestamp_v2 timings.txt

timings.txt将具有这样的输出

timings.txt will have output like this

# timecode format v2
1521177189530
1521177189630
1521177189700
1521177189770
1521177189820
1521177189870
1521177189920
1521177189970
...

其中每个读数是Unix纪元时间(以毫秒为单位).

where each reading is the Unix epoch time in milliseconds.

我已切换到输出帧数限制以停止该过程,而不是 -t 60 .您可以在第一个输出中使用 -t 60 ,因为我们正在此处重置时间戳,但不能在第二个输出中使用.如果这样做,请记住仅使用文本文件中的前N个条目,其中N是生成的图像数.

I've switched to output frame count limit to stop the process instead of -t 60. You can use -t 60 for the first output since we are resetting timestamps there, but not for the second. If you do that, remember to only use the first N entries from the text file, where N is the number of images produced.

这篇关于使用ffmpeg同步文件时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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