Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

What list of commands should I do in ffmpeg/mencoder/some_other_CLI_app to get a video in all the right formats to use Video for Everybody?

i.e. Is there a subtlety that prevents there being a mechanical tutorial that says

TYPE=$(ffmpeg --find-information-about-the-video ... )
ffmpeg ... > video.mov
ffmpeg ... > video.flv
ffmpeg ... > video.webm
ffmpeg ... > video.h.264

Then copy and paste the Video for Everybody code into your page?

My goal is to have an embedded video in my personal webpage hosted by me. HTML5 with flash fallback is preferred, so the simplest way seems to be Video for Everybody. But that page leaves the most complicated part, encoding the video into all the different formats, to the reader to figure out by reading a long and complete article about video formats. Surely this isn't necessary. I could provide a list of commands for a user to blindly convert an audio file into a bunch of different formats. Hopefully an ffmpeg guru could do the same for video.

share|improve this question
Minor comment to your pseudocode examples: There's no .mov for HTML5 video, and there's no h.264 extension either. There is .264, which is the raw Annex B bytestream for NAL units. Video encoding is no rocket science, but you need to invest a little time to get to know the concepts. –  slhck May 13 '12 at 16:12

1 Answer 1

up vote 18 down vote accepted

Which profile / quality to choose?

I think the article you linked to is quite well written. You need a basic understanding of media encoding terminology to get started and not confuse codecs and containers as well as their properties.

Moreover, not every video is the same. Depending on the content and your presentation scenario you may want to change the encoding settings. Let's start with the profiles in H.264. From the article you posted:

Higher profiles use more optional features, offer better visual quality at smaller file sizes, take longer to encode, and require more CPU power to decode in real-time.

While mobile devices typically only support video encoded with the "baseline" profile, desktop applications can play "main" or "high" profile videos without issues. Here you need to make your first decision when encoding.

Then, think about quality and bit rate. Setting a quality factor for a certain video results in a certain average bit rate, and vice versa. There's no one command fits all here. In the following, you'll always have the choice between constraining a video to a certain bitrate or just setting a quality factor. The latter typically improves quality whereas the former gives you more control over a streaming scenario.

In general, the FFmpeg syntax for video bitrate is -b:v <rate>, where <rate> could be 1000k or 1M, et cetera.

So I think you just need FFmpeg calls to create the following video files, based on the article about video on the web. Someone has already done this for Windows (although they seem outdated with regards to FFmpeg options). I tried to come up with my own commands.

First off, make sure to download a recent ffmpeg version (don't call apt-get install ffmpeg or similar). Ideally, compile it yourself. It doesn't take too long.

WebM (VP8 / Vorbis)

Make one version that uses WebM (VP8 + Vorbis)

Let's start here. We specify the video and audio codecs with c:v and c:a.

We can use qmax and qmin value for the encoder to choose when trying to reduce the file size. You should set the b:v option to specify bitrate as well. Achieving good quality with libvpx is a little hard – see the VPX encoding guide for more info.

ffmpeg -i input.mp4 -c:v libvpx -qmax 42 -qmin 10 -b:v 1M -c:a libvorbis -q:a 4 -f webm out.webm

Play around with the audio options if you like. Vorbis defaults to 128 kBit/s but you can set q:a between 0 and 10 (higher means better), with 4 being default.

MP4 (H.264 / AAC)

Make another version that uses H.264 baseline video and AAC “low complexity” audio in an MP4 container.

That's pretty easy. Specify the codec and profile. Now you can choose a quality lefel (CRF, constant rate factor) for x264. Set it lower for higher quality and higher for worse quality (17-28 are sane values). You can also exchange the crf option with b:v for a certain bitrate. Check the x264 encoding guide for more info.

ffmpeg -i input.mp4 -c:v libx264 -profile:v baseline -crf 23 -c:a libfaac out.mp4

Change baseline to main if you target only desktop clients.

The audio defaults to 128 kBit/s again, but you can set q:a for variable bitrate, where values range from 0 to 500. 100 is default and higher means better.

By default you will get AAC-LC (Low Complexity) audio. If libfaac does not work for you, use -c:a aac -strict experimental instead, which doesn't deliver as good quality and doesn't do VBR, so you can only use b:a. You can also use libfdk_aac, which is the highest quality AAC encoder for FFmpeg. See the AAC encoding guide for more info.

Ogg (Theora / Vorbis)

Make another version that uses Theora video and Vorbis audio in an Ogg container.

Again, we'll specify the codec and re-use the audio options from above. You can set the quality through q:v and q:a, where higher values mean higher quality. Values range from 0 to 10.

ffmpeg -i input.mp4 -c:v libtheora -q:v 4 -c:a libvorbis -q:a 4 out.ogg

Or just use a bitrate with b:v instead.

ffmpeg -i input.mp4 -c:v libtheora -b:v 1M -c:a libvorbis -q:a 4 out.ogg

Also check out the Theora/Vorbis encoding guide.

share|improve this answer
The 2013-12-19 version of one of your paragraphs cuts off in mid-sentence. "The audio defaults to 128 kBit/s again, but you can set q:a for variable bitrate, where values range from 0 to 500. 100 is default and higher means better. If" –  Alan De Smet May 2 '14 at 18:57
Thanks, not sure what I did there. –  slhck May 2 '14 at 19:20
@slhck makes a lot of sense, but my two cents are that you drop Ogg and replace it with mpegts/m3u8 to support all the iOS devices or those that accept HLS. You can reuse the .mp4 files and just add the mpeg-ts processing in ffmpeg. –  Mondain Dec 20 '14 at 15:41
@Mondain Indeed, but MPEG-TS/.m3u8 is not generally HTML5-compatible video. You need an HLS server and you need to know a little more about streaming, which is not really within the scope of this question. –  slhck Dec 20 '14 at 15:49
Good points, but from my experience thus far a simple http server can serve m3u8 to a video tag. The only thing one normally needs to do is add the mime types for m3u8 and ts to the respective server configuration. –  Mondain Dec 20 '14 at 15:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.