2011-05-06 22:39:56 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# simple.py
|
|
|
|
#
|
|
|
|
# Copyright (C) 2011 Thibault Saunier <thibault.saunier@collabora.co.uk>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2.1 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
|
|
|
|
# Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this program; if not, write to the
|
|
|
|
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
# Boston, MA 02111-1307, USA.
|
|
|
|
# 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, or (at your option)
|
|
|
|
# any later version.
|
|
|
|
|
|
|
|
import sys
|
2011-08-11 16:26:08 +00:00
|
|
|
import optparse
|
|
|
|
|
2011-05-06 22:39:56 +00:00
|
|
|
import glib
|
2011-08-11 16:26:08 +00:00
|
|
|
import gobject
|
|
|
|
gobject.threads_init()
|
|
|
|
|
|
|
|
import gst
|
|
|
|
import ges
|
|
|
|
|
|
|
|
class Simple:
|
|
|
|
def __init__(self, uris):
|
|
|
|
# init ges to have debug logs
|
|
|
|
ges.init()
|
|
|
|
self.mainloop = glib.MainLoop()
|
|
|
|
|
|
|
|
timeline = ges.timeline_new_audio_video()
|
|
|
|
self.layer = ges.SimpleTimelineLayer()
|
|
|
|
timeline.add_layer(self.layer)
|
|
|
|
|
|
|
|
self.pipeline = ges.TimelinePipeline()
|
|
|
|
self.pipeline.add_timeline(timeline)
|
|
|
|
bus = self.pipeline.get_bus()
|
|
|
|
bus.set_sync_handler(self.bus_handler)
|
2011-05-06 22:39:56 +00:00
|
|
|
|
2011-08-11 16:26:08 +00:00
|
|
|
# all timeline objects except the last will have a transition at the end
|
|
|
|
for n in uris[:-1]:
|
|
|
|
self.add_timeline_object(n, True)
|
|
|
|
self.add_timeline_object(uris[-1], False)
|
2011-05-06 22:39:56 +00:00
|
|
|
|
2011-08-11 16:26:08 +00:00
|
|
|
def add_timeline_object(self, uri, do_transition):
|
|
|
|
filesource = ges.TimelineFileSource (uri)
|
|
|
|
filesource.set_duration(long (gst.SECOND * 5))
|
|
|
|
self.layer.add_object(filesource, -1)
|
2011-05-06 22:39:56 +00:00
|
|
|
|
2011-08-11 16:26:08 +00:00
|
|
|
if do_transition:
|
|
|
|
transition = ges.TimelineStandardTransition("crossfade")
|
|
|
|
transition.duration = gst.SECOND * 2
|
|
|
|
self.layer.add_object(transition, -1)
|
2011-05-06 22:39:56 +00:00
|
|
|
|
|
|
|
def bus_handler(self, unused_bus, message):
|
|
|
|
if message.type == gst.MESSAGE_ERROR:
|
|
|
|
print "ERROR"
|
|
|
|
self.mainloop.quit()
|
|
|
|
elif message.type == gst.MESSAGE_EOS:
|
|
|
|
print "Done"
|
|
|
|
self.mainloop.quit()
|
|
|
|
|
|
|
|
return gst.BUS_PASS
|
|
|
|
|
|
|
|
def run(self):
|
2011-08-11 16:26:08 +00:00
|
|
|
if (self.pipeline.set_state(gst.STATE_PLAYING) == \
|
|
|
|
gst.STATE_CHANGE_FAILURE):
|
2011-05-06 22:39:56 +00:00
|
|
|
print "Couldn't start pipeline"
|
|
|
|
|
|
|
|
self.mainloop.run()
|
|
|
|
|
|
|
|
|
2011-08-11 16:26:08 +00:00
|
|
|
def main(args):
|
|
|
|
usage = "usage: %s URI-OF-VIDEO-1 ... URI-OF-VIDEO-n\n" % args[0]
|
|
|
|
|
|
|
|
if len(args) < 2:
|
|
|
|
sys.stderr.write(usage)
|
|
|
|
sys.exit(1)
|
2011-05-06 22:39:56 +00:00
|
|
|
|
2011-08-11 16:26:08 +00:00
|
|
|
parser = optparse.OptionParser (usage=usage)
|
|
|
|
(options, args) = parser.parse_args ()
|
2011-05-06 22:39:56 +00:00
|
|
|
|
2011-08-11 16:26:08 +00:00
|
|
|
simple = Simple(args)
|
|
|
|
simple.run()
|
2011-05-06 22:39:56 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2011-08-11 16:26:08 +00:00
|
|
|
sys.exit(main(sys.argv))
|