mirror of
https://github.com/ytdl-org/youtube-dl
synced 2025-03-18 05:52:21 +09:00
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.
This commit is contained in:
parent
3f0537dd4a
commit
19e2352b4b
@ -77,7 +77,17 @@ class FFmpegPostProcessor(PostProcessor):
|
|||||||
cmd = ([self._exes['avconv'] or self._exes['ffmpeg'], '-y', '-i', encodeFilename(path)]
|
cmd = ([self._exes['avconv'] or self._exes['ffmpeg'], '-y', '-i', encodeFilename(path)]
|
||||||
+ opts +
|
+ opts +
|
||||||
[encodeFilename(self._ffmpeg_filename_argument(out_path))])
|
[encodeFilename(self._ffmpeg_filename_argument(out_path))])
|
||||||
|
|
||||||
|
# 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)
|
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
|
|
||||||
stdout,stderr = p.communicate()
|
stdout,stderr = p.communicate()
|
||||||
if p.returncode != 0:
|
if p.returncode != 0:
|
||||||
stderr = stderr.decode('utf-8', 'replace')
|
stderr = stderr.decode('utf-8', 'replace')
|
||||||
@ -125,7 +135,13 @@ class FFmpegExtractAudioPP(FFmpegPostProcessor):
|
|||||||
acodec_opts = []
|
acodec_opts = []
|
||||||
else:
|
else:
|
||||||
acodec_opts = ['-acodec', codec]
|
acodec_opts = ['-acodec', codec]
|
||||||
|
|
||||||
|
# Dirty fix for opus format
|
||||||
|
if codec == 'opus':
|
||||||
|
opts = ['-f', 'wav', '-', '|', 'opusenc', '-']
|
||||||
|
else:
|
||||||
opts = ['-vn'] + acodec_opts + more_opts
|
opts = ['-vn'] + acodec_opts + more_opts
|
||||||
|
|
||||||
try:
|
try:
|
||||||
FFmpegPostProcessor.run_ffmpeg(self, path, out_path, opts)
|
FFmpegPostProcessor.run_ffmpeg(self, path, out_path, opts)
|
||||||
except FFmpegPostProcessorError as err:
|
except FFmpegPostProcessorError as err:
|
||||||
@ -182,6 +198,8 @@ class FFmpegExtractAudioPP(FFmpegPostProcessor):
|
|||||||
if self._preferredcodec == 'wav':
|
if self._preferredcodec == 'wav':
|
||||||
extension = 'wav'
|
extension = 'wav'
|
||||||
more_opts += ['-f', '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
|
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
|
new_path = prefix + sep + extension
|
||||||
|
Loading…
Reference in New Issue
Block a user