gmyth-stream/server/0.2/plugins/transcoders/gmencoder.py
author morphbr
Mon Apr 30 18:16:36 2007 +0100 (2007-04-30)
branchtrunk
changeset 605 4dd9bf602c18
parent 595 5c5cff842d57
child 672 4e623a4274a1
permissions -rw-r--r--
[svn r611] * GMyth-Streamer
- updated mencoder plugin

* GMyth
- samples: gmyth_cat code update
     1 import os
     2 import shlex
     3 import signal
     4 import subprocess
     5 
     6 import lib.utils as utils
     7 import lib.server as server
     8 
     9 __all__ = ("TranscoderGMencoder",)
    10 
    11 class TranscoderGMencoder(server.Transcoder):
    12     gmencoder_path = utils.which("gmencoder")
    13     name = "gmencoder"
    14     priority = -1
    15     proc = None
    16 
    17     def __init__(self, params):
    18         server.Transcoder.__init__(self, params)
    19         self.opts = []
    20     # __init__()
    21 
    22     def _insert_param (self, name, value):
    23         if (value != ""):
    24             self.opts.append(name)
    25             self.opts.append(value)
    26 
    27     def _parser_params (self):
    28         self._insert_param("-i", \
    29             "%s://%s" % (self.params_first("uri_prefix", "file"), self.params_first("uri_path", "")))
    30         self._insert_param("--video-encode", self.params_first("ve", ""))
    31         self._insert_param("--video-opts", "bitrate=200,pass=2,quantizer=5")
    32         self._insert_param("--video-fps", self.params_first("fps", ""))
    33         self._insert_param("--video-width", self.params_first("width", ""))
    34         self._insert_param("--video-height", self.params_first("height", ""))
    35         self._insert_param("--audio-rate", "32000")
    36         self._insert_param("--audio-encode", self.params_first("ae", ""))
    37     # _parse_params
    38 
    39     def start(self, outfd):
    40         self.opts.append (self.gmencoder_path)
    41         self._parser_params ()
    42         self._insert_param ("-o", "fd://%d" % outfd.fileno())
    43 
    44         cmd = " ".join(self.opts)
    45         self.log.info ("GMencoder: %s", cmd)
    46 
    47         try:
    48             self.proc = subprocess.Popen(self.opts, stdin=subprocess.PIPE)
    49         except Exception, e:
    50             self.log.error("Error executing GMencoder: %s" % e)
    51             return False
    52 
    53         try:
    54              self.proc.wait()
    55         except Exception, e:
    56             self.log.error("Problems handling data: %s" % e)
    57             return False
    58 
    59         return True
    60     # start()
    61 
    62 
    63     def stop(self):
    64         if self.proc:
    65             self.log.info ("STOPed GMencoder plugin")
    66             try:
    67                 self.proc.stdin.write ("QUIT\n")
    68             except Exception, e:
    69                 pass
    70 
    71             try:
    72                 self.proc.wait()
    73             except Exception, e:
    74                 pass
    75 
    76             self.proc = None
    77     # stop()
    78 
    79 # TranscoderGMencoder