OK, that's great. It means your cameras are all synchronising correctly, as expected. So there's nothing strange going on, and we ought to be able to get everything to work.
Now, I'm going to give you two more scripts. This time I'll use links, because they're starting to get just a bit long. Download sync_capture_server.py and sync_server_client.py. In the server script, you'll need to put the IP address of your client rather than mine!
In these two scripts, I'm just setting up a socket so that I can communicate between the server and client Pis. The server decides when to trigger the capture - but how do we get the client to do its captures at the same moment? The obvious strategy - sending a message to the client, so that it can capture immediately is not great - simply because the message might be late, and you could end up with the next frame.
Instead the strategy I've chosen is for the server to calculate a time, a little bit in the future, when the capture will happen. It sends this time to the client, which will then capture at the same time.
The time in the future that we send is the most recent wallclock time, which the server gets by checking the next frame, plus one AND A HALF frame times (a frame time being 200ms at 5fps). The half is important. If we sent a regular frame time, we'd have a race problem, because the frame times will randomly be just before or after, depending on jitter. But by sending a time exactly between two frames, we can safely say "capture the first frame later than this".
The scripts work very well for me - see how you get on. Note there is still a technical possibility that one or more of your cameras might drop a frame, so they won't all match. But firstly, this is going to be very rare on a Pi 5 at 5fps (maybe even impossible), and if it does happen, you would need to put in some checking and either fail or just try again.
Finally, we ought to be able to guarantee that the two cameras on the server capture at the same moment, and the two cameras on the client do as well. But we still need to check the images between server and client. You can capture images of, for example, a stopwatch running on a phone. If these differ, then I think the only explanation is that the wallclocks on the two Pis are not properly synchronised - but I think let's leave that until it turns out to be a problem!
Now, I'm going to give you two more scripts. This time I'll use links, because they're starting to get just a bit long. Download sync_capture_server.py and sync_server_client.py. In the server script, you'll need to put the IP address of your client rather than mine!
In these two scripts, I'm just setting up a socket so that I can communicate between the server and client Pis. The server decides when to trigger the capture - but how do we get the client to do its captures at the same moment? The obvious strategy - sending a message to the client, so that it can capture immediately is not great - simply because the message might be late, and you could end up with the next frame.
Instead the strategy I've chosen is for the server to calculate a time, a little bit in the future, when the capture will happen. It sends this time to the client, which will then capture at the same time.
The time in the future that we send is the most recent wallclock time, which the server gets by checking the next frame, plus one AND A HALF frame times (a frame time being 200ms at 5fps). The half is important. If we sent a regular frame time, we'd have a race problem, because the frame times will randomly be just before or after, depending on jitter. But by sending a time exactly between two frames, we can safely say "capture the first frame later than this".
The scripts work very well for me - see how you get on. Note there is still a technical possibility that one or more of your cameras might drop a frame, so they won't all match. But firstly, this is going to be very rare on a Pi 5 at 5fps (maybe even impossible), and if it does happen, you would need to put in some checking and either fail or just try again.
Finally, we ought to be able to guarantee that the two cameras on the server capture at the same moment, and the two cameras on the client do as well. But we still need to check the images between server and client. You can capture images of, for example, a stopwatch running on a phone. If these differ, then I think the only explanation is that the wallclocks on the two Pis are not properly synchronised - but I think let's leave that until it turns out to be a problem!
Statistics: Posted by therealdavidp — Mon Jun 16, 2025 10:03 am