Significant latency when using Degirum PySDK gstreamer streaming

Hi. I am using gstreamer using pygobject module to display live stream video with object detection shown here hailo_examples/examples/016_custom_video_source.ipynb at main · DeGirum/hailo_examples · GitHub. I noticed there is a significant amount of delay in the video which is unlike the code shown here hailo-apps-infra/hailo_apps/hailo_app_python/apps/detection at main · hailo-ai/hailo-apps-infra · GitHub . Also, I am using PyGobject version 3.50.1 due to a metageneration error when I was installing the latest version, not sure if this is causing the latency though.

Hi @Fong_Zi_Hao Can you share the gstreamer pipeline that you are using for streaming ?

Also, can you confirm if you run the pipeline from terminal using gst-launch-1.0 command, does that work as expected ?

Hi. I am not too sure on which pipeline my gstreamer is using but I am using the same code that is provided by Degirum under ‘Using Gstreamer using Pygobject module’. Am I required to add in pipeline myself to the code?

Running gst-launch-1.0 v4l2src device=/dev/video0 ! videoconvert ! autovideosink displays the live video. The stream doesn’t seem to be running at 30fps like hailo-infra-examples but there is very minimal latency.

Setting pipeline to PAUSED …
Pipeline is live and does not need PREROLL …
Pipeline is PREROLLED …
Setting pipeline to PLAYING …
New clock: GstSystemClock
Redistribute latency…
ERROR: from element /GstPipeline:pipeline0/GstAutoVideoSink:autovideosink0/GstXvImageSink:autovideosink0-actual-sink-xvimage: Output window was closed
Additional debug info:
../sys/xvimage/xvimagesink.c(586): gst_xv_image_sink_handle_xevents (): /GstPipeline:pipeline0/GstAutoVideoSink:autovideosink0/GstXvImageSink:autovideosink0-actual-sink-xvimage
Execution ended after 0:00:16.435377363
Setting pipeline to NULL …
Freeing pipeline .

Alright, I have swapped out the pipeline_str under custom video generator function with this.

pipeline_str = (
"v4l2src device=/dev/video0 ! "
"image/jpeg, width=1280, height=720, framerate=30/1 ! "
"jpegdec ! videoconvert ! video/x-raw, format=BGR ! "
“appsink name=sink emit-signals=true max-buffers=1 drop=true”
)

Stream is running smooth but there is still some latency.

@Fong_Zi_Hao It seems like you are using your webcam as camera input. Can you confirm if the width and height in the gstreamer pipeline (1280, 720) is the same as your camera resolution ? Sometimes resizing adds up little latency . Also please try changing max-buffers=2 in the pipeline_str

Thanks for your reply. Yep, the width and height is the same. I checked with v4l2-ctl --list-formats-ext and it shows

‘MJPG’ (Motion-JPEG, compressed)
Size: Discrete 1280x720
Interval: Discrete 0.017s (60.000 fps)
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.040s (25.000 fps)

Changing max-buffers=2 doesn’t improve the latency either.