I want to synchronize multiple RPIs to a single clock. For this I use a computer as the ntp server for all of them. All the RPIs now have the same time(server time). After synchronizing I want record videos simultaneously from all of them like a CCTv.

I am planning to use Presentation timestamps of frames of videos being simultaneously recorded. Now if I have those timestamps giving me time w.r.t RPI's clock then my problem is solved(as all RPIs have same clock). I change (following a suggestion from Camera Forum) line 573 of picamera/camera.py

cc.use_stc_timestamp = mmal.MMAL_PARAM_TIMESTAMP_MODE_RAW_STC

Now I expect to get RAW_STCfor each timestamp. But I see that this value gets reseted every-time I switch on / off the pi? So what RAW_STC is giving me is the time since Pi has been On. It is not using pi's clock(the one I have synced with external server) for this timestamppig. How Can I use that clock for Presentation timestamp? Once I get timestamps relative to the Pi's clock I think all the timestamps can be compared.

  • 1
    The title of your question does not reflect the real question you are asking, which is "How do I set NTP time on my PiCamera/camera.py video feed?". Can you edit your question to update the title? – Phil B. May 20 '15 at 12:17
  • 1
    I'm not familiar with mmal. I guess MMAL_PARAM_TIMESTAMP_MODE_RAW_STC is the free running microseconds since boot system clock. It will drift with the crystal on each Pi. I suppose you could record the system clock with the wall time clock at the start and end of each session and then interpolate to synchronise. – joan May 20 '15 at 12:17
  • As joan says, that's probably uncorrected time since boot. I don't know if the drift will amount to that much unless you start getting into days up. In any case, if you leave NTP running, it should correct the system time (which is not "uncorrected time since boot") for drift, and although the corrections won't be simultaneous, it should mean no one is more that a second off. Every programming language has a simple way to get the system time in "(milli)seconds since the epoch", I'm sure you can look that up easily, and if they are all running NTP, they should all be within 1 second. – goldilocks May 20 '15 at 13:29
  • NTP will correct the system time, but how do I use the corrected time for timestamps? Currently timestamps are using time since system boot – Coderaemon May 21 '15 at 4:17
  • There's no way via the firmware to get the actual timestamp for frames (unsurprisingly given the firmware is derived from mobile phone firmware in which the file's timestamp is good enough as an indicator of when it's recorded, and relative PTS is all that's needed within the file). You could query the system's uptime and figure out the boot time from there (then add it to the relative PTS) but I've no idea how accurate that is (I doubt it's millisecond accurate which is what you'd need for frame-level synchronization). – Dave Jones May 21 '15 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.