Changeset d4def89a0aa71b415b52c96b310cbe0802aecc00

Show
Ignore:
Timestamp:
02/07/08 19:14:10 (1 year ago)
Author:
wgw <tjm1100@gmail.com>
git-committer:
wgw <tjm1100@gmail.com> 1202433250 -0600
git-parent:

[a1e71c3240d1a9db343a7a25b7f71146ea1115ef], [8edc3cb0c223ad8727c31e51d88c4199b382bdcb]

git-author:
wgw <tjm1100@gmail.com> 1202433250 -0600
Message:

Merge branch 'master' into subfolders-8.3

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • config.py

    ra1e71c3 rd4def89  
    9999        return config.get('Server', 'ffmpeg_prams', raw=True) 
    100100    except NoOptionError: #default 
    101         return '-vcodec mpeg2video -r 29.97 -b %(video_br)s -maxrate %(max_video_br)s -bufsize %(buff_size)s %(aspect_ratio)s -comment pyTivo.py %(audio_codec)s -ab %(audio_br)s -f vob -' 
     101        return '-vcodec mpeg2video -r 29.97 -b %(video_br)s -maxrate %(max_video_br)s -bufsize %(buff_size)s %(aspect_ratio)s -comment pyTivo.py %(audio_codec)s -ab %(audio_br)s -copyts -f vob -' 
    102102 
    103103def isHDtivo(tsn):  # tsn's of High Definition Tivo's 
  • plugins/video/transcode.py

    r8c44a00 r8edc3cb  
    44info_cache = lrucache.LRUCache(1000) 
    55 
    6  
    76debug = config.getDebug() 
    87BUFF_SIZE = config.getBuffSize() 
    9  
    108FFMPEG = config.get('Server', 'ffmpeg') 
     9videotest = os.path.join(os.path.dirname(__file__), 'videotest.mpg') 
    1110 
    1211def debug_write(data): 
     
    3231if mswindows: 
    3332    patchSubprocess() 
    34          
     33 
    3534def output_video(inFile, outFile, tsn=''): 
    3635    if tivo_compatable(inFile, tsn): 
     
    4746    settings = {} 
    4847    settings['audio_br'] = config.getAudioBR(tsn) 
    49     settings['audio_codec'] = select_audiocodec(tsn) 
     48    settings['audio_codec'] = select_audiocodec(inFile, tsn) 
    5049    settings['video_br'] = config.getVideoBR(tsn) 
    5150    settings['max_video_br'] = config.getMaxVideoBR() 
     
    6463        kill(ffmpeg.pid) 
    6564 
    66 def select_audiocodec(tsn = ''): 
    67     #check for HD tivo and return compatible audio parameters 
     65def select_audiocodec(inFile, tsn = ''): 
     66    # Default, compatible with all TiVo's 
     67    codec = '-acodec mp2 -ac 2 -ar 44100' 
     68    type, width, height, fps, millisecs, kbps, akbps, acodec =  video_info(inFile) 
     69    if akbps == None and acodec in ('liba52', 'mp2'): 
     70        cmd_string = '-y -vcodec mpeg2video -r 29.97 -b 1000k -acodec copy -t 00:00:01 -f vob -' 
     71        if video_check(inFile, cmd_string): 
     72            type, width, height, fps, millisecs, kbps, akbps, acodec =  video_info(videotest) 
    6873    if config.isHDtivo(tsn): 
    69         return '-acodec ac3 -ar 48000' 
    70     else: 
    71         return '-acodec mp2 -ac 2 -ar 44100' 
     74        # Is HD Tivo, use ac3 
     75        codec = '-acodec ac3 -ar 48000' 
     76        if acodec == 'liba52' and not akbps == None and \ 
     77            int(akbps) <= config.getMaxAudioBR(tsn): 
     78            # compatible codec and bitrate, do not reencode audio 
     79            codec = '-acodec copy' 
     80    if acodec == 'mp2' and not akbps == None and \ 
     81        int(akbps) <= config.getMaxAudioBR(tsn): 
     82        # compatible codec and bitrate, do not reencode audio 
     83        codec = '-acodec copy' 
     84    return codec 
    7285 
    7386def select_aspect(inFile, tsn = ''): 
    7487    TIVO_WIDTH = config.getTivoWidth(tsn) 
    7588    TIVO_HEIGHT = config.getTivoHeight(tsn) 
    76      
    77     type, width, height, fps, millisecs, kbps, akbps =  video_info(inFile) 
     89 
     90    type, width, height, fps, millisecs, kbps, akbps, acodec =  video_info(inFile) 
    7891 
    7992    debug_write(['tsn:', tsn, '\n']) 
     
    220233def tivo_compatable(inFile, tsn = ''): 
    221234    supportedModes = [[720, 480], [704, 480], [544, 480], [480, 480], [352, 480]] 
    222     type, width, height, fps, millisecs, kbps, akbps =  video_info(inFile) 
    223     #print type, width, height, fps, millisecs, kbps, akbps 
     235    type, width, height, fps, millisecs, kbps, akbps, acodec =  video_info(inFile) 
     236    #print type, width, height, fps, millisecs, kbps, akbps, acodec 
    224237 
    225238    if (inFile[-5:]).lower() == '.tivo': 
     
    263276def video_info(inFile): 
    264277    mtime = os.stat(inFile).st_mtime 
    265     if inFile in info_cache and info_cache[inFile][0] == mtime: 
    266         debug_write(['video_info: ', inFile, ' cache hit!', '\n']) 
    267         return info_cache[inFile][1] 
     278    if inFile != videotest: 
     279        if inFile in info_cache and info_cache[inFile][0] == mtime: 
     280            debug_write(['video_info: ', inFile, ' cache hit!', '\n']) 
     281            return info_cache[inFile][1] 
    268282 
    269283    if (inFile[-5:]).lower() == '.tivo': 
    270         info_cache[inFile] = (mtime, (True, True, True, True, True, True, True)) 
     284        info_cache[inFile] = (mtime, (True, True, True, True, True, True, True, True)) 
    271285        debug_write(['video_info: ', inFile, ' ends in .tivo.\n']) 
    272         return True, True, True, True, True, True, True 
     286        return True, True, True, True, True, True, True, True 
    273287 
    274288    cmd = [FFMPEG, '-i', inFile ]  
     
    283297    if ffmpeg.poll() == None: 
    284298        kill(ffmpeg.pid) 
    285         info_cache[inFile] = (mtime, (None, None, None, None, None, None, None)) 
    286         return None, None, None, None, None, None, None 
     299        info_cache[inFile] = (mtime, (None, None, None, None, None, None, None, None)) 
     300        return None, None, None, None, None, None, None, None 
    287301 
    288302    output = ffmpeg.stderr.read() 
     
    294308        codec = x.group(1) 
    295309    else: 
    296         info_cache[inFile] = (mtime, (None, None, None, None, None, None, None)) 
     310        info_cache[inFile] = (mtime, (None, None, None, None, None, None, None, None)) 
    297311        debug_write(['video_info: failed at codec\n']) 
    298         return None, None, None, None, None, None, None 
     312        return None, None, None, None, None, None, None, None 
    299313 
    300314    rezre = re.compile(r'.*Video: .+, (\d+)x(\d+)[, ].*') 
     
    304318        height = int(x.group(2)) 
    305319    else: 
    306         info_cache[inFile] = (mtime, (None, None, None, None, None, None, None)) 
     320        info_cache[inFile] = (mtime, (None, None, None, None, None, None, None, None)) 
    307321        debug_write(['video_info: failed at width/height\n']) 
    308         return None, None, None, None, None, None, None 
     322        return None, None, None, None, None, None, None, None 
    309323 
    310324    rezre = re.compile(r'.*Video: .+, (.+) (?:fps|tb).*') 
     
    313327        fps = x.group(1) 
    314328    else: 
    315         info_cache[inFile] = (mtime, (None, None, None, None, None, None, None)) 
     329        info_cache[inFile] = (mtime, (None, None, None, None, None, None, None, None)) 
    316330        debug_write(['video_info: failed at fps\n']) 
    317         return None, None, None, None, None, None, None 
     331        return None, None, None, None, None, None, None, None 
    318332 
    319333    # Allow override only if it is mpeg2 and frame rate was doubled to 59.94 
     
    358372        debug_write(['video_info: failed at akbps\n']) 
    359373 
    360     info_cache[inFile] = (mtime, (codec, width, height, fps, millisecs, kbps, akbps)) 
    361     debug_write(['video_info: Codec=', codec, ' width=', width, ' height=', height, ' fps=', fps, ' millisecs=', millisecs, ' kbps=', kbps, ' akbps=', akbps, '\n']) 
    362     return codec, width, height, fps, millisecs, kbps, akbps 
     374    #get audio codec of source for tivo compatibility test. 
     375    rezre = re.compile(r'.*Audio: ([^,]+),.*') 
     376    x = rezre.search(output) 
     377    if x: 
     378        acodec = x.group(1) 
     379    else: 
     380        acodec = None 
     381        debug_write(['video_info: failed at acodec\n']) 
     382 
     383    info_cache[inFile] = (mtime, (codec, width, height, fps, millisecs, kbps, akbps, acodec)) 
     384    debug_write(['video_info: Codec=', codec, ' width=', width, ' height=', height, ' fps=', fps, ' millisecs=', millisecs, ' kbps=', kbps, ' akbps=', akbps, ' acodec=', acodec, '\n']) 
     385    return codec, width, height, fps, millisecs, kbps, akbps, acodec 
     386 
     387def video_check(inFile, cmd_string): 
     388    cmd = [FFMPEG, '-i', inFile] + cmd_string.split() 
     389    ffmpeg = subprocess.Popen(cmd, stdout=subprocess.PIPE) 
     390    try: 
     391        shutil.copyfileobj(ffmpeg.stdout, open(videotest, 'wb')) 
     392        return True 
     393    except: 
     394        kill(ffmpeg.pid) 
     395        return False 
    363396 
    364397def supported_format(inFile): 
  • pyTivo.conf.dist

    r4fab8f8 r8edc3cb  
    4343#width=1280 
    4444#height=720 
    45  
    46 #ffmpeg_prams=-vcodec mpeg2video -r 29.97 -b %(video_br)s -maxrate %(max_video_br)s -bufsize %(buff_size)s %(aspect_ratio)s -comment pyTivo.py %(audio_codec)s -ab %(audio_br)s -f vob - 
     45#ffmpeg_prams=-vcodec mpeg2video -r 29.97 -b %(video_br)s -maxrate %(max_video_br)s -bufsize %(buff_size)s %(aspect_ratio)s -comment pyTivo.py %(audio_codec)s -ab %(audio_br)s -copyts -f vob - 
    4746 
    4847# Per tivo options 
     
    5756#audio_br=320K 
    5857#video_br=12Mi 
    59  
    60 #ffmpeg_prams=-vcodec mpeg2video -r 29.97 -b %(video_br)s -maxrate %(max_video_br)s -bufsize %(buff_size)s %(aspect_ratio)s -comment pyTivo.py %(audio_codec)s -ab %(audio_br)s -f vob - 
     58#ffmpeg_prams=-vcodec mpeg2video -r 29.97 -b %(video_br)s -maxrate %(max_video_br)s -bufsize %(buff_size)s %(aspect_ratio)s -comment pyTivo.py %(audio_codec)s -ab %(audio_br)s -copyts -f vob - 
    6159 
    6260[MyMovies]