|
|
@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
|
|
from math import inf
|
|
|
|
from math import inf
|
|
|
|
|
|
|
|
|
|
|
|
from .common import PostProcessor
|
|
|
|
from .common import PostProcessor
|
|
|
@ -61,24 +63,9 @@ class MP4FixupTimestampPP(PostProcessor):
|
|
|
|
|
|
|
|
|
|
|
|
return smallest_bmdt, sdur_cutoff
|
|
|
|
return smallest_bmdt, sdur_cutoff
|
|
|
|
|
|
|
|
|
|
|
|
def modify_mp4(self, src, dst, bmdt_offset, sdur_cutoff):
|
|
|
|
@staticmethod
|
|
|
|
with open(src, 'rb') as r, open(dst, 'wb') as w:
|
|
|
|
def transform(r, bmdt_offset, sdur_cutoff):
|
|
|
|
def converter():
|
|
|
|
for btype, content in r:
|
|
|
|
moov_over, in_secondary_moov = False, False
|
|
|
|
|
|
|
|
for btype, content in parse_mp4_boxes(r):
|
|
|
|
|
|
|
|
# skip duplicate MOOV boxes
|
|
|
|
|
|
|
|
if btype == 'moov':
|
|
|
|
|
|
|
|
if moov_over:
|
|
|
|
|
|
|
|
in_secondary_moov = True
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
elif btype is None and content == 'moov':
|
|
|
|
|
|
|
|
in_secondary_moov = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if moov_over:
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
moov_over = True
|
|
|
|
|
|
|
|
elif in_secondary_moov:
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
if btype == 'tfdt':
|
|
|
|
if btype == 'tfdt':
|
|
|
|
version, _ = unpack_ver_flags(content[0:4])
|
|
|
|
version, _ = unpack_ver_flags(content[0:4])
|
|
|
|
if version == 0:
|
|
|
|
if version == 0:
|
|
|
@ -115,7 +102,10 @@ class MP4FixupTimestampPP(PostProcessor):
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
yield (btype, content)
|
|
|
|
yield (btype, content)
|
|
|
|
|
|
|
|
|
|
|
|
write_mp4_boxes(w, converter())
|
|
|
|
|
|
|
|
|
|
|
|
def modify_mp4(self, src, dst, bmdt_offset, sdur_cutoff):
|
|
|
|
|
|
|
|
with open(src, 'rb') as r, open(dst, 'wb') as w:
|
|
|
|
|
|
|
|
write_mp4_boxes(w, self.transform(parse_mp4_boxes(r)))
|
|
|
|
|
|
|
|
|
|
|
|
def run(self, information):
|
|
|
|
def run(self, information):
|
|
|
|
filename = information['filepath']
|
|
|
|
filename = information['filepath']
|
|
|
@ -137,6 +127,6 @@ class MP4FixupTimestampPP(PostProcessor):
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
self.report_warning(f'Failed to fix duration of the file. (baseMediaDecodeTime offset = {bmdt_offset}, sample duration cutoff = {sdur_cutoff})')
|
|
|
|
self.report_warning(f'Failed to fix duration of the file. (baseMediaDecodeTime offset = {bmdt_offset}, sample duration cutoff = {sdur_cutoff})')
|
|
|
|
|
|
|
|
|
|
|
|
self._downloader.replace(temp_filename, filename)
|
|
|
|
os.replace(temp_filename, filename)
|
|
|
|
|
|
|
|
|
|
|
|
return [], information
|
|
|
|
return [], information
|
|
|
|