#/usr/bin/python import pygst pygst.require('0.10') import gst import gobject import sys def make_source(filename, caps, mediastart, start, duration): """ make a gnlfilesource for the given file with the given properties """ source = gst.element_factory_make("gnlfilesource") source.set_property("location", filename) source.set_property("start", start) source.set_property("media-start", mediastart) source.set_property("duration", duration) source.set_property("media-duration", duration) source.set_property("caps", caps) return source def get_compositions(filename): """ return the video composition and the audio composition """ # in the videocomposition we put the video part of the file videocomp = gst.element_factory_make("gnlcomposition", "videocomp") # from 0 to 5s we put the part starting at 20s in the file src1 = make_source(filename, gst.caps_from_string("video/x-raw-yuv"), 20 * gst.SECOND, 0, 5 * gst.SECOND) # from 5s to 10s we put the part starting at 5s in the file src2 = make_source(filename, gst.caps_from_string("video/x-raw-yuv"), 5 * gst.SECOND, 5 * gst.SECOND, 5 * gst.SECOND) videocomp.add(src1, src2) # for audio we put 10s starting at the beginning of the file audiocomp = gst.element_factory_make("gnlcomposition", "audiocomp") src3 = make_source(filename, gst.caps_from_string("audio/x-raw-int"), 0, 0 * gst.SECOND, 10 * gst.SECOND) audiocomp.add(src3) return (videocomp, audiocomp) def comp_pad_added_cb(comp, pad, sink): """ callback to connect to sinks """ gst.debug("got new pad %s" % pad.get_caps().to_string()) pad.link(sink.get_pad("sink")) # our pipeline, mainloop and audio/video compositions pipeline = gst.Pipeline() mainloop = gobject.MainLoop() vcomp, acomp = get_compositions(sys.argv[1]) pipeline.add(vcomp, acomp) # The sinks vsink = gst.element_factory_make("xvimagesink") csp = gst.element_factory_make("ffmpegcolorspace") asink = gst.element_factory_make("alsasink") aconv = gst.element_factory_make("audioconvert") vq = gst.element_factory_make("queue") aq = gst.element_factory_make("queue") pipeline.add(vsink, asink, vq, aq, csp, aconv) vq.link(csp) csp.link(vsink) aq.link(aconv) aconv.link(asink) # connect to the compositions callback vcomp.connect("pad-added", comp_pad_added_cb, vq) acomp.connect("pad-added", comp_pad_added_cb, aq) pipeline.set_state(gst.STATE_PLAYING) # IMPORTANT : gnonlin needs a mainloop mainloop.run()