Deepstream Detections to MQTT working sample

Hello! I’d like to share a working sample on how to use Mosquitto with Deepstream to output detections via MQTT.

Github - pabsan-0/libnvds_mqtt_proto

The code for the MQTT library itself was taken from the forums after lots of searching. Then, it still took some serious time to find a working configuration to go with it. I hope with all my heart this is useful to anyone wanting to use MQTT.

Tested on DeepStream 6.0.1 & DeepStream 6.1 for pipelines built on gst-launch

Cheers!

2 Likes

Thank you for sharing the sample.
Compiled libnvds_mqtt_proto.cpp and generated libnvds_mqtt_proto.so as per your github readme instructions.
When the sink is enabled the inferencing not working.
If we disable the sink the video output is getting generated.
What could be the issue?
Running on Tesla T4 GPU Deepstream 6.1 SDK.

Here is the sink configuration

[sink1]
enable=1
type=6
msg-broker-conn-str=127.0.0.1;1883
msg-broker-proto-lib=/opt/nvidia/deepstream/deepstream-6.1/lib/libnvds_mqtt_proto.so
topic=hello
msg-conv-payload-type=0
msg-conv-config=msgconv_config.txt

Hello! I’m going to have a look at it. Could you please share the rest of the configuration?

Thanks for your swift reply.
Mosquitto installed correctly. Verified by publishing and subscribing using mosquitto_pub and mosquitto_sub.
msgconv_config.txt is same as your github version.
Adding remaining deepstream config here.

[application]
enable-perf-measurement=1
perf-measurement-interval-sec=1

[tiled-display]
enable=1
rows=1
columns=1
width=1280
height=720
gpu-id=0
nvbuf-memory-type=0

[source0]
enable=1
#Type - 1=CameraV4L2 2=URI 3=MultiURI 4=RTSP
type=3
uri=file://../../streams/D01_20220906164630.mp4
#num-sources=15
#drop-frame-interval=2
gpu-id=0
cudadec-memtype=0


[sink0]
enable=1
type=3
#1=mp4 2=mkv
container=1
#1=h264 2=h265
codec=1
#encoder type 0=Hardware 1=Software
enc-type=0
sync=0
#iframeinterval=10
bitrate=2000000
#H264 Profile - 0=Baseline 2=Main 4=High
#H265 Profile - 0=Main 1=Main10
profile=0
output-file=out.mp4
source-id=0

[sink1]
enable=1
type=6
msg-broker-conn-str=127.0.0.1;1883
msg-broker-proto-lib=/opt/nvidia/deepstream/deepstream-6.1/lib/libnvds_mqtt_proto.so
topic=hello
msg-conv-payload-type=0
msg-conv-config=msgconv_config.txt
#newapi=1
#msg-conv-frame-interval=1 

[osd]
enable=1
gpu-id=0
border-width=1
text-size=15
text-color=1;1;1;1;
text-bg-color=0.3;0.3;0.3;1
font=Serif
show-clock=0
clock-x-offset=800
clock-y-offset=820
clock-text-size=12
clock-color=1;0;0;0
nvbuf-memory-type=0


[streammux]
gpu-id=0
##Boolean property to inform muxer that sources are live
live-source=0
batch-size=30
##time out in usec, to wait after the first buffer is available
##to push the batch even if the complete batch is not formed
batched-push-timeout=40000
## Set muxer output width and height
width=1920
height=1080
##Enable to maintain aspect ratio wrt source, and allow black borders, works
##along with width, height properties
enable-padding=0
nvbuf-memory-type=0
## If set to TRUE, system timestamp will be attached as ntp timestamp
## If set to FALSE, ntp timestamp from rtspsrc, if available, will be attached
# attach-sys-ts-as-ntp=1

# config-file property is mandatory for any gie section.
# Other properties are optional and if set will override the properties set in
# the infer config file.
[primary-gie]
enable=1
gpu-id=0
model-engine-file=../../models/Primary_Detector/resnet10.caffemodel_b30_gpu0_int8.engine
#Required to display the PGIE labels, should be added even when using config-file
#property
batch-size=30
#Required by the app for OSD, not a plugin property
bbox-border-color0=1;0;0;1
bbox-border-color1=0;1;1;1
bbox-border-color2=0;0;1;1
bbox-border-color3=0;1;0;1
interval=0
#Required by the app for SGIE, when used along with config-file property
gie-unique-id=1
nvbuf-memory-type=0
config-file=config_infer_primary.txt

[tests]
file-loop=0


[secondary-gie0]
enable=1
model-engine-file=../../models/Secondary_VehicleTypes/resnet18.caffemodel_b16_gpu0_int8.engine
gpu-id=0
batch-size=16
gie-unique-id=4
operate-on-gie-id=1
operate-on-class-ids=0;
config-file=config_infer_secondary_vehicletypes.txt

[nvds-analytics]
enable=1
config-file=config_nvdsanalytics.txt

[tracker]
enable=1
# For NvDCF and DeepSORT tracker, tracker-width and tracker-height must be a multiple of 32, respectively
tracker-width=1216
tracker-height=928
ll-lib-file=/opt/nvidia/deepstream/deepstream/lib/libnvds_nvmultiobjecttracker.so
# ll-config-file required to set different tracker types
# ll-config-file=config_tracker_IOU.yml
ll-config-file=config_tracker_NvDCF_perf.yml
# ll-config-file=config_tracker_NvDCF_accuracy.yml
# ll-config-file=config_tracker_DeepSORT.yml
gpu-id=0
enable-batch-process=1
enable-past-frame=1
display-tracking-id=1

Hey, thanks! I am testing different configs and also get errors for deepstream-app -c. I also re-checked that mqtt works normally for the sample gst-launch pipeline.

On the other hand, this is what I get for deepstream-app -c (some test pipeline, not the one you just sent)

root@nvds:/nvds/assets# deepstream-app -c mqtt_deepstream_app_config.txt 
** ERROR: <main:716>: Failed to set pipeline to PAUSED
Quitting
ERROR from sink_sub_bin_sink1: Could not configure supporting library.
Debug info: gstnvmsgbroker.cpp(605): new_gst_nvmsgbroker_start (): /GstPipeline:pipeline/GstBin:sink_sub_bin1/GstNvMsgBroker:sink_sub_bin_sink1:
unable to connect to nvmsgbroker library
ERROR from sink_sub_bin_sink1: GStreamer error: state change failed and some element failed to post a proper error message with the reason for the failure.
Debug info: gstbasesink.c(5367): gst_base_sink_change_state (): /GstPipeline:pipeline/GstBin:sink_sub_bin1/GstNvMsgBroker:sink_sub_bin_sink1:
Failed to start
App run failed

But now it just hit me that deepstream-app might not even support broker messaging. I recall seeing lots of forum topics about using deepstream-test5-app for that. Are you aware of this? How are you calling the program?

EDIT: I have been using deepstream-test5-app with the same outcome. I traced the code and libmqtt breaks at the connect routine, right when trying to connect to the broker. It is exactly as if mosquitto hadn’t been started (do make sure it is up and running at the right port for your tests). I’m out of ideas for now. Please reach out if you figure it out

Hello,
Already tried connecting to kafka and redis using test5 app. Getting following error

unable to open shared library

As mentioned in my previous comment mosquitto is working correctly, when used with mosquitto_sub and mosquitto_pub.