From 15ba9d416ada94931ef76ed035ee3767c9e73ebb Mon Sep 17 00:00:00 2001 From: Michael Krebs Date: Sat, 8 Aug 2020 07:16:56 -0700 Subject: [PATCH 1/2] Fix size estimation for MPEG-4 transport streams. This can reduce the number of programs that TiVo deletes upon their transfer. TiVo requests the expected transfer size *before* it tries to actually transfer a file, and it does not send a desired MIME type along with that request. When that MIME type is missing and the vCodec is "h264", tivo_compatible_video() returned false -- which resulted in __est_size() estimating the size as if it will transcode the video. And, without also having this fix in tivo_compatible_container(), that estimated size can be 2-3 times too big because the bitrate may not reflect what's in the actual file. --- plugins/video/transcode.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugins/video/transcode.py b/plugins/video/transcode.py index 09599e76..5e09a221 100644 --- a/plugins/video/transcode.py +++ b/plugins/video/transcode.py @@ -534,6 +534,11 @@ def tivo_compatible_video(vInfo, tsn, mime=''): message = (False, 'vCodec %s not compatible' % codec) break + # Some requests from the TiVo don't have an associated MIME type. In + # that case assume an 'h264' codec is going to be compatible. + if mime == '' and codec == 'h264': + logger.debug('Assuming vCodec %s will be compatible', codec) + break if codec not in ('mpeg2video', 'mpeg1video'): message = (False, 'vCodec %s not compatible' % codec) @@ -613,6 +618,11 @@ def tivo_compatible_audio(vInfo, inFile, tsn, mime=''): def tivo_compatible_container(vInfo, inFile, mime=''): message = (True, '') container = vInfo.get('container', '') + # Some requests from the TiVo don't have an associated MIME type. In + # that case assume a 'mpegts' container is going to be compatible. + if (mime == '' and container == 'mpegts'): + logger.debug('Assuming container %s will be compatible', container) + return message if ((mime == 'video/x-tivo-mpeg-ts' and container != 'mpegts') or (mime in ['video/x-tivo-mpeg', 'video/mpeg', ''] and (container != 'mpeg' or vInfo['vCodec'] == 'mpeg1video'))): From db5465fccc626e6414c411627b7da09d797bd4b3 Mon Sep 17 00:00:00 2001 From: Michael Krebs Date: Sat, 8 Aug 2020 07:54:05 -0700 Subject: [PATCH 2/2] Per wmcbrine's suggestion, check if a TiVo supports transport streams in my latest change. --- plugins/video/transcode.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/video/transcode.py b/plugins/video/transcode.py index 5e09a221..8cb6ba5a 100644 --- a/plugins/video/transcode.py +++ b/plugins/video/transcode.py @@ -536,7 +536,7 @@ def tivo_compatible_video(vInfo, tsn, mime=''): break # Some requests from the TiVo don't have an associated MIME type. In # that case assume an 'h264' codec is going to be compatible. - if mime == '' and codec == 'h264': + if config.is_ts_capable(tsn) and mime == '' and codec == 'h264': logger.debug('Assuming vCodec %s will be compatible', codec) break @@ -615,12 +615,12 @@ def tivo_compatible_audio(vInfo, inFile, tsn, mime=''): return message -def tivo_compatible_container(vInfo, inFile, mime=''): +def tivo_compatible_container(vInfo, inFile, tsn, mime=''): message = (True, '') container = vInfo.get('container', '') # Some requests from the TiVo don't have an associated MIME type. In # that case assume a 'mpegts' container is going to be compatible. - if (mime == '' and container == 'mpegts'): + if (config.is_ts_capable(tsn) and mime == '' and container == 'mpegts'): logger.debug('Assuming container %s will be compatible', container) return message if ((mime == 'video/x-tivo-mpeg-ts' and container != 'mpegts') or @@ -650,7 +650,7 @@ def tivo_compatible(inFile, tsn='', mime=''): message = amessage break - cmessage = tivo_compatible_container(vInfo, inFile, mime) + cmessage = tivo_compatible_container(vInfo, inFile, tsn, mime) if not cmessage[0]: message = cmessage