Another option if you're looking for an easy graphical way to accomplish this is HandBrake (although HandBrake does come in a commandline flavor as well, in case you're scripting the process, or maybe just prefer the commandline). Like the ffmpeg
that others have suggested here, HandBrake is available on Linux, Mac, and Windows, so it won't matter what operating system you're using. The process and interface will be almost exactly the same.
Now, the .webm
container is basically just a Matroska file, but what really makes it webm is the streams it contains. According to the WebM Project, the video stream must be either VP8 or VP9, and the audio stream must be either Vorbis, or Opus, so when using HandBrake, you'll need to make sure you're setting those options properly.
So, to encode a video to webm, naturally, you'll need to select a video, so let's do that first. In the toolbar across the top of the HandBrake window, the first option says "Open Source". It doesn't refer to the nature of the software (even though it is actually Open Source software), but rather it refers to opening a source of video using your operating system's standard file requester window which you've probably seen more than once already. Click that button, and navigate to a video on your system which you'd like to encode to a webm file.
Now that you've got a file selected, a few bits of the interface update with some new information, and you can start to select options for your conversion. There's a buncha interesting choices, but for this answer we'll focus on the ones related to the question of "How to create a webm video file?" rather than go over each option in detail. You can always read the HandBrake Documentation if you're interested in more details.
- On the first page of options that you see after starting HandBrake, about halfway down, you see "Format:" with an option for "MPEG-4" or "Matroska". This chooses the container. For webm, you'll want "Matroska".
- Above that you'll see a bar of option buttons that switches between various pages. You can set a variety of nifty options there, but the one we want next is "Video", so click that and look for "Video Encoder:" which you'll set to either "VP8" or "VP9" depending on your preference and use-case. VP9 is newer and compresses better, but requires a bit more CPU work for both encoding and playback, so keep that in mind.
- Last, but not least, let's look at the "Audio" options. Because you chose a video, there should be at least one (possibly more than one) audio stream in the "Track List" box on the "Audio" page. The left side of that audio track lists what format the track is currently (Something like
English (AC3)(5.1 ch)(48khz) Bitrate: 448kbps
for example). The right side of the ->
there lists what format you're converting to from what's on the left. That's where we need to ensure either Vorbis or Opus.
- Click the little pencil icon at the far right of the audio track you're encoding, and you'll get a new window on your screen where you can choose which track to encode and more importantly, the encoder details. Be sure the encoder is set to either Vorbis or Opus (Opus is newer and overall better than Vorbis, so probably the one you want to choose nearly every time), and choose 128, 160, or 192 for the bitrate for most normal purposes. You can go higher or lower, but know that higher will increase the size of the audio track without much (if any) noticeable improvement in audio quality, and much lower you may start to actually notice degradation in your audio track. The "Mix" setting will be personal preference, depending on source material and your needs for the output. Sample rate should generally be set to 48. "Gain" and "DRC" are if your audio track is too quiet, and if there's a really huge difference between loud and soft levels throughout the track. Click "OK" on that window to lock in your choices.
- At the bottom of the window, you see "Save As:" with a filename, and "To:" with a folder. "To:" is where you can choose where you want the file(s) saved at, and "Save As:" is where you choose what to name the file you're creating. Make sure that if you're trying to create a
.webm
file, that your filename actually ends with .webm
, or you're just creating a Matroska file with webm streams. (Totally valid, but some less sophisticated software might get confused if it expects webm and the file is named as something.mkv
despite them being the same thing, just with a different filename.)
At this point you should be ready to click "Start Encoding" in the toolbar to immediately begin the encode, or "Add to Queue" if you're encoding many videos and want to just start a list and do them all one after another automagically. And now you just wait. It can take a while, so be patient. It'll let you know when it's done.