Last active
June 17, 2020 05:33
-
-
Save cfoch/b62726c917c8d0303ecabd7667c22293 to your computer and use it in GitHub Desktop.
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
import gi | |
gi.require_version("Gtk", "3.0") | |
gi.require_version("GES", "1.0") | |
gi.require_version("GstController", "1.0") | |
import signal | |
from gi.repository import Gtk | |
from gi.repository import GES | |
from gi.repository import Gst | |
from gi.repository import GObject | |
from gi.repository import GstController | |
DEFAULT_DURATION = 10 * Gst.SECOND | |
def handle_sigint(sig, frame): | |
Gtk.main_quit() | |
def bus_message_cb(bus, message): | |
if message.type == Gst.MessageType.EOS: | |
Gtk.main_quit() | |
def control_source_value_changed_cb(control_source, value): | |
print("value changed") | |
def effect_control_binding_added_cb(effect, binding): | |
control_source = binding.props.control_source | |
control_source.connect("value-changed", control_source_value_changed_cb) | |
# framepositioner defines: | |
# MAX_PIXELS = 100000; MIN_PIXELS = -100000 | |
# 0.5 -> 0px | |
control_source.set(0 * Gst.SECOND, 0.5) | |
# 0.5005 -> 100px (100 / 100000 * 0.5 + 0.5) | |
control_source.set(4 * Gst.SECOND, 0.5005) | |
def bg_clip_child_added_cb(clip, track_element): | |
if not isinstance(track_element, GES.Effect): | |
return | |
track_element.connect("control-binding-added", | |
effect_control_binding_added_cb) | |
control_source = GstController.InterpolationControlSource() | |
control_source.props.mode = GstController.InterpolationMode.LINEAR | |
track_element.set_control_source(control_source, "posx", "direct") | |
if __name__ == "__main__": | |
Gst.init(None) | |
GES.init() | |
timeline = GES.Timeline() | |
track = GES.VideoTrack.new() | |
timeline.add_track(track) | |
layer = timeline.append_layer() | |
asset = GES.Asset.request(GES.TestClip, None) | |
bg_clip = layer.add_asset(asset, 0, 0, DEFAULT_DURATION, | |
GES.TrackType.VIDEO) | |
bg_clip.connect("child-added", bg_clip_child_added_cb) | |
bg_clip.props.vpattern = GES.VideoTestPattern.WHITE | |
effect = GES.Effect.new( | |
"videotestsrc ! framepositioner name=positioner ! gescompositor") | |
bg_clip.add_top_effect(effect, -1) | |
pipeline = GES.Pipeline() | |
sink = Gst.ElementFactory.make("xvimagesink", None) | |
pipeline.preview_set_video_sink(sink) | |
pipeline.set_timeline(timeline) | |
bus = pipeline.get_bus() | |
bus.connect("message", bus_message_cb) | |
bus.add_signal_watch() | |
pipeline.set_state(Gst.State.PLAYING) | |
signal.signal(signal.SIGINT, handle_sigint) | |
Gtk.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment