I need to record from my 2 webcams and output each frame recorded into images. An additional requirement is I need the time when the image is captured (it has to be precise up to around 10 milliseconds)
Things I've tried:
ffmpeg -y -f video4linux2 -r $frame_rate -i /dev/video0 -vframes 100 -strftime 1 cam0_"%H-%M-%S".png &
ffmpeg -y -f video4linux2 -r $frame_rate -i /dev/video1 -vframes 100 -strftime 1 cam1_"%H-%M-%S".png
This is only good up to a second, so if 2 images are taken within 1 second, 1 is overwritten.
for i in [1..100]
ffmpeg -y -f video4linux2 -r $frame_rate -i /dev/video0 -vframes 1 -strftime 1 cam0_%5d.png
date +%s%3N >> time.txt
Then 2 scripts are run in parallel. The timing is now precise up to a millisecond but this degrades the performance a lot since ffmpeg has to be initialized again each time I call the script.
I also tried this
ffmpeg -f video4linux2 -pixel_format yuv420p -timestamps abs -copyts \
-i /dev/video0 -vf setpts=PTS-STARTPTS -vsync 0 -vframes 10 \
camera0-%5d.jpeg -c copy -vsync 0 -vframes 10 -f mkvtimestamp_v2 timings.txt
And here's timings.txt
1614427227518
1614427227718
1614427227818
1614427227918
1614427228018
1614427228118
1614427228218
1614427228318
1614427228418
1614427228518
This is good up to 100ms.
Is there any better way to do this?