mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-11-22 02:01:50 +00:00
[postproc/ffmpeg] fix opus using default quality of 5 as bitrate (closes #28389)
Fix #28389. When extracting audio, and the containing format isn't 'opus', but the requested format is, then youtube-dl will call ffmpeg to do the conversion. Without specifying the preferred quality, youtube-dl defaults to '5'. Integers 0-9 are currently sent to ffmpeg as the bitrate for 'opus', which is clearly an error and this commit fixes that. It uses an arbitrary (specific to opus) scale to convert 0-9 into reasonable bitrates between 6 kb/s to 210 kb/s.... with 5 (the default) giving 96 kb/s
This commit is contained in:
parent
c7965b9fc2
commit
5831f6feef
1 changed files with 11 additions and 3 deletions
|
@ -21,6 +21,7 @@ from ..utils import (
|
||||||
dfxp2srt,
|
dfxp2srt,
|
||||||
ISO639Utils,
|
ISO639Utils,
|
||||||
replace_extension,
|
replace_extension,
|
||||||
|
compat_str,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -307,9 +308,16 @@ class FFmpegExtractAudioPP(FFmpegPostProcessor):
|
||||||
extension = self._preferredcodec
|
extension = self._preferredcodec
|
||||||
more_opts = []
|
more_opts = []
|
||||||
if self._preferredquality is not None:
|
if self._preferredquality is not None:
|
||||||
# The opus codec doesn't support the -aq option
|
if int(self._preferredquality) < 10:
|
||||||
if int(self._preferredquality) < 10 and extension != 'opus':
|
if extension == 'opus':
|
||||||
more_opts += ['-q:a', self._preferredquality]
|
# The opus codec doesn't support the -q:a option
|
||||||
|
# Magic number of 24 used to give quality numbers 0-9 *some* meaning (as suggested by "knarrff" on Github)
|
||||||
|
# 0 (best quality) gives 210 kb/s
|
||||||
|
# 5 (default) gives 96 kb/s
|
||||||
|
# 9 (worst quality) gives 6 kb/s, which is the opus minimum (and 0 kb/s wouldn't make any sense)
|
||||||
|
more_opts += ['-b:a', compat_str(max(6, int((9 - int(self._preferredquality)) * 24))) + 'k']
|
||||||
|
else:
|
||||||
|
more_opts += ['-q:a', self._preferredquality]
|
||||||
else:
|
else:
|
||||||
more_opts += ['-b:a', self._preferredquality + 'k']
|
more_opts += ['-b:a', self._preferredquality + 'k']
|
||||||
if self._preferredcodec == 'aac':
|
if self._preferredcodec == 'aac':
|
||||||
|
|
Loading…
Reference in a new issue