I need to convert audio files to mp3 using ffmpeg.
When I write the command as ffmpeg -i audio.ogg -acodec mp3 newfile.mp3
, I get the error:
<
You could use this command:
ffmpeg -i input.wav -vn -ar 44100 -ac 2 -b:a 192k output.mp3
Explanation of the used arguments in this example:
-i
- input file
-vn
- Disable video, to make sure no video (including album cover image) is included if the source would be a video file
-ar
- Set the audio sampling frequency. For output streams it is set by default to the frequency of the corresponding input stream. For input streams this option only makes sense for audio grabbing devices and raw demuxers and is mapped to the corresponding demuxer options.
-ac
- Set the number of audio channels. For output streams it is set by default to the number of input audio channels. For input streams this option only makes sense for audio grabbing devices and raw demuxers and is mapped to the corresponding demuxer options. So used here to make sure it is stereo (2 channels)
-b:a
- Converts the audio bitrate to be exact 192kbit per second
https://trac.ffmpeg.org/wiki/Encode/MP3
VBR Encoding:
ffmpeg -vn -ar 44100 -ac 2 -q:a 1 -codec:a libmp3lame output.mp3
If you have a folder and sub-folder full of wav's you want to convert, put below command in a file, save it in a .bat file in the root of the folder where you wan to convert, and then run the bat file
for /R %%g in (*.wav) do start /b /wait "" "C:\ffmpeg-4.0.1-win64-static\bin\ffmpeg" -threads 16 -i "%%g" -acodec libmp3lame "%%~dpng.mp3" && del "%%g"
Never mind,
I am converting my audio files to mp2 by using the command:
ffmpeg -i input.wav -f mp2 output.mp3
This command works perfectly.
I know that this actually converts the files to mp2 format, but then the resulting file sizes are the same..
As described here input and output extension will detected by ffmpeg
so there is no need to worry about the formats, simply run this command:
ffmpeg -i inputFile.ogg outputFile.mp3