mirror of
https://github.com/yt-dlp/yt-dlp
synced 2025-01-31 12:32:27 +01:00
Handle cutting after last keyframe
This commit is contained in:
parent
751f71a644
commit
ecae8eb19f
2 changed files with 9 additions and 6 deletions
|
@ -564,7 +564,7 @@ class TestModifyChaptersPP(unittest.TestCase):
|
||||||
{'start_time': 0, 'end_time': 2},
|
{'start_time': 0, 'end_time': 2},
|
||||||
{'start_time': 2, 'end_time': 6, 'remove': True},
|
{'start_time': 2, 'end_time': 6, 'remove': True},
|
||||||
{'start_time': 6, 'end_time': 10, 'remove': False},
|
{'start_time': 6, 'end_time': 10, 'remove': False},
|
||||||
])
|
], duration=12)
|
||||||
self.assertEqual(chapters, [
|
self.assertEqual(chapters, [
|
||||||
{'start_time': 0, 'end_time': 2},
|
{'start_time': 0, 'end_time': 2},
|
||||||
{'start_time': 2, 'end_time': 5, 'remove': True},
|
{'start_time': 2, 'end_time': 5, 'remove': True},
|
||||||
|
@ -577,7 +577,7 @@ class TestModifyChaptersPP(unittest.TestCase):
|
||||||
{'start_time': 0, 'end_time': 2},
|
{'start_time': 0, 'end_time': 2},
|
||||||
{'start_time': 3, 'end_time': 7, 'remove': True},
|
{'start_time': 3, 'end_time': 7, 'remove': True},
|
||||||
{'start_time': 6, 'end_time': 10, 'remove': False},
|
{'start_time': 6, 'end_time': 10, 'remove': False},
|
||||||
])
|
], duration=12)
|
||||||
self.assertEqual(chapters, [
|
self.assertEqual(chapters, [
|
||||||
{'start_time': 0, 'end_time': 2},
|
{'start_time': 0, 'end_time': 2},
|
||||||
{'start_time': 3, 'end_time': 7, 'remove': True},
|
{'start_time': 3, 'end_time': 7, 'remove': True},
|
||||||
|
@ -589,7 +589,7 @@ class TestModifyChaptersPP(unittest.TestCase):
|
||||||
chapters = self._pp._round_remove_chapters(keyframes, [
|
chapters = self._pp._round_remove_chapters(keyframes, [
|
||||||
{'start_time': 0, 'end_time': 2},
|
{'start_time': 0, 'end_time': 2},
|
||||||
{'start_time': 3, 'end_time': 8, 'remove': True},
|
{'start_time': 3, 'end_time': 8, 'remove': True},
|
||||||
])
|
], duration=8)
|
||||||
self.assertEqual(chapters, [
|
self.assertEqual(chapters, [
|
||||||
{'start_time': 0, 'end_time': 2},
|
{'start_time': 0, 'end_time': 2},
|
||||||
{'start_time': 3, 'end_time': 8, 'remove': True},
|
{'start_time': 3, 'end_time': 8, 'remove': True},
|
||||||
|
@ -600,7 +600,7 @@ class TestModifyChaptersPP(unittest.TestCase):
|
||||||
chapters = self._pp._round_remove_chapters(keyframes, [
|
chapters = self._pp._round_remove_chapters(keyframes, [
|
||||||
{'start_time': 0, 'end_time': 2},
|
{'start_time': 0, 'end_time': 2},
|
||||||
{'start_time': 8, 'end_time': 9, 'remove': True},
|
{'start_time': 8, 'end_time': 9, 'remove': True},
|
||||||
])
|
], duration=10)
|
||||||
self.assertEqual(chapters, [
|
self.assertEqual(chapters, [
|
||||||
{'start_time': 0, 'end_time': 2},
|
{'start_time': 0, 'end_time': 2},
|
||||||
])
|
])
|
||||||
|
|
|
@ -42,7 +42,7 @@ class ModifyChaptersPP(FFmpegPostProcessor):
|
||||||
chapters += sponsor_chapters
|
chapters += sponsor_chapters
|
||||||
if self._round_to_keyframes:
|
if self._round_to_keyframes:
|
||||||
keyframes = self.get_keyframe_timestamps(info['filepath'])
|
keyframes = self.get_keyframe_timestamps(info['filepath'])
|
||||||
self._round_remove_chapters(keyframes, chapters)
|
self._round_remove_chapters(keyframes, chapters, info.get('duration') or real_duration)
|
||||||
|
|
||||||
info['chapters'], cuts = self._remove_marked_arrange_sponsors(chapters)
|
info['chapters'], cuts = self._remove_marked_arrange_sponsors(chapters)
|
||||||
if not cuts:
|
if not cuts:
|
||||||
|
@ -334,13 +334,16 @@ class ModifyChaptersPP(FFmpegPostProcessor):
|
||||||
return out_file
|
return out_file
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _round_remove_chapters(keyframes, chapters):
|
def _round_remove_chapters(keyframes, chapters, duration):
|
||||||
result = []
|
result = []
|
||||||
for c in chapters:
|
for c in chapters:
|
||||||
if not c.get('remove', False) or not keyframes:
|
if not c.get('remove', False) or not keyframes:
|
||||||
result.append(c)
|
result.append(c)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if c['end_time'] > keyframes[-1] and c['end_time'] != duration:
|
||||||
|
continue
|
||||||
|
|
||||||
if c['end_time'] < keyframes[-1]:
|
if c['end_time'] < keyframes[-1]:
|
||||||
c['end_time'] = keyframes[bisect.bisect_right(keyframes, c['end_time']) - 1]
|
c['end_time'] = keyframes[bisect.bisect_right(keyframes, c['end_time']) - 1]
|
||||||
result.append(c)
|
result.append(c)
|
||||||
|
|
Loading…
Add table
Reference in a new issue