Including feature to increase or decrease media (volume) audio level

This commit is contained in:
Paulo Nahes 2016-01-14 19:11:07 -02:00
parent 40cf7fcbd2
commit bed282f939
4 changed files with 24 additions and 2 deletions

View File

@ -361,6 +361,9 @@ which means you can modify it, redistribute it or use it however you like.
a value between 0 (better) and 9 (worse) a value between 0 (better) and 9 (worse)
for VBR or a specific bitrate like 128K for VBR or a specific bitrate like 128K
(default 5) (default 5)
--audio-volume VOLUME Specify ffmpeg/avconv audio volume, insert
a value in dB to increase audio volume.
(default 4)
--recode-video FORMAT Encode the video to another format if --recode-video FORMAT Encode the video to another format if
necessary (currently supported: necessary (currently supported:
mp4|flv|ogg|webm|mkv|avi) mp4|flv|ogg|webm|mkv|avi)

View File

@ -168,6 +168,11 @@ def _real_main(argv=None):
opts.audioquality = opts.audioquality.strip('k').strip('K') opts.audioquality = opts.audioquality.strip('k').strip('K')
if not opts.audioquality.isdigit(): if not opts.audioquality.isdigit():
parser.error('invalid audio quality specified') parser.error('invalid audio quality specified')
if opts.audiovolume:
if not opts.audioquality.isdigit():
parser.error('invalid audio volume specified')
if opts.recodevideo is not None: if opts.recodevideo is not None:
if opts.recodevideo not in ['mp4', 'flv', 'webm', 'ogg', 'mkv', 'avi']: if opts.recodevideo not in ['mp4', 'flv', 'webm', 'ogg', 'mkv', 'avi']:
parser.error('invalid video recode format specified') parser.error('invalid video recode format specified')
@ -221,6 +226,7 @@ def _real_main(argv=None):
'key': 'FFmpegExtractAudio', 'key': 'FFmpegExtractAudio',
'preferredcodec': opts.audioformat, 'preferredcodec': opts.audioformat,
'preferredquality': opts.audioquality, 'preferredquality': opts.audioquality,
'preferredvolume': opts.audiovolume,
'nopostoverwrites': opts.nopostoverwrites, 'nopostoverwrites': opts.nopostoverwrites,
}) })
if opts.recodevideo: if opts.recodevideo:
@ -377,7 +383,7 @@ def _real_main(argv=None):
with YoutubeDL(ydl_opts) as ydl: with YoutubeDL(ydl_opts) as ydl:
# Update version # Update version
if opts.update_self: if opts.update_self:
update_self(ydl.to_screen, opts.verbose, ydl._opener) update_self(ydl.to_screen, opts.verbose)
# Remove cache dir # Remove cache dir
if opts.rm_cachedir: if opts.rm_cachedir:

View File

@ -688,6 +688,12 @@ def parseOpts(overrideArguments=None):
'--audio-quality', metavar='QUALITY', '--audio-quality', metavar='QUALITY',
dest='audioquality', default='5', dest='audioquality', default='5',
help='Specify ffmpeg/avconv audio quality, insert a value between 0 (better) and 9 (worse) for VBR or a specific bitrate like 128K (default %default)') help='Specify ffmpeg/avconv audio quality, insert a value between 0 (better) and 9 (worse) for VBR or a specific bitrate like 128K (default %default)')
postproc.add_option(
'--audio-volume', metavar='QUALITY',
dest='audiovolume', default=None,
help='Specify ffmpeg/avconv audio volume, insert a value in dB to increase audio volume (default %default)')
postproc.add_option( postproc.add_option(
'--recode-video', '--recode-video',
metavar='FORMAT', dest='recodevideo', default=None, metavar='FORMAT', dest='recodevideo', default=None,

View File

@ -166,12 +166,13 @@ class FFmpegPostProcessor(PostProcessor):
class FFmpegExtractAudioPP(FFmpegPostProcessor): class FFmpegExtractAudioPP(FFmpegPostProcessor):
def __init__(self, downloader=None, preferredcodec=None, preferredquality=None, nopostoverwrites=False): def __init__(self, downloader=None, preferredcodec=None, preferredquality=None, preferredvolume=None, nopostoverwrites=False):
FFmpegPostProcessor.__init__(self, downloader) FFmpegPostProcessor.__init__(self, downloader)
if preferredcodec is None: if preferredcodec is None:
preferredcodec = 'best' preferredcodec = 'best'
self._preferredcodec = preferredcodec self._preferredcodec = preferredcodec
self._preferredquality = preferredquality self._preferredquality = preferredquality
self._preferredvolume = preferredvolume
self._nopostoverwrites = nopostoverwrites self._nopostoverwrites = nopostoverwrites
def get_audio_codec(self, path): def get_audio_codec(self, path):
@ -242,6 +243,8 @@ class FFmpegExtractAudioPP(FFmpegPostProcessor):
more_opts += ['-q:a', self._preferredquality] more_opts += ['-q:a', self._preferredquality]
else: else:
more_opts += ['-b:a', self._preferredquality + 'k'] more_opts += ['-b:a', self._preferredquality + 'k']
if self._preferredvolume is not None:
more_opts += ['-af', 'volume=volume='+self._preferredvolume+'dB:precision=fixed']
else: else:
# We convert the audio (lossy) # We convert the audio (lossy)
acodec = {'mp3': 'libmp3lame', 'aac': 'aac', 'm4a': 'aac', 'opus': 'opus', 'vorbis': 'libvorbis', 'wav': None}[self._preferredcodec] acodec = {'mp3': 'libmp3lame', 'aac': 'aac', 'm4a': 'aac', 'opus': 'opus', 'vorbis': 'libvorbis', 'wav': None}[self._preferredcodec]
@ -253,6 +256,10 @@ class FFmpegExtractAudioPP(FFmpegPostProcessor):
more_opts += ['-q:a', self._preferredquality] more_opts += ['-q:a', self._preferredquality]
else: else:
more_opts += ['-b:a', self._preferredquality + 'k'] more_opts += ['-b:a', self._preferredquality + 'k']
if self._preferredvolume is not None:
more_opts += ['-af', 'volume=volume='+self._preferredvolume+'dB:precision=fixed']
if self._preferredcodec == 'aac': if self._preferredcodec == 'aac':
more_opts += ['-f', 'adts'] more_opts += ['-f', 'adts']
if self._preferredcodec == 'm4a': if self._preferredcodec == 'm4a':