X-Git-Url: https://git.ao2.it/vidi-player.git/blobdiff_plain/7b9f8f4c6ed554ec3ec6e83e614ca9e9600ab913..f74787f4bc5d288f0853000145e96d3a077c9c6a:/vidi/Timeline.py diff --git a/vidi/Timeline.py b/vidi/Timeline.py index 59c891a..ef04c99 100755 --- a/vidi/Timeline.py +++ b/vidi/Timeline.py @@ -29,15 +29,26 @@ GES.init() from .Player import Player +TITLE_BACKGROUND = 0xFF000000 +TITLE_COLOR = 0xFFFFFFFF +TITLE_OUTLINE_COLOR = 0x00000000 +TITLE_FONT_DESC = "Georgia, 24" class Timeline(object): - def __init__(self): + def __init__(self, canvas_size=None): self.project = GES.Project(extractable_type=GES.Timeline) self.timeline = GES.Asset.extract(self.project) audio_track = GES.AudioTrack.new() video_track = GES.VideoTrack.new() + if canvas_size: + width, height = canvas_size + caps = Gst.Caps.new_empty_simple("video/x-raw") + caps.set_value("width", width) + caps.set_value("height", height) + video_track.set_restriction_caps(caps) + self.timeline.add_track(audio_track) self.timeline.add_track(video_track) @@ -47,6 +58,23 @@ class Timeline(object): ges_pipeline.set_timeline(self.timeline) self.player = Player(ges_pipeline) + def add_title_clip(self, text, start_time, duration): + title_clip = GES.TitleClip() + title_clip.set_start(start_time * Gst.SECOND) + title_clip.set_duration(duration * Gst.SECOND) + self.layer.add_clip(title_clip) + + # Now that the clip is inserted in the timeline, it has a source which + # can be used to set its properties. (comment taken from Pitivi) + title_source = title_clip.find_track_element(None, GES.TitleSource) + title_source.set_child_property("text", text) + title_source.set_child_property("background", TITLE_BACKGROUND) + title_source.set_child_property("color", TITLE_COLOR) + title_source.set_child_property("outline-color", TITLE_OUTLINE_COLOR) + title_source.set_child_property("font-desc", TITLE_FONT_DESC) + title_source.set_child_property("halignment", GES.TextVAlign.ABSOLUTE) + title_source.set_child_property("valignment", GES.TextHAlign.ABSOLUTE) + def add_clip(self, clip_path, start_time, duration): clip_uri = Gst.filename_to_uri(clip_path) asset = GES.UriClipAsset.request_sync(clip_uri)