Hi,
I want to get capabilities set on my sink pad in a pipe ! Let suppose my pipe is as follows gst-launch-1.0 -e filesrc location=rawvideo_yuv420.yuv blocksize=460800 ! video/x-raw,format=I420,width=640,height=480,framerate=30/1 ! myh264encoder silent=true ! decodebin ! autovideosink My gstreamer plugin is myh264encoder. Now how can I get width as 640 and height as 480 and framerate as 30 from the caps "video/x-raw,format=I420,width=640,height=480,framerate=30/1" inside my gstreamer plugin's init function ? I tried the following but it didn't worked 1) This give me width=[ 16, 2147483647 ] GstPad *pad = gst_pad_new_from_static_template (&sink_factory,"sink"); GstCaps *caps = gst_pad_get_pad_template_caps (pad); GstStructure *structure = gst_caps_get_structure (caps, 0); gchar *str = gst_value_serialize (gst_structure_get_value(structure,"width")); g_print("width = %s\n",str); g_free(str); 2) This give me width=(null) GstPad *pad = gst_pad_new_from_static_template (&sink_factory,"sink"); GstCaps *caps = gst_pad_get_current_caps (pad); GstStructure *structure = gst_caps_get_structure (caps, 0); gchar *str = gst_value_serialize (gst_structure_get_value(structure,"width")); g_print("width = %s\n",str); g_free(str); 3) I used gst_pad_set_event_function technique, but am not sure that am implementing it correctly - Under init function of my plugin I do as below filter->sinkpad = gst_pad_new_from_static_template (&sink_factory, "sink"); gst_pad_set_event_function (filter->sinkpad,GST_DEBUG_FUNCPTR(gst_myencoder_sink_event)); gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad); - Implementing the sink event function as below static gboolean gst_myencoder_sink_event (GstPad * pad, GstObject * parent, GstEvent * event) { gboolean ret; GstMyEncoder *filter = GST_MYENCODER (parent); switch (GST_EVENT_TYPE (event)) { case GST_EVENT_CAPS: { GstCaps * caps; gst_event_parse_caps (event, &caps); /* do something with the caps */ GstStructure *structure = gst_caps_get_structure (caps, 0); gchar *str = gst_value_serialize (gst_structure_get_value(structure,"width")); g_print("width = %s\n",str); g_free(str); /* and forward */ ret = gst_pad_event_default (pad, parent, event); break; } default: ret = gst_pad_event_default (pad, parent, event); break; } return ret; } Please let me know, as my requirement is to parse the caps and initialize the encoder resply to the caps.
Regards,
Sunny.
|
On Thu, 2016-01-28 at 01:52 -0800, ssshukla26 wrote:
Hi, > I want to get capabilities set on my sink pad in a pipe ! > > Let suppose my pipe is as follows > > gst-launch-1.0 -e filesrc location=rawvideo_yuv420.yuv > blocksize=460800 ! > *video/x-raw,format=I420,width=640,height=480,framerate=30/1* ! > myh264encoder silent=true ! decodebin ! autovideosink > > My gstreamer plugin is *myh264encoder*. > > Now how can I get width as 640 and height as 480 and framerate as 30 > from > the caps "*video/x- > raw,format=I420,width=640,height=480,framerate=30/1*" > inside my gstreamer plugin's init function ? You can't get this information in your plugin's init function, because when you are in your init function, the data flow hasn't started yet, so the caps are not known yet. Your element will receive a CAPS event on its sink pad when the caps are known. If you use the GstVideoEncoder base class (as you should) you can override the ::set_format() vfunc to get the input caps. > 3) I used *gst_pad_set_event_function* technique, but am not sure > that am > implementing it correctly > > - /*Under init function of my plugin I do as below*/ > > filter->sinkpad = gst_pad_new_from_static_template (&sink_factory, > "sink"); > gst_pad_set_event_function > (filter->sinkpad,GST_DEBUG_FUNCPTR(g*st_myencoder_sink_event*)); > gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad); > > - /*Implementing the sink event function as below*/ > > static gboolean *gst_myencoder_sink_event* (GstPad * pad, GstObject * > parent, GstEvent * event) > { > gboolean ret; > GstMyEncoder *filter = GST_MYENCODER (parent); > > switch (GST_EVENT_TYPE (event)) { > case GST_EVENT_CAPS: > { > GstCaps * caps; > > gst_event_parse_caps (event, &caps); > /* do something with the caps */ > GstStructure *structure = gst_caps_get_structure > (caps, 0); > gchar *str = gst_value_serialize > (gst_structure_get_value(structure,"width")); > g_print("width = %s\n",str); > g_free(str); > > /* and forward */ > ret = gst_pad_event_default (pad, parent, event); > break; > } > default: > ret = gst_pad_event_default (pad, parent, event); > break; > } > return ret; > } This looks fine, but I don't think you want to forward the caps event here, since your encoder will output different caps. Just use the GstVideoEncoder base class instead. Cheers -Tim -- Tim Müller, Centricular Ltd - http://www.centricular.com _______________________________________________ gstreamer-devel mailing list [hidden email] http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
As you suggested, I did the following inside my ::set_format function
static gboolean gst_myencoder_set_format (GstVideoEncoder *encoder, GstVideoCodecState *state) { g_print("%s....................\n",__func__); GstStructure *structure = gst_caps_get_structure (state->caps, 0); gchar *width = gst_value_serialize (gst_structure_get_value(structure,"width")); gchar *height = gst_value_serialize (gst_structure_get_value(structure,"height")); gchar *framerate = gst_value_serialize (gst_structure_get_value(structure,"framerate")); g_print("Width = %s, Height = %s, Framerate = %s\n",width,height,framerate); g_free(width); g_free(height); g_free(framerate); gst_video_encoder_set_output_state(encoder,gst_caps_new_empty_simple ("video/x-h264"),state); return TRUE; } And it worked. But after all what the use of it ? This function is called after ::open() and ::start() function of GstVideoEncoder base class. I want this "video/x-raw,format=I420,width=640,height=480,framerate=30/1" information before my encoder is initialized in open and start function. Else things won't work for me. Can you please suggest a way out ?
Regards,
Sunny.
|
On Thu, 2016-01-28 at 02:44 -0800, ssshukla26 wrote:
> And it worked. > > But after all what the use of it ? This function is called after > ::open() > and ::start() function of GstVideoEncoder base class. > > I want this "*video/x- > raw,format=I420,width=640,height=480,framerate=30/1*" > information before my encoder is initialized in *open* and *start* > function. > Else things won't work for me. Can you please suggest a way out ? You will just have to initialize your encoder in set_format() then :) Cheers -Tim -- Tim Müller, Centricular Ltd - http://www.centricular.com _______________________________________________ gstreamer-devel mailing list [hidden email] http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
how can i link caps with pipeline??
-- Sent from: http://gstreamer-devel.966125.n4.nabble.com/ _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel |
Free forum by Nabble | Edit this page |