From: Einar Jørgen Haraldseid Date: Wed, 18 Jun 2014 13:53:11 +0000 (+0200) Subject: First commit, progress so far X-Git-Url: https://git.slaskete.net/python-gstreamer-examples/commitdiff_plain/2da3df6c3227bf894baa8410917f6150a280025f First commit, progress so far --- 2da3df6c3227bf894baa8410917f6150a280025f diff --git a/README.md b/README.md new file mode 100644 index 0000000..0cd5581 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +Python/GStreamer examples +========================= +This is my first foray into Gstreamer programming with Python, I'm working from this tutorial: + +http://www.jonobacon.org/2006/08/28/getting-started-with-gstreamer-with-python/ + +I know little to no Python before starting on this, and the tutorial is nearly eight years old, so this ought to be interesting … diff --git a/example1.py b/example1.py new file mode 100755 index 0000000..d69135a --- /dev/null +++ b/example1.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python +# This is a reworked version of the example from Jono Bacon's Python+Gstreamer +# primer: http://www.jonobacon.org/2006/08/28/getting-started-with-gstreamer-with-python/ +# +# It uses Gstreamer 1.0, and replaces alsa with pulse for audio output, and +# drops the use of the GTK main loop, since we're not bothered with a GUI +# Info on porting python scripts to Gstreamer 1.0 can be found here: +# https://wiki.ubuntu.com/Novacut/GStreamer1.0 + + +import gi +gi.require_version('Gst', '1.0') +from gi.repository import Gst +import gobject + +class Main: + def __init__(self): + # Initiate the pipeline + Gst.init(None) + self.pipeline = Gst.Pipeline("mypipeline") + + # Add an audiotestsrc element to the pipeline + self.audiotestsrc = Gst.ElementFactory.make("audiotestsrc", "audio") + self.pipeline.add(self.audiotestsrc) + + # Add a pulsesink element to the pipeline + self.pulsesink = Gst.ElementFactory.make("pulsesink", "sink") + self.pipeline.add(self.pulsesink) + + # Link the two elements together + self.audiotestsrc.link(self.pulsesink) + + # Set the pipeline to the playing state + self.pipeline.set_state(Gst.State.PLAYING) + +# Create the pipelie and enter main loop, quit with ctrl+c +start = Main() +mainloop = gobject.MainLoop() +mainloop.run() diff --git a/example2.glade b/example2.glade new file mode 100644 index 0000000..dec56c2 --- /dev/null +++ b/example2.glade @@ -0,0 +1,71 @@ + + + + + + False + Gstreamer-test + audio-volume-high + + + True + False + 20 + 20 + 20 + 10 + 10 + True + center + + + gtk-media-play + True + True + True + True + True + + + + False + True + 0 + + + + + gtk-stop + True + True + True + True + True + + + + False + True + 1 + + + + + gtk-quit + True + True + True + True + True + + + + False + True + 2 + + + + + + diff --git a/example2.py b/example2.py new file mode 100755 index 0000000..21d4dbb --- /dev/null +++ b/example2.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python +# This is a reworked version of the example from Jono Bacon's Python+Gstreamer primer: +# http://www.jonobacon.org/2006/08/28/getting-started-with-gstreamer-with-python/ +# +# It uses Gstreamer 1.0, GTK3, and replaces alsa with pulse for audio output +# Info on porting python scripts to GStreamer 1.0 can be found here: +# https://wiki.ubuntu.com/Novacut/GStreamer1.0 + +from gi.repository import Gtk, Gst +import signal + +class Main: + def __init__(self): + + # Create gui bits and bobs + + self.wTree = Gtk.Builder() + self.wTree.add_from_file("example2.glade") + + signals = { + "on_play_clicked" : self.OnPlay, + "on_stop_clicked" : self.OnStop, + "on_quit_clicked" : self.OnQuit, + } + + self.wTree.connect_signals(signals) + + # Create GStreamer bits and bobs + + # Initiate the pipeline + Gst.init(None) + self.pipeline = Gst.Pipeline("mypipeline") + + # Add an audiotestsrc element to the pipeline + self.audiotestsrc = Gst.ElementFactory.make("audiotestsrc", "audio") + self.audiotestsrc.set_property("freq", 200) + self.pipeline.add(self.audiotestsrc) + + # Add a pulsesink element to the pipeline + self.pulsesink = Gst.ElementFactory.make("pulsesink", "sink") + self.pipeline.add(self.pulsesink) + + # Link the two elements together + self.audiotestsrc.link(self.pulsesink) + + # Summon the window and connect the window's close button to Quit + self.window = self.wTree.get_object("mainwindow") + self.window.connect("delete-event", Gtk.main_quit) + self.window.show_all() + + + def OnPlay(self, widget): + print "play" + self.pipeline.set_state(Gst.State.PLAYING) + + def OnStop(self, widget): + print "stop" + self.pipeline.set_state(Gst.State.READY) + + def OnQuit(self, widget): + print "quit" + Gtk.main_quit() + + # Workaround to get Ctrl+C to terminate from command line + # ref: https://bugzilla.gnome.org/show_bug.cgi?id=622084#c12 + signal.signal(signal.SIGINT, signal.SIG_DFL) + +start = Main() +Gtk.main()