How to shuttle GstMeta information between Python and C?
I have been having great difficulty grasping the concept of GstMeta and using it from Python. A minimal-not-working-example can be found here.
I created a basic pipeline ([videotestsrc] - [capsfilter] - [xvimagesink[) with a buffer probe on the capsfilter src pad. My goal is to add GstVideoCropMeta to each passing buffer (in python). Xvimagesink already implements a get_meta for this metadata type so that should be easy to debug.
Unfortunately, I am unable to figure out how to actually store x, y, width and height in the GstVideoCropMeta instance and making xvimagesink to pick-up these values.
Implying that, after doing the gst_buffer_add_video_crop_meta, I should store the x, y, width and height directly on its return value (a Gst.Meta). But that's doesn't really make sense right?
Setting GST_DEBUG=xvimagesink*:8, I can see that xvimagesink is picking up the metadata, but x, y, width and height are still 0 (or worse, are sometimes random numbers from uninitialized memory locations making things crash and burn).
I have been reading the docs a dozen times but I am still a bit lost.
Re: How to shuttle GstMeta information between Python and C?
This post was updated on .
It turns out this is actually quite an old bug which was mentioned in this message on the Gstreamer list in November 2014. In short, we cannot assign values to a GstMeta object in python and recover them in C. The reverse, however, is possible using some tweaks.
I came up with the following work-around.
First of all, use the latest gobject introspection bindings when compiling GStreamer from source. For this, you need to install:
to check the location of the typelib files in use by pygi.
Based on bug #702921 I was able to add a couple of publicly accessible methods (gst_buffer_get_video_meta and gst_buffer_set_video_meta) to gstvideometa.c and gstvideometa.h (gst-plugins-base) which allow me to explicitly set and get the contents of a GstVideoCropMeta metadata instance in the C environment.
In python you can then use:
from gi.repository import Gst, GstVideo
# Add metadata to GstBuffer
gstMeta = buffer.add_meta(GstVideo.VideoCropMeta.get_info(), 0)
# Set metadata values to GstMeta
GstVideo.buffer_set_video_crop_meta(gstMeta, 10, 20, 100, 200)
# To verify whether we really wrote the metadata, we retrieve a fresh reference to the metadata on the GstBuffer
gstVideoVideoCropMeta = GstVideo.buffer_get_video_crop_meta(buffer)
# Should print 10
Note, as Stian Stelnes already mentioned in the bugreport above, the publicly accessible methods must be functions, not macros!