# Holistic Record and Replay

To simplify development and later testing and debugging of your application, you can record and replay test data. This can be done
without any changes to your code with the use of environmental variables and configuration files.

Holistic record and replay works by recording data (messages) of source nodes used in an application
([Camera](https://docs.luxonis.com/software-v3/depthai/depthai-components/nodes/camera.md) and
[IMU](https://docs.luxonis.com/software-v3/depthai/depthai-components/nodes/imu.md)) which can then be replayed as if the source
nodes sent the same data again.

## Holistic Record

Holistic record records enabled source node streams to a tar file. This can be enabled in code:

#### Python

```python
with dai.Pipeline as pipeline:
    config = dai.RecordConfig()
    config.outputDir = "./recordings";
    config.videoEncoding.enabled = True # Use video encoding
    config.videoEncoding.profile = dai.VideoEncoderProperties.Profile.H264_MAIN

    pipeline.enableHolisticRecord(config)
```

#### C++

```cpp
dai::Pipeline pipeline;
dai::RecordConfig config;
config.outputDir = "./recordings";
config.videoEncoding.enabled = true;  // Use video encoding
config.videoEncoding.profile = dai::VideoEncoderProperties::Profile::H264_MAIN;

pipeline.enableHolisticRecord(config);
```

or by using the DEPTHAI_RECORD environment variable:

```bash
DEPTHAI_RECORD="./recordings" python3 application.py
```

### Environment variable configuration

In the above example, the DEPTHAI_RECORD environment variable is set to the recording output directory. This enabled holistic
recording with the default configuration options. If you want more control you set the variable to the path to a configuration
file:

```json
{
    "compressionLevel": 3,
    "outputDir": "recordings/",
    "videoEncoding": {
	"enabled": true,
        "bitrate": 0,
        "lossless": false,
        "profile": "MJPEG",
        "quality": 80
    }
}
```

The configuration parameters are as follows:

 * compressionLevel configures the compression of the metadata. It ranges from 0 to 5 (inclusive) which corresponds to the
   following compression levels: NONE, FASTEST, FAST, DEFAULT, SLOW, SLOWEST
 * outputDir sets the output directory of the recording
 * videoEncoding configures the
   [VideoEncoder](https://docs.luxonis.com/software-v3/depthai/depthai-components/nodes/video_encoder.md) that encodes the camera
   stream:
   * enabled enables the [VideoEncoder](https://docs.luxonis.com/software-v3/depthai/depthai-components/nodes/video_encoder.md).
     When false, the output of the [Camera](https://docs.luxonis.com/software-v3/depthai/depthai-components/nodes/camera.md) node
     is recorded which can decrease the device CPU usage while increasing bandwidth usage
   * profile sets the encoding profile
   * bitrate sets the [VideoEncoder](https://docs.luxonis.com/software-v3/depthai/depthai-components/nodes/video_encoder.md)
     bitrate (when set to 0 it is determined automatically)
   * lossless determines whether the encoding should be lossles where applicable
   * quality determines the encoding quality where applicable

## Example of functionality

 * [Holistic Record](https://docs.luxonis.com/software-v3/depthai/examples/record_replay/holistic_record.md)

## Holistic Replay

Holistic replay replays recorded source streams. Similarly to holistic record it can be enabled in code:

#### Python

```python
with dai.Pipeline as pipeline:
    pipeline.enableHolisticReplay("./recordings/recording.tar")
```

#### C++

```cpp
dai::Pipeline pipeline;
pipeline.enableHolisticReplay("./recordings/recording.tar");
```

or by using the DEPTHAI_REPLAY environment variable:

```bash
DEPTHAI_REPLAY="./recordings/recording.tar" python3 application.py
```

## Example of functionality

 * [Holistic Replay](https://docs.luxonis.com/software-v3/depthai/examples/record_replay/holistic_replay.md)

## Limitations

This functionality is a work in progress and comes with some limitations:

 * As it currently only records source node streams, replaying on a different device can produce unexpected results (e.g. as
   camera extrinsics are not recorded, StereoDepth can produce incorrect results if the calibration differs between the recording
   and replaying cameras)
 * At this point in time, only single device pipelines can be holistically recorded and replayed.
