While WebM is a lightweight and efficient web-friendly video format, it can be tricky to make it works on different devices and platforms. One workaround is to convert your WebM files to other popular formats like MP4, AVI, or MKV to ensure compatibility with various media players and platforms.
This article shows you how to convert WebM videos to your desired formats on Ubuntu Linux using various tools such as FFmpeg, VLC, and Handbrake.
Note: While the instruction here is focused on Linux, the tools used are cross-platform compatible, which means they will work on macOS and Windows too.
Introduction to WebM Format
WebM is a free and open-source media file format that is primarily used to deliver video content on the Internet. It is designed to provide high-quality video at a smaller file size relative to other formats like MP4 or AVI. WebM is based on the VP8 and VP9 video codecs and the Opus and Vorbis audio codecs.
Converting WebM Videos Using FFmpeg
FFmpeg is a multimedia framework that is free, open-source, and works on various platforms like Windows, Linux, and macOS. You can use the FFmpeg command line tool to convert, record, stream, and manage video and audio files of various formats.
Installation
Before we start converting, ensure that you have FFmpeg available on your distributions. You can verify your version using this command:
ffmpeg -version
If FFmpeg is present, you’ll see its version information. If not, you can use your default package manager to install it.
For example, on Ubuntu/Debian-based systems, run this:
sudo apt install ffmpeg
To install FFmpeg on CentOS/Fedora or REHEL-based distro, you can use this command:
sudo dnf install ffmpeg
Similarly, for Arch Linux, run the following command:
sudo pacman -S ffmpeg
Conversion
Navigate to the directory that contains the video using the cd command in the terminal.
After that, type the following ffmpeg
command, replacing output.mp4
with your desired output filename:
ffmpeg -i myvideo.webm output.mp4
Here -i
flag specifies the input file, and the rest is pretty straightforward. Hit enter, and FFmpeg will start converting your WebM file to MP4.
You can also use the previous ffmpeg
command to convert WebM to other formats by specifying the desired output format extension, such as .avi, .mkv.
If you want more control during the conversion process, you can specify additional parameters. For example, to encode a WebM video to MP4 with the H.264 video codec and the AAC audio codec, your command would look like this:
ffmpeg -i input.webm -c:v libx264 -c:a aac output.mp4
Here, -c:v libx264
specifies the H.264 video codec, and -c:a aac
selects the AAC audio codec.
Additionally, you can control the output quality using the -qscale
or -crf
options:
ffmpeg -i sample.webm -q 0 sample2_ffmpeg.mkv
You can also adjust the bitrate, CRF value, and other options to optimize the output quality and file size based on your needs.
Converting WebM Videos Using VLC
VLC is another cross-platform multimedia player that can be used for converting video files. While not as feature-rich as FFmpeg, VLC offers a convenient graphical interface for basic conversions.
Installation
Most Linux distributions usually have VLC pre-installed on them. If it isn’t present, you can install it by using your default package manager, such as apt.
For example, on Ubuntu/Debian-based systems, use:
sudo apt install vlc
On Fedora or CentOS, run the following command:
sudo dnf install vlc
For Arch Linux, use this:
sudo pacman -S vlc
Conversion
Open the VLC media player. Next, open the conversion window by selecting Media -> Convert/Save:
Click the Add button and choose the WebM file you intend to convert. After that, click the Convert/Save button to open the conversion window:
Within the conversion window, specify your output format by clicking the Browse button next to the Destination File option. Then, from the Profile dropdown menu, select your desired output format (e.g., MP4):
Finally, click Start, and VLC will convert your WebM video to an MP4 video using the H.264 codec and MP3 audio.
That’s it! VLC will handle the rest, and you’ll have your video converted to the desired format.
Furthermore, you can adjust the video encoding settings, such as video bitrate and resolution, by clicking on the Settings button.
Converting WebM Videos Using HandBrake
HandBrake is an open-source video transcoder that can handle multiple video formats, including WebM. It offers both GUI and CLI interfaces for converting videos.
Installation
Just like VLC and FFmpeg, HandBrake is also found in the repositories of various Linux distributions. For example, to install HandBrake on Ubuntu or Debian, run this:
sudo apt install handbrake
This will install the graphical interface of the HandBrake. However, you can use the below command to install a command-line interface:
sudo apt install handbrake-cli
On Arch Linux, Fedora, or CentOS, you can install HandBrake using Flatpak:
flatpak install flathub fr.handbrake.ghb
Conversion
Launch HandBrake and click the Open Source button located at the top left. Choose your desired WebM file and click Open:
Next, choose your desired output format from the Preset dropdown menu (e.g., MP4). After that, specify the format of the output video and its destination location along with the output file name:
HandBrake provides various options for tweaking settings like video quality, bitrate, and audio encoding. You can adjust them based on your needs by switching to their specific subsection.
Once you are done with your adjustment, you can click Start Encode to begin the conversion process.
That’s it, you have converted the WebM videos to MP4 format.
Furthermore, if you prefer to use HandBrake CLI, you can use the following command to encode WebM to MP4 using the x264 video codec and a quality setting of 20:
HandBrakeCLI -i input_file.webm -o output_file.mp4 -f mp4 -e x264 -q 20
You can also convert any video files to H.264 MP4 format using the HandBrake command line tool.
Converting Multiple WebM Files Using Bash Script
Do you want to convert multiple WebM videos to any other format at once? If yes, then look no further than bash scripting. For example, to convert all WebM files to MP4 format using FFmpeg, you can use this script:
#!/bin/bash #WebM Converting Bash Script for file in *.webm; do ffmpeg -i "$file" -c:v libx264 -c:a aac "${file%.webm}.mp4" done
After creating a script, you need to save this script as a file, such as sample_script.sh
, and make it executable with this command:
chmod +x sample_script.sh
Lastly, run the script to initiate the batch conversion:
./convert_webm.sh
This script will iterate over all WebM files in the specified directory and encode them to MP4 using the AAC audio codec and H.264 video codec.
Additionally, you can modify this script to specify a different output format by changing the extension in the FFmpeg command in the bash script.
Wrapping Up
You’ve successfully learned various methods to convert WebM videos to other video formats on Linux. For Windows users, you can try these video converters too.
All images and screenshots by Haroon Javed.
Our latest tutorials delivered straight to your inbox