1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-11-02 09:12:40 +01:00

[ModifyChapters] Fix repeated removal of small segments

Closes #3846
This commit is contained in:
pukkandan 2022-05-23 16:10:09 +05:30
parent 11233f2afd
commit d9473db78a
No known key found for this signature in database
GPG Key ID: 7EEE9E1E817D0A39
2 changed files with 4 additions and 4 deletions

View File

@ -284,12 +284,12 @@ def _get_real_video_duration(self, filepath, fatal=True):
if fatal: if fatal:
raise PostProcessingError(f'Unable to determine video duration: {e.msg}') 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: if not d1 or not d2:
return None return None
# The duration is often only known to nearest second. So there can be <1sec disparity natually. # The duration is often only known to nearest second. So there can be <1sec disparity natually.
# Further excuse an additional <1sec difference. # 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): def run_ffmpeg_multiple_files(self, input_paths, out_path, opts, **kwargs):
return self.real_run_ffmpeg( return self.real_run_ffmpeg(

View File

@ -32,13 +32,13 @@ def run(self, info):
real_duration = self._get_real_video_duration(info['filepath']) real_duration = self._get_real_video_duration(info['filepath'])
if not chapters: 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) info['chapters'], cuts = self._remove_marked_arrange_sponsors(chapters + sponsor_chapters)
if not cuts: if not cuts:
return [], info 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']): 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') self.to_screen(f'Skipping {self.pp_key()} since the video appears to be already cut')
return [], info return [], info