How to custom Json message sent to kafka server

when i run deepstream-test5-app, i has receive message:

{
  "messageid" : "8ba9bc9d-c341-4019-beb5-c80d08765e62",
  "mdsversion" : "1.0",
  "@timestamp" : "2020-11-05T03:45:29.191Z",
  "place" : {
    "id" : "0",
    "name" : "HWY_20_AND_LOCUST__EBA",
    "type" : "intersection/road",
    "location" : {
      "lat" : 30.32,
      "lon" : -40.549999999999997,
      "alt" : 100.0
    },
    "entrance" : {
      "name" : "C_127_158",
      "lane" : "Lane 1",
      "level" : "P1",
      "coordinate" : {
        "x" : 1.0,
        "y" : 2.0,
        "z" : 3.0
      }
    }
  },
  "sensor" : {
    "id" : "HWY_20_AND_LOCUST__EBA__4_11_2018_4_59_59_508_AM_UTC-07_00",
    "type" : "Camera",
    "description" : "Aisle Camera",
    "location" : {
      "lat" : 45.293701446999997,
      "lon" : -75.830391449900006,
      "alt" : 48.155747933800001
    },
    "coordinate" : {
      "x" : 5.2000000000000002,
      "y" : 10.1,
      "z" : 11.199999999999999
    }
  },
  "analyticsModule" : {
    "id" : "XYZ_1",
    "description" : "Vehicle Detection and License Plate Recognition",
    "source" : "OpenALR",
    "version" : "1.0",
    "confidence" : 0.0
  },
  "object" : {
    "id" : "-1",
    "speed" : 0.0,
    "direction" : 0.0,
    "orientation" : 0.0,
    "plate" : {
    },
    "bbox" : {
      "topleftx" : 515,
      "toplefty" : 0,
      "bottomrightx" : 573,
      "bottomrighty" : 45
    },
    "location" : {
      "lat" : 0.0,
      "lon" : 0.0,
      "alt" : 0.0
    },
    "coordinate" : {
      "x" : 0.0,
      "y" : 0.0,
      "z" : 0.0
    }
  },
  "event" : {
    "id" : "29f887f5-39a3-4c42-89f6-fc9979a95292",
    "type" : "entry"
  },
  "videoPath" : ""
}

now i want to custom this format to:

{
  "messageid" : "8ba9bc9d-c341-4019-beb5-c80d08765e62",
  "sourceid" : "0",
  "@timestamp" : "2020-11-05T03:45:29.191Z",
  "object" : {
      "objectID" : "0",
      "label" : "34LK1234",
      "img" : ",byte convert of object image"
  }
}

What are the files i need to custom for purpose, Someone can help me
thanks

For the customization of Jason message. Please refer to https://docs.nvidia.com/metropolis/deepstream/dev-guide/text/DS_plugin_gst-nvmsgconv.html#schema-customization

The /opt/nvidia/deepstream/deepstream-5.0/sources/libs/nvmsgconv/ codes are a sample for generate Jason message. You can modify it as you like or generate your own library to replace this default one.

1 Like

oh, thank your response, i will check and update late.

thank so much

Hi @Fiona.Chen, i think i need to custom PAYLOAD before custom Json format, because PAYLOAD DEEPSTREAM didn’t have contain like string base64 of object image and label.
You can help me

I need to load object or frame image and label to kafka or some where, so consumer can get this contain
So chose solution custom payload to add this contain, and custom Json format to sent to kafka.
are you think right? @Fiona.Chen.

Currently there is no image in NvDsEventMsgMeta. You may need to customize your own message meta which can be used by extMsg in NvDsEventMsgMeta. Please refer to the source codes /opt/nvidia/deepstream/deepstream-5.0/sources/gst-plugins/gst-nvmsgconv , /opt/nvidia/deepstream/deepstream-5.0/sources/libs/nvmsgconv

There is sample of how to use extMsg in app: /opt/nvidia/deepstream/deepstream-5.0/sources/apps/sample_apps/deepstream-test4

hi @Fiona.Chen
in line from 569 to 588 of gstnvmsgconv.c

        NvDsEvent event;

        eventMsg = (NvDsEventMsgMeta *) user_event_meta->user_meta_data;

        if (self->compId && eventMsg->componentId != self->compId)
          continue;

        event.eventType = eventMsg->type;
        event.metadata = eventMsg;

        guint payloadCount=0;

        if(self->multiplePayloads)
          payloads = self->msg2p_generate_multiple (self->pCtx, &event, 1, &payloadCount);
        else
        {
          payloads = (NvDsPayload **) g_malloc0 (sizeof (NvDsPayload*) * 1);
          payloads[0] = self->msg2p_generate (self->pCtx, &event, 1);
          payloadCount = 1;
        }

At position event.metadata = eventMsg; mean Object image data had transfer to msg2p_generate and msg2p_generate_multiple function, it rigth ?

Yes.

1 Like

thank,
But json lib didn’t support gpointer data type, so can i convert gpointer to what data format can use for to set to json member

Can your server access the pointer? The pointer in one system means nothing to another system, why do you want to transfer pointer to the server?

my server want receive base64 fomat

but Json member didn’t support base64. So
can you suggest me the format at my server to can decode to image

Json library support int64. https://developer.gnome.org/json-glib/stable/json-glib-JSON-Object.html#json-object-set-int-member

Will you use it to transfer image data or the pointer of a memory?

1 Like

Hi,
meta->extMsg has data format is gpointer, so what i need to do to add it to JSON payload?
My idea is convert gpointer to base64 and add to object json. at the consumer will convert base64 to image data type

at file gstnvmsgconv.c, can i get object metadata and frame metadata ? @Fiona.Chen

Yes, you can get frame meta and object meta if the nvmsgconv is after nvinfer in the pipeline.

1 Like

gstnvmsgconv.c:(.text+0x1894): undefined reference to `gst_buffer_get_nvds_batch_meta’

this problem show when i use gst_buffer_get_nvds_batch_meta to get metadat, help me @Fiona.Chen

You need to include the header file “gstnvdsmeta.h”. The Makefile also needs change to link to the library. Please refer to dsexample source codes and makefile.

hi, in file gstnvdsmeta.h had include in gstnvmsgconv.c

This link failure. Please check your makefile