Sat, 22 Feb 2025 08:44:53 +0000
WEBM is one of the most popular video formats used for web streaming. MP3 is one of the formats used for audio playback. There will be times where you will need to extract audio from a WEBM file and covert it to a MP3 file. With Linux, there are command-line tools for almost everything and this use case is not an exception. In this guide, we will explain different methods to convert WEBM to MP3 using ffmpeg, sox, and a few online tools.
Why Should You Convert WEBM to MP3?
Let us see some use cases where you will have to convert a WEBM file to MP3 file:
- You need only the audio from a web video
- Your media player does not play WEBM file
- Convert a speech recording from video to audio format
- Reduce file size for storage and sharing
How to Convert WEBM to MP3 Using ffmpeg
Let us use Linux’s in-built tool “ffmpeg” to extract audio from a WEBM file.
How to Install ffmpeg
If your Linux system already has ffmpeg, you can skip this step. If your device doesn’t have this command-line tool installed, execute the appropriate command based on the distribution:
sudo apt install ffmpeg # For Debian and Ubuntu sudo dnf install ffmpeg # For Fedora sudo pacman -S ffmpeg # For Arch Linux
Convert with Default Settings
To convert a WEBM file to MP3, execute this command:
ffmpeg -i WEBMFileName.webm -q:a 0 -map a MP3FileOutput.mp3
How to Convert and Set a Specific Bitrate
To set a bitrate while converting WEBM to MP3, execute this command:
ffmpeg -i WEBMFileName.webm -b:a 192k MP3FileOutput.mp3
How to Extract Only a Specific Part of Video to Audio
There will be times where you don’t have to extract the complete audio from a WEBM file. In those cases, specify the timestamp by following this syntax:
ffmpeg -i WEBMFileName.webm -ss 00:00:30 -to 00:01:30 -q:a 0 -map a MP3Output.mp3
Executing this command extracts the audio between timestamps 30 seconds and one minute 30 seconds and saves it as a MP3 file.
Advanced WEBM to MP3 Conversion
Here is an alternative command that processes the WEBM file faster. This method uses “-vn” parameter to remove the video and uses the LAME MP3 encoder (indicated by the “-acodec libmp3lame” parameter) and sets a quality scale of 4. This balances the file size and quality.
ffmpeg -i input.webm -vn -acodec libmp3lame -q:a 4 output.mp3
How to Convert WEBM to MP3 Using sox
The “sox” tool is an “ffmpeg” alternative. To install sox, execute the command:
sudo apt install sox libsox-fmt-all
This command works best for Debian and Ubuntu distros. If the above command does not work, use the ffmpeg tool explained earlier.
To extract audio from the WEBM file, use the command:
sox WEBMFileName.webm AudioFile.mp3
How to Use avconv to Extract Audio
Some Linux distributions provide “avconv”, part of the libav-tools package, as an alternative to ffmpeg. Here is how you can use install and use it to extract MP3 audio from a WEBM file:
sudo apt install libav-tools avconv -i VideoFile.webm -q:a 0 -map a AudioFile.mp3
How to Convert WEBM to MP3 Using Online Tools
If you do not have a Linux device at the moment, prefer a graphical user interface, or in a hurry to get the audio extracted from WEBM files, you can use any of these web-based converters:
How to Check MP3 File Properties
Once you have converted the WEBM file to a MP3 file, it is a good practice to check the properties or details of the MP3 file. To do that, execute the command:
ffmpeg -i ExtractedAudioFile.mp3
One of the best practices is to check the audio bitrate and format by executing the command:
mediainfo ExtractedAudioFile.mp3
How to Automate WEBM to MP3 Conversion
The simple answer to this problem is by using scripts. Auto converting video files to audio files will help you if you frequently convert a large number of files. Here is a sample script to get you started. You can tweak this script to your requirements based on the command we just explained earlier.
for file in *.webm; do ffmpeg -i "$file" -q:a 0 -map a "${file%.webm}.mp3" done
Next step is to save this script with the name “convert-webm.sh” and make it executable.
chmod +x convert-webm.sh
To run this script in a directory with WEBM files, navigate to the required directory in the terminal window and run the command:
./convert-webm.sh
Key Takeaways
Extracting audio from a WEBM file and saving it as MP3 file is very easy if you have a Linux device. Using tools like ffmpeg, sox, and avconv, this seemingly daunting task gets over in matter of a few seconds. If you frequently do this, consider creating a script and run it on the directory containing the required WEBM files. With these techniques, you can extract and save high-quality audio files from a WEBM video file.
We have explained more about ffmpeg module in our detailed guide to TS files article. We believe it will be useful for you.
The post WEBM to MP3: How can You Convert In Linux appeared first on Unixmen.
Recommended Comments