From b24676ce888c6b597b7e9ca6bb0fca82d71f2ec5 Mon Sep 17 00:00:00 2001 From: Filippo Valsorda Date: Sat, 14 Jul 2012 19:43:24 +0200 Subject: changed --audio-quality behaviour to support both CBR and VBR --- youtube_dl/PostProcessor.py | 10 ++++++++-- youtube_dl/__init__.py | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'youtube_dl') diff --git a/youtube_dl/PostProcessor.py b/youtube_dl/PostProcessor.py index 527dc3a3d..375da1aa3 100644 --- a/youtube_dl/PostProcessor.py +++ b/youtube_dl/PostProcessor.py @@ -142,14 +142,20 @@ class FFmpegExtractAudioPP(PostProcessor): extension = 'mp3' more_opts = [] if self._preferredquality is not None: - more_opts += [self._exes['avconv'] and '-b:a' or '-ab', self._preferredquality] + if int(self._preferredquality) < 10: + more_opts += [self._exes['avconv'] and '-q:a' or '-aq', self._preferredquality] + else: + more_opts += [self._exes['avconv'] and '-b:a' or '-ab', self._preferredquality] else: # We convert the audio (lossy) acodec = {'mp3': 'libmp3lame', 'aac': 'aac', 'm4a': 'aac', 'vorbis': 'libvorbis', 'wav': None}[self._preferredcodec] extension = self._preferredcodec more_opts = [] if self._preferredquality is not None: - more_opts += [self._exes['avconv'] and '-b:a' or '-ab', self._preferredquality] + if int(self._preferredquality) < 10: + more_opts += [self._exes['avconv'] and '-q:a' or '-aq', self._preferredquality] + else: + more_opts += [self._exes['avconv'] and '-b:a' or '-ab', self._preferredquality] if self._preferredcodec == 'aac': more_opts += ['-f', 'adts'] if self._preferredcodec == 'm4a': diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py index f10822db1..2bc9a3fa6 100644 --- a/youtube_dl/__init__.py +++ b/youtube_dl/__init__.py @@ -296,8 +296,8 @@ def parseOpts(): help='convert video files to audio-only files (requires ffmpeg or avconv and ffprobe or avprobe)') postproc.add_option('--audio-format', metavar='FORMAT', dest='audioformat', default='best', help='"best", "aac", "vorbis", "mp3", "m4a", or "wav"; best by default') - postproc.add_option('--audio-quality', metavar='QUALITY', dest='audioquality', default='128K', - help='ffmpeg/avconv audio bitrate specification, 128k by default') + postproc.add_option('--audio-quality', metavar='QUALITY', dest='audioquality', default='5', + help='ffmpeg/avconv audio quality specification, insert a value between 0 (highest) and 9 (lowest) or a specific bitrate like 128 (default 5)') postproc.add_option('-k', '--keep-video', action='store_true', dest='keepvideo', default=False, help='keeps the video file on disk after the post-processing; the video is erased by default') -- cgit v1.2.3 From 3a68d7b467d59e6df4d8473989dcd9edb460dd75 Mon Sep 17 00:00:00 2001 From: Filippo Valsorda Date: Sun, 19 Aug 2012 23:25:16 +0200 Subject: tweaked the --audio-quality input validation/specification --- youtube_dl/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'youtube_dl') diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py index 2bc9a3fa6..8817228f3 100644 --- a/youtube_dl/__init__.py +++ b/youtube_dl/__init__.py @@ -297,7 +297,7 @@ def parseOpts(): postproc.add_option('--audio-format', metavar='FORMAT', dest='audioformat', default='best', help='"best", "aac", "vorbis", "mp3", "m4a", or "wav"; best by default') postproc.add_option('--audio-quality', metavar='QUALITY', dest='audioquality', default='5', - help='ffmpeg/avconv audio quality specification, insert a value between 0 (highest) and 9 (lowest) or a specific bitrate like 128 (default 5)') + help='ffmpeg/avconv audio quality specification, insert a value between 0 (better) and 9 (worse) for VBR or a specific bitrate like 128K (default 5)') postproc.add_option('-k', '--keep-video', action='store_true', dest='keepvideo', default=False, help='keeps the video file on disk after the post-processing; the video is erased by default') @@ -443,6 +443,10 @@ def _real_main(): if opts.extractaudio: if opts.audioformat not in ['best', 'aac', 'mp3', 'vorbis', 'm4a', 'wav']: parser.error(u'invalid audio format specified') + if opts.audioquality: + opts.audioquality = opts.audioquality.strip('k').strip('K') + if not opts.audioquality.isdigit(): + parser.error(u'invalid audio quality specified') # File downloader fd = FileDownloader({ -- cgit v1.2.3