All pastes #895873 Raw Edit

Unnamed

public python v1 · immutable
·published 2008-02-08 03:55 UTC
rendered paste body
import gstimport sysimport gobject def linkDynamic(element, target):    def onPad(obj, pad, target):        sinkpad = target.get_compatible_pad(pad, pad.get_caps())        if sinkpad:            pad.link(sinkpad)    element.connect('pad-added', onPad, target) def queryDuration(fname, callback):    # create a simple pipeline: source -> decode -> fakesink    pipeline = gst.Pipeline()    source = gst.element_factory_make('filesrc')    source.set_property('location', fname)    decode = gst.element_factory_make('decodebin')    sink = gst.element_factory_make('fakesink')    pipeline.add(source, decode, sink)    source.link(decode)    linkDynamic(decode, sink)     # <excerpt 1> #    # connect a message handler to the pipeline    def messageHandler(bus, message):        try:            callback(fname, pipeline.query_duration(gst.FORMAT_TIME)[0])        except gst.QueryError:            pass    bus = pipeline.get_bus()    bus.add_signal_watch()    bus.connect('message', messageHandler)     # pull the trigger    pipeline.set_state(gst.STATE_PAUSED)    # </excerpt> if __name__ == '__main__':    # <excerpt 2> #    # example usage    import gtk     def printDuration(fname, duration):        print "%s: length='%s' seconds" % (fname, float(duration) / gst.SECOND)        gtk.main_quit()     gobject.threads_init();    queryDuration(sys.argv[1], printDuration)    gtk.main()    # </excerpt>