I'm using ffmpeg from the command line to capture from a webcam to a file using the following:
ffmpeg -y -rtbufsize 702000k -f dshow -s 320x240 -r 25 -i video="<device name>" -t 10 -vcodec mjpeg -q:v 2 out.mp4
There is a slight delay between executing the command and the start of the capture (~0.5 sec). I'm trying to find a way to accurately determine the start time (UTC/GMT) of the capture.
My initial thought was to use the file-creation time as this might accurately reflect when the first frame was encoded (as opposed to when the command was executed). Unfortunately the file creation time is only accurate to the second which is not precise enough (and I'm not sure this would have given an accurate result anyway).
My next thought was to use ffmpegs timestamp option. According to the documentation (http://www.ffmpeg.org/ffmpeg.html):
‘-timestamp time (output)’
Set the recording timestamp in the container. The syntax for time is: now|([(YYYY-MM-DD|YYYYMMDD)[T|t| ]]((HH:MM:SS[.m...])|(HHMMSS[.m...]))[Z|z])
If the value is "now" it takes the current time. Time is local time unless ’Z’ or ’z’ is appended, in which case it is interpreted as UTC. If the year-month-day part is not specified it takes the current year-month-day.
So I added the option:
ffmpeg -y -rtbufsize 702000k -f dshow -s 320x240 -r 25 -i video="<device name>" -t 10 -vcodec mjpeg -q:v 2 -timestamp now out.mp4
Unfortunately ffmpeg doesn't seem to like this:
Option timestamp (set the recording timestamp ('now' to set the current time)) cannot be applied to output file out.mp4 -- you are trying to apply an input option to an output file or vice versa. Move this option before the file it belongs to.
Error parsing options for output file out.mp4.
Error opening output files: Error number -22 occurred
The documentation says -timestamp is an output option and it appears to be applied to the output file so I'm confused by this error.
Can anyone suggest a way to accurately determine the capture start time?
Does anyone know why the -timestamp option gives an error?