All pastes #51579 Raw Edit

concat ogg

public python v1 · immutable
#51579 ·published 2006-04-26 19:29 UTC
rendered paste body
#!/usr/bin/env pythonimport sysimport gstclass Decoder:    "A GStreamer class for a generic audio/video decoder"    def __init__(self):        self.pipeline = gst.parse_launch('filesrc name=source ! ' +                                         'decodebin name=b ' +                                         '{ b. ! ' +                                         '  audioconvert ! '+                                          '  queue name=audio ' +                                         '} ' +                                         '{ b. ! ' +                                         '  videoscale ! ' +                                         '  video/x-raw-yuv,width=352,height=288 ! ' +                                         '  alpha ! ' +                                         '  ffmpegcolorspace ! ' +                                         '  queue name=video ' +                                         '} ')        self.source = self.pipeline.get_by_name('source')        self.audio = self.pipeline.get_by_name('audio')        self.video = self.pipeline.get_by_name('video')        self.bus = self.pipeline.get_bus()            def play(self):        self.pipeline.set_state(gst.STATE_PLAYING)    def stop(self):        self.pipeline.set_state(gst.STATE_NULL)        def concat(input, output):   "A GStreamer converter for fisl7.0 videos"   anim_in_path = '/tmp/teste.ogg'   anim_out_path = '/tmp/teste.ogg'   logo_path = '/tmp/logo.png'   # create a bin for the initial animation   anim_in = Decoder()   anim_in.source.set_property('location', anim_in_path)   # create a bin for the final animation   anim_out = Decoder()   anim_out.source.set_property('location', anim_out_path)   # create a logo bin   logo_bin = gst.parse_launch('filesrc name=source ! pngdec ! alphacolor ! queue name=logo')   logo_src = logo_bin.get_by_name('source')   logo_src.set_property('location', logo_path)   logo_out = logo_bin.get_by_name('logo')   # create a lecture bin   lecture = Decoder()   lecture.source.set_property('location', input)   # create a mixer bin   mixer_bin = gst.parse_launch('videomixer name=in ! ffmpegcolorspace ! theoraenc name=v-enc ! queue name=out ')   mixer_in = mixer_bin.get_by_name('in')   mixer_out = mixer_bin.get_by_name('out')   theora = mixer_bin.get_by_name('v-enc')   theora.set_property('quality', 22)   # create an audio bin   audio_bin = gst.parse_launch('audioconvert name=in ! vorbisenc name=a-enc ! queue name=out ')   audio_in = audio_bin.get_by_name('in')   audio_out = audio_bin.get_by_name('out')   # create a muxer bin   muxer = gst.parse_launch('oggmux name=mux ! filesink name=sink')   mux = muxer.get_by_name('mux')   sink = muxer.get_by_name('sink')   sink.set_property('location', output)   pipeline = gst.Pipeline('pipeline')   pipeline.add(anim_in.pipeline)   pipeline.add(mixer_bin)   pipeline.add(audio_bin)   pipeline.add(muxer)   mixer_out.link(mux)   audio_out.link(mux)      anim_in.video.link(mixer_in)   anim_in.audio.link(audio_in)   bus = pipeline.get_bus()   # start playing - record the anim_in   pipeline.set_state(gst.STATE_PLAYING)   try:     while 1:        msg = bus.poll(gst.MESSAGE_EOS | gst.MESSAGE_ERROR, gst.SECOND)        if msg:           pipeline.set_state(gst.STATE_NULL)           break   except KeyboardInterrupt:     pass   # unlink anim_in   anim_in.video.unlink(mixer_in)   anim_in.audio.unlink(audio_in)       pipeline.remove(anim_in.pipeline)      pipeline.add(logo_bin)   pipeline.add(lecture.pipeline)   logo_out.link(mixer_in)   lecture.video.link(mixer_in)   lecture.audio.link(audio_in)    # start playing - record the lecture   pipeline.set_state(gst.STATE_PLAYING)   try:     while 1:        msg = bus.poll(gst.MESSAGE_EOS | gst.MESSAGE_ERROR, gst.SECOND)        if msg:           pipeline.set_state(gst.STATE_NULL)           break   except KeyboardInterrupt:     pass   # unlink lecture   lecture.video.unlink(mixer_in)   lecture.audio.unlink(audio_in)   logo_out.unlink(mixer_in)       pipeline.remove(logo_bin)   pipeline.remove(lecture.pipeline)      pipeline.add(anim_out.pipeline)   anim_out.video.link(mixer_in)   anim_out.audio.link(audio_in)    # start playing - record the lecture   pipeline.set_state(gst.STATE_NULL)   try:     while 1:        msg = bus.poll(gst.MESSAGE_EOS | gst.MESSAGE_ERROR, gst.SECOND)        if msg:           pipeline.set_state(gst.STATE_PAUSED)           break   except KeyboardInterrupt:     pass   # stop the bin   pipeline.set_state(gst.STATE_NULL)def main(args):   if len(args) != 3:      print 'usage: %s source dest' % (sys.argv[0])      return -1   return concat(args[1], args[2])def test_decoder(args):   bla = Decoder()   bla.source.set_property('location', '/tmp/vinheta_entrada.mpg')   sink = gst.parse_launch('aasink name=sink')   pipeline = gst.Pipeline('pipeline')   pipeline.add(bla.pipeline)   pipeline.add(sink)   bla.video.link(sink)      # start playing - record the lecture   pipeline.set_state(gst.STATE_PLAYING)   bus = pipeline.get_bus()   try:     while 1:        msg = bus.poll(gst.MESSAGE_EOS | gst.MESSAGE_ERROR, gst.SECOND)        if msg:           break   except KeyboardInterrupt:     passif __name__ == '__main__':   sys.exit(main(sys.argv))#   sys.exit(test_decoder(sys.argv))