# MessageDemux

The MessageDemux (Demultiplexer) node is used to separate a
[MessageGroup](https://docs.luxonis.com/software/depthai-components/messages/message_group.md) into individual outputs. It
currently serves as way to demultiplex the output of [Sync](https://docs.luxonis.com/software/depthai-components/nodes/sync.md)
node.

## How to Place It

#### Python

```python
pipeline = dai.Pipeline()
demux = pipeline.create(dai.node.MessageDemux)
```

#### C++

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

## Inputs and Outputs

## Usage

The MessageDemux node is particularly useful for handling different types of data coming from a single source. For example, when
the [Sync](https://docs.luxonis.com/software/depthai-components/nodes/sync.md) node is used to synchronize the outputs of multiple
nodes, the output of the Sync node is a
[MessageGroup](https://docs.luxonis.com/software/depthai-components/messages/message_group.md) containing all the messages from
the synchronized nodes. The Demux node can be used to separate the messages into individual streams.

#### Python

```python
# Create sync node and set sync threshold
sync = pipeline.create(dai.node.Sync)
sync.setSyncThresholdMs(timedelta(milliseconds=100))

# Create demux node
demux = pipeline.create(dai.node.MessageDemux)

# Sync the outputs of multiple nodes
rgb.preview.link(sync.inputs["rgb"])
stereo.depth.link(sync.inputs["depth"])
script.outputs["out"].link(sync.inputs["script"])

sync.out.link(demux.input) # Sync output is a MessageGroup containing all the messages from the synchronized nodes

# Demux the MessageGroup into individual messages
demux.outputs["rgb"].link(xout1.input)
demux.outputs["depth"].link(xout2.input)
demux.outputs["script"].link(xout3.input)
```

#### C++

```cpp
// Create sync node and set sync threshold
auto sync = pipeline.create<dai::node::Sync>();
sync->setSyncThreshold(std::chrono::milliseconds(100));

// Create demux node
auto demux = pipeline.create<dai::node::MessageDemux>();

// Sync the outputs of multiple nodes
rgb.preview.link(sync->input["rgb"]);
stereo.depth.link(sync->input["depth"]);
script.outputs["out"].link(sync->input["script"]);

sync->out.link(demux->input); // Sync output is a MessageGroup containing all the messages from the synchronized nodes

// Demux the MessageGroup into individual messages
demux->outputs["rgb"].link(xout1.input);
demux->outputs["depth"].link(xout2.input);
demux->outputs["script"].link(xout3.input);
```

## Examples of Functionality

 * [Demuxing Synchronized Script Outputs](https://docs.luxonis.com/software/depthai-components/messages/image_manip_config.md)

## Reference

### depthai.node.MessageDemux(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

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

Kind: Method

Set on which processor the node should run

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

#### input

Kind: Property

Input message of type MessageGroup

#### outputs

Kind: Property

A map of outputs, where keys are same as in the input MessageGroup

### Need assistance?

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