]> jfr.im git - yt-dlp.git/commitdiff
[ModifyChapters] Fix repeated removal of small segments
authorpukkandan <redacted>
Mon, 23 May 2022 10:40:09 +0000 (16:10 +0530)
committerpukkandan <redacted>
Mon, 23 May 2022 10:42:33 +0000 (16:12 +0530)
Closes #3846

yt_dlp/postprocessor/ffmpeg.py
yt_dlp/postprocessor/modify_chapters.py

index cb33c35829357e28ec9493802728b88de3134ec5..5a1d8561fa6f245d26d788bdff336abeefccf42e 100644 (file)
@@ -284,12 +284,12 @@ def _get_real_video_duration(self, filepath, fatal=True):
             if fatal:
                 raise PostProcessingError(f'Unable to determine video duration: {e.msg}')
 
-    def _duration_mismatch(self, d1, d2):
+    def _duration_mismatch(self, d1, d2, tolerance=2):
         if not d1 or not d2:
             return None
         # The duration is often only known to nearest second. So there can be <1sec disparity natually.
         # Further excuse an additional <1sec difference.
-        return abs(d1 - d2) > 2
+        return abs(d1 - d2) > tolerance
 
     def run_ffmpeg_multiple_files(self, input_paths, out_path, opts, **kwargs):
         return self.real_run_ffmpeg(
index 8a2ef906512055eca54923944434f9aa9abf9f35..de3505e11b83b6ddd14ebc9990fe779d88fea386 100644 (file)
@@ -32,13 +32,13 @@ def run(self, info):
 
         real_duration = self._get_real_video_duration(info['filepath'])
         if not chapters:
-            chapters = [{'start_time': 0, 'end_time': real_duration, 'title': info['title']}]
+            chapters = [{'start_time': 0, 'end_time': info.get('duration') or real_duration, 'title': info['title']}]
 
         info['chapters'], cuts = self._remove_marked_arrange_sponsors(chapters + sponsor_chapters)
         if not cuts:
             return [], info
 
-        if self._duration_mismatch(real_duration, info.get('duration')):
+        if self._duration_mismatch(real_duration, info.get('duration'), 1):
             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