This sample demonstrates how to build a Python application that constructs and executes a DL Streamer pipeline.
filesrc -> decodebin3 -> gvadetect -> gvawatermark -> autovideosink
The individual pipeline stages implement the following functions:
- filesrc element reads video stream from a local file
- decodebin3 element decodes video stream into individual frames
- gvadetect element runs AI inference object detection for each frame
- gvawatermark element draws (overlays) object bounding boxes on top of analyzed frames
- autovideosink element renders video stream on local display
In addition, the sample uses 'queue' and 'videoconvert' elements to adapt interface between functional stages. The resulting behavior is similar to hello_dlstreamer.sh using command line.
First, the application creates a GStreamer pipeline object.
The sample code demonstrates two methods for pipeline creation:
-
OPTION A: Use
gst_parse_launchmethod to construct the pipeline from a string representation. This is the default method. It uses a single API call to create a set of elements and links them together into a pipeline.pipeline = Gst.parse_launch(...) -
OPTION B: Use a sequence of GStreamer API calls to create individual elements, configure their properties and link together to form a pipeline. This method allows fine-grained control over pipeline elements.
element = Gst.ElementFactory.make(...) element.set_property(...) pipeline.add(element) element.link(next_element)
Both methods are equivalent and produce same output pipeline.
The application registers a custom callback (GStreamer probe) on the sink pad of gvawatermark element. The GStreamer pipeline will invoke the callback function on each buffer pushed to the sink pad.
watermarksinkpad = watermark.get_static_pad("sink")
watermarksinkpad.add_probe(watermark_sink_pad_buffer_probe, ...)
In this example, the callback function inspects GstAnalytics metadata produced by the gvadetect element. The callback counts the number of detected objects in each category, and attaches a custom classification string to the processed frame.
The last step is to run the pipeline. The application sets the pipeline state to PLAYING and implements the message processing loop. Once the input video file is fully replayed, the filesrc element will send end-of-stream message.
pipeline.set_state(Gst.State.PLAYING)
terminate = False
while not terminate:
msg = bus.timed_pop_filtered(...)
... set terminate=TRUE on end-of-stream message
pipeline.set_state(Gst.State.NULL)
The sample application requires two local files with input video and an object detection model. Here is an example command line to download sample assets. Please note the model download step may take up to several minutes as it includes model quantization to INT8.
cd <python/hello_dlstreamer directory>
export MODELS_PATH=${PWD}
wget https://videos.pexels.com/video-files/1192116/1192116-sd_640_360_30fps.mp4
../../../download_public_models.sh yolo11n coco128Once assets are downloaded to the local disk, the sample application can be started as any other regular python application.
python3 ./hello_dlstreamer.py 1192116-sd_640_360_30fps.mp4 public/yolo11n/INT8/yolo11n.xmlThe sample opens a window and renders a video stream along with object detection annotations - bounding boxes and object classes.