From 179402fc8314937e41ca6f971dfd38847c2d2059 Mon Sep 17 00:00:00 2001 From: Jason Michalski Date: Wed, 7 Nov 2007 01:46:53 +0000 Subject: [PATCH] Added support for ffmpeg command templates Moved dist config --- Config.py | 15 ++++++++++++++- plugins/video/transcode.py | 33 ++++++++++++++------------------- pyTivo.conf => pyTivo.conf.dist | 6 ++++++ 3 files changed, 34 insertions(+), 20 deletions(-) rename pyTivo.conf => pyTivo.conf.dist (71%) diff --git a/Config.py b/Config.py index aaca46b..a1a7d85 100644 --- a/Config.py +++ b/Config.py @@ -40,6 +40,18 @@ def getDebug(): def get(section, key): return config.get(section, key) +def getFFMPEGTemplate(tsn): + if tsn and config.has_section('_tivo_' + tsn): + try: + return config.get('_tivo_' + tsn, 'ffmpeg_prams', raw = True) + except NoOptionError: + pass + + try: + return config.get('Server', 'ffmpeg_prams', raw = True) + except NoOptionError: #default + return '-i %(in_file)s -vcodec mpeg2video -r 29.97 -b %(video_br)s -maxrate %(max_video_br)s -bufsize %(buff_size)s %(aspect_ratio)s -comment pyTivo.py -ac 2 -ab %(audio_br)s -ar 44100 -f vob -' + def getValidWidths(): return [1440, 720, 704, 544, 480, 352] @@ -63,7 +75,8 @@ def nearestTivoWidth(width): def getTivoHeight(tsn): if tsn and config.has_section('_tivo_' + tsn): try: - return config.get('_tivo_' + tsn, 'height_br') + height = int(config.get('_tivo_' + tsn, 'height_br')) + return nearest(height, getValidHeights()) except NoOptionError: pass diff --git a/plugins/video/transcode.py b/plugins/video/transcode.py index 95ff58f..c1bc638 100644 --- a/plugins/video/transcode.py +++ b/plugins/video/transcode.py @@ -44,25 +44,20 @@ def output_video(inFile, outFile, tsn=''): transcode(inFile, outFile, tsn) def transcode(inFile, outFile, tsn=''): - audio_br = Config.getAudioBR(tsn) - video_br = Config.getVideoBR(tsn) - - cmd = [ FFMPEG, - '-i', inFile, - '-vcodec', 'mpeg2video', - '-r', '29.97', - '-b', video_br, - '-maxrate', MAX_VIDEO_BR, - '-bufsize', BUFF_SIZE - ] + select_aspect(inFile, tsn) + [ - '-comment', 'pyTivo.py', - '-ac', '2', - '-ab', audio_br, - '-ar', '44100', - '-f', 'vob', - '-' ] - - debug_write(['transcode: ffmpeg command is ', ''.join(cmd), '\n']) + + settings = {} + settings['audio_br'] = Config.getAudioBR(tsn) + settings['video_br'] = Config.getVideoBR(tsn) + settings['in_file'] = inFile + settings['max_video_br'] = MAX_VIDEO_BR + settings['buff_size'] = BUFF_SIZE + settings['aspect_ratio'] = ' '.join(select_aspect(inFile, tsn)) + + cmd_string = Config.getFFMPEGTemplate(tsn) % settings + + cmd = [FFMPEG] + cmd_string.split() + + debug_write(['transcode: ffmpeg command is ', ' '.join(cmd), '\n']) ffmpeg = subprocess.Popen(cmd, stdout=subprocess.PIPE) try: shutil.copyfileobj(ffmpeg.stdout, outFile) diff --git a/pyTivo.conf b/pyTivo.conf.dist similarity index 71% rename from pyTivo.conf rename to pyTivo.conf.dist index 5c52bd6..012a6fe 100644 --- a/pyTivo.conf +++ b/pyTivo.conf.dist @@ -27,6 +27,7 @@ ffmpeg=/usr/bin/ffmpeg #Valid: 720, 704, 544, 480, 352 #width=1440 #height=720 +ffmpeg_prams=-i %(in_file)s -vcodec mpeg2video -r 29.97 -b %(video_br)s -maxrate %(max_video_br)s -bufsize %(buff_size)s %(aspect_ratio)s -comment pyTivo.py -ac 2 -ab %(audio_br)s -ar 44100 -f vob - ##Per tivo options # section named _tivo_TSN with the tsn in all caps @@ -34,6 +35,11 @@ ffmpeg=/usr/bin/ffmpeg #If you want to use 16:9 or 4:3 on this tivo #aspect169=true +#width=1440 +#height=720 +#audio_br=320K +#video_br=12Mi +#ffmpeg_prams=-i %(in_file)s -vcodec mpeg2video -r 29.97 -b %(video_br)s -maxrate %(max_video_br)s -bufsize %(buff_size)s %(aspect_ratio)s -comment pyTivo.py -ac 2 -ab %(audio_br)s -ar 44100 -f vob - #audio_br=320K #video_br=12Mi -- 2.11.4.GIT