Ram Rachum
Ram Rachum

Reputation: 88528

Increasing a file's volume using VLC CLI

My goal is to have a script that takes an audio file and increases its volume by 50%.

I currently use the following AutoHotKey snippet to encode a file to MP3:

run_string := "bash -c ""\""c:\Program Files\VideoLAN\VLC\vlc.exe\"" -I dummy \""" . file_path . "\"" --sout='#transcode{acodec=mp3,vcodec=dummy}:standard{access=file,mux=raw,dst=\""" . file_path . ".mp3\""}' vlc://quit"""

How can I modify this line to not only encode to mp3, but also increase the volume of the file by 50%? I tried setting --volume 150 but it just made the file play, while I don't want to play, I want to have it saved with that volume.

If you have suggestions for other Windows-compatible tools to modify audio that can do this, (along with instructions on how to do this) I'll be happy to hear about them.

Upvotes: 8

Views: 12599

Answers (5)

MPaulo
MPaulo

Reputation: 1491

Run this on a dir to increasing all files volume on that dir, one by one (or else it would eat up all CPU)

FOR %f IN (*) DO (start /wait "" "C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" %f :sout=#transcode{acodec=mp3,afilter=compressor}:file{dst=Boost%f} :sout-all :sout-keep --play-and-exit --compressor-makeup-gain=10)

Upvotes: 1

orrd
orrd

Reputation: 9917

The "--volume" option in VLC doesn't actually change the volume of the output video as you would think it would. What you want to do is add the compressor filter and then set the "compressor-makup-gain". Set it to a value from 1-24 depending on how loud you want the video to be. So your command would be something like this:

run_string := "bash -c ""\""c:\Program Files\VideoLAN\VLC\vlc.exe\"" -I dummy \""" . file_path . "\"" --sout='#transcode{acodec=mp3,vcodec=dummy,afilter=compressor}:standard{access=file,mux=raw,dst=\""" . file_path . ".mp3  --compressor-makeup-gain=20\""}' vlc://quit"""

By the way, for anyone who is trying to figure out how to use VLC to increase the volume of the audio in a video file, here's how you can do that:

"C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" yoursourcefile.mp4 :sout=#transcode{acodec=mp3,ab=128,channels=2,samplerate=44100,afilter=compressor}:file{dst=outputfilename.mp4} :sout-all :sout-keep --compressor-makeup-gain=20

Replace "yoursourcefile.mp4" and "outputfilename.mp4" with your own file names. In my experience, VLC crashed about half the time I ran this command, so you may need to try it more than once if it crashes on you.

Upvotes: 2

khan
khan

Reputation: 4489

I suggest you to use ffmpeg. it is very powerful, cross platform 32 or 64 bit, audio and video converter. Can be downloaded from Zeranoe FFmpeg - Builds

Below sample commands work for audio extracting from video, or audio converter with volume increasing or decreasing support.

Extract audio from video to MP3, or convert audio to MP3 (sample InputFilePath_VideoOrAudio = "e:\video.mp4" or "e:\audio.m4a")

e:\ffmpeg\ffmpeg.exe -y -i "InputFilePath_VideoOrAudio" -acodec libmp3lame -ab 192k -ar 48000 -sn -dn -vn "E:\out.mp3"

Extract audio from video to MP3 and increase volume 150% while extracting add -af "volume=1.5" parameter.

e:\ffmpeg\ffmpeg.exe -y -i "InputFilePath_VideoOrAudio" -acodec libmp3lame -ab 192k -ar 48000 -sn -dn -vn -af "volume=1.5" "E:\out.mp3"

List of audio converter parameters (mp3,ogg,ac3,wma,flac,wav,aiff,m4a....). to change volume level while converting to audio add -af "volume=VolumeValue" parameter.

VolumeValue=0.5 decrease volume %50

VolumeValue=1.5 increase volume %150

VolumeValue=2.0 increase volume %200 and so on.

e:\ffmpeg\ffmpeg.exe -y -i "InputFilePath_VideoOrAudio" -acodec libmp3lame -ab 192k -ar 48000 -sn -dn -vn -af "E:\out.mp3"
e:\ffmpeg\ffmpeg.exe -y -i "InputFilePath_VideoOrAudio" -acodec ac3 -ab 192k -ar 48000 -sn -dn -vn "E:\out.ac3"
e:\ffmpeg\ffmpeg.exe -y -i "InputFilePath_VideoOrAudio" -f ogg -acodec libvorbis -ab 192k -ar 48000 -sn -dn -vn "E:\out.ogg"
e:\ffmpeg\ffmpeg.exe -y -i "InputFilePath_VideoOrAudio" -acodec wmav2 -ab 192k -ar 48000 -sn -dn -vn "E:\out.wma"
e:\ffmpeg\ffmpeg.exe -y -i "InputFilePath_VideoOrAudio" -acodec flac -sn -dn -vn "E:\out.flac"
e:\ffmpeg\ffmpeg.exe -y -i "InputFilePath_VideoOrAudio" -sn -dn -vn "E:\out.wav"
e:\ffmpeg\ffmpeg.exe -y -i "InputFilePath_VideoOrAudio" -f aiff -sn -dn -vn "E:\out.aiff"
e:\ffmpeg\ffmpeg.exe -y -i "InputFilePath_VideoOrAudio" -acodec aac -ab 192k -ar 48000 -sn -dn -vn "E:\out.m4a" 

Note 1: some codecs can be experimental in such case you should use -strict experimental or -strict -2 parameters.

Note 2: -ab parameter means audio bit rate. Some devices can not play audio file that bit rate greater than -ab 192k. Use -ab 128k or -ab 192k with -ar 44100 parameters to produce audio file that can be playable most of the mobile devices. -ac 2 parameter means stereo -ac 1 means mono.

to convert specific part of the input file use -ss 00:00:00 and -t parameters. -ss means Start From -t means duration. Important: parameter -ss should placed before the -i parameter, otherwise ffmpeg seeks to -ss position slowly.

Samples: assume that input file duration is 00:20:00 (20 minutes)

using only -ss 00:05:00 means convert input file starting from 5th minute to end of the input file. Duration of the output file will be 15 minutes.

using -ss 00:05:00 with -t 120 or -t 00:02:00 means convert 120 seconds, starting from 5th minute. Duration of the output file will be 120 seconds.

e:\ffmpeg\ffmpeg.exe -y -ss 00:05:00 -i "InputFilePath_VideoOrAudio" -t 120 -acodec libmp3lame -ab 192k -ar 48000 -sn -dn -vn -af "E:\out.mp3"

Note: -y means in advance YES to ffmpeg's yes/no questions such as output file already exist, over write? with -y parameters ffmpeg over writes the output file if it is already exist without asking the user.

-sn disables subtitle, -vn disable video, -dn disable data streams for output file.

Upvotes: 6

Scis
Scis

Reputation: 2984

If you just want a CLI tool then you could use ffmpeg:

ffmpeg.exe -i test.mp3 -af volume=1.5 loud.mp3
                 ^            ^         ^
               input  new volume level  output name

If you'd like to be able to do it programmatically, looking at your profile I deduced that python should not be a problem :)

So you can use the nice pydub module together with ffmpeg (or avconv which it also supports) for your task.

E.g:

from pydub import AudioSegment
AudioSegment.converter = r"C:\PATH_TO_FFMPEG_DIR\bin\ffmpeg.exe"
sound = AudioSegment.from_mp3("test.mp3") # <- the input file
new = sound.export("loud.mp3", format="mp3", parameters=["-vol", "384"]) # 384 <-> 150% volume
new.flush()
new.close()

The reason for 384 is that the ffmpeg doc states that

-vol volume change audio volume (256=normal)

So 256*1.5 = 384

Tested this on my windows 7 machine just now...

Hope this helps.

Upvotes: 4

MonkeyPushButton
MonkeyPushButton

Reputation: 1085

I believe mp3gain has a command line option for this. You could run this as a separate pass over the generated file:

http://mp3gain.sourceforge.net/

Upvotes: 0

Related Questions