/
basic-tutorial-2-ex-vertigo.py
executable file
·68 lines (54 loc) · 1.98 KB
/
basic-tutorial-2-ex-vertigo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python3
# http://docs.gstreamer.com/display/GstSDK/Basic+tutorial+2%3A+GStreamer+concepts
import sys
import gi
gi.require_version('Gst', '1.0')
from gi.repository import Gst, GLib, GObject
# initialize GStreamer
Gst.init(None)
# create the elements
source = Gst.ElementFactory.make("videotestsrc", "source")
filter_vertigo = Gst.ElementFactory.make("vertigotv", "vertigo-filter")
videoconvert = Gst.ElementFactory.make("videoconvert", "video-convert")
sink = Gst.ElementFactory.make("autovideosink", "sink")
# create the empty pipeline
pipeline = Gst.Pipeline.new("test-pipeline")
if not pipeline or not source or not filter_vertigo or not videoconvert or not sink:
print("ERROR: Not all elements could be created")
sys.exit(1)
# build the pipeline
pipeline.add(source, filter_vertigo, videoconvert, sink)
if not source.link(filter_vertigo):
print("ERROR: Could not link source to filter-vertigo")
sys.exit(1)
if not filter_vertigo.link(videoconvert):
print("ERROR: Could not link filter-vertigo to videoconvert")
sys.exit(1)
if not videoconvert.link(sink):
print("ERROR: Could not link videoconvert to sink")
sys.exit(1)
# modify the source's properties
source.set_property("pattern", 0)
# start playing
ret = pipeline.set_state(Gst.State.PLAYING)
if ret == Gst.StateChangeReturn.FAILURE:
print("ERROR: Unable to set the pipeline to the playing state")
# wait for EOS or error
bus = pipeline.get_bus()
msg = bus.timed_pop_filtered(
Gst.CLOCK_TIME_NONE,
Gst.MessageType.ERROR | Gst.MessageType.EOS
)
if msg:
t = msg.type
if t == Gst.MessageType.ERROR:
err, dbg = msg.parse_error()
print("ERROR:", msg.src.get_name(), ":", err.message)
if dbg:
print("debugging info:", dbg)
elif t == Gst.MessageType.EOS:
print("End-Of-Stream reached")
else:
# this should not happen. we only asked for ERROR and EOS
print("ERROR: Unexpected message received.")
pipeline.set_state(Gst.State.NULL)