Faster example using videomixer
[python-gstreamer-examples] / example1.py
1 #!/usr/bin/env python
2 # This is a reworked version gstreamer example 1 from Jono Bacon's Python and
3 # Gstreamer primer:
4 # http://www.jonobacon.org/2006/08/28/getting-started-with-gstreamer-with-python
5 #
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
10
11 import gi, time, signal
12 gi.require_version('Gst', '1.0')
13 from gi.repository import Gst
14
15 class Main:
16 def __init__(self):
17 # Initiate the pipeline
18 Gst.init(None)
19 self.pipeline = Gst.Pipeline()
20
21 # Add an audiotestsrc element to the pipeline
22 self.audiotestsrc = Gst.ElementFactory.make("audiotestsrc", "audio")
23 self.pipeline.add(self.audiotestsrc)
24
25 # Add a pulsesink element to the pipeline
26 self.pulsesink = Gst.ElementFactory.make("pulsesink", "sink")
27 self.pipeline.add(self.pulsesink)
28
29 # Link the two elements together
30 self.audiotestsrc.link(self.pulsesink)
31
32 # Set the pipeline to the playing state
33 self.pipeline.set_state(Gst.State.PLAYING)
34
35 # We want a graceful shutdown on CTRL+C
36 def quit(signal, frame):
37 print("stopping")
38 exit(0)
39
40 # Trap SIGINT
41 signal.signal(signal.SIGINT, quit)
42
43 # Create the pipeline and enter main loop, quit with ctrl+c
44
45 Main()
46 while True:
47 time.sleep(0.001)