Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to accomplish something similar to YouTube player. The biggest issue I'm facing now is how should I process user uploaded video files.

For example, since I want to switch between 240p, 360p, 480p and 720p I need to convert each uploaded video file to 4 different files for each resolution, and because not all browsers can play .mp4 I need .ogg, .mp4, .webm, so that makes 12 video files. If it takes 10 minutes to process 1h video file it would take me about 2h just to process that file which is insane. I know that YouTube uses cloud servers to process each video file and has a lot of processing power but I think there must be some kind of trick to this.

So my question is what can I do about this and how does YouTube deal with this?

My second question is, is FFmpeg suited for this kind of work, and if so why does this command take pretty much for ever to finish? I ran this command on a 720p 3 minutes long video file and after 15 minutes of processing I just canceled the process.

ffmpeg -i hd.webm a.mp4

This one on the other hand took about 7 minutes to finish but it generated 200mb video file out of 25mb file:

ffmpeg -i hd.webm -c:v libx264 -preset ultrafast a.mp4
share|improve this question
up vote 3 down vote accepted

You will need only 4 video files for the different video sizes. But you actually don't want those 3 different media containers, where you want just one container which can be handled by your video player. Encode the video using only one codec, like H.264.

Now you are just processing video's without knowing what you are actually doing. The default settings by FFmpeg are used, that's why you experience those results. The ultrafast setting for libx264 encodes relatively fast, but causes a bigger filesize. Read the x264 encoding guide for more information about the most important settings for libx264.

If you want to encode a video to e.g. 480p here is an example of a command line:

ffmpeg -i hd.webm -s 854x480 -b:v 15M -b:a 128k -c:v libx264 -c:a libfdk_aac -preset veryfast output.mp4

Also this YouTube support page describes how YouTube likes to receive videos. Maybe you can learn something from it as well.

share|improve this answer
You're basically right, but if the OP needs HTML5 video, the problem is that still not all browsers support H.264, so the OP needs at least VP-8 or Theora if they want to stay backwards-compatible with some browsers. For the other formats/codecs see also: What bunch of ffmpeg scripts do I need to run “Video for everybody”? – slhck May 16 '13 at 10:10
Also note that to get libfdk_aac, you'll have to compile it yourself (there are guides on the ffmpeg wiki) - due to license incompatibilities, fdk_aac can't be distributed in binary form with ffmpeg. This is certainly worth it, though, since libfdk_aac is so much better than the other AAC encoders ffmpeg can use. – evilsoup May 16 '13 at 15:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .