# Sync

The Sync node is used for synchronizing multiple input streams based on their timestamps. It outputs a grouped message containing
synchronized frames from the input streams. The output message is a
[MessageGroup](https://docs.luxonis.com/software/depthai-components/messages/message_group.md) containing synchronized messages
from all the input streams. These can be demultiplexed using the
[MessageDemux](https://docs.luxonis.com/software/depthai-components/nodes/message_demux.md) node.

## How to Place it

#### Python

```python
pipeline = dai.Pipeline()
sync = pipeline.create(dai.node.Sync)
```

#### C++

```cpp
dai::Pipeline pipeline;
auto sync = pipeline.create<dai::node::Sync>();
```

## Inputs and Outputs

## Message Synchronization

The Sync node aligns incoming messages based on their timestamps. The synchronization criteria and behavior can be configured
using the depthai.node.Sync.setSyncThreshold and depthai.node.Sync.setSyncAttempts method. More info in the [Reference
section](#Sync-Reference).

### Sync Logic

## Usage

#### Python

```python
pipeline = dai.Pipeline()
sync = pipeline.create(dai.node.Sync)

# Configure threshold for timestamp alignment
sync.setSyncThreshold(timedelta(milliseconds=50))

# Configure inputs to be synchronized
camRgb.video.link(sync.inputs["input1"])
stereo.depth.link(sync.inputs["input2"])

sync.out.link(xout.input)
# ...
```

#### C++

```cpp
dai::Pipeline pipeline;
auto sync = pipeline.create<dai::node::Sync>();

// Configure threshold for timestamp alignment
sync->setSyncThreshold(std::chrono::milliseconds(50));

// Configure inputs to be synchronized
camRgb.video.link(sync->input["input1"]);
stereo.depth.link(sync->input["input2"]);

sync->out.link(xout.input);
// ...
```

## Examples of Functionality

 * [Depth and Video Sync](https://docs.luxonis.com/software/depthai/examples/depth_video_sync.md)
 * [Multiple Scripts Sync](https://docs.luxonis.com/software/depthai/examples/scripts_sync.md)
 * [IMU and Video Sync](https://docs.luxonis.com/software/depthai/examples/imu_video_sync.md)
 * [Demuxing Synchronized Script Outputs](https://docs.luxonis.com/software/depthai-components/messages/image_manip_config.md)

## Reference

### depthai.node.Sync(depthai.Node)

Kind: Class

#### getProcessor(self) -> depthai.ProcessorType: depthai.ProcessorType

Kind: Method

Get on which processor the node should run

Returns:
Processor type - Leon CSS or Leon MSS

#### getSyncAttempts(self) -> int: int

Kind: Method

Gets the number of sync attempts

#### getSyncThreshold(self) -> datetime.timedelta: datetime.timedelta

Kind: Method

Gets the maximal interval between messages in the group in milliseconds

#### setProcessor(self, arg0: depthai.ProcessorType)

Kind: Method

Set on which processor the node should run

Parameter ``type``:
Processor type - Leon CSS or Leon MSS

#### setSyncAttempts(self, maxDataSize: typing.SupportsInt)

Kind: Method

Set the number of attempts to get the specified max interval between messages in
the group

Parameter ``syncAttempts``:
Number of attempts to get the specified max interval between messages in the
group: - if syncAttempts = 0 then the node sends a message as soon at the
group is filled - if syncAttempts > 0 then the node will make syncAttemts
attempts to synchronize before sending out a message - if syncAttempts = -1
(default) then the node will only send a message if successfully
synchronized

#### setSyncThreshold(self, syncThreshold: datetime.timedelta)

Kind: Method

Set the maximal interval between messages in the group

Parameter ``syncThreshold``:
Maximal interval between messages in the group

#### inputs

Kind: Property

A map of inputs

#### out

Kind: Property

Output message of type MessageGroup

### Need assistance?

Head over to [Discussion Forum](https://discuss.luxonis.com/) for technical support or any other questions you might have.
