1
0
mirror of https://codeberg.org/polarisfm/youtube-dl synced 2024-11-29 19:47:54 +01:00

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

This commit is contained in:
Paulo Nahes 2016-03-02 14:21:19 -03:00
parent 3318832e9d
commit 1a27022a63
3 changed files with 14 additions and 1 deletions

View File

@ -168,6 +168,9 @@ 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 +224,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:

View File

@ -701,6 +701,10 @@ 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='VOLUME',
dest='audiovolume',
help='Specify ffmpeg/avconv audio volume, insert a value in dB to increase audio volume')
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,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']
if self._preferredcodec == 'aac': if self._preferredcodec == 'aac':
more_opts += ['-f', 'adts'] more_opts += ['-f', 'adts']
if self._preferredcodec == 'm4a': if self._preferredcodec == 'm4a':