Created
March 17, 2017 21:15
-
-
Save lsiden/649d8ef9e02758ffde30b2b10fbac45a to your computer and use it in GitHub Desktop.
Gst control source demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import gi | |
import sys | |
import threading | |
import time | |
from gi.repository import GObject | |
gi.require_version('Gst', '1.0') | |
from gi.repository import Gst, GstController, GLib | |
def get_alpha_controller(pad): | |
cs = GstController.InterpolationControlSource() | |
cs.set_property('mode', GstController.InterpolationMode.LINEAR) | |
cb = GstController.DirectControlBinding.new(pad, 'alpha', cs) | |
pad.add_control_binding(cb) | |
return cs | |
GObject.threads_init() | |
Gst.init(sys.argv) | |
pipeline = Gst.parse_launch (""" | |
videomixer name="mix" ! autovideosink | |
videotestsrc pattern="green" ! video/x-raw,width=400,height=400 ! decodebin ! mix.sink_0 | |
videotestsrc pattern="black" ! video/x-raw,width=200,height=200 ! decodebin ! mix.sink_1 | |
""") | |
print([ pad.name for pad in pipeline.get_by_name('mix').pads ]) | |
green_sink = pipeline.get_by_name('mix').get_request_pad('sink_0') | |
black_sink = pipeline.get_by_name('mix').get_request_pad('sink_1') | |
print([ pad.name for pad in pipeline.get_by_name('mix').pads ]) | |
black_sink.set_property('xpos', 50) | |
black_sink.set_property('ypos', 50) | |
cs = get_alpha_controller(black_sink) | |
cs.set(1*Gst.SECOND, 1) | |
cs.set(2*Gst.SECOND, 0) | |
cs.set(3*Gst.SECOND, 0) | |
cs.set(4*Gst.SECOND, 1) | |
pipeline.set_state (Gst.State.PLAYING) | |
GLib.MainLoop.new(None, False).run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment