Use gst_buffer_add_nvds_meta() function in python

Hi,

I was wondering how can I properly use the gst_buffer_add_nvds_meta with python. I saw this related post:

but i don’t think there is a solution yet. I’m creating a custom gstream plugin with python and i need to copy the NvDsBatchMeta from the input buffer to the output buffer.

Here is how i’m currently trying to copy the NvDsBatchMeta to the output buffer:

pyds.gst_buffer_add_nvds_meta(outbuf,
                                          pyds.gst_buffer_get_nvds_batch_meta(hash(inbuf)), 
                                          None, 
                                          pyds.nvds_batch_meta_copy_func, 
                                          pyds.nvds_batch_meta_release_func)

But i get this error:

TypeError: gst_buffer_add_nvds_meta(): incompatible function arguments. The following argument types are supported:
    1. (buffer: _GstBuffer, meta_data: capsule, user_data: capsule, copy_func: void* (void*, void*), release_func: void (void*, void*)) -> _NvDsMeta

Invoked with: <Gst.Buffer object at 0x739b93d35760 (GstBuffer at 0x739b0802b000)>, <pyds.NvDsBatchMeta object at 0x739b93d3dd70>, None, c_void_p(1414320), c_void_p(1414325)

So my question is how can I properly invoke the gst_buffer_add_nvds_meta with python or if there is any alternative approach on how can i copy the NvDsMeta from the input buffer to the output buffer.

Hi,

You should use the GstMetaInfo transform function instead. Here is how it is done in C:

        if (gst_meta_api_type_has_tag (gst_meta->info->api, nvdsmeta_quark)) {
          GstMetaTransformCopy copy_data = { FALSE, 0, -1 };
          const GstMetaInfo *info = gst_meta->info;
          info->transform_func (destiny_buffer, gst_meta, origin_buffer,
              _gst_meta_transform_copy, &copy_data);
        }

I haven’t tested it in Python, but there should be an equivalent function call.

You can also refer to our FAQ to customize your own metadata.

I don’t need to create my own custom metadata, i need to know how to add metadata into a Gst.Buffer with the gst_buffer_add_nvds_meta() in python

Hi,
Thanks for the reply! I’m trying to override the do_transform function from the GstBase.BaseTransform class to create a custom plugin. where would your code fit in the do_transform function and where would i get the gst_meta and nvdsmeta-quark parameters? Also i could not find the GstMetaTransformCopy in python nor tre transform_func

On Python you can implement something like this to just copy the metadata from inbuf

    def do_transform(self, inbuf, outbuf):
        # Get the size of the input buffer
        size = inbuf.get_size()
        # Copy all metadata from the input buffer to the output buffer
        inbuf.copy_into(outbuf, Gst.BufferCopyFlags.META, 0, size)
        return Gst.FlowReturn.OK

This only copies the metadata, assuming that the outbuf has been properly allocated beforehand.

If that option doesn’t suit you and you prefer just the DeepStream meta, you can use the following equivalent functions instead:

Iterate meta → Gst.Buffer.foreach_meta()
gst_meta->info;Gst.Meta.get_info()
gst_meta_api_type_has_tag ()Gst.MetaInfo.type
info->transform_func ()Gst.MetaInfo.transform_func

The PyGObject API reference can help you get the correct parameters.

okay, once the metadata is copied how would you recommend to fill the output buffer?

Currently i’m using the Gst.Buffer.fill function. But i don’t know which offset should i use to start filling it.

inbuf.copy_into(outbuf, Gst.BufferCopyFlags.META, 0, inbuf.get_size())
outbuf.fill(0, img.tobytes())

Because the issue is that i need to get the image from the input buffer, change the image dimensions and add channels to it (basically reduce the width and height of the image and add an extra channel), and then fill the output buffer with the new image. But the issue is that i need to copy the metadata to the output buffer so that the rest of the elements of the pipeline can access the metadata. Otherwise the next element after the custom plugin will complain that the metadata is not present:

[gst-stream-error-quark: GstNvTiler: FATAL ERROR; NvDsMeta->NvDsBatchMeta missing in the input buffer (1)]

You can also refer to our demo code CUSTOMUSERMETAGUIDE.md and deepstream_custom_binding_test.py.

There is no update from you for a period, assuming this is not an issue anymore. Hence we are closing this topic. If need further support, please open a new one. Thanks

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.