(Original post from 30. Oct. 2011)
Right folks, so first things first. Let’s try and get something easy going. You know, nothing fancy. Just a simple output. No gui nothing. For that, as a starting point, I chose the tutorial from the following website:
In this tutorial (feel free to browse, it’s good), the author writes a very good introduction to what GStreamer is all about and explains the mechanics (Sinks, Pipelines etc.)… Unfortunately for me, for Linux. He gives a script that plays an audible tone, just to test if everything is working fine. Of course, taking it over to Windows is an issue.
Here is the code as quoted on JonoBacon’s website (many thanks for it):
#!/usr/bin/python import pygst pygst.require("0.10") import gst import pygtk import gtk class Main: def __init__(self): self.pipeline = gst.Pipeline("mypipeline") self.audiotestsrc = gst.element_factory_make("audiotestsrc", "audio") self.pipeline.add(self.audiotestsrc) self.sink = gst.element_factory_make("alsasink", "sink") self.pipeline.add(self.sink) self.audiotestsrc.link(self.sink) self.pipeline.set_state(gst.STATE_PLAYING) start=Main() gtk.main()
If you try the same code as stated on the website, you will receive a
in windows. After some browsing the web and learning about the combination of cygwin and the gst-inspect and gst-launch commands (google it, if you want to know more), I finally found the answer. First though, here are the website, I had that were useful to me in this instance:
The problem lies with using “alsasink”. ALSA is Linux’ way of playing sound. The equivalent of DirectSound for Windows if you want. Therefore, you need to find the right sink, to play audio on Windows. Alsasink won’t cut it, as it quite clearly is made for Linux. After trying several sinks via trial and error (osssink, esdsink, artsdsink, etc.) and no joy, I tried cygwin and gst-inspect to figure out which one I had, but this was also not successful. Finally, after a while, I came across a totally unrelated site, that mentions “autoaudiosink” as the auto-detect for your sound. Replacing “alsasink” with “autoaudiosink” and voilá, the sound was there when the script was run. Just careful and don’t turn the volume up too high. I did after a million and two failed tries and it almost blew me off my chair :D.
One last thing that I wanted to address was the pseudo-dependency on gtk. I say, pseudo, because the grand majority of examples were given with pygtk and thus most people have used gtk with it. Again a little bit of searching around, I found that the need for a gtk.main() call, was simply because GStreamer uses the Gobject module and its threads (see among others, this forum post: http://ubuntuforums.org/showthread.php?t=1168455 ). Once I found that, I was able to remove the gtk and pygtk import and replace it with the gobject import and the code still ran.
Thus, to some things up, the minimal example that works for Windows is as follows:
# replaces the call to gtk and pygtk
self.pipeline = gst.Pipeline("mypipeline")
self.audiotestsrc = gst.element_factory_make("audiotestsrc", "audio")
self.sink = gst.element_factory_make("autoaudiosink", "sink")
gobject.MainLoop().run() # instead of gtk.main()
Having this in hand, I will next look at playing a simple audio file and testing the scope, i.e. which common formats work and if I can play several at the same time. Since I was able to remove gtk and replace it with gobject, I can now use wxpython to serve as my GUI of choice.