9 May

I wanted to share this example I found on another blog. It's my first working Python code using the gstreamer framework. It loads an mpeg movie file and an MP3 into the pipeline at the same time, in effect compositing them together.

I will spending the next many days fine tuning my Python skills and learning more about the Eclipse IDE, but this example gives me some confidence that this project might actually work!

Video & Audio Example Python Code:

#!/usr/bin/python
import pygst
pygst.require("0.10")
import gst
import gtk

class Main:
def __init__(self):

#GUI
self.window = gtk.Window()
self.window.connect("unmap", self.OnQuit)
self.vbox = gtk.VBox()
self.da = gtk.DrawingArea()
self.bb = gtk.HButtonBox()
self.da.set_size_request(300, 150)
self.playButton = gtk.Button(stock='gtk-media-play')
self.playButton.connect("clicked", self.OnPlay)
self.stopButton = gtk.Button(stock='gtk-media-stop')
self.stopButton.connect("clicked", self.OnStop)
self.quitButton = gtk.Button(stock='gtk-quit')
self.quitButton.connect("clicked", self.OnQuit)
self.vbox.pack_start(self.da, expand=True)
self.bb.add(self.playButton)
self.bb.add(self.stopButton)
self.bb.add(self.quitButton)
self.vbox.pack_start(self.bb, expand=False)
self.window.add(self.vbox)

# Create GStreamer bits and bobs
self.pipeline = gst.Pipeline("mypipeline")
pbin = gst.element_factory_make("playbin", "pbin")
pbin.set_property("uri", "file:///home/jonathan/Cow.mpg")
self.pipeline.add(pbin)
vsink = gst.element_factory_make("xvimagesink", "vsink")
self.vsink = vsink
pbin.set_property("video-sink", vsink)
vsink.set_property("force-aspect-ratio", True)

pbin1 = gst.element_factory_make("playbin", "pbin1")
pbin1.set_property("uri", "file:///home/jonathan/Fly.mp3")
self.pipeline.add(pbin1)
pbin1.set_property("video-sink", vsink)

self.window.show_all()

def OnPlay(self, widget):
self.vsink.set_xwindow_id(self.da.window.xid)
self.pipeline.set_state(gst.STATE_PLAYING)

def OnStop(self, widget):
self.pipeline.set_state(gst.STATE_READY)

def OnQuit(self, widget):
self.pipeline.set_state(gst.STATE_READY)
gtk.main_quit()

start=Main()
gtk.main()