Show
Ignore:
Timestamp:
03/11/07 23:54:01 (2 years ago)
Author:
Jason Michalski <armooo@armooo.net>
git-committer:
Jason Michalski <armooo@armooo.net> 1173675241 +0000
git-parent:

[22c71e076b9374066aebe1a63e75ee594dab4ea1]

git-author:
Jason Michalski <armooo@armooo.net> 1173675241 +0000
Message:

pyTivo
- Don't do reverse DNS lookups when logging (adds 4.5 sec to response time)
- Check for Appears to be film source: (\d+) and override fps with it
- Set an audio sample rate
- Caching video info
- Timeout for ffmpeg getting video info

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/video/transcode.py

    r22c71e0 rcafe669  
    1 import subprocess, shutil, os, re, sys, ConfigParser 
     1import subprocess, shutil, os, re, sys, ConfigParser, time, lrucache  
    22 
    33from Config import config 
     4 
     5info_cache = lrucache.LRUCache(1000) 
    46 
    57FFMPEG = config.get('Server', 'ffmpeg') 
     
    3133 
    3234def transcode(inFile, outFile): 
    33     cmd = [FFMPEG, '-i', inFile, '-vcodec', 'mpeg2video', '-r', '29.97', '-b', '4096K'] + select_aspect(inFile)  +  ['-comment', 'pyTivo.py', '-ac', '2', '-ab', '192', '-f', 'vob', '-' ]    
     35    cmd = [FFMPEG, '-i', inFile, '-vcodec', 'mpeg2video', '-r', '29.97', '-b', '4096K'] + select_aspect(inFile)  +  ['-comment', 'pyTivo.py', '-ac', '2', '-ab', '192','-ar', '44100', '-f', 'vob', '-' ]    
    3436    ffmpeg = subprocess.Popen(cmd, stdout=subprocess.PIPE) 
    3537    try: 
    3638        shutil.copyfileobj(ffmpeg.stdout, outFile) 
    3739    except: 
    38         if mswindows: 
    39             win32kill(ffmpeg.pid) 
    40         else: 
    41             import os, signal 
    42             os.kill(ffmpeg.pid, signal.SIGKILL) 
    43  
     40        kill(ffmpeg.pid) 
     41        
    4442def select_aspect(inFile): 
    4543    type, width, height, fps, millisecs =  video_info(inFile) 
     
    127125 
    128126def video_info(inFile): 
     127    print  inFile 
     128    if inFile in info_cache: 
     129        return info_cache[inFile] 
     130 
    129131    if (inFile[-5:]).lower() == '.tivo': 
     132        info_cache[inFile] = (True, True, True, True, True) 
    130133        return True, True, True, True, True 
     134 
    131135    cmd = [FFMPEG, '-i', inFile ]  
    132136    ffmpeg = subprocess.Popen(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, stdin=subprocess.PIPE) 
     137 
     138    # wait 4 sec if ffmpeg is not back give up 
     139    for i in range(80): 
     140        time.sleep(.05) 
     141        if not ffmpeg.poll() == None: 
     142            break 
     143     
     144    if ffmpeg.poll() == None: 
     145        kill(ffmpeg.pid) 
     146        info_cache[inFile] = (None, None, None, None, None) 
     147        return None, None, None, None, None 
     148 
    133149    output = ffmpeg.stderr.read() 
     150 
    134151    durre = re.compile(r'.*Duration: (.{2}):(.{2}):(.{2})\.(.),') 
    135152    d = durre.search(output) 
     
    140157        codec = x.group(1) 
    141158    else: 
     159        info_cache[inFile] = (None, None, None, None, None) 
    142160        return None, None, None, None, None 
    143161 
     
    148166        height = int(x.group(2)) 
    149167    else: 
     168        info_cache[inFile] = (None, None, None, None, None) 
    150169        return None, None, None, None, None 
    151170 
     
    155174        fps = x.group(1) 
    156175    else: 
    157         return None, None, None, None, None 
     176        info_cache[inFile] = (None, None, None, None, None) 
     177        return None, None, None, None, None 
     178 
     179    rezre = re.compile(r'.*film source: (\d+).*') 
     180    x = rezre.search(output.lower()) 
     181    if x: 
     182        fps = x.group(1) 
    158183 
    159184    millisecs = ((int(d.group(1))*3600) + (int(d.group(2))*60) + int(d.group(3)))*1000 + (int(d.group(4))*100) 
     185    info_cache[inFile] = (codec, width, height, fps, millisecs) 
    160186    return codec, width, height, fps, millisecs 
    161187        
     
    166192        return False 
    167193 
     194def kill(pid): 
     195    if mswindows: 
     196        win32kill(pid) 
     197    else: 
     198        import os, signal 
     199        os.kill(pid, signal.SIGKILL) 
     200 
    168201def win32kill(pid): 
    169202        import ctypes