I am currently implementing custom Deepstream plugin for video analytics. This plugin will come after “nvstreammux” element in pipeline. The logic of the plugin is as follow:
Map input buffer (GstBuffer) to NvBufSurface.
Obtain NvDsBatchMeta of input buffer.
Create new NvBufSurface and new NvDsBatchMeta, both empty.
Fill new NvBufSurface and NvDsBatchMeta, from point 3, with modified data based on original input buffer objects, from point 1 and 2.
Convert filled NvBufSurface, from point 4, to GstBuffer.
Convert filled NvDsBatchMeta, from point 4, to GstMeta.
Attach metadata, from point 6, to buffer, from point 5.
Discard original buffer along with its metadata, from point 1 and 2.
Push modified buffer, from point 7, to srcpad.
In short I want to create brand new buffer based on NvBufSurface along with brand new metadata based on NvDsBatchMeta and push it downstream, while discarding original buffer.
The thing is I cannot find appropriate way to “convert” NvDsBatchMeta to GstBuffer and NvDsBatchMeta to GstMeta, so that the next element in pipeline “nvinfer” will handle them.
I would appreciate any help in this subject. I just hope I am not missing some crucial point.
The plugin I mentioned have to basically clone and process frames incoming from “nvstreammux” element. On the output buffer I would like to have not only the original frames I got but also their copies, three for each, with some filter applied. Therefore there are 3 times more frames on the output than on the input. Processing is done purely by OpenCV cuda contrib modules.
Currently I am stuck at the very end where new NvBufSurface was created and filled, along with NvDsBatchMeta, via filling individual NvDsFrameMeta’s. NvBufSurface is copied to new, mapped data of GstBuffer. NvDsBatchMeta is added to output buffer via gst_buffer_add_nvds_meta. Still, the response from the “nvinfer” element, which is next, is:
nvinfer batch-size should be greater or equal than source numbers or streammux numbers, or it will encounter error, how about your nvinfer batch-size, since you clone 3 more frames from streammux, nvinfer batch-size should change accordingly.
batch-size property of “nvinfer” element, controlled via config.txt file, is set correctly, that’s sure. For batch-size property of “nvstreammux” element equal to 2, I am setting 6 for batch-size of “nvinfer”.
I imagine the problem lies in one of those places:
NvBufSurface for individual frames
NvFrameMeta for individual frames
NvDsBatchMeta parameters
The way I am converting NvBufSurface to GstBuffer and the way I am adding NvDsBatchMeta to this buffer.
As a sanity check I have created additional dummy element, which I have placed after my plugin element in the pipeline. There, I have read the buffer and the contents looks exactly the same as in my plugin, therefore I suspect that the problem is not in the last point.
I imagine that the only place where the example how new Nv* structures are created and pushed is precisely “nvstreammux” element, for which source code isn’t public, is it?