8 gi.require_version('Gst', '1.0')
9 from gi.repository import Gst
12 from gi.repository import GLib
16 videotestsrc pattern=18 background-color=4294901760 ! intervideosink
20 #v4l2src ! video/x-raw,width=320,height=240 ! intervideosink
24 intervideosrc timeout=-1 ! videoconvert ! rotate name=rotate ! videoconvert ! autovideosink
30 self.loop = GLib.MainLoop()
31 self.pipeline_src = Gst.parse_launch(PIPELINE_SRC)
32 self.pipeline_sink = Gst.parse_launch(PIPELINE_SINK)
34 self.rotate = self.pipeline_sink.get_by_name('rotate')
38 bus = self.pipeline_src.get_bus()
39 bus.add_signal_watch()
40 bus.connect('message::eos', self.on_eos)
41 bus.connect('message::error', self.on_error)
42 bus.connect('message::state-changed', self .on_state_changed)
45 self.pipeline_src.set_state(Gst.State.PLAYING)
46 self.pipeline_sink.set_state(Gst.State.PLAYING)
50 self.pipeline_sink.set_state(Gst.State.NULL)
51 self.pipeline_src.set_state(Gst.State.NULL)
55 self.angle -= pi / 100
57 self.rotate.set_property("angle", self.angle)
62 self.pipeline_src.set_state(Gst.State.PLAYING)
64 self.pipeline_src.set_state(Gst.State.PAUSED)
68 def on_eos(self, bus, msg):
71 def on_error(self, bus, msg):
72 (err, debug) = msg.parse_error()
73 print("Error: %s" % err)
76 def on_state_changed(self, bus, msg):
77 if msg.src != self.pipeline_src:
80 old_state, new_state, pending = msg.parse_state_changed()
81 print("%s from %s to %s" % (msg.src.get_name(), old_state, new_state))
87 def stdin_cb(source, condition):
96 GLib.io_add_watch(sys.stdin, GLib.IO_IN, stdin_cb)
97 GLib.timeout_add(100, timeout_cb)
99 print("\nPress Enter to freeze the video\n")
103 if __name__ == '__main__':