aboutsummaryrefslogtreecommitdiff
path: root/yt_dlp/postprocessor/modify_chapters.py
diff options
context:
space:
mode:
authorpukkandan <pukkandan.ytdlp@gmail.com>2021-09-04 01:37:41 +0530
committerpukkandan <pukkandan.ytdlp@gmail.com>2021-09-04 01:39:31 +0530
commit165efb823b3a8a6a6788cfe23e6b93dfbe150568 (patch)
treed9dc55050e3dd37827380cd2b256f7daa9dddd76 /yt_dlp/postprocessor/modify_chapters.py
parentdd594deb2a0449dd8b145ef0552235f66ee3d454 (diff)
[ModifyChapters] fixes (See desc)
* [docs] Fix typo * Do not enable `sponskrub` by default * Fix `--force-keyframes-at-cuts` * Don't embed subtitles if the video has been cut. Previously, running `--remove-chapters` with `--embed-subs` multiple times caused repeated cuts and out-of-sync subtitles * Store `_real_duration` to prevent running ffprobe multiple times
Diffstat (limited to 'yt_dlp/postprocessor/modify_chapters.py')
-rw-r--r--yt_dlp/postprocessor/modify_chapters.py18
1 files changed, 5 insertions, 13 deletions
diff --git a/yt_dlp/postprocessor/modify_chapters.py b/yt_dlp/postprocessor/modify_chapters.py
index 3d6493b68..9a7ba8eff 100644
--- a/yt_dlp/postprocessor/modify_chapters.py
+++ b/yt_dlp/postprocessor/modify_chapters.py
@@ -9,11 +9,9 @@ from .ffmpeg import (
)
from .sponsorblock import SponsorBlockPP
from ..utils import (
- float_or_none,
orderedSet,
PostProcessingError,
prepend_extension,
- traverse_obj,
)
@@ -37,7 +35,7 @@ class ModifyChaptersPP(FFmpegPostProcessor):
if not chapters and not sponsor_chapters:
return [], info
- real_duration = self._get_real_video_duration(info['filepath'])
+ real_duration = self._get_real_video_duration(info)
if not chapters:
chapters = [{'start_time': 0, 'end_time': real_duration, 'title': info['title']}]
@@ -45,8 +43,8 @@ class ModifyChaptersPP(FFmpegPostProcessor):
if not cuts:
return [], info
- if abs(real_duration - info['duration']) > 1:
- if abs(real_duration - info['chapters'][-1]['end_time']) < 1:
+ if self._duration_mismatch(real_duration, info.get('duration')):
+ if not self._duration_mismatch(real_duration, info['chapters'][-1]['end_time']):
self.to_screen(f'Skipping {self.pp_key()} since the video appears to be already cut')
return [], info
if not info.get('__real_download'):
@@ -72,6 +70,7 @@ class ModifyChaptersPP(FFmpegPostProcessor):
os.replace(out_file, in_file)
files_to_remove.append(uncut_file)
+ info['_real_duration'] = info['chapters'][-1]['end_time']
return files_to_remove, info
def _mark_chapters_to_remove(self, chapters, sponsor_chapters):
@@ -101,13 +100,6 @@ class ModifyChaptersPP(FFmpegPostProcessor):
return chapters, sponsor_chapters
- def _get_real_video_duration(self, filename):
- duration = float_or_none(
- traverse_obj(self.get_metadata_object(filename), ('format', 'duration')))
- if duration is None:
- raise PostProcessingError('ffprobe returned empty duration')
- return duration
-
def _get_supported_subs(self, info):
for sub in (info.get('requested_subtitles') or {}).values():
sub_file = sub.get('filepath')
@@ -311,7 +303,7 @@ class ModifyChaptersPP(FFmpegPostProcessor):
in_file = filename
out_file = prepend_extension(in_file, 'temp')
if force_keyframes:
- in_file = self.force_keyframes(in_file, (t for r in ranges_to_cut for t in r))
+ in_file = self.force_keyframes(in_file, (t for c in ranges_to_cut for t in (c['start_time'], c['end_time'])))
self.to_screen(f'Removing chapters from {filename}')
self.concat_files([in_file] * len(concat_opts), out_file, concat_opts)
if in_file != filename: