(for an intro to GStreamer, see my previous article)

You know, one thing that gets people confused in GStreamer is the idea of Dynamic Pads. Some elements, most notably the decodebin and gnlcomposition only have certain pads at certain times. This is because they figure out what kind of content they are processing, and apply the relevant pads where needed. This is often told to new users, but then they wonder how exactly these dynamic pads are handled.

Here is how it works, using decodebin as an example:

  • When the pipeline is run, the decodebin generates a signal that says a new pad has been added. In the case of decodebin this is the new-decoded-pad signal, in the case of gnlcomposition this is a pad-added signal.
  • You hook this signal up to your own callback, such as OnDecodedPad().
  • The signal passes your callback the pad that was added and some other stuff. You then link this pad to the next element along in the pipeline. So if your pipeline is filesrc ! decodebin ! audioconvert ! alsasink, the pad passed to your OnDecodeBin() method would be linked to the audioconvert.

To outline this, I have written a sample script to show how it works:


import pygst
import gst
import pygtk
import gtk

class Main:
    def __init__(self):
        self.pipeline = gst.Pipeline("mypipeline")

        self.filesrc = gst.element_factory_make("filesrc", "source")
        self.filesrc.set_property("location", "/home/jono/Desktop/jonobacon-voicesoffreedom.ogg")

        self.decode = gst.element_factory_make("decodebin", "decode")
        self.decode.connect("new-decoded-pad", self.OnDynamicPad)


        self.convert = gst.element_factory_make("audioconvert", "convert")

        self.sink = gst.element_factory_make("alsasink", "sink")



    def OnDynamicPad(self, dbin, pad, islast):
        print "OnDynamicPad Called!"


You can grab the script from here. Hope this helps some of you. 🙂

Pin It on Pinterest

Share This