# HG changeset patch # User renatofilho # Date 1176993709 -3600 # Node ID 00ecee7b96255d1b36a8df17172969cb113ac216 # Parent 644a526d408672bdd398af42798bbf657a8390aa [svn r575] updated diff -r 644a526d4086 -r 00ecee7b9625 gmyth-stream/server/0.2/plugins/transcoders/gstreamer.py --- a/gmyth-stream/server/0.2/plugins/transcoders/gstreamer.py Thu Apr 19 15:13:48 2007 +0100 +++ b/gmyth-stream/server/0.2/plugins/transcoders/gstreamer.py Thu Apr 19 15:41:49 2007 +0100 @@ -42,6 +42,7 @@ def __init__(self, params): server.Transcoder.__init__(self, params) + gobject.threads_init () # set gstreamer basic options self.connection = None self.addr = None @@ -56,7 +57,7 @@ self.log.info("Opening Uri:" + uri) src = gst.element_make_from_uri(gst.URI_SRC, uri, "src") decode = gst.element_factory_make("decodebin", "decode") - mux = gst.element_factory_make("avimux", "mux") + mux = gst.element_factory_make("ffmux_mpeg", "mux") sink = gst.element_factory_make("fdsink", "sink") return [src, decode, mux, sink] @@ -67,10 +68,13 @@ vqueue = gst.element_factory_make("queue", "vqueue") colorspace = gst.element_factory_make("ffmpegcolorspace", "") vrate = gst.element_factory_make("videorate", "vrate") - vencode = gst.element_factory_make("ffenc_mpeg4", "vencode") + #vencode = gst.element_factory_make("ffenc_mpeg4", "vencode") + vencode = gst.element_factory_make("ffenc_mpeg1video", "vencode") vqueue_src = gst.element_factory_make("queue", "vqueue_src") vencode.set_property("bitrate", 200) + vencode.set_property ("pass", 2) + vencode.set_property ("quantizer", 5) if None in [vbin, vqueue, vrate, vencode, vqueue_src]: self.log.info("Fail to create video encode elements.") @@ -122,22 +126,42 @@ def _setup_audio_encode(self, abin): aqueue = gst.element_factory_make("queue", "aqueue") aconvert = gst.element_factory_make("audioconvert", "aconvert") - arate = gst.element_factory_make("audioresample", "arate") - aencode = gst.element_factory_make("queue", "aencode") + #aencode = gst.element_factory_make("queue", "aencode") + #aencode = gst.element_factory_make("ffenc_mp2", "aencode") + aencode = gst.element_factory_make("lame", "aencode") aqueue_src = gst.element_factory_make("queue", "aqueue_src") - - if None in [abin, aqueue, arate, aencode, aqueue_src]: + + if None in [abin, aqueue, aencode, aqueue_src]: self.log.info("Fail to create video encode elements.") return False - abin.add(aqueue, aconvert, arate, aencode, aqueue_src) + #aencode.set_property ("bitrate", 32) + #aencode.set_property ("vbr-quality", 2) - if not gst.element_link_many(aqueue, aconvert, arate, aencode, aqueue_src): + abin.add(aqueue, aconvert, aencode, aqueue_src) + + self.log.info ("Link queue -> aconvert") + if not aqueue.link (aconvert): + self.log.info("Fail to link queue video") + return False + + self.log.info ("Link aconvert -> aencode") + if not aconvert.link (aencode): self.log.info("Fail to link video elements") return False - abin.add_pad(gst.GhostPad("sink", aqueue.get_pad("sink"))) - abin.add_pad(gst.GhostPad("src", aqueue_src.get_pad("src"))) + self.log.info ("Link aencode -> aqueue_src") + if not aencode.link (aqueue_src): + self.log.info("Fail to link aencode -> aqueue_src") + return False + + self.log.info ("Link:OK") + + ghost_sink = gst.GhostPad("sink", aqueue.get_pad("sink")) + ghost_src = gst.GhostPad("src", aqueue_src.get_pad("src")) + #ghost_src.set_caps (gst.caps_from_string ("audio/mpeg,mpegversion=(int)1,layer=(int)3,rate=(int)32000")) + abin.add_pad(ghost_sink) + abin.add_pad(ghost_src) return True # _setup_audio_encode() @@ -208,6 +232,7 @@ def __on_bus_message(self, bus, message, stream_data): t = message.type + self.log.info ("__on_bus_message") if t == gst.MESSAGE_STATE_CHANGED: oldstate = -1 @@ -230,14 +255,18 @@ elif t == gst.MESSAGE_EOS: self.log.info("Pipe finished") - stream_data.Loop.quit() - self.quit = True + if stream_data.Ready: + self.stop() + else: + stream_data.Loop.quit() elif t == gst.MESSAGE_ERROR: err, debug = message.parse_error() self.log.error("Error: %s %s" %(err, debug)) - stream_data.Loop.quit() - stream_data.Ready = False + if stream_data.Ready: + self.stop() + else: + stream_data.Loop.quit() return True # __on_bus_message() @@ -270,7 +299,8 @@ def start(self, outfd): params_first = self.params_first - self.setup(params_first("uri", ""), params_first("mux", "avi"), + uri = '%s://%s' % (params_first("uri_prefix", ""), params_first("uri_path", "")) + self.setup(uri, params_first("mux", "avi"), params_first("vcodec", "ffenc_h263p"), params_first("vbitrate", 256000), params_first("fps", 25), params_first("acodec", "faac"), params_first("abitrate", 192000), params_first("width", 320), @@ -282,12 +312,7 @@ self.stream_data.Pipe.set_state(gst.STATE_PLAYING) # keep playing until EOS - self.log.info("QUIT: %s" % self.quit) - - i = 0 - loop = gobject.MainLoop() - loop.run() - + self.stream_data.Loop.run() self.log.info("quit loop") return True @@ -298,8 +323,9 @@ if self.stream_data: self.stream_data.Pipe.set_state(gst.STATE_NULL) - self.quit = True + self.stream_data.Ready = False + self.stream_data.Loop.quit () del self.stream_data self.stream_data = None # stop