Changeset dec540c029571cc494be31e4767d41b0bf7fe165

Show
Ignore:
Timestamp:
03/20/08 22:09:39 (10 months ago)
Author:
wgw <tjm1100@gmail.com>
git-committer:
wgw <tjm1100@gmail.com> 1206068979 -0500
git-parent:

[644796c86169fd365a409e91f3c2e71fd7c28f31]

git-author:
wgw <tjm1100@gmail.com> 1206068979 -0500
Message:

Pixel Aspect Ratio Patch by carl edman

If transcoding to an S3 is required, PAR is changed to 1:1 if
ffmpeg reports the PAR correctly and PAR is not already 1:1.

This is essentially the foundation of the PAR patch
submitted by Carl Edman. I have removed the config setting
and tivo_compatible par 1:1 check because I want to change the
functionality to work a bit differently than submitted.

Files:

Legend:

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

    r94ce527 rdec540c  
    1 import subprocess, shutil, os, re, sys, ConfigParser, time, lrucache 
     1import subprocess, shutil, os, re, sys, ConfigParser, time, lrucache, math 
    22import config 
    33from debug import debug_write, fn_attr 
     
    6565    codec = 'ac3' 
    6666    if config.getAudioCodec(tsn) == None: 
    67         type, width, height, fps, millisecs, kbps, akbps, acodec, afreq =  video_info(inFile) 
     67        type, width, height, fps, millisecs, kbps, akbps, acodec, afreq, vpar =  video_info(inFile) 
    6868        if acodec in ('ac3', 'liba52', 'mp2'): 
    6969            if akbps == None: 
    7070                cmd_string = '-y -vcodec mpeg2video -r 29.97 -b 1000k -acodec copy -t 00:00:01 -f vob -' 
    7171                if video_check(inFile, cmd_string): 
    72                     type, width, height, fps, millisecs, kbps, akbps, acodec, afreq =  video_info(videotest) 
     72                    type, width, height, fps, millisecs, kbps, akbps, acodec, afreq, vpar =  video_info(videotest) 
    7373            if not akbps == None and int(akbps) <= config.getMaxAudioBR(tsn): 
    7474                # compatible codec and bitrate, do not reencode audio 
     
    8080def select_audiofr(inFile, tsn): 
    8181    freq = '48000'  #default 
    82     type, width, height, fps, millisecs, kbps, akbps, acodec, afreq =  video_info(inFile) 
     82    type, width, height, fps, millisecs, kbps, akbps, acodec, afreq, vpar =  video_info(inFile) 
    8383    if not afreq == None and afreq in ('44100', '48000'): 
    8484        # compatible frequency 
     
    134134    TIVO_HEIGHT = config.getTivoHeight(tsn) 
    135135 
    136     type, width, height, fps, millisecs, kbps, akbps, acodec, afreq =  video_info(inFile) 
     136    type, width, height, fps, millisecs, kbps, akbps, acodec, afreq, vpar =  video_info(inFile) 
    137137 
    138138    debug_write(__name__, fn_attr(), ['tsn:', tsn]) 
     
    164164    
    165165    if config.isHDtivo(tsn) and height <= TIVO_HEIGHT and not optres: 
    166         return [] #pass all resolutions to S3/HD, except heights greater than conf height 
    167                 # else, optres is enabled and resizes SD video to the "S2" standard on S3/HD. 
     166        #pass all resolutions to S3, except heights greater than conf height 
     167        if not vpar == None: 
     168            # adjust for pixel aspect ratio, if set, because TiVo expects square pixels 
     169            if vpar<1.0: 
     170                return ['-s', str(width) + 'x' + str(int(math.ceil(height/vpar)))] 
     171            elif vpar>1.0: 
     172                # FFMPEG expects width to be a multiple of two 
     173                return ['-s', str(int(math.ceil(width*vpar/2.0)*2)) + 'x' + str(height)] 
     174        return [] 
     175    # else, optres is enabled and resizes video to the "S2" standard. 
    168176    elif (rwidth, rheight) in [(4, 3), (10, 11), (15, 11), (59, 54), (59, 72), (59, 36), (59, 54)]: 
    169177        debug_write(__name__, fn_attr(), ['File is within 4:3 list.']) 
     
    279287def tivo_compatable(inFile, tsn = ''): 
    280288    supportedModes = [[720, 480], [704, 480], [544, 480], [480, 480], [352, 480]] 
    281     type, width, height, fps, millisecs, kbps, akbps, acodec, afreq =  video_info(inFile) 
     289    type, width, height, fps, millisecs, kbps, akbps, acodec, afreq, vpar =  video_info(inFile) 
    282290    #print type, width, height, fps, millisecs, kbps, akbps, acodec 
    283291 
     
    340348 
    341349    if (inFile[-5:]).lower() == '.tivo': 
    342         info_cache[inFile] = (mtime, (True, True, True, True, True, True, True, True, True)) 
     350        info_cache[inFile] = (mtime, (True, True, True, True, True, True, True, True, True, True)) 
    343351        debug_write(__name__, fn_attr(), ['VALID, ends in .tivo.', inFile]) 
    344         return True, True, True, True, True, True, True, True, True 
     352        return True, True, True, True, True, True, True, True, True, True 
    345353 
    346354    cmd = [ffmpeg_path(), '-i', inFile ]  
     
    355363    if ffmpeg.poll() == None: 
    356364        kill(ffmpeg.pid) 
    357         info_cache[inFile] = (mtime, (None, None, None, None, None, None, None, None, None)) 
    358         return None, None, None, None, None, None, None, None, None 
     365        info_cache[inFile] = (mtime, (None, None, None, None, None, None, None, None, None, None)) 
     366        return None, None, None, None, None, None, None, None, None, None 
    359367 
    360368    output = ffmpeg.stderr.read() 
     
    366374        codec = x.group(1) 
    367375    else: 
    368         info_cache[inFile] = (mtime, (None, None, None, None, None, None, None, None, None)) 
     376        info_cache[inFile] = (mtime, (None, None, None, None, None, None, None, None, None, None)) 
    369377        debug_write(__name__, fn_attr(), ['failed at video codec']) 
    370         return None, None, None, None, None, None, None, None, None 
     378        return None, None, None, None, None, None, None, None, None, None 
    371379 
    372380    rezre = re.compile(r'.*Video: .+, (\d+)x(\d+)[, ].*') 
     
    376384        height = int(x.group(2)) 
    377385    else: 
    378         info_cache[inFile] = (mtime, (None, None, None, None, None, None, None, None, None)) 
     386        info_cache[inFile] = (mtime, (None, None, None, None, None, None, None, None, None, None)) 
    379387        debug_write(__name__, fn_attr(), ['failed at width/height']) 
    380         return None, None, None, None, None, None, None, None, None 
     388        return None, None, None, None, None, None, None, None, None, None 
    381389 
    382390    rezre = re.compile(r'.*Video: .+, (.+) (?:fps|tb).*') 
     
    385393        fps = x.group(1) 
    386394    else: 
    387         info_cache[inFile] = (mtime, (None, None, None, None, None, None, None, None, None)) 
     395        info_cache[inFile] = (mtime, (None, None, None, None, None, None, None, None, None, None)) 
    388396        debug_write(__name__, fn_attr(), ['failed at fps']) 
    389         return None, None, None, None, None, None, None, None, None 
     397        return None, None, None, None, None, None, None, None, None, None 
    390398 
    391399    # Allow override only if it is mpeg2 and frame rate was doubled to 59.94 
     
    448456        debug_write(__name__, fn_attr(), ['failed at afreq']) 
    449457 
    450     info_cache[inFile] = (mtime, (codec, width, height, fps, millisecs, kbps, akbps, acodec, afreq)) 
    451     debug_write(__name__, fn_attr(), ['Codec=', codec, ' width=', width, ' height=', height, ' fps=', fps, ' millisecs=', millisecs, ' kbps=', kbps, ' akbps=', akbps, ' acodec=', acodec, ' afreq=', afreq]) 
    452     return codec, width, height, fps, millisecs, kbps, akbps, acodec, afreq 
     458    #get par. 
     459    rezre = re.compile(r'.*Video: .+PAR ([0-9]+):([0-9]+) DAR [0-9:]+.*') 
     460    x = rezre.search(output) 
     461    if x and x.group(1)!="0" and x.group(2)!="0": 
     462        vpar = float(x.group(1))/float(x.group(2)) 
     463    else: 
     464        vpar = None 
     465  
     466    info_cache[inFile] = (mtime, (codec, width, height, fps, millisecs, kbps, akbps, acodec, afreq, vpar)) 
     467    debug_write(__name__, fn_attr(), ['Codec=', codec, ' width=', width, ' height=', height, ' fps=', fps, ' millisecs=', millisecs, ' kbps=', kbps, ' akbps=', akbps, ' acodec=', acodec, ' afreq=', afreq, ' par=', vpar]) 
     468    return codec, width, height, fps, millisecs, kbps, akbps, acodec, afreq, vpar 
    453469 
    454470def video_check(inFile, cmd_string):