From 19e2352b4b64c0ce0c39c1fda81b58922d168b9c Mon Sep 17 00:00:00 2001 From: Nikola Taushanov Date: Mon, 19 Aug 2013 02:57:35 +0300 Subject: [PATCH] Dirty fix for opus format. The opus format require some special execution. The usual one with avconv/ffmpeg is not enough. The easiest way to do it is by converting to wav with avconv/ffmpeg and then using opusenc to convert it to opus. opusenc is part of the opus-tools package. --- youtube_dl/PostProcessor.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/youtube_dl/PostProcessor.py b/youtube_dl/PostProcessor.py index fddf58606..482823c61 100644 --- a/youtube_dl/PostProcessor.py +++ b/youtube_dl/PostProcessor.py @@ -77,7 +77,17 @@ class FFmpegPostProcessor(PostProcessor): cmd = ([self._exes['avconv'] or self._exes['ffmpeg'], '-y', '-i', encodeFilename(path)] + opts + [encodeFilename(self._ffmpeg_filename_argument(out_path))]) - p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + # Dirty fix for executing two piped commands + if '|' in cmd: + pipe_position = cmd.index('|') + first_cmd = cmd[:pipe_position] + second_cmd = cmd[(pipe_position + 1):] + p1 = subprocess.Popen(first_cmd, stdout=subprocess.PIPE) + p = subprocess.Popen(second_cmd, stdin=p1.stdout, stdout=subprocess.PIPE) + else: + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout,stderr = p.communicate() if p.returncode != 0: stderr = stderr.decode('utf-8', 'replace') @@ -125,7 +135,13 @@ class FFmpegExtractAudioPP(FFmpegPostProcessor): acodec_opts = [] else: acodec_opts = ['-acodec', codec] - opts = ['-vn'] + acodec_opts + more_opts + + # Dirty fix for opus format + if codec == 'opus': + opts = ['-f', 'wav', '-', '|', 'opusenc', '-'] + else: + opts = ['-vn'] + acodec_opts + more_opts + try: FFmpegPostProcessor.run_ffmpeg(self, path, out_path, opts) except FFmpegPostProcessorError as err: @@ -182,6 +198,8 @@ class FFmpegExtractAudioPP(FFmpegPostProcessor): if self._preferredcodec == 'wav': extension = 'wav' more_opts += ['-f', 'wav'] + if self._preferredcodec == 'opus': + more_opts += [] prefix, sep, ext = path.rpartition(u'.') # not os.path.splitext, since the latter does not work on unicode in all setups new_path = prefix + sep + extension