d69135a8f06d0ab39c45eacf288b7e18444a3b03
[python-gstreamer-examples] / example1.py
1 #!/usr/bin/env python
2 # This is a reworked version of the example from Jono Bacon's Python+Gstreamer
3 # primer: http://www.jonobacon.org/2006/08/28/getting-started-with-gstreamer-with-python/
4 #
5 # It uses Gstreamer 1.0, and replaces alsa with pulse for audio output, and
6 # drops the use of the GTK main loop, since we're not bothered with a GUI
7 # Info on porting python scripts to Gstreamer 1.0 can be found here:
8 # https://wiki.ubuntu.com/Novacut/GStreamer1.0
9
10
11 import gi
12 gi.require_version('Gst', '1.0')
13 from gi.repository import Gst
14 import gobject
15
16 class Main:
17 def __init__(self):
18 # Initiate the pipeline
19 Gst.init(None)
20 self.pipeline = Gst.Pipeline("mypipeline")
21
22 # Add an audiotestsrc element to the pipeline
23 self.audiotestsrc = Gst.ElementFactory.make("audiotestsrc", "audio")
24 self.pipeline.add(self.audiotestsrc)
25
26 # Add a pulsesink element to the pipeline
27 self.pulsesink = Gst.ElementFactory.make("pulsesink", "sink")
28 self.pipeline.add(self.pulsesink)
29
30 # Link the two elements together
31 self.audiotestsrc.link(self.pulsesink)
32
33 # Set the pipeline to the playing state
34 self.pipeline.set_state(Gst.State.PLAYING)
35
36 # Create the pipelie and enter main loop, quit with ctrl+c
37 start = Main()
38 mainloop = gobject.MainLoop()
39 mainloop.run()