From 8cf4defe8250d6c7825262329d83c9478360df1b Mon Sep 17 00:00:00 2001 From: lucas_nz Date: Sat, 4 Jan 2014 20:57:28 +1300 Subject: [PATCH] added subtitle support for ass and srt files using a new meta data element subtitles. e.g. subtitles: subtitles=subtitles.srt subtitles: ass=subtitles.ass --- plugins/video/transcode.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/plugins/video/transcode.py b/plugins/video/transcode.py index ec08d43..2457f97 100644 --- a/plugins/video/transcode.py +++ b/plugins/video/transcode.py @@ -94,7 +94,7 @@ def transcode(isQuery, inFile, outFile, tsn='', mime='', thead=''): else: cmd = [ffmpeg_path, '-i', fname] + cmd_string.split() ffmpeg = subprocess.Popen(cmd, bufsize=(512 * 1024), - stdout=subprocess.PIPE) + stdout=subprocess.PIPE, cwd=os.path.split(inFile)[0]) if cmd: debug('transcoding to tivo model ' + tsn[:3] + ' using ffmpeg command:') @@ -320,6 +320,10 @@ def select_videofps(inFile, tsn): def select_videocodec(inFile, tsn, mime=''): vInfo = video_info(inFile) + subtitles = vInfo.get('subtitles') + vf = '' + if subtitles: + vf = '-vf %s ' % subtitles if tivo_compatible_video(vInfo, tsn, mime)[0]: codec = 'copy' if (mime == 'video/x-tivo-mpeg-ts' and @@ -327,7 +331,7 @@ def select_videocodec(inFile, tsn, mime=''): codec += ' -bsf h264_mp4toannexb' else: codec = 'mpeg2video' # default - return '-vcodec ' + codec + return vf + '-vcodec ' + codec def select_videobr(inFile, tsn, mime=''): return '-b ' + str(select_videostr(inFile, tsn, mime) / 1000) + 'k' @@ -538,6 +542,11 @@ def select_aspect(inFile, tsn = ''): def tivo_compatible_video(vInfo, tsn, mime=''): message = (True, '') while True: + if vInfo.get('subtitles'): + message = (False, 'Subtitle hard-coding requires reencoding') + + break + codec = vInfo.get('vCodec', '') if mime == 'video/mp4': if codec != 'h264': @@ -982,6 +991,8 @@ def video_info(inFile, cache=True): vInfo[key.replace('Override_', '')] = int(data[key]) else: vInfo[key.replace('Override_', '')] = data[key] + elif key.lower() == 'subtitles': + vInfo['subtitles'] = data[key] if cache: info_cache[inFile] = (mtime, vInfo) -- 2.11.4.GIT