Skip to content

Instantly share code, notes, and snippets.

@dominicthomas
Created October 7, 2014 09:30
Show Gist options
  • Star 43 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save dominicthomas/52e610c9cd4083408371 to your computer and use it in GitHub Desktop.
Save dominicthomas/52e610c9cd4083408371 to your computer and use it in GitHub Desktop.
Convert a wav to a 320k mp3 using ffmpeg.
ffmpeg -i inputfile.wav -ab 320k outputfile.mp3
@gregtemp
Copy link

gregtemp commented Feb 9, 2018

/// batch
for i in *.wav; do ffmpeg -i "$i" -ab 320k "${i%.*}.mp3"; done

@Wlada
Copy link

Wlada commented Aug 16, 2018

Thanks

@manojkumarlinux
Copy link

manojkumarlinux commented Mar 4, 2019

mono to stereo conversion

ffmpeg -i test.wav -af "pan=stereo|c0=c0|c1=c0" out.wav
StackOverflow

@quindariuss
Copy link

Very good very nice 👍

@matthewjenkins97
Copy link

Windows Batch equivalent:

for %f in (*.wav) do ( ffmpeg -i "%~nf.wav" -b:a 320k "%~nf.mp3" )

Thanks for this!

@andreimoment
Copy link

Thank you for this

@gaspard
Copy link

gaspard commented Apr 27, 2022

Yeahioui yeah 😍

@burntscarr
Copy link

mono to stereo conversion

ffmpeg -i test.wav -af "pan=stereo|c0=c0|c1=c0" out.wav StackOverflow

-ac 1
instead of the -af part works well too.

@Joshfindit
Copy link

If someone is converting to 320k specifically to have the highest quality MP3 available, they may also want to add -ac 2 -ar 44100 -joint_stereo 0

  • -ac 2 specifies two channels (stereo)
  • -ar 44100 makes sure to output 44100Hz
  • -joint_stereo 0 this is not commonly thought about, but it makes a difference. Basically this tells the encoder to keep the channels separate during compression and output. Joint stereo is a space-saving measure that can cause stereo separation to get muddy.

@chepe263
Copy link

chepe263 commented Feb 4, 2024

ffmpeg -i inputfile.wav -ab 320k -ac 2 -ar 44100 -joint_stereo 0 outputfile.mp3

@geextahslex
Copy link

geextahslex commented Mar 10, 2024

What is the difference between -ab and -b:a?
Why with -b:a 320k -ac 2 -ar 44100 -joint_stereo 0 it displays "guessed channel layout stereo"? Is -ac 2 not stereo?

joint stereo question
joint stereo is suppose to save space but both files have the same size 8,56mb
I compared them with "spek" and you can see that joint stereo have more data than stereo

@Joshfindit @chepe263
joint stereo
shana2

normal stereo
stereo2

@Joshfindit
Copy link

Is -ac 2 not stereo?

In practice yes 99% of the time but FFMPEG avoids black-box assumptions. Maybe someone wants to encode front-left and rear-left for some reason, or centre and a sub.

joint stereo question joint stereo is suppose to save space but both files have the same size 8,56mb I compared them with "spek" and you can see that joint stereo have more data than stereo

That’s the other reason I always choose separated stereo: when specifying CBR of 320k, the “on-disk” size will be the same since each second contains 320kb regardless of joint or separated stereo and therefore you can’t get any of the “space saving benefits” and just get the muddiness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment