GStreamer1.0

Revision 27 as of 2012-06-21 07:03:36

Clear message

Novacut Wiki Home > GStreamer 1.0

GStreamer 1.0 packages are now available in Ubuntu Quantal. For Ubuntu Precise (12.04 LTS) users, there are back-ported packages available in the GStreamer developers PPA.

Note that GnonLin and GES packages are not yet available for GStreamer 1.0.

Although GStreamer 1.0 is not backward compatible with the GStreamer 0.10 series, it is parallel-installable. So you can safely install GStreamer 1.0 without effect on the many applications using GStreamer 0.10.

Adding PPA for Ubuntu Precise

To use the back-ported packages for Ubuntu 12.04 LTS, add the GStreamer developers PPA like this:

  • sudo apt-add-repository ppa:gstreamer-developers/ppa
    sudo apt-get update

Installing GStreamer 1.0 packages

This should give you all the packages you likely want:

  • sudo apt-get install gstreamer1.0-tools \
        gir1.2-gstreamer-1.0 \
        gir1.2-gst-plugins-base-1.0 \
        gstreamer1.0-plugins-good \
        gstreamer1.0-plugins-ugly \
        gstreamer1.0-plugins-bad \
        gstreamer1.0-libav

Using GStreamer 1.0 from Python

You can use GStreamer 1.0 from Python (2 or 3) using PyGI like this:

  • >>> import gi
    >>> gi.require_version('Gst', '1.0')
    >>> from gi.repository import Gst
    >>> Gst.version()
    (1, 0, 0, 0)

Although currently the default will be Gst 1.0 if available, it's still a good idea to gi.require_version('Gst', '1.0') so that the code will clearly fail if Gst 1.0 isn't available.

The biggest change for Python users will be using the introspected API rather than the static python-gst bindings. However, there are also API changes in the GStreamer itself, although these changes are generally more subtle.

Python Porting Guide

debian/control

You'll have to update your debian/control, of course. So replace:

  • Depends: python-gst0.10

With:

  • Depends: python-gi, gir1.2-gstreamer-1.0, gir1.2-gst-plugins-base-1.0

Imports

Replace:

  • import gobject
    import gst

With:

  • import gi
    gi.require_version('Gst', '1.0')
    from gi.repository import GObject, Gst

After that a bit of search and replace (used with care) can help. Basically:

  • gobject.* => GObject.*
    gst.* => Gst.*

Gst.init()

You should call GObject.threads_init() in your module-scope, right after your imports. Unlike the static bindings, you also need to call Gst.init(). So replace:

  • gobject.threads_init()

With:

  • GObject.threads_init()
    Gst.init(None)

element_factory_make()

Replace:

  • src = gst.element_factory_make('filesrc')

With:

  • src = Gst.ElementFactory.make('filesrc', None)

There is no equivalent to gst.element_link_many(), so replace:

  • gst.element_link_many(one, two, three)

With:

  • one.link(two)
    two.link(three)

Pipeline.add(one, two)

Bin.add() can't be overloaded to add multiple elements at once. So replace:

  • pipeline = gst.Pipeline()
    pipeline.add(one, two)

With:

  • pipeline = Gst.Pipeline()
    pipeline.add(one)
    pipeline.add(two)

one.link(two, mycaps)

Replace:

  • one.link(two, mycaps)

With:

  • one.link_filtered(two, mycaps)

STATE_PLAYING

Replace:

  • pipeline.set_state(gst.STATE_PLAYING)

With:

  • pipeline.set_state(Gst.State.PLAYING)

And so on. Some search-and-replace is helpful here, basically:

  • gst.STATE_* => Gst.State.*

GhostPad

You've got to use GhostPad.new(). So replace:

  • ghost = gst.GhostPad('sink', mysinkpad)

With:

  • ghost = Gst.GhostPad.new('sink', mysinkpad)

Pad.get_caps()

In callbacks for "pad-added" events and similar, it's common to use the string representation of the pad caps as a way to decide whether to link a pad and what to link the pad to.

You need to use Pad.query_caps() instead of Pad.get_caps(), and the returned object is no longer array-like. So in general replace this pattern:

  • def on_pad_added(element, pad):
        string = pad.get_caps()[0].get_name()
        if string.startswith('audio/'):
            <link to some audio elements>

With this:

  • def on_pad_added(element, pad):
        string = pad.query_caps(None).to_string()
        if string.startswith('audio/'):
            <link to some audio elements>

Element.get_pad()

Element.get_pad() has been renamed Element.get_static_pad(). So replace something like this:

  • src = gst.element_factory_make('filesink')
    pad = src.get_pad('sink')

With this:

  • src = Gst.ElementFactory.make('filesink', None)
    pad = src.get_static_pad('sink')

Pad.get_negotiated_caps()

Pad.get_negotiated_caps() has been renamed Pad.get_current_caps(), so replace:

  • caps = pad.get_negotiated_caps()

With:

  • caps = pad.get_current_caps()

caps[0]

Caps objects are not array-like from PyGI, so replace:

  • cap = caps[0]

With:

  • cap = caps.get_structure(0)

caps[0]['foo']

Individual capability structures are not dictionary-like objects from PyGI, so you need to use type-appropriate accessor methods instead. For example, replace this:

  • framerate = caps[0]['framerate']
    width = caps[0]['width']
    height = caps[0]['height']

With:

  • (success, num, denom) = caps.get_structure(0).get_fraction('framerate')
    (success, width) = caps.get_structure(0).get_int('width')
    (success, height) = caps.get_structure(0).get_int('height')

query_new_duration(), FORMAT_TIME

Replace:

  • query = gst.query_new_duration(Gst.FORMAT_TIME)

With:

  • query = Gst.Query.new_duration(Gst.Format.TIME)

audio/x-raw, video/x-raw

"audio/x-raw-int" and "audio/x-raw-float" have been condensed into a unified "audio/x-raw" with a flexible format description.

Likewise, "video/x-raw-yuv" and "video/x-raw-rgb" have been condensed into a unified "video/x-raw" with a flexible format description.

This is much nicer because in GStreamer 0.10 certain element details were leaked that really shouldn't have been. For example, if you wanted filter caps to force a certain sample-rate, you previously needed to know whether, say, an audio encoder took audio/x-raw-int or audio/x-raw-float.

So now you can replace say:

  • caps = gst.caps_from_string('audio/x-raw-float, rate=(int)44100')

With:

  • caps = gst.caps_from_string('audio/x-raw, rate=(int)44100')

As you're only interested in specifying the rate anyway, it's much nicer to be truly abstracted from the format details.

decodebin2

The "decodebin2" element has been renamed to "decodebin", and the old "decodebin" element has been removed.