From d2fdec2f09ba754f09244922b4d0e641c1a9cdff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Alfredo=20N=C3=BA=C3=B1ez?= Date: Mon, 12 Mar 2018 17:01:14 -0300 Subject: [PATCH] Fixed duration calculation and moved checks to __init__ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcos Alfredo Núñez --- youtube_dl/postprocessor/ffmpeg.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/youtube_dl/postprocessor/ffmpeg.py b/youtube_dl/postprocessor/ffmpeg.py index b5bae917f..1ad4935c8 100644 --- a/youtube_dl/postprocessor/ffmpeg.py +++ b/youtube_dl/postprocessor/ffmpeg.py @@ -221,6 +221,11 @@ class FFmpegCutVideoPP(FFmpegPostProcessor): self._startTime = startTime self._endTime = endTime + if self._endTime and self._endTime <= self._startTime: + raise PostProcessingError("end time smaller or equal to the start time") + if self._endTime == 0: + raise PostProcessingError("end time can't be zero") + def toTime(self, seconds): m, s = divmod(seconds, 60) h, m = divmod(m, 60) @@ -231,16 +236,10 @@ class FFmpegCutVideoPP(FFmpegPostProcessor): self._downloader.to_screen('[ffmpeg] No start time or end time. Keeping original') return [], information - if self._endTime and self._endTime <= self._startTime: - raise PostProcessingError("end time smaller or equal to the start time") - - if self._endTime == 0: - raise PostProcessingError("end time can't be zero") - duration = information.get('duration') if self._endTime and duration and self._endTime >= duration: - self._downloader.to_screen('WARNING: end time greater than video duration') + self._downloader.to_screen('WARNING: end time greater or equal to duration') self._endTime = None options = ['-c', 'copy'] @@ -258,7 +257,7 @@ class FFmpegCutVideoPP(FFmpegPostProcessor): options.extend(['-to', end]) message += 'to %s' % (end) if duration: - duration -= self._endTime + duration = self._endTime - (duration - self._endTime) if '-to' not in options and '-ss' not in options: self._downloader.to_screen('[ffmpeg] Nothing to cut. Keeping original')