Here is a summary of the solutions outlined above.
1 Edit file. eventmsg_payload.cpp
,
cd /opt/nvidia/deepstream/deepstream/sources/libs/nvmsgconv/deepstream_schema/
vim eventmsg_payload.cpp
in generate_event_message
func
gchar* generate_event_message (void *privData, NvDsEventMsgMeta *meta)
{
JsonNode *rootNode;
JsonObject *rootObj;
JsonObject *placeObj;
JsonObject *sensorObj;
JsonObject *analyticsObj;
JsonObject *eventObj;
JsonObject *objectObj;
gchar *message;
uuid_t msgId;
gchar msgIdStr[37];
uuid_generate_random (msgId);
uuid_unparse_lower(msgId, msgIdStr);
// place object
// placeObj = generate_place_object (privData, meta);
// sensor object
// sensorObj = generate_sensor_object (privData, meta);
// analytics object
// analyticsObj = generate_analytics_module_object (privData, meta);
// object object
// objectObj = generate_object_object (privData, meta);
// event object
// eventObj = generate_event_object (privData, meta);
// root object
rootObj = json_object_new ();
json_object_set_string_member (rootObj, "messageid", msgIdStr);
json_object_set_string_member (rootObj, "mdsversion", "1.0");
json_object_set_string_member (rootObj, "@timestamp", meta->ts);
// json_object_set_object_member (rootObj, "place", placeObj);
// json_object_set_object_member (rootObj, "sensor", sensorObj);
// json_object_set_object_member (rootObj, "analyticsModule", analyticsObj);
// json_object_set_object_member (rootObj, "object", objectObj);
// json_object_set_object_member (rootObj, "event", eventObj);
// if (meta->videoPath)
// json_object_set_string_member (rootObj, "videoPath", meta->videoPath);
// else
// json_object_set_string_member (rootObj, "videoPath", "");
rootNode = json_node_new (JSON_NODE_OBJECT);
json_object_set_string_member (rootObj, "otherAttrs", meta->otherAttrs);
json_node_set_object (rootNode, rootObj);
message = json_to_string (rootNode, TRUE);
json_node_free (rootNode);
json_object_unref (rootObj);
return message;
}
cd ..
make && make install
2, in your python code,
json_str = json.dumps(payload).encode('utf-8')
user_event_meta = pyds.nvds_acquire_user_meta_from_pool(batch_meta)
if user_event_meta:
msg_meta = pyds.alloc_nvds_event_msg_meta(user_event_meta)
msg_meta = pyds.NvDsEventMsgMeta.cast(msg_meta)
msg_meta.otherAttrs = json_str
msg_meta.ts = pyds.alloc_buffer(MAX_TIME_STAMP_LEN + 1)
pyds.generate_ts_rfc3339(msg_meta.ts, MAX_TIME_STAMP_LEN)
user_event_meta.user_meta_data = msg_meta
user_event_meta.base_meta.meta_type = pyds.NvDsMetaType.NVDS_EVENT_MSG_META
pyds.nvds_add_user_meta_to_frame(frame_meta, user_event_meta)
else:
logger.error("Unable to get user meta")
you will get msg
{
"messageid": "c3518967-0de4-4c82-9e10-369407f3225e",
"mdsversion": "1.0",
"@timestamp": "2024-11-27T11:28:51.407Z",
"otherAttrs": "{\"source_id\": 2, \"pts\": 62601937403, \"ntp\": 1732706667686326123, \"width\": 2560, \"height\": 1440, \"frame_num\": 1411, \"objects\": [{\"class_id\": 34, \"class_name\": \"Car\", \"confidence\": \"0.98\", \"box\": [815, 485, 182, 274]}, {\"class_id\": 27, \"class_name\": \"Car\", \"confidence\": \"1.00\", \"box\": [1007, 492, 187, 270]}]}",
}