# HG changeset patch # User renatofilho # Date 1176495412 -3600 # Node ID 514f55d6b47ae553562fc385d2083d371e7699d0 # Parent b81aea41900f37d3cae17df0fa099a8d9af900b1 [svn r554] fixed gstreamer plugin diff -r b81aea41900f -r 514f55d6b47a gmyth-stream/server/plugins/media/gstreamer.py --- a/gmyth-stream/server/plugins/media/gstreamer.py Fri Apr 13 21:03:50 2007 +0100 +++ b/gmyth-stream/server/plugins/media/gstreamer.py Fri Apr 13 21:16:52 2007 +0100 @@ -4,6 +4,7 @@ import gst import gobject import socket +import time from threading import Thread class Media: @@ -50,6 +51,7 @@ self.connection = None self.addr = None self.ready = False + self.current = None def setup(self, uri, mux, vcodec, vbitrate, @@ -59,15 +61,19 @@ pipe = gst.Pipeline () print "Opening Uri:" + uri src = gst.element_make_from_uri (gst.URI_SRC, uri, "src") + #src = gst.element_factory_make ("gnomevfssrc", "src") + src.set_property ("location", uri) if (src is None): print "Fail to create src element" return None + print ("Create source") decode = gst.element_factory_make ("decodebin", "decode") if (decode is None): print "Fail to create decodebin" return None + print ("Create source") mux = gst.element_factory_make ("avimux", "mux") if (mux is None): print "Fail to create mux" @@ -78,76 +84,94 @@ print "Fail to create fdsink" return None + print ("Create source") #video encode #queue ! videoscale ! video/x-raw-yuv,width=240,height=144 ! videorate ! ffenc_h263p bitrate=256000 me-method=2 ! rtph263ppay ! udpsink host=224.0.0.1 port=5000 vbin = gst.Bin () vqueue = gst.element_factory_make ("queue", "vqueue") - vscale = gst.element_factory_make ("videoscale", "vscale") colorspace = gst.element_factory_make ("ffmpegcolorspace", "") vrate = gst.element_factory_make ("videorate", "vrate") - vencode = gst.element_factory_make ("ffenc_h263p", "vencode") + vencode = gst.element_factory_make ("ffenc_mpeg4", "vencode") + #vencode = gst.element_factory_make ("ffenc_msmpeg4v1", "vencode") + vqueue_src = gst.element_factory_make ("queue", "vqueue_src") + #if (int(vbitrate) > 0): + vencode.set_property ("bitrate", 200) + #vencode.set_property ("quant-type", 1) + vencode.set_property ("pass", 2) + vencode.set_property ("quantizer", 5) + #vencode.set_property ("me-method", 1) - if (None in [vbin, vqueue, vscale, vrate, vencode]): + + if (None in [vbin, vqueue, vrate, vencode, vqueue_src]): print "Fail to create video encode elements." return None - ''' - vscale_pad = vscale.get_pad("sink") - if (vscale_pad is None): - print "Fail to get vscale sink pad." + vbin.add (vqueue) + if ((int(width) > 0) and (int(height) > 0)): + print ("formating output to %d / %d" % (int(width), int(height))) + + vscale = gst.element_factory_make ("ffvideoscale", "vscale") + + vbin.add (vscale); + if (not vqueue.link (vscale)): + print "Fail to link video elements" + return None + + vbin.add (colorspace) + + if (not vscale.link (colorspace, \ + gst.caps_from_string ("video/x-raw-yuv,width=(int)%d,height=(int)%d" % (int(width), int(height))))): + print "Fail to link video elements" + return None + else: + vbin.add (colorspace) + vqueue.link (colorspace) + + vbin.add (vrate, vencode, vqueue_src) + if (not colorspace.link (vrate)): + print "Fail to colorspace with vrate" return None - vscale_caps = gst.caps_from_string ("video/x-raw-yuv,width=%d,height=(int)%d" % (int(width), int(height))) - if (vscale_caps is None): - print "Fail to create video caps" + + if (not vrate.link (vencode, \ + gst.caps_from_string ("video/x-raw-yuv,framerate=(fraction)10/1"))): + print "Fail to link vrate element" return None - if (not vscale_pad.set_caps (vscale_caps)): - print "Fail to set video output caps" - return None - ''' - - vbin.add (vqueue, vscale, colorspace, vrate, vencode) - if (not vqueue.link (vscale)): - print "Fail to link video elements" - return None - - if (not vscale.link (colorspace, \ - gst.caps_from_string ("video/x-raw-yuv,width=%d,height=(int)%d" % (int(width), int(height))))): - print "Fail to link video elements" - return None - - if (not gst.element_link_many (colorspace, vrate, vencode)): - print "Fail to link video elements" + if (not vencode.link (vqueue_src)): + print "Fail to link video encode with queue" return None vbin.add_pad (gst.GhostPad ("sink", vqueue.get_pad ("sink"))) - vbin.add_pad (gst.GhostPad ("src", vencode.get_pad ("src"))) + vbin.add_pad (gst.GhostPad ("src", vqueue_src.get_pad ("src"))) #audio encode #audio/x-raw-int ! queue ! audioconvert ! faac ! rtpmp4gpay ! udpsink name=upd_audio host=224.0.0.1 port=5002 abin = gst.Bin () - aqueue = gst.element_factory_make ("queue", "vqueue") + 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 ("ffenc_ac3", "aencode") - aencode = gst.element_factory_make ("lame", "aencode") + aencode = gst.element_factory_make ("queue", "aencode") + #aencode = gst.element_factory_make ("lame", "aencode") + #aencode = gst.element_factory_make ("ffenc_mp2", "aencode") + aqueue_src = gst.element_factory_make ("queue", "aqueue_src") - if (None in [abin, aqueue, aconvert, aencode]): + if (None in [abin, aqueue, arate, aencode, aqueue_src]): print "Fail to create video encode elements." return None - abin.add (aqueue, aconvert, aencode) - if (not gst.element_link_many (aqueue, aconvert, aencode)): + abin.add (aqueue, aconvert, arate, aencode, aqueue_src) + if (not gst.element_link_many (aqueue, aconvert, arate, aencode, aqueue_src)): print "Fail to link video elements" return None abin.add_pad (gst.GhostPad ("sink", aqueue.get_pad ("sink"))) - abin.add_pad (gst.GhostPad ("src", aencode.get_pad ("src"))) + abin.add_pad (gst.GhostPad ("src", aqueue_src.get_pad ("src"))) #Finish Pipeline - pipe.add (src, decode, abin, vbin, mux, sink) gst.element_link_many (src, decode) gst.element_link_many (mux, sink) @@ -175,6 +199,7 @@ decode.connect("new-decoded-pad", self.__on_decode_new_pad, stream_data) decode.connect("unknown-type", self.__on_decode_unknown_type, stream_data) + print ("Create source") pipe.set_state (gst.STATE_PAUSED) print "Running Pipe" stream_data.Loop.run () @@ -189,16 +214,28 @@ return (True, "") def play(self): + print "Play" stream = self.streams[0] - current = self.StreamListener(stream) - current.start () - print "Saindo" + self.current = self.StreamListener(stream) + self.current.start () + time.sleep (1) return (True, "") def stop(self): + self.current.join () + self.current = None stream = self.streams[0] stream.Pipe.set_state(gst.STATE_NULL) - stream.Connection.close () + del (stream.Pipe) + stream.Pipe = None + stream.Abin = None + stream.Vbin = None + stream.Sink = None + if (stream.Connection != None): + stream.Connection.close () + + self.streams = [] + time.sleep (5) return (True, "") @@ -249,4 +286,5 @@ return None else: print "Invalid caps" + print "Linked" diff -r b81aea41900f -r 514f55d6b47a gmyth-stream/server/stream.conf --- a/gmyth-stream/server/stream.conf Fri Apr 13 21:03:50 2007 +0100 +++ b/gmyth-stream/server/stream.conf Fri Apr 13 21:16:52 2007 +0100 @@ -4,7 +4,7 @@ [Media] -engine = mencoder +engine = gstreamer [Vlc]