Please provide complete information as applicable to your setup.
• Hardware Platform (Jetson / GPU): GPU
• DeepStream Version: 7.1
• TensorRT Version: 10.3.0.26
• NVIDIA GPU Driver Version (valid for GPU only): 555.58.02
• Issue Type( questions, new requirements, bugs): questions
Hello. I’m working with deepstream using python. I have now started working with the nvmultiurisrcbin module. And I ran into the following problem. When I send messages to the broker, I need to get information about the data source of each frame. If in the case of deep stream c++ this can be done using the get_sensor_info function, then there is no implementation for python. And if i will add it to pyds yourself, then for this I need to have the AppCtx class, which I do not know how to get in python.
How can I get information about the data source of each frame in deep
stream python? I need to get camera_id and camera_name
If you only need to get camera_id
and camera_name
, you only need to call a resful api.
Such as
start pipeline
gst-launch-1.0 nvmultiurisrcbin port=9000 ip-address=localhost batched-push-timeout=33333 max-batch-size=10 drop-pipeline-eos=1 live-source=1 width=2560 height=1440 uri-list=rtsp://xxxx ! nvmultistreamtiler ! nv3dsink
add a rtsp camera
curl -XPOST 'http://localhost:9000/api/v1/stream/add' -d '{
"key": "sensor",
"value": {
"camera_id": "uniqueSensorID1",
"camera_name": "front_door",
"camera_url": "rtsp://xxxxxx",
"change": "camera_add",
"metadata": {
"resolution": "1920 x1080",
"codec": "h264",
"framerate": 30
}
},
"headers": {
"source": "vst",
"created_at": "2021-06-01T14:34:13.417Z"
}
}'
call get-stream-info
curl -XGET 'http://localhost:9000/api/v1/stream/get-stream-info'
result
{
"reason" : "GET_LIVE_STREAM_INFO_SUCCESS",
"status" : "HTTP/1.1 200 OK",
"stream-info" :
{
"stream-count" : 2,
"stream-info" :
[
{
"camera_id" : "uniqueSensorID1",
"camera_name" : "front_door"
},
{
"camera_id" : "",
"camera_name" : ""
}
]
}
}
However, if you want to get more information about the sensor, such as the URL, the restful API currently does not provide this feature.
It is recommended that you save it in yourself program when adding, after all, this is just sending a restful request, and sending a request is a user behavior and has nothing to do with deepstream.
Thanks for the reply. And how to correlate the results of a GET request and information from pyds in the form of stream_id? Because the stream_id is set based on the pads id. And in a simple way it is impossible to understand which camera_id the stream_id from the buffer belongs to.
Take deepstream_test_1.py
as an example,
def osd_sink_pad_buffer_probe(pad,info,u_data):
frame_number=0
num_rects=0
gst_buffer = info.get_buffer()
if not gst_buffer:
print("Unable to get GstBuffer ")
return
# Retrieve batch metadata from the gst_buffer
# Note that pyds.gst_buffer_get_nvds_batch_meta() expects the
# C address of gst_buffer as input, which is obtained with hash(gst_buffer)
batch_meta = pyds.gst_buffer_get_nvds_batch_meta(hash(gst_buffer))
l_frame = batch_meta.frame_meta_list
while l_frame is not None:
try:
# Note that l_frame.data needs a cast to pyds.NvDsFrameMeta
# The casting is done by pyds.NvDsFrameMeta.cast()
# The casting also keeps ownership of the underlying memory
# in the C code, so the Python garbage collector will leave
# it alone.
frame_meta = pyds.NvDsFrameMeta.cast(l_frame.data)
Get source_id
from frame_meta. Such as frame_meta.source_id
https://docs.nvidia.com/metropolis/deepstream/dev-guide/python-api/PYTHON_API/NvDsMeta/NvDsFrameMeta.html
I have a problem with something else. I know how to get the stream_id within the pad_buffer_probe function. I do not know how to link the stream_id from this function and the camera_id that I will get thanks to the GET request
GET request
can only get the list of all currently added cameras. The source_id
cannot be obtained for the time being, this may be an area for improvement
If you want to find the camera corresponding to each frame in the batch.
1.Each time a camera is added, a new_stream_add
message is sent, and the corresponding nvmessage
is parsed in bus_callback
to get the source_id
case GST_MESSAGE_ELEMENT: {
if (gst_nvmessage_is_force_pipeline_eos(message)) {
gboolean app_quit = FALSE;
if (gst_nvmessage_parse_force_pipeline_eos(message, &app_quit)) {
if (app_quit)
appCtx->quit = TRUE;
}
}
if (gst_nvmessage_is_stream_add(message)) {
g_mutex_lock(&(appCtx->perf_struct).struct_lock);
appCtx->config.num_source_sub_bins++;
NvDsSensorInfo sensorInfo = {0};
gst_nvmessage_parse_stream_add(message, &sensorInfo);
- Get
source_id
from frame_meta.
Or Modify s_get_request_api_impl
in /opt/nvidia/deepstream/deepstream/sources/gst-plugins/gst-nvmultiurisrcbin/gstdsnvmultiurisrcbin.cpp
to take source_id
as response, then rebuild and install
@@ -2336,6 +2339,7 @@ s_get_request_api_impl (NvDsServerGetRequestInfo * get_request_info, void *ctx)
else
stream["camera_name"] = std::string("");
+ stream["source_id"] = sensor_info->source_id;
//Add the stream info objects into stream info JSON array
streamInfo.append(stream);
Thanks! The second option was suitable for my case. Hopefully in future updates you will add information about source_id to s_get_request_api_impl