Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/GStreamer/gst-plugins-good.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJan Schmidt <thaytan@noraisin.net>2015-04-26 19:43:14 +0300
committerTim-Philipp Müller <tim@centricular.com>2020-07-10 18:44:41 +0300
commitacc7449d282544e2d32a910471bc7923f111f3f1 (patch)
treef6deb0d90e812b1f3af5c26b0519e5b901df102c /tests
parent3b85ddd90eaf950ac5fe4f24c18d186125256262 (diff)
rpicamsrc: Add dynamic properties example
Python example of adjusting saturation on the fly
Diffstat (limited to 'tests')
-rwxr-xr-xtests/examples/rpicamsrc/dynamicprops.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/examples/rpicamsrc/dynamicprops.py b/tests/examples/rpicamsrc/dynamicprops.py
new file mode 100755
index 000000000..6c1816fbe
--- /dev/null
+++ b/tests/examples/rpicamsrc/dynamicprops.py
@@ -0,0 +1,68 @@
+#!/usr/bin/python3
+
+import sys
+import gi
+gi.require_version('Gst', '1.0')
+from gi.repository import GObject, Gst
+
+def bus_call(bus, msg, *args):
+ # print("BUSCALL", msg, msg.type, *args)
+ if msg.type == Gst.MessageType.EOS:
+ print("End-of-stream")
+ loop.quit()
+ return
+ elif msg.type == Gst.MessageType.ERROR:
+ print("GST ERROR", msg.parse_error())
+ loop.quit()
+ return
+ return True
+
+saturation = -100
+def set_saturation(pipeline):
+ global saturation
+ if saturation <= 100:
+ print("Setting saturation to {0}".format(saturation))
+ videosrc.set_property("saturation", saturation)
+ videosrc.set_property("annotation-text", "Saturation %d" % (saturation))
+ else:
+ pipeline.send_event (Gst.Event.new_eos())
+ return False
+ saturation += 10
+ return True
+
+
+if __name__ == "__main__":
+ GObject.threads_init()
+ # initialization
+ loop = GObject.MainLoop()
+ Gst.init(None)
+
+ pipeline = Gst.parse_launch ("rpicamsrc name=src ! video/x-h264,width=320,height=240 ! h264parse ! mp4mux ! filesink name=s")
+ if pipeline == None:
+ print ("Failed to create pipeline")
+ sys.exit(0)
+
+ # watch for messages on the pipeline's bus (note that this will only
+ # work like this when a GLib main loop is running)
+ bus = pipeline.get_bus()
+ bus.add_watch(0, bus_call, loop)
+
+ videosrc = pipeline.get_by_name ("src")
+ videosrc.set_property("saturation", saturation)
+ videosrc.set_property("annotation-mode", 1)
+
+ sink = pipeline.get_by_name ("s")
+ sink.set_property ("location", "test.mp4")
+
+ # this will call set_saturation every 1s
+ GObject.timeout_add(1000, set_saturation, pipeline)
+
+ # run
+ pipeline.set_state(Gst.State.PLAYING)
+ try:
+ loop.run()
+ except Exception as e:
+ print(e)
+ # cleanup
+ pipeline.set_state(Gst.State.NULL)
+