gmyth-stream/server/0.3/plugins/transcoders/gmencoder.py
author morphbr
Tue May 29 21:24:48 2007 +0100 (2007-05-29)
branchtrunk
changeset 718 3fbcd3d9b2d1
child 719 668ecfca1789
permissions -rw-r--r--
[svn r724] * GMyth-Streamer version 0.3 released
- Improved Log architecture;
- Creation of a history for the transcoder's actions
- Creation of an id for each transcoder instanciated
- Also wrapps default actions for python's default logger

- Created new functions to make use of this new Log architecture;
- serve_new_id
- serve_get_log
- serve_get_all_log

- _Lot_ of small bug fixes;

- Inserted header for all files;

- Splited files with too many lines (more than 1 class per file)
in more files;
     1 #!/usr/bin/env python
     2 
     3 __author__ = "Renato Filho"
     4 __author_email__ = "renato.filho@indt.org.br"
     5 __license__ = "GPL"
     6 __version__ = "0.1"
     7 
     8 import os
     9 import shlex
    10 import signal
    11 import subprocess
    12 import time
    13 
    14 import select
    15 
    16 import lib.utils as utils
    17 import lib.server as server
    18 import lib.transcoder as transcoder
    19 
    20 __all__ = ("TranscoderGMencoder",)
    21 
    22 class TranscoderGMencoder(transcoder.Transcoder):
    23     gmencoder_path = utils.which("gmencoder")
    24     name = "gmencoder"
    25     priority = -1
    26     proc = None
    27 
    28     def __init__(self, params):
    29         transcoder.Transcoder.__init__(self, params)
    30         self.opts = []
    31     # __init__()
    32 
    33     def _insert_param (self, name, value):
    34         if (value != ""):
    35             self.opts.append(name)
    36             self.opts.append(value)
    37 
    38     def _parser_params (self):
    39         self._insert_param("-i", \
    40             "%s://%s" % (self.params_first("type", "file"), self.params_first("uri", "")))
    41         self._insert_param("--video-encode", self.params_first("ve", ""))
    42         self._insert_param("--video-opts", "bitrate=200,pass=2,quantizer=5")
    43         self._insert_param("--video-fps", self.params_first("fps", ""))
    44         self._insert_param("--video-width", self.params_first("width", ""))
    45         self._insert_param("--video-height", self.params_first("height", ""))
    46         self._insert_param("--audio-rate", "32000")
    47         self._insert_param("--audio-encode", self.params_first("ae", ""))
    48     # _parse_params
    49 
    50     def start(self, outfd):
    51         self.opts.append (self.gmencoder_path)
    52         self._parser_params ()
    53         self._insert_param ("-o", "fd://%d" % outfd.fileno())
    54 
    55         cmd = " ".join(self.opts)
    56         self.log.info ("GMencoder: %s", cmd)
    57 
    58         try:
    59             self.proc = subprocess.Popen(self.opts, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
    60         except Exception, e:
    61             self.log.error(self.tid, "Error executing GMencoder: %s" % e)
    62             return False
    63 
    64         try:
    65             while (self.proc and self.proc.poll() == None):
    66                 r, w, x = select.select([self.proc.stdout], [], [], 0)
    67                 if self.proc.stdout in r:
    68                     progress = self.proc.stdout.readline()
    69                     self.log.info ("stdout %s" % progress)
    70                     if (progress.find ("PROGRESS") >= 0):
    71                         self.status = progress.split (":")[1]
    72                         #if (progress.find ("DONE") >= 0):
    73                         #	break
    74 			self.log.info ("Process exit")
    75         except Exception, e:
    76             self.log.error(self.tid, "Problems handling data: %s" % e)
    77             return False
    78 
    79         return True
    80     # start()
    81 
    82 
    83     def stop(self):
    84         if self.proc:
    85             self.log.info ("STOPED GMencoder plugin")
    86             try:
    87                 self.proc.stdin.write ("QUIT\n")
    88             except Exception, e:
    89                 pass
    90 
    91             try:
    92                 self.proc.wait()
    93             except Exception, e:
    94                 pass
    95 
    96             self.proc = None
    97     # stop()
    98 
    99 # TranscoderGMencoder