| 1 |
# GStreamer |
| 2 |
# |
| 3 |
# Copyright (C) 2013 Thibault Saunier <[email protected] |
| 4 |
# |
| 5 |
# This library is free software; you can redistribute it and/or |
| 6 |
# modify it under the terms of the GNU Library General Public |
| 7 |
# License as published by the Free Software Foundation; either |
| 8 |
# version 2 of the License, or (at your option) any later version. |
| 9 |
# |
| 10 |
# This library is distributed in the hope that it will be useful, |
| 11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
# Library General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU Library General Public |
| 16 |
# License along with this library; if not, write to the |
| 17 |
# Free Software Foundation, Inc., 51 Franklin Street, Suite 500, |
| 18 |
# Boston, MA 02110-1335, USA. |
| 19 |
|
| 20 |
import os |
| 21 |
from gi.repository import Gst, GES, GLib |
| 22 |
|
| 23 |
|
| 24 |
class Simple: |
| 25 |
def __init__(self, uri): |
| 26 |
timeline = GES.Timeline.new_audio_video() |
| 27 |
self.project = timeline.get_asset() |
| 28 |
|
| 29 |
self.project.connect("asset-added", self._asset_added_cb) |
| 30 |
self.project.connect("error-loading-asset", self._error_loading_asset_cb) |
| 31 |
self.project.create_asset(uri, GES.UriClip) |
| 32 |
self.layer = timeline.append_layer() |
| 33 |
self._create_pipeline(timeline) |
| 34 |
self.loop = GLib.MainLoop() |
| 35 |
|
| 36 |
def _create_pipeline(self, timeline): |
| 37 |
self.pipeline = GES.Pipeline() |
| 38 |
self.pipeline.set_timeline(timeline) |
| 39 |
bus = self.pipeline.get_bus() |
| 40 |
bus.add_signal_watch() |
| 41 |
bus.connect("message", self.bus_message_cb) |
| 42 |
|
| 43 |
def bus_message_cb(self, unused_bus, message): |
| 44 |
if message.type == Gst.MessageType.EOS: |
| 45 |
print "eos" |
| 46 |
self.loop.quit() |
| 47 |
elif message.type == Gst.MessageType.ERROR: |
| 48 |
error = message.parse_error() |
| 49 |
print "error %s" % error[1] |
| 50 |
self.loop.quit() |
| 51 |
|
| 52 |
def start(self): |
| 53 |
self.loop.run() |
| 54 |
|
| 55 |
def _asset_added_cb(self, project, asset): |
| 56 |
self.layer.add_asset(asset, 0, 0, Gst.SECOND * 5, GES.TrackType.UNKNOWN) |
| 57 |
self.pipeline.set_state(Gst.State.PLAYING) |
| 58 |
|
| 59 |
def _error_loading_asset_cb(self, project, error, asset_id, type): |
| 60 |
print "Could not load asset %s: %s" % (asset_id, error) |
| 61 |
self.loop.quit() |
| 62 |
|
| 63 |
if __name__ == "__main__": |
| 64 |
if len(os.sys.argv) != 2: |
| 65 |
print "You must specify a file URI" |
| 66 |
exit(-1) |
| 67 |
|
| 68 |
Gst.init(None) |
| 69 |
GES.init() |
| 70 |
simple = Simple(os.sys.argv[1]) |
| 71 |
simple.start() |