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