Sync files timestamp with ffmpeg

允我心安 提交于 2021-02-08 09:40:55

问题


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

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

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

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?


回答1:


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 will have output like this

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

where each reading is the Unix epoch time in milliseconds.

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.



来源:https://stackoverflow.com/questions/49287744/sync-files-timestamp-with-ffmpeg

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!