# 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-v3/depthai/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-v3/depthai/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

 * [Sync](https://docs.luxonis.com/software-v3/depthai/examples/sync/sync.md) -Synchronize two or more data streams.
 * [Demuxing Synchronized Script
   Outputs](https://docs.luxonis.com/software-v3/depthai/depthai-components/messages/image_manip_config.md) - Use Sync node to
   synchronize multiple outputs from a Script node and demux them using MessageDemux.

## Reference

### dai::node::Sync

Kind: class

Sync node. Performs syncing between image frames.

#### InputMap inputs

Kind: variable

A map of inputs

#### Output out

Kind: variable

Output message of type MessageGroup

#### void setSyncThreshold(std::chrono::nanoseconds syncThreshold)

Kind: function

Set the maximal interval between messages in the group parameters: syncThreshold: Maximal interval between messages in the group

#### void setSyncAttempts(int syncAttempts)

Kind: function

Set the number of attempts to get the specified max interval between messages in the group parameters: 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

#### void setProcessor(ProcessorType type)

Kind: function

Specify on which processor the node should run. RVC2 only. parameters: type: Processor type - Leon CSS or Leon MSS

#### ProcessorType getProcessor()

Kind: function

Get on which processor the node should run return: Processor type - Leon CSS or Leon MSS

#### std::chrono::nanoseconds getSyncThreshold()

Kind: function

Gets the maximal interval between messages in the group in milliseconds

#### int getSyncAttempts()

Kind: function

Gets the number of sync attempts

#### void setRunOnHost(bool runOnHost)

Kind: function

Specify whether to run on host or device By default, the node will run on device.

#### bool runOnHost()

Kind: function

Check if the node is set to run on host

#### void run()

Kind: function

#### DeviceNodeCRTP()

Kind: function

#### DeviceNodeCRTP(const std::shared_ptr< Device > & device)

Kind: function

#### DeviceNodeCRTP(std::unique_ptr< Properties > props)

Kind: function

#### DeviceNodeCRTP(std::unique_ptr< Properties > props, bool confMode)

Kind: function

#### DeviceNodeCRTP(const std::shared_ptr< Device > & device, std::unique_ptr< Properties > props, bool confMode)

Kind: function

### Need assistance?

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