By Capture_sequence method of Picamera, I can capture consecutive images. I want the exact timestamp of each of the image that I capture. I can embedded time.time() in the name of each file that is being captured but there will a small lag. Is there any way by which I can capture the time at which image is taken in a more accurate manner ?
Video frames have presentation_timestamp property, does any such property exists for single images?
My capture code :

 def filenames():
        frame = 0
        while frame < frames:
            yield 'image%02d.data' % frame
            frame += 1
camera.capture_sequence(filenames(), format = "yuv")

2 Answers 2


Are these jpegs?

Quite often the date/time (nearest second) is encoded as part of the jpeg header.

Right click on an image and check its detailed properties.

Alternatively for jpegs download the jhead package to view and manipulate jpeg headers.

sudo apt-get install jhead

  • Edited the question with details. I am capturing Raw uncompressed data files.i.e Format YUV
    – Coderaemon
    Mar 13, 2015 at 9:49
  • Have a look through raspberrypi.org/forums/…
    – joan
    Mar 13, 2015 at 10:19

The presentation timestamp is the time according to the camera's clock. While that will be by far the most accurate measure of the frame's capture time you may not find it that much use as the camera's clock is not synced to the Pi's clock and has no idea what the "real" time is. In other words, it's just a count of microseconds since the camera was initialized.

I think about the closest you can easily get to the precise frame capture time (at least according to the Pi's internal clock) will be the time that the first packet of the frame's data gets written to the requested output. You could capture this pretty easily with a custom output. For example, the following little script enhances the PiYUVArray class to include a timestamp set on the first write to the stream (it also resets it on truncate in case you want to reuse the stream for multiple captures):

import picamera
import picamera.array
import time

class TimestampedArray(picamera.array.PiYUVArray):
    def __init__(self, camera, size=None):
        super(TimestampedArray, self).__init__(camera, size)
        self.captured_at = None

    def write(self, b):
        if self.captured_at is None:
            self.captured_at = time.time()
        return super(TimestampedArray, self).write(b)

    def truncate(self, size):
        self.captured_at = None
        return super(TimestampedArray, self).truncate(size)

with picamera.PiCamera() as camera:
    with TimestampedArray(camera) as stream:
        camera.capture(stream, format='yuv')
        print('Frame was captured just before: %s' % stream.captured_at)
        print('Frame shape: [%dx%dx%d]' % stream.array.shape)

This still won't be absolutely precise - it's the time of the first write from the firmware to the output object after capture, rather than the time of the capture itself but I suspect it's as close as you can easily get without measuring things like the time it takes the firmware to do de-mosaic, lens shading, etc. etc. (which you could apply as a negative offset to the answer of the script above).

  • I captured all the Presentation time stamps of a video file in a text file. Now I calculated the time-duration between consecutive frames (inter-frame duration) and 99% of frames have the same inter-frame duration. I find this too good to be true. Is this expected or something wrong is happening ?
    – Coderaemon
    Mar 20, 2015 at 6:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.