From d94fc760f73c9c4faf32b46c8741b4f0b0595a32 Mon Sep 17 00:00:00 2001 From: AGSPhoenix Date: Mon, 7 Apr 2014 11:52:15 -0400 Subject: [PATCH] Add ffmpeg concat postprocessor Code's a bit sloppy, but it seems to work. --- youtube_dl/postprocessor/__init__.py | 2 ++ youtube_dl/postprocessor/ffmpeg.py | 23 +++++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/youtube_dl/postprocessor/__init__.py b/youtube_dl/postprocessor/__init__.py index 7f19f717f..c003d7a74 100644 --- a/youtube_dl/postprocessor/__init__.py +++ b/youtube_dl/postprocessor/__init__.py @@ -1,6 +1,7 @@ from .ffmpeg import ( FFmpegMergerPP, + FFmpegConcatPP, FFmpegMetadataPP, FFmpegVideoConvertor, FFmpegExtractAudioPP, @@ -10,6 +11,7 @@ from .xattrpp import XAttrMetadataPP __all__ = [ 'FFmpegMergerPP', + 'FFmpegConcatPP', 'FFmpegMetadataPP', 'FFmpegVideoConvertor', 'FFmpegExtractAudioPP', diff --git a/youtube_dl/postprocessor/ffmpeg.py b/youtube_dl/postprocessor/ffmpeg.py index 98b5eccb4..9d8344901 100644 --- a/youtube_dl/postprocessor/ffmpeg.py +++ b/youtube_dl/postprocessor/ffmpeg.py @@ -40,16 +40,19 @@ class FFmpegPostProcessor(PostProcessor): def _uses_avconv(self): return self._get_executable() == self._exes['avconv'] - def run_ffmpeg_multiple_files(self, input_paths, out_path, opts): + def run_ffmpeg_multiple_files(self, input_paths, out_path, opts, preopts=None): if not self._get_executable(): raise FFmpegPostProcessorError(u'ffmpeg or avconv not found. Please install one.') + preopt_cmd = [] + if preopts: + preopt_cmd = preopts files_cmd = [] for path in input_paths: files_cmd.extend(['-i', encodeFilename(path, True)]) - cmd = ([self._get_executable(), '-y'] + files_cmd - + opts + - [encodeFilename(self._ffmpeg_filename_argument(out_path), True)]) + cmd = ([self._get_executable(), '-y'] + + preopt_cmd + files_cmd + opts + + [encodeFilename(self._ffmpeg_filename_argument(out_path), True)]) if self._downloader.params.get('verbose', False): self._downloader.to_screen(u'[debug] ffmpeg command line: %s' % shell_quote(cmd)) @@ -484,3 +487,15 @@ class FFmpegMergerPP(FFmpegPostProcessor): self.run_ffmpeg_multiple_files(info['__files_to_merge'], filename, args) return True, info +class FFmpegConcatPP(FFmpegPostProcessor): + def run(self, info): + filename = info['filepath'] + concatargs = ['-f', 'concat'] + args = ['-c', 'copy'] + self._downloader.to_screen(u'[ffmpeg] Appending files into "%s"' % filename) + with open(u'youtube-dl_ffmpeg_append_list.txt', 'wb') as f: + for file in info['__files_to_merge']: + f.write("file '" + file + "'\n") + self.run_ffmpeg_multiple_files([u'youtube-dl_ffmpeg_append_list.txt'], filename, args, preopts=concatargs) + os.unlink('youtube-dl_ffmpeg_append_list.txt') + return True, info