I want to convert avi and wmv to mp4 for web and I use below code:
ffmpeg -I input.wmv output.mp4
Is that enough?


Yes it is. This will give you the default encoding settings, which are generally fine for web use.

You can specify settings to tweak the size, speed and quality, but you don't need to to get good results. The best guide I know of is the ffmpeg h.264 encoding guide wiki page.

For example, you could adjust the quality with the Constant Rate Factor setting (don't worry too much about what constant rate factor actually means, it's really just the quality setting) using -crf x where x is an interger between 0 (lossless, large file size not generally compatible with web delivery) and 51 (pretty crappy, small file size). The default is 23, which is pretty good, 17 is regarded as visually lossless, and somewhere between 17-28 is a sane value.

Another setting is the speed. If you're using CRF, adjusting the speed won't affect the quality of the output, it will just affect the file size—faster compression basically means the software will spend less time optimising, so the file will be larger. Speed is controlled by using the option
-preset presetname, where presetname is one of (in decreasing order of speed / increasing file size): ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, and placebo.

The playback devices that you expect the video to be played on is another thing you might want to consider. Setting the -profile:v and -level option (the :v bit means you're setting the profile for the video stream only) means that you can choose between more efficient compression with a higher profile/level, and greater compatibility with older or less powerful devices with lower profile/ level. -profile main is probably wise if you're expecting a general web audience, it's compatible with all iPads, apple tv2 and iPhone4 and their non-fruity equivalents. If your target audience is likely to be using an iPod touch gen 2 you might want to go with -profile:v baseline and if you want to be certain it can be played by as many devices as possibel you could specify the level as well, -profile:v baseline -level 3.0

As @LordNeckbeard pointed out, if you're encoding for web use where the video will be embedded in an HTML5 <video> tag then adding the option -movflags +faststart will allow the video to start playing as it downloads.

Putting it all together, this is an example of how you chain options together in ffmpeg. This is a very basic example, ffmpeg is extremely powerful and your commands can be as complicated as you want them to be. This example will give you high quality, be playable on older/less powerful machines, and chooses smaller file size over encoding speed. It is not a recommended setting, just an example of how you specify the encoding options:

ffmpeg -i thefile.wmv -profile:v main -crf 20 -preset slow output.mp4
  • I wouldn't use veryslow. That ramps up the refs count to upto 16. Can't be pleasant on underpowered devices. May also add some latency to startup. Stick to slow or add -x264-params refs=4 – Gyan Jun 21 '18 at 5:40
  • @stib For viewing via progressive download, such as putting the MP4 on a server and presenting it with the HTML5 <video> element, adding -movflags +faststart is highly recommended. Otherwise the video will need to be completely downloaded before playback can begin. – llogan Jun 21 '18 at 20:03
  • Thanks. I'll make some edits. I should note that the example isn't necessarily a recommended setting, just an example of how you chain options together in ffmpeg. – stib Jun 22 '18 at 1:49

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