Use webm for the videofont, it has better support than shroedinger
[vidi-player.git] / vidi / Timeline.py
1 #!/usr/bin/env python3
2 #
3 # Timeline - very simple GES timeline wrapper
4 #
5 # Copyright (C) 2016  Antonio Ospite <ao2@ao2.it>
6 #
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.
11 #
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.
16 #
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/>.
19
20 import gi
21
22 gi.require_version('Gst', '1.0')
23 from gi.repository import Gst
24 Gst.init(None)
25
26 gi.require_version('GES', '1.0')
27 from gi.repository import GES
28 GES.init()
29
30 from .Player import Player
31
32
33 class Timeline(object):
34     def __init__(self):
35         self.project = GES.Project(extractable_type=GES.Timeline)
36         self.timeline = GES.Asset.extract(self.project)
37
38         audio_track = GES.AudioTrack.new()
39         video_track = GES.VideoTrack.new()
40
41         self.timeline.add_track(audio_track)
42         self.timeline.add_track(video_track)
43
44         self.layer = self.timeline.append_layer()
45
46         ges_pipeline = GES.Pipeline()
47         ges_pipeline.set_timeline(self.timeline)
48         self.player = Player(ges_pipeline)
49
50     def add_clip(self, clip_path, start_time, duration):
51         clip_uri = Gst.filename_to_uri(clip_path)
52         asset = GES.UriClipAsset.request_sync(clip_uri)
53         self.layer.add_asset(asset, start_time * Gst.SECOND, 0,
54                              duration * Gst.SECOND, GES.TrackType.UNKNOWN)
55
56     def play(self):
57         self.timeline.commit()
58         self.player.play()
59
60     def stop(self):
61         self.player.stop()
62
63     def save(self, path):
64         uri = Gst.filename_to_uri(path)
65         self.project.save(self.timeline, uri, None, False)