morphbr@453: import pygst morphbr@453: pygst.require("0.10") morphbr@453: import gst morphbr@453: import gobject morphbr@453: morphbr@453: class Media: morphbr@453: morphbr@453: def __init__(self, config): morphbr@453: morphbr@453: # set gstreamer basic options morphbr@453: self.config = config morphbr@453: self.pipe = "" morphbr@453: morphbr@466: morphbr@466: def setup(self, filename, mux, vcodec, vbitrate,\ morphbr@466: fps, acodec, abitrate, width, height, port): morphbr@453: morphbr@453: self.filename = filename morphbr@466: self.mux = mux morphbr@466: self.vcodec = vcodec morphbr@466: self.vbitrate = int(vbitrate) morphbr@466: self.fps = int(fps) morphbr@466: self.acodec = acodec morphbr@466: self.abitrate = int(abitrate) morphbr@453: self.width = int(width) morphbr@453: self.height = int(height) morphbr@466: morphbr@453: self.port = int(port) morphbr@453: morphbr@453: ## Pipelines morphbr@453: morphbr@453: #queue ! videoscale ! video/x-raw-yuv,width=240,height=144\ morphbr@453: #! videorate ! ffenc_h263p bitrate=256000 me-method=2 \ morphbr@453: #! rtph263ppay ! udpsink host=224.0.0.1 port=5000 morphbr@453: morphbr@453: morphbr@453: #audio/x-raw-int ! queue ! audioconvert ! faac ! rtpmp4gpay\ morphbr@453: #! udpsink name=upd_audio host=224.0.0.1 port=5002 morphbr@453: morphbr@453: self.pipe = "filesrc location=%s ! decodebin name=d ! queue ! videoscale !"\ morphbr@453: "video/x-raw-yuv,width=(int)%d,height=(int)%d ! ffenc_h263p bitrate=%d"\ morphbr@453: " me-method=2 ! rtph263ppay ! udpsink host=224.0.0.1 port=%d d. ! "\ morphbr@453: "queue ! audioconvert ! faac ! rtpmp4gpay ! udpsink name=udp_audio "\ morphbr@453: "host=224.0.0.1 port=%d" % (self.filename, self.width, self.height,\ morphbr@466: self.vbitrate, self.port, self.port+2) morphbr@453: morphbr@453: #self.pipe = "filesrc location=/tmp/mpg/cpm.mpg ! decodebin ! ffmpegcolorspace ! ximagesink" morphbr@453: morphbr@453: self.pipeline = gst.parse_launch(self.pipe) morphbr@453: morphbr@453: morphbr@453: def play(self): morphbr@453: morphbr@453: print "Trying to play pipeline: %s" % self.pipe morphbr@453: try: morphbr@453: if (self.pipeline): morphbr@453: self.pipeline.set_state(gst.STATE_PLAYING) morphbr@453: except gobject.GError, e: morphbr@453: print "Error: " + str(e) morphbr@453: morphbr@453: morphbr@453: def stop(self): morphbr@453: morphbr@453: print "Trying to stop pipeline: %s" % self.pipe morphbr@453: try: morphbr@453: if (self.pipeline): morphbr@453: self.pipeline.set_state(gst.STATE_NULL) morphbr@453: except gobject.GError, e: morphbr@453: print "Error: " + str(e) morphbr@453: