3 # Timeline - very simple GES timeline wrapper
5 # Copyright (C) 2016 Antonio Ospite <ao2@ao2.it>
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 gi.require_version('Gst', '1.0')
23 from gi.repository import Gst
26 gi.require_version('GES', '1.0')
27 from gi.repository import GES
30 from .Player import Player
33 class Timeline(object):
35 self.project = GES.Project(extractable_type=GES.Timeline)
36 self.timeline = GES.Asset.extract(self.project)
38 audio_track = GES.AudioTrack.new()
39 video_track = GES.VideoTrack.new()
41 self.timeline.add_track(audio_track)
42 self.timeline.add_track(video_track)
44 self.layer = self.timeline.append_layer()
46 def add_clip(self, clip_path, start_time, duration):
47 clip_uri = Gst.filename_to_uri(clip_path)
48 asset = GES.UriClipAsset.request_sync(clip_uri)
49 self.layer.add_asset(asset, start_time * Gst.SECOND, 0,
50 duration * Gst.SECOND, GES.TrackType.UNKNOWN)
53 self.timeline.commit()
55 ges_pipeline = GES.Pipeline()
56 ges_pipeline.set_timeline(self.timeline)
57 Player(ges_pipeline).play()
60 uri = Gst.filename_to_uri(path)
61 self.project.save(self.timeline, uri, None, False)