use constant from math module

This commit is contained in:
Lesmiscore 2022-06-11 16:13:21 +09:00
parent d4c52a28af
commit 3fac07c04a
No known key found for this signature in database
GPG Key ID: 0EC2B52CF86236FF

View File

@ -1,3 +1,5 @@
from math import inf
from .common import PostProcessor from .common import PostProcessor
from ..utils import prepend_extension from ..utils import prepend_extension
@ -20,7 +22,7 @@ def available(self):
def analyze_mp4(self, filepath): def analyze_mp4(self, filepath):
""" returns (baseMediaDecodeTime offset, sample duration cutoff) """ """ returns (baseMediaDecodeTime offset, sample duration cutoff) """
smallest_bmdt, known_sdur = float('inf'), set() smallest_bmdt, known_sdur = inf, set()
with open(filepath, 'rb') as r: with open(filepath, 'rb') as r:
for btype, content in parse_mp4_boxes(r): for btype, content in parse_mp4_boxes(r):
if btype == 'tfdt': if btype == 'tfdt':
@ -55,7 +57,7 @@ def analyze_mp4(self, filepath):
if len(set(x for x in known_sdur if x > sdur_cutoff)) < 3: if len(set(x for x in known_sdur if x > sdur_cutoff)) < 3:
break break
else: else:
sdur_cutoff = float('inf') sdur_cutoff = inf
return smallest_bmdt, sdur_cutoff return smallest_bmdt, sdur_cutoff
@ -107,12 +109,12 @@ def run(self, information):
self.write_debug('Analyzing MP4') self.write_debug('Analyzing MP4')
bmdt_offset, sdur_cutoff = self.analyze_mp4(filename) bmdt_offset, sdur_cutoff = self.analyze_mp4(filename)
working = float('inf') not in (bmdt_offset, sdur_cutoff) working = inf not in (bmdt_offset, sdur_cutoff)
# if any of them are Infinity, there's something wrong # if any of them are Infinity, there's something wrong
# baseMediaDecodeTime = to shift PTS # baseMediaDecodeTime = to shift PTS
# sample duration = to define duration in each segment # sample duration = to define duration in each segment
self.write_debug(f'baseMediaDecodeTime offset = {bmdt_offset}, sample duration cutoff = {sdur_cutoff}') self.write_debug(f'baseMediaDecodeTime offset = {bmdt_offset}, sample duration cutoff = {sdur_cutoff}')
if bmdt_offset == float('inf'): if bmdt_offset == inf:
# safeguard # safeguard
bmdt_offset = 0 bmdt_offset = 0
self.modify_mp4(filename, temp_filename, bmdt_offset, sdur_cutoff) self.modify_mp4(filename, temp_filename, bmdt_offset, sdur_cutoff)