8 gi.require_version('Gst', '1.0')
9 from gi.repository import Gst
12 from gi.repository import GObject
13 GObject.threads_init()
17 videotestsrc pattern=18 background-color=4294901760 ! intervideosink
21 #v4l2src ! video/x-raw,width=320,height=240 ! intervideosink
25 intervideosrc timeout=-1 ! videoconvert ! rotate name=rotate ! videoconvert ! autovideosink
31 self.loop = GObject.MainLoop()
32 self.pipeline_src = Gst.parse_launch(PIPELINE_SRC)
33 self.pipeline_sink = Gst.parse_launch(PIPELINE_SINK)
35 self.rotate = self.pipeline_sink.get_by_name('rotate')
39 bus = self.pipeline_src.get_bus()
40 bus.add_signal_watch()
41 bus.connect('message::eos', self.on_eos)
42 bus.connect('message::error', self.on_error)
43 bus.connect('message::state-changed', self .on_state_changed)
46 self.pipeline_src.set_state(Gst.State.PLAYING)
47 self.pipeline_sink.set_state(Gst.State.PLAYING)
51 self.pipeline_sink.set_state(Gst.State.NULL)
52 self.pipeline_src.set_state(Gst.State.NULL)
56 self.angle -= pi / 100
58 self.rotate.set_property("angle", self.angle)
63 self.pipeline_src.set_state(Gst.State.PLAYING)
65 self.pipeline_src.set_state(Gst.State.PAUSED)
69 def on_eos(self, bus, msg):
72 def on_error(self, bus, msg):
73 (err, debug) = msg.parse_error()
74 print("Error: %s" % err)
77 def on_state_changed(self, bus, msg):
78 if msg.src != self.pipeline_src:
81 old_state, new_state, pending = msg.parse_state_changed()
82 print("%s from %s to %s" % (msg.src.get_name(), old_state, new_state))
88 def stdin_cb(source, condition):
97 GObject.io_add_watch(sys.stdin, GObject.IO_IN, stdin_cb)
98 GObject.timeout_add(100, timeout_cb)
100 print("\nPress Enter to freeze the video\n")
104 if __name__ == '__main__':