I am trying to use v4l2_buffer's timestamp value (type timeval) to synchronize images captured from a UVC webcam to external events.
However the timestamp is not the same as the system time, or the up time, etc:
printf("image captured at %ld, %ld\n",
buffer->timestamp.tv_sec,
buffer->timestamp.tv_usec);
struct timeval tv;
gettimeofday(&tv, 0);
printf("current time %ld, %ld\n", tv.tv_sec, tv.tv_usec);
Results in
image captured at 367746, 476270
current time 1335083395, 11225
My uptime is 10 days.
According to http://comments.gmane.org/gmane.linux.drivers.video-input-infrastructure/39892 some v4l2 drivers (including the UVC one) do not use the realtime clock (wall time) but rather a monotonic clock that counts from a not specified point in time. On Linux, this is the boot time (i.e. uptime), however (and I suspect this is the cause of your mismatch) only the time that the computer was actually running (i.e. this clock does not run when the computer is suspended).
If you have the OP's problem, and you're trying to get to epoch timestamps for each frame, you can use the code snippet below to do so.