Custom plugin in python3 by subclassing GstBase.BaseTransform

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Custom plugin in python3 by subclassing GstBase.BaseTransform

Jimmy De Pauw
Hello everyone,

I am currently in the process of making a custom plugin that would alter frames from a video file or a stream.
As i could gather the best base for this is to subclass BaseTransform.

The base code for this is :

*****
class TfObjectDetection(GstBase.BaseTransform):
    __gsttemplates__ = (
        Gst.PadTemplate.new(
            "src",
            Gst.PadDirection.SRC,
            Gst.PadPresence.ALWAYS,
            Gst.Caps.from_string("video/x-raw,format=(string)RGB")),

        Gst.PadTemplate.new(
            "sink",
            Gst.PadDirection.SINK,
            Gst.PadPresence.ALWAYS,
            Gst.Caps.from_string("video/x-raw,format=(string)RGB"))
    )

    def __init__(self):
        GstBase.BaseTransform.__init__(self)

        self.set_passthrough(False)
        self.set_in_place(False)

    def do_transform(self, inbuf, outbuf):
        print("Tensorflow plugin    :   processing frame at timestamp(buffer):%s" % (Gst.TIME_ARGS(inbuf.pts)))
        print("                         buffer size is :%s" % (inbuf.get_size()))

        * do stuff *

        outbuf.fill(0, data)

        return Gst.FlowReturn.OK
*****

Nothing fancy but whatever i try : (<unknown>:63739): GStreamer-CRITICAL **: gst_buffer_fill: assertion 'gst_buffer_is_writable (buffer)' failed
Trying in-place result in the same error so i really don’t know what i should do.
I also tried to subclass Element but i cannot fathom how caps negotiations works and it always fail with a « non negotiated » error.
I listened to queries and put a method like this :
def _src_query(self, pad, parent, query):
if query.type == Gst.QueryType.CAPS:
print("Got query '" + Gst.QueryType.get_name(query.type) + "' on pad '" + pad.get_name() + "'")
query.set_caps_result(Gst.Caps.from_string("video/x-raw,format=(string)RGB,width=4096,height=2160,framerate=0/1"))
return True
else:
return pad.query_default(parent, query)
but i have no idea what i should do in there so the next element accept my source pad.

Checking the C code for BaseTransform is way too complicated, after all my plugin used fixed caps since it only support RGB frame on its sink.

Version for gstreamer is 1.12.3 and it is installed on OSX using brew.
Python is 3.6

I’ve been stuck on this for a week now and i don’t really know what to do.
I could abandon Python and write everything in C but that would require all my frame processing code to be rewritten in C as well which i would rather avoid.

I would be very grateful for any insight.
Thanks


_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Custom plugin in python3 by subclassing GstBase.BaseTransform

filnet
You might want to subclass GstVideoFilter.


And, in any case, the gstvideofilter.c has code to make buffers writable.


Le Jeudi 7 décembre 2017 14h07, Jimmy De Pauw <[hidden email]> a écrit :


Hello everyone,

I am currently in the process of making a custom plugin that would alter frames from a video file or a stream.
As i could gather the best base for this is to subclass BaseTransform.

The base code for this is :

*****
class TfObjectDetection(GstBase.BaseTransform):
    __gsttemplates__ = (
        Gst.PadTemplate.new(
            "src",
            Gst.PadDirection.SRC,
            Gst.PadPresence.ALWAYS,
            Gst.Caps.from_string("video/x-raw,format=(string)RGB")),

        Gst.PadTemplate.new(
            "sink",
            Gst.PadDirection.SINK,
            Gst.PadPresence.ALWAYS,
            Gst.Caps.from_string("video/x-raw,format=(string)RGB"))
    )

    def __init__(self):
        GstBase.BaseTransform.__init__(self)

        self.set_passthrough(False)
        self.set_in_place(False)

    def do_transform(self, inbuf, outbuf):
        print("Tensorflow plugin    :   processing frame at timestamp(buffer):%s" % (Gst.TIME_ARGS(inbuf.pts)))
        print("                         buffer size is :%s" % (inbuf.get_size()))

        * do stuff *

        outbuf.fill(0, data)

        return Gst.FlowReturn.OK
*****

Nothing fancy but whatever i try : (<unknown>:63739): GStreamer-CRITICAL **: gst_buffer_fill: assertion 'gst_buffer_is_writable (buffer)' failed
Trying in-place result in the same error so i really don’t know what i should do.
I also tried to subclass Element but i cannot fathom how caps negotiations works and it always fail with a « non negotiated » error.
I listened to queries and put a method like this :
def _src_query(self, pad, parent, query):
if query.type == Gst.QueryType.CAPS:
print("Got query '" + Gst.QueryType.get_name(query.type) + "' on pad '" + pad.get_name() + "'")
query.set_caps_result(Gst.Caps.from_string("video/x-raw,format=(string)RGB,width=4096,height=2160,framerate=0/1"))
return True
else:
return pad.query_default(parent, query)
but i have no idea what i should do in there so the next element accept my source pad.

Checking the C code for BaseTransform is way too complicated, after all my plugin used fixed caps since it only support RGB frame on its sink.

Version for gstreamer is 1.12.3 and it is installed on OSX using brew.
Python is 3.6

I’ve been stuck on this for a week now and i don’t really know what to do.
I could abandon Python and write everything in C but that would require all my frame processing code to be rewritten in C as well which i would rather avoid.

I would be very grateful for any insight.
Thanks

_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel



_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel