gmyth-stream/plugins/media/gstreamer.py
author morphbr
Sun Apr 01 03:11:01 2007 +0100 (2007-04-01)
branchtrunk
changeset 475 2521ec986005
parent 453 a806d8ad0ff0
child 483 8edb3b445cac
permissions -rw-r--r--
[svn r480] * GMyth-Stream:
- Support for dvds
- Support regarding playing the file locally
     1 import pygst
     2 pygst.require("0.10")
     3 import gst
     4 import gobject
     5 
     6 class Media:
     7 
     8     def __init__(self, config):
     9 
    10         # set gstreamer basic options
    11         self.config = config
    12         self.pipe = ""
    13 
    14 
    15     def setup(self, filename, mux, vcodec, vbitrate,\
    16               fps, acodec, abitrate, width, height, port):
    17 
    18         self.filename = filename
    19         self.mux = mux
    20         self.vcodec = vcodec
    21         self.vbitrate = int(vbitrate)
    22         self.fps = int(fps)
    23         self.acodec = acodec
    24         self.abitrate = int(abitrate)
    25         self.width = int(width)
    26         self.height = int(height)
    27 
    28         self.port = int(port)
    29 
    30         ## Pipelines
    31 
    32         #queue ! videoscale ! video/x-raw-yuv,width=240,height=144\
    33         #! videorate ! ffenc_h263p bitrate=256000 me-method=2 \
    34         #! rtph263ppay ! udpsink  host=224.0.0.1 port=5000
    35 
    36 
    37         #audio/x-raw-int ! queue ! audioconvert ! faac ! rtpmp4gpay\
    38         #!  udpsink name=upd_audio host=224.0.0.1 port=5002
    39 
    40         self.pipe = "filesrc location=%s ! decodebin name=d ! queue ! videoscale !"\
    41                     "video/x-raw-yuv,width=(int)%d,height=(int)%d ! ffenc_h263p bitrate=%d"\
    42                     " me-method=2 ! rtph263ppay ! udpsink host=224.0.0.1 port=%d d. ! "\
    43                     "queue  ! audioconvert ! faac ! rtpmp4gpay ! udpsink name=udp_audio "\
    44                     "host=224.0.0.1 port=%d" % (self.filename, self.width, self.height,\
    45                                                 self.vbitrate, self.port, self.port+2)
    46 
    47         #self.pipe = "filesrc location=/tmp/mpg/cpm.mpg ! decodebin ! ffmpegcolorspace ! ximagesink"
    48 
    49         self.pipeline = gst.parse_launch(self.pipe)
    50 
    51 
    52     def play(self):
    53 
    54         print "Trying to play pipeline: %s" % self.pipe
    55         try:
    56             if (self.pipeline):
    57                 self.pipeline.set_state(gst.STATE_PLAYING)
    58         except gobject.GError, e:
    59             print "Error: " + str(e)
    60 
    61 
    62     def stop(self):
    63 
    64         print "Trying to stop pipeline: %s" % self.pipe
    65         try:
    66             if (self.pipeline):
    67                 self.pipeline.set_state(gst.STATE_NULL)
    68         except gobject.GError, e:
    69             print "Error: " + str(e)
    70