# Python MultiStreamHandler - results out of sync

**URL:** <https://forum.commonvisionblox.com/t/python-multistreamhandler-results-out-of-sync/1820>\
**Category:** Python API\
**Tags:** acquisition, gigevision\
**Created:** [October 26, 2022, 1:52pm UTC](https://forum.commonvisionblox.com/t/python-multistreamhandler-results-out-of-sync/1820 "2022-10-26T13:52:37Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexm](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@alexm](https://forum.commonvisionblox.com/u/alexm)\
**Post date:** [October 26, 2022, 1:52pm UTC](https://forum.commonvisionblox.com/t/python-multistreamhandler-results-out-of-sync/1820/1 "2022-10-26T13:52:37Z")

</div>

Hi,

I’m using 2 GigE cameras to acquire images in CVBpy. I’m utilising a MultiStreamHandler to do so, as in the linked issue:  
[https://forum.commonvisionblox.com/t/cvb-python-multi-camera-acquisition/1781/14](https://forum.commonvisionblox.com/t/cvb-python-multi-camera-acquisition/1781/14)

I’ve followed the setup guide to enable PTP, and checking the camera raw\_timestamp values shows them to be within around 25 micro-seconds of each other, which is more than good enough for my application.

However, visually inspecting the captured images shows them to be around 3 or 4 frames out of sync with one another (images acquired in the same iteration of the handle\_async\_wait\_result). I’m acquiring at 120 FPS.

Is this a known issue? Anything I can look at to resolve it? If the behaviour is consistent I could work around it, but it seems odd!

Thanks,  
Alex

---

<div class="post-metadata">

**Author:** ![Andreas](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/andreas/32/75_2.png) [@Andreas](https://forum.commonvisionblox.com/u/Andreas)\
**Post date:** [November 4, 2022, 10:51am UTC](https://forum.commonvisionblox.com/t/python-multistreamhandler-results-out-of-sync/1820/2 "2022-11-04T10:51:13Z")

</div>

Hi @alexm,

can you tell us more details?

Are the images asynchronous right from the beginning? Be aware that you should start the acquisition on both cameras before enabling the trigger otherwise one camera will run ahead.

Please also check if you have lost image due to locked buffers (see stream statistics). By default only three buffers are allocated for images to be delivered to the host. If your application is not fast enough to acquire them in time images may be lost and result in a out of sync impression like you describe.  
As a rule of thump the number of buffers should be high enough to store one second of acquisition. This way you application will be more resilient against OS system hick ups.

---

<div class="post-metadata">

**Author:** ![alexm](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@alexm](https://forum.commonvisionblox.com/u/alexm)\
**Post date:** [November 4, 2022, 11:25am UTC](https://forum.commonvisionblox.com/t/python-multistreamhandler-results-out-of-sync/1820/3 "2022-11-04T11:25:21Z")

</div>

Hi Andreas,

Thanks for getting back to me.

Forgive me I’m a bit confused by the first point. I have set PTP enabled in the GenICam Browser. I don’t change those settings, but then run the cameras with the code in the linked issue. So they are both running using handle\_async\_wait\_result from the beginning. Could you send an example of how you mean to run them?

The ring buffer count is changed before running any acquisition, so I don’t think that’s the issue. At the moment I run at 120 FPS, so have allocated 200 on each camera.

Also in the attached issue, I only use images where both cameras have returned cvb.WaitStatus.Ok, so that should take care of situations where one camera has an issue? Unless there is another check I can do?

Thanks,

Alex

---

<div class="post-metadata">

**Author:** ![Andreas](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/andreas/32/75_2.png) [@Andreas](https://forum.commonvisionblox.com/u/Andreas)\
**Post date:** [November 4, 2022, 2:30pm UTC](https://forum.commonvisionblox.com/t/python-multistreamhandler-results-out-of-sync/1820/4 "2022-11-04T14:30:45Z")

</div>

Hi @alexm

> [@alexm](#):
>
> Forgive me I’m a bit confused by the first point. I have set PTP enabled in the GenICam Browser. I don’t change those settings, but then run the cameras with the code in the linked issue. So they are both running using handle\_async\_wait\_result from the beginning. Could you send an example of how you mean to run them?

You should open the cameras and start the acquisition (run the handler) while PTP is disabled. Otherwise one camera might already acquire images while the other is still starting and they will be out off sync from the application perspective. Starting the stream is a quite expensive operation. After that the acquisition engine on the host will just wait for new images to arrive. Once it is stared enabling PTP is fast.  
You should also start the PTP slave first, to add extra safety.

Unfortunately I do not have a code sample for this so I hope my explanation is sufficient.

Please note, that your ring buffer count is fine, but you cannot detect all possible issues. By the the `cvb.WaitStatus`. E.g. it will always be ok, even if you loose images as long as there are new ones arriving within the given timeout. Monitor the stream statistics to detect transport issues.

---

<div class="post-metadata">

**Author:** ![alexm](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@alexm](https://forum.commonvisionblox.com/u/alexm)\
**Post date:** [November 7, 2022, 5:27pm UTC](https://forum.commonvisionblox.com/t/python-multistreamhandler-results-out-of-sync/1820/5 "2022-11-07T17:27:51Z")

</div>

Hi Andreas,

Thanks for explaining. Unfortunately I haven’t been able to solve the issue based on that advice.

I set PtpEnable to False in the GenICamBrowser. I then tried the following code snippet at various points in the code (I then switched back to False at the end):

```auto
nm_1["PtpEnable"].value = True
nm_2["PtpEnable"].value = True

```

where:

```auto
nm_1 = device1.node_maps["Device"]
nm_2 = device2.node_maps["Device"]

```

I tried changing the values to True:

1. After defining each camera stream.
2. After defining the handler.
3. Running the handler for 0.1 seconds, then switching PTP on.

Is there anything else you can recommend? Or maybe a verified Python example (with accompanying browser settings) you can share?

Cheers,

Alex

---

<div class="post-metadata">

**Author:** ![Andreas](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.commonvisionblox.com/andreas/32/75_2.png) [@Andreas](https://forum.commonvisionblox.com/u/Andreas)\
**Post date:** [November 9, 2022, 1:02pm UTC](https://forum.commonvisionblox.com/t/python-multistreamhandler-results-out-of-sync/1820/6 "2022-11-09T13:02:19Z")

</div>

Hi @alexm

did you checkout PTP docu [here](https://help.commonvisionblox.com/NextGen/14.0/md __c___ j_workspace __next_gen_docume___ fa12bcb2_theory_of_operation_hardware __gen_i_cam__ c_v_b__user_guide.html#gcug_chmtopic36)  
If you need further assistance please contact our support

---

<div class="post-metadata">

**Author:** ![alexm](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@alexm](https://forum.commonvisionblox.com/u/alexm)\
**Post date:** [November 14, 2022, 11:38am UTC](https://forum.commonvisionblox.com/t/python-multistreamhandler-results-out-of-sync/1820/7 "2022-11-14T11:38:40Z")

</div>

Hi @Andreas,

I had been sent the Alvium GigE guide from UK support, which I have followed. Looking through this it seems broadly the same. I’ll play around with trying to check some of the parameters in Python and report back.

In general though, I don’t feel it’s an unreasonable ask for more Python examples on multi-camera acquisition, in a few common hardware setups (I doubt I’m the only person using 2 GigE cameras and PTP).

Thanks,

Alex

---

<div class="post-metadata">

**Author:** ![alexm](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@alexm](https://forum.commonvisionblox.com/u/alexm)\
**Post date:** [November 14, 2022, 12:02pm UTC](https://forum.commonvisionblox.com/t/python-multistreamhandler-results-out-of-sync/1820/8 "2022-11-14T12:02:33Z")

</div>

Hi @Andreas,

Checking PtpStatus shows that it seems to be always “Initializing”. I’ve tried re-ordering when I start up streams and change settings in the camera node maps.

Is there any other advice on what to try? All I seem to have access to in the device nodemaps is PtpEnable and PtpOperationMode. Other parameters are read only.

Thanks,

Alex

---

<div class="post-metadata">

**Author:** ![alexm](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@alexm](https://forum.commonvisionblox.com/u/alexm)\
**Post date:** [December 12, 2022, 12:10pm UTC](https://forum.commonvisionblox.com/t/python-multistreamhandler-results-out-of-sync/1820/9 "2022-12-12T12:10:31Z")

</div>

An update just in case anyone else is bumping into this:

Looks like it’s an issue with the cameras (Alvium G5) which have implemented a new method of PTP acquisition. From a code point of view - node map checks seem to suggest that it is running after executing a DataSetLatch. But, the observed results are out of sync.

Current best work-around is to just offset the resulting image arrays by 3 images (found through trial and error). But the observed differences in lighting show that the PTP is still not working as expected.
