Changeset 8edc3cb0c223ad8727c31e51d88c4199b382bdcb
- Timestamp:
- 02/07/08 18:33:25 (1 year ago)
- git-parent:
[d66ab95ed7b0ed44eb94f30e0ae9945acc2b4d9a], [6fa0a24470349d9df18882dd65b57570e4149335]
- Files:
-
- config.py (modified) (1 diff)
- plugins/video/transcode.py (modified) (11 diffs)
- pyTivo.conf.dist (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
config.py
rd66ab95 r8edc3cb 89 89 return config.get('Server', 'ffmpeg_prams', raw=True) 90 90 except NoOptionError: #default 91 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 -'91 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 -' 92 92 93 93 def isHDtivo(tsn): # tsn's of High Definition Tivo's plugins/video/transcode.py
r8c44a00 r8edc3cb 4 4 info_cache = lrucache.LRUCache(1000) 5 5 6 7 6 debug = config.getDebug() 8 7 BUFF_SIZE = config.getBuffSize() 9 10 8 FFMPEG = config.get('Server', 'ffmpeg') 9 videotest = os.path.join(os.path.dirname(__file__), 'videotest.mpg') 11 10 12 11 def debug_write(data): … … 32 31 if mswindows: 33 32 patchSubprocess() 34 33 35 34 def output_video(inFile, outFile, tsn=''): 36 35 if tivo_compatable(inFile, tsn): … … 47 46 settings = {} 48 47 settings['audio_br'] = config.getAudioBR(tsn) 49 settings['audio_codec'] = select_audiocodec( tsn)48 settings['audio_codec'] = select_audiocodec(inFile, tsn) 50 49 settings['video_br'] = config.getVideoBR(tsn) 51 50 settings['max_video_br'] = config.getMaxVideoBR() … … 64 63 kill(ffmpeg.pid) 65 64 66 def select_audiocodec(tsn = ''): 67 #check for HD tivo and return compatible audio parameters 65 def 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) 68 73 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 72 85 73 86 def select_aspect(inFile, tsn = ''): 74 87 TIVO_WIDTH = config.getTivoWidth(tsn) 75 88 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) 78 91 79 92 debug_write(['tsn:', tsn, '\n']) … … 220 233 def tivo_compatable(inFile, tsn = ''): 221 234 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 224 237 225 238 if (inFile[-5:]).lower() == '.tivo': … … 263 276 def video_info(inFile): 264 277 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] 268 282 269 283 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)) 271 285 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 273 287 274 288 cmd = [FFMPEG, '-i', inFile ] … … 283 297 if ffmpeg.poll() == None: 284 298 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 287 301 288 302 output = ffmpeg.stderr.read() … … 294 308 codec = x.group(1) 295 309 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)) 297 311 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 299 313 300 314 rezre = re.compile(r'.*Video: .+, (\d+)x(\d+)[, ].*') … … 304 318 height = int(x.group(2)) 305 319 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)) 307 321 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 309 323 310 324 rezre = re.compile(r'.*Video: .+, (.+) (?:fps|tb).*') … … 313 327 fps = x.group(1) 314 328 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)) 316 330 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 318 332 319 333 # Allow override only if it is mpeg2 and frame rate was doubled to 59.94 … … 358 372 debug_write(['video_info: failed at akbps\n']) 359 373 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 387 def 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 363 396 364 397 def supported_format(inFile): pyTivo.conf.dist
r4fab8f8 r8edc3cb 43 43 #width=1280 44 44 #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 - 47 46 48 47 # Per tivo options … … 57 56 #audio_br=320K 58 57 #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 - 61 59 62 60 [MyMovies]
