#!/usr/bin/env python3 # # Timeline - very simple GES timeline wrapper # # Copyright (C) 2016 Antonio Ospite # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . import gi gi.require_version('Gst', '1.0') from gi.repository import Gst Gst.init(None) gi.require_version('GES', '1.0') from gi.repository import GES GES.init() from .Player import Player class Timeline(object): def __init__(self): 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() self.timeline.add_track(audio_track) self.timeline.add_track(video_track) self.layer = self.timeline.append_layer() ges_pipeline = GES.Pipeline() ges_pipeline.set_timeline(self.timeline) self.player = Player(ges_pipeline) def add_clip(self, clip_path, start_time, duration): clip_uri = Gst.filename_to_uri(clip_path) asset = GES.UriClipAsset.request_sync(clip_uri) self.layer.add_asset(asset, start_time * Gst.SECOND, 0, duration * Gst.SECOND, GES.TrackType.UNKNOWN) def play(self): self.timeline.commit() self.player.play() def stop(self): self.player.stop() def save(self, path): uri = Gst.filename_to_uri(path) self.project.save(self.timeline, uri, None, False)