2 # This is a reworked version gstreamer example 1 from Jono Bacon's Python and
4 # http://www.jonobacon.org/2006/08/28/getting-started-with-gstreamer-with-python
6 # It uses Gstreamer 1.0, and replaces alsa with pulse for audio output, and
7 # drops the use of the GTK main loop, since we're not bothered with a GUI
8 # Info on porting python scripts to Gstreamer 1.0 can be found here:
9 # https://wiki.ubuntu.com/Novacut/GStreamer1.0
11 import gi
, time
, signal
12 gi
.require_version('Gst', '1.0')
13 from gi
.repository
import Gst
17 # Initiate the pipeline
19 self
.pipeline
= Gst
.Pipeline()
21 # Add an audiotestsrc element to the pipeline
22 self
.audiotestsrc
= Gst
.ElementFactory
.make("audiotestsrc", "audio")
23 self
.pipeline
.add(self
.audiotestsrc
)
25 # Add a pulsesink element to the pipeline
26 self
.pulsesink
= Gst
.ElementFactory
.make("pulsesink", "sink")
27 self
.pipeline
.add(self
.pulsesink
)
29 # Link the two elements together
30 self
.audiotestsrc
.link(self
.pulsesink
)
32 # Set the pipeline to the playing state
33 self
.pipeline
.set_state(Gst
.State
.PLAYING
)
35 # We want a graceful shutdown on CTRL+C
36 def quit(self
, *args
):
41 signal
.signal(signal
.SIGINT
, quit
)
43 # Create the pipeline and enter main loop, quit with ctrl+c