If you need to extract the audio from an .WEBM
movie file to an .MP3
audio file you can execute the following:
FILE="the-file-you-want-to-process.webm"; ffmpeg -i "${FILE}" -vn -ab 128k -ar 44100 -y "${FILE%.webm}.mp3";
The first command will assign the file name to a variable, we do this to avoid typing errors in the second command where we might want to use the same name for the audio file.
The second command, will use ffmpeg
to extract the audio. The -i
flag, indicates the file name of the input. We used the flag -vn
that will instruct ffmpeg
to disable video recording. The -ab
flag will set the bit rate to 128k. The -ar
flag will set the audio sample rate to 441000 Hz. The -y
flag will overwrite output file without asking, so be careful when you use it.
In case we want to automatically process (batch process) all .WEBM
video files in a folder we can use the following:
for FILE in *.webm; do echo -e "Processing video '\e[32m$FILE\e[0m'"; ffmpeg -i "${FILE}" -vn -ab 128k -ar 44100 -y "${FILE%.webm}.mp3"; done;
The above script will find all .WEBM
files in the folder and process them one after the other.
UPDATE:
The following command will find all webm
files that are in the current directory and in all sub-folders and extract the audio to mp3
format.
find . -type f -iname "*.webm" -exec bash -c 'FILE="$1"; ffmpeg -i "${FILE}" -vn -ab 128k -ar 44100 -y "${FILE%.webm}.mp3";' _ '{}' \;
The filename of the audio file will be the same as the webm
video with the correct extension. The webm
extension will be removed and replaced by the mp3
extension e.g hi.webm
will become hi.mp3
This post is also available in: Greek
Post updated to show a one line solution to extract audio from all video files in current folder and its sub-folders.
WOW this is totally perfect, thanks so much!!
thank you very much,
the first method didn’t work here
Seems stream 0 codec frame rate differs from container frame rate: 1000.00 (1000/1) -> 15.00 (15/1)
Input #0, matroska,webm, from ‘NIBIRU IS COMING WITH ITS ANNUNAKI WARRIORS part 2 of 2 Project Camelot-saDSLcHMzMU.webm’:
Duration: 01:00:25.03, start: 0.000000, bitrate: N/A
Stream #0.0: Video: vp8, yuv420p, 320×240, PAR 1:1 DAR 4:3, 1k fps, 15 tbr, 1k tbn, 1k tbc (default)
Stream #0.1: Audio: vorbis, 44100 Hz, stereo, s16 (default)
Unable to find a suitable output format for ‘NIBIRU IS COMING WITH ITS ANNUNAKI WARRIORS part 2 of 2 Project Camelot-saDSLcHMzMU.webm,mp3’
but your update got it done –
cool!
Good morning,
All 3 snippets use the same basic command to process the files.
As I can see from you log information (thank you for posting that as well), it appears that you used a comma ‘,’ instead of a full stop ‘.’ right before the mp3 file extension.
Your output filename should be ‘NIBIRU IS COMING WITH ITS ANNUNAKI WARRIORS part 2 of 2 Project Camelot-saDSLcHMzMU.webm.mp3’ instead of ‘NIBIRU IS COMING WITH ITS ANNUNAKI WARRIORS part 2 of 2 Project Camelot-saDSLcHMzMU.webm,mp3’.
Because of that typo, ffmpeg thought that the desired extension was ‘.webm,mp3’, which it does not know, instead of ‘.mp3’ and that is why you got the error.
Thank you for posting this very useful information.
Thank you!
for you guys out there who want a quick bash function to do the above:
mp3conv320 () {
INFILE=$1
ffmpeg -i “$INFILE” -vn -ab 320k -ar 44100 -loglevel 48 “${INFILE%.*}.mp3”
}
Now, to execute:
$ mp3conv320 input-file.webm
It will convert the webm file to mp3, and output:
input-file.mp3
I would place this function into your ~/.bashrc file.
enjoy 😉
Which is great until your file has spaces in it. Then it doesn’t work.
Thanks a lot !
Thanks, the script worked well!
2021 works perfect ubuntu…thanks so much
Manjaro i3 Jan 2022. Works out of the box
Pingback: Convert audio files to mp3 using ffmpeg - Design Corral