gmyth-stream/server/0.2/plugins/transcoders/gmencoder.py
author renatofilho
Thu Apr 26 22:33:00 2007 +0100 (2007-04-26)
branchtrunk
changeset 600 7da2a5e32fa6
parent 589 549c4664701e
child 602 4b0b8c58b532
permissions -rw-r--r--
[svn r606] added suport for multiple files
     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 
    31         #self._insert_param("-i", self.params_first("uri", ""))
    32 
    33         self._insert_param("--video-encode", self.params_first("ve", ""))
    34         self._insert_param("--video-opts", "bitrate=200,pass=2,quantizer=5")
    35         self._insert_param("--video-fps", self.params_first("fps", ""))
    36         self._insert_param("--video-width", self.params_first("width", ""))
    37         self._insert_param("--video-height", self.params_first("height", ""))
    38         self._insert_param("--audio-encode", self.params_first("ae", ""))
    39         self._insert_param("--output-element", "fdsink")
    40     # _parse_params
    41 
    42     def start(self, outfd):
    43         self.opts.append (self.gmencoder_path)
    44         self._parser_params ()
    45         self.opts.append ("--output-opts")
    46         self.opts.append ("fd=%d" % outfd.fileno())
    47 
    48         cmd = " ".join(self.opts)
    49         self.log.info ("GMencoder: %s", cmd)
    50 
    51         try:
    52             self.proc = subprocess.Popen(self.opts, stdin=subprocess.PIPE)
    53         except Exception, e:
    54             self.log.error("Error executing GMencoder: %s" % e)
    55             return False
    56 
    57         try:
    58              self.proc.wait()
    59         except Exception, e:
    60             self.log.error("Problems handling data: %s" % e)
    61             return False
    62 
    63         return True
    64     # start()
    65 
    66 
    67     def stop(self):
    68         if self.proc:
    69             self.log.info ("STOPed GMencoder plugin")
    70             try:
    71                 self.proc.stdin.write ("QUIT\n")
    72             except Exception, e:
    73                 pass
    74 
    75             try:
    76                 self.proc.wait()
    77             except Exception, e:
    78                 pass
    79 
    80             self.proc = None
    81     # stop()
    82 
    83 # TranscoderGMencoder