From 71d5459c0b33e0ae8fa4d42b90e5a849373e0e12 Mon Sep 17 00:00:00 2001 From: noureddin Date: Tue, 29 May 2018 07:29:53 +0200 Subject: [PATCH] fix args order in FFmpegFD In `ytdl --external-downloader ffmpeg --external-downloader-args '-ss 1 -t 2'`, youtube-dl will give all the external downloader args to ffmpeg *before* the input url; but some of them need to be given after the input url. This patch moves `-t`, `-to`, and `-fs` (if given) to be after the input. --- youtube_dl/downloader/external.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/youtube_dl/downloader/external.py b/youtube_dl/downloader/external.py index 958d00aac..47c14e524 100644 --- a/youtube_dl/downloader/external.py +++ b/youtube_dl/downloader/external.py @@ -233,7 +233,24 @@ class FFmpegFD(ExternalFD): # http://trac.ffmpeg.org/ticket/6125#comment:10 args += ['-seekable', '1' if seekable else '0'] - args += self._configuration_args() + # args += self._configuration_args() + # Some ffmpeg options need to come after the input url. + # `-to` and `-fs` must. `-t` should. + # Also, in ffmpeg, options and values must be separated with a space; + # so, we will never see `-t2` but will see `-t 2`. + + self._input_args = self._configuration_args() + self._output_args = [] + + for opt in ['-t', '-to', '-fs']: + try: + idx = self._input_args.index(opt) + self._output_args.append(self._input_args.pop(idx)) # the option + self._output_args.append(self._input_args.pop(idx)) # the value + except ValueError: + pass + + args += self._input_args # start_time = info_dict.get('start_time') or 0 # if start_time: @@ -295,6 +312,7 @@ class FFmpegFD(ExternalFD): args += ['-rtmp_live', 'live'] args += ['-i', url, '-c', 'copy'] + args += self._output_args if self.params.get('test', False): args += ['-fs', compat_str(self._TEST_FILE_SIZE)]