gmyth-stream/server/0.2/plugins/transcoders/gmencoder.py
author rosfran
Wed Apr 25 15:50:41 2007 +0100 (2007-04-25)
branchtrunk
changeset 594 f36075170a4e
child 595 5c5cff842d57
permissions -rw-r--r--
[svn r600] Added clean-up code to the GMyth test cases.
     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     args = {}
    17 
    18     def __init__(self, params):
    19         server.Transcoder.__init__(self, params)
    20         self.opts = []
    21     # __init__()
    22 
    23     def _insert_param (self, name, value):
    24         if (value != ""):
    25             self.opts.append(name)
    26             self.opts.append(value)
    27 
    28     def _parser_params (self):
    29         self._insert_param("-i", \
    30             "%s://%s" % (self.params_first("uri_prefix", "file"), self.params_first("uri_path", "")))
    31         self._insert_param("--video-encode", self.params_first("ve", ""))
    32         self._insert_param("--video-opts", "bitrate=200,pass=2,quantizer=5")
    33         self._insert_param("--video-fps", self.params_first("fps", ""))
    34         self._insert_param("--video-width", self.params_first("width", ""))
    35         self._insert_param("--video-height", self.params_first("height", ""))
    36         self._insert_param("--audio-encode", self.params_first("ae", ""))
    37         self._insert_param("--output-element", "fdsink")
    38     # _parse_params 
    39     
    40     def start(self, outfd):
    41         self.opts.append (self.gmencoder_path)
    42         self._parser_params ()
    43         self.opts.append ("--output-opts")
    44         self.opts.append ("fd=%d" % outfd.fileno())
    45 
    46         cmd = " ".join(self.opts)
    47         self.log.info ("Gmemconder: %s", cmd)
    48 
    49         try:
    50             self.proc = subprocess.Popen(self.opts, stdin=subprocess.PIPE)
    51         except Exception, e:
    52             self.log.error("Error executing gmencoder: %s" % e)
    53             return False
    54 
    55         try:
    56              self.proc.wait()
    57             
    58         except Exception, e:
    59             self.log.error("Problems handling data: %s" % e)
    60             return False
    61 
    62         return True
    63     # start()
    64 
    65 
    66     def stop(self):
    67         if self.proc:
    68             self.log.info ("STOP")
    69             try:
    70                 self.proc.stdin.write ("QUIT\n")
    71             except Exception, e:
    72                 pass
    73 
    74             try:
    75                 self.proc.wait()
    76             except Exception, e:
    77                 pass
    78 
    79             self.proc = None
    80     # stop()
    81 
    82 # TranscoderGMencoder