Gst-nvreplay
The Gst-nvreplay plugin loads pre-generated metadata from external files and injects it into DeepStream pipelines, effectively replacing the actual inference of corresponding plugins. This enables flexible proof-of-concepts, reproducible evaluations, and efficient parameter tuning by decoupling metadata generation from the pipeline.
The plugin currently supports loading detection metadata equivalent to a primary inference engine (PGIE). It reads bounding box annotations from txt files in MOT challenge format and attaches them as NvDsObjectMeta to frames, allowing testing of downstream components (trackers, analytics modules, visualizations) without running computationally expensive inference operations.
Typical Pipeline Structure: source -> decoder -> nvstreammux -> nvreplay -> nvtracker -> nvdsosd -> sink
Inputs and Outputs
-
Inputs
- Gst Buffer with NV12/RGBA/I420 format (NVMM memory)
- NvDsBatchMeta (must be attached by upstream components)
- Detection label files in MOT challenge format
-
Output
- Gst Buffer
- NvDsObjectMeta filled with bounding box coordinates, confidence score, and class information
- The frame_meta->bInferDone flag is set to TRUE, indicating detection completion
Features
The following table summarizes the features of the plugin.
Gst-nvreplay plugin features
Gst Properties
The following table describes the Gst properties of the Gst-nvreplay plugin.
Gst-nvreplay gst properties
MOT Detection Format
The plugin expects detection data in the MOT (Multiple Object Tracking) challenge format, which is a CSV format where each line represents one detection. The format is widely used in computer vision research and provides a standardized way to represent object detections.
Format Specification:
Each line in the CSV file has the following structure:
frame_num, object_id, left, top, width, height, confidence
Where:
- frame_num: Frame number (1-indexed in the label file, converted to 0-indexed internally)
- object_id: Always set to -1 for detection
- left: Left coordinate of the bounding box (x-coordinate of top-left corner)
- top: Top coordinate of the bounding box (y-coordinate of top-left corner)
- width: Width of the bounding box
- height: Height of the bounding box
- confidence: Detection confidence score, or valid flag (range: 0.0 to 1.0)
Example:
This example shows two objects detected in frame 1 and 2 each.
Important Notes:
- Frame numbers in label files start from 1, but are converted to 0-indexed internally by DeepStream
- All coordinates are in the scale defined by
label-widthandlabel-heightproperties - The plugin automatically scales coordinates to match the actual frame resolution
- If a frame has no detections, it can be omitted from the label file (the plugin handles missing frames)
Configuration
The Gst-nvreplay plugin can be configured through the DeepStream application configuration file or through GStreamer properties.
DeepStream Configuration File Example:
When using the plugin in a DeepStream application, you must disable the primary inference engine and enable the replay plugin:
File Organization:
The plugin supports two directory structures:
- Flat structure (all files in the label directory):
- Nested structure (files organized in subdirectories):
Metadata Generation
The plugin generates NvDsObjectMeta for each detection in the label files with the following attributes:
-
rect_params: Bounding box coordinates (scaled to actual frame dimensions)
- left, top, width, height: Scaled from label coordinates to frame coordinates
-
object_id: Set to UNTRACKED_OBJECT_ID (default: 0xFFFFFFFFFFFFFFFF)
-
class_id: Set to LABEL_CLASS (default: 1)
-
obj_label: Set to “Person” by default
-
confidence: Detection confidence score from the label file
-
unique_component_id: Set to 15 (default unique ID for the plugin)
-
text_params: Display parameters for object label
The plugin also sets frame_meta->bInferDone = TRUE to indicate that “inference” (in this case, label loading) has been completed for the frame.
Coordinate Scaling:
The plugin automatically handles coordinate scaling between label space and actual frame space:
- scale_width = frame_width / label_width
- scale_height = frame_height / label_height
All bounding box coordinates from the label file are multiplied by these scale factors to ensure correct positioning on frames of any resolution.
Source Code and Compilation
The source code for Gst-nvreplay is located in:
deepstream/sources/gst-plugins/gst-nvreplay/
Key Files:
gstnvreplay.cpp: Main plugin implementationgstnvreplay.h: Plugin header and data structuresgstnvreplay_lib.h: Library interface headerREADME: Detailed usage instructions and examples
Compilation:
To compile and install the plugin:
Customization
To customize the plugin for specific use cases, you may need to modify the source code:
Multi-class Support: Modify attach_metadata_full_frame() in gstnvreplay.cpp to parse class IDs from label files. The current implementation assigns all objects to the class ID specified by LABEL_CLASS (default: 1).
Object Label Customization: Change the LABEL_CLASS and LABEL_NAME constants to customize the default object class ID and label:
Support for Additional Formats: Extend load_replay_data() function to parse label formats other than MOT (e.g., COCO JSON, KITTI format, or custom formats).
After making modifications, recompile and reinstall the plugin.