How to Compress a Video for the Internet

This article explains how to compress a video for the Internet, and what settings work best. It is assumed that you are after the best quality, within your limitations.

It builds on three earlier articles, which might be good reading before you go on:

How to compress a video

Reduce size without loss in quality. If you’re using a professional NLE, then I recommend you compress your video from it. My favorite encoder bar none is Adobe Media Encoder or Adobe After Effects.

If you don’t have access to professional tools, use Handbrake. Well, actually, even if you have professional tools, try it – sometimes it does better.

Let’s look at how images compress in JPEG (actual size of the image is 1920×1080 8-bit RGB):

As you can see, quality 8 shows visible artifacts, while quality 12 is visually indistinguishable.

In video-speak, let’s assume the frame rate is 24 fps. If the size of each frame is 575 KB, then the data rate is about 100 Mbps. This is why broadcast guidelines often call for 100 Mbps as the data rate if you’re using an intra-frame codec. Nowadays, most cameras record in inter-frame mode.

For the purposes of this article, I’ve used Canon C300 footage generously made available by Alister Chapman. You can download it here. I’m only going to show you stills from the video, since Youtube re-compresses already compressed footage and that’s quite pointless for evaluative purposes. Here’s the original image, exported as a TIFF from After Effects (I’ve compressed it using the 12 JPEG setting):AA003601 (98842)_12

Here’s what happens if we compress the original TIFF file with various JPEG settings (similar to what we’ve done above, click to enlarge):

JPEG Side by Side Compression

The results are similar to our ‘perfect’ image above. From quality level 8 on down you can see clear artifacting.

The difference with Inter-frame compression

What happens when we use inter-frame compression? We actually get more leeway, since we have frames adjacent to the current frame to use for compression as well. The C300 typically shoots 50 Mbps Long GOP, which is the minimum recommended data rate by broadcasters for inter-frame codecs.

In order to compress the sequence, I imported the clip into After Effects and rendered the movie in H.264 with various bit rate settings. The results are as follows (click to enlarge):

Same Frame H264 Compression Side by Side H264 Compression

Do you see what I see? At 5 Mbps, the details in the image turn into mush (look at the tree, bricks and sky). 10 Mbps seems to be the limit, even though it doesn’t look very pretty. 20 Mbps is more like it.

What do we make of this?

Well, if 100 Mbps is good for intra-frame codecs, and level 8 (corresponding to 50 Mbps) is acceptable for web viewing, then similarly, 20 Mbps is acceptable web viewing for a 50 Mbps video. In any case, most Internet video platforms are based on H.264, which is an inter-frame codec. What this means is, no matter what you’re shooting with, you might want to have a resulting video that is at least 20 Mbps in size for it to be reasonably good web video quality.

And that might not be enough, either.

Youtube and Vimeo settings

What does Youtube and Vimeo have to say? First, check out their specifications:

In the case of Youtube, they recommend a minimum of 8 Mbps for 1080p videos, but would prefer 50 Mbps if you have the Internet connection to swing it.

In the case of Vimeo, they recommend at least 10 Mbps for 1080p, and ideally 20 Mbps if you can swing it.

The question is: Can you swing 10 Mbps or more? Most consumer Internet connections have fast download speeds, but slow upload speeds. At 4 Mbps upload, you will need to wait for 2.5 times the video duration for your upload to complete (assuming your video is compressed at 10 Mbps). What if your video is compressed to 20 Mbps? A five minute video being uploaded at 4 Mbps will take 25 minutes and will be 750 MB. A five minute 50 Mbps video will take an hour to upload and will be about 1.8 GB. A 50 Mbps video that is an hour long will take about 2.5 days and be 110 GB.

A slower Internet connection means more time to upload. If your video is really important, that’s what you should aim for. Look at your limitations, and work backwards. Don’t compromise quality by being in a hurry.

Okay, so why did I say 20 Mbps might not be good enough?

Youtube and Vimeo will further compress your videos if they see fit. You usually have no choice in this regard. I’ve found they further compress your videos by half. E.g., 1080p videos tend to become 5 Mbps and 720p videos tend to become 2.5 Mbps or so. It’s their ‘secret sauce’, which ruins our recipe! I mean, isn’t it easier for them to tell us to encode at their preferred data rate and let us manage the compression? We’re doing it anyway, right?

Here are some other settings to look out for:

  • Progressive scan (no interlacing) only. Leave interlacing to broadcasters.
  • Color bit depth is 8 and chroma sub-sampling is 4:2:0. Color space is Rec. 709, though it should be sRGB (the differences are negligible so don’t worry about it).
  • High Profile H.264 instead of Main Profile.
  • 2 consecutive B frames, which means a keyframe every third frame.
  • Closed GOP. GOP of half the frame rate. Choosing the keyframe or I-frame frequency lets you control this.
  • CABAC – it’s just another level of coding that gives you better quality, but takes more time to encode.
  • Variable bit rate if possible, though I highly recommend Constant Bit Rate (CBR) if you don’t care about the file size.
  • Audio is AAC-LC, sampled at 48 KHz, at 384 kbps (stereo) or better.

As far as data rate is concerned, try your best to go as high as possible, with 50 Mbps being the benchmark. If your data rate is lower than this, you lose control over your quality. You should always test your videos in small chunks – don’t get lazy.

Uploading videos to the Internet isn’t rocket science. I hope this simple article has explained how to compress a video for Internet consumption.

What do you think? What results have you achieved in your own uploads?

6 replies on “How to Compress a Video for the Internet”

  1. Hello Sareesh….thanks for your many great articles.

    I am having some trouble understanding the optimum settings for ‘Key Frame Distance” in Premiere Pro. I have seen some say I should choose the equivalent of my frame rate (e.g. ‘Key Frame Distance: 24’ for a 24fps video export).

    Please help me to understand this setting.

    Thanks!

    1. When you’re talking about that are you referring to the export settings when you choose interframe codecs? If yes, then for example once you select the appropriate codec leave the distance as is, as the long GOP defaults have been tuned for best results. A few years ago I did test this but I never found any improvements. Try rendering a clip at default settings and then change, render, rinse and repeat.

      I leave it at their default values.

      1. Hello, when you say a Keyframe every third frame it means a keyframe distance = 3? I’m trying to export a 360 video to youtube, we are having the problem to buffering the video in our 360 app. Our video has 24fps. Could you help with this issue?
        (I followed the other settings like youtube has suggested).

        Thanks in advance.

  2. Compressing a video is essential when you want to upload a video which is too large in size. In doing this, we have to be familiar with terminologies often related to compressing a video file like codec, key frame, artifacts, Bit/data rate, variable bit rates, frame rates and resolution. Compressing a video file is easy to do by following these basic steps: Understand why you need to Upload a video, Open your raw video file in a video editing program, Export the video, Select the file format, Select the video format (codec), Select the bit rate, Select the resolution, Adjust the key frame and frame rate, select the encoding mode, Select your audio options. In line with this, monitoring your videos in Vimeo and Youtube will be a hassle-free with the use of BeUpon online tool. This system will help you track the status of your videos 24/7. It alerts you whenever your videos were down. It also helps to set-up back up videos. For more information, visit this site: http://www.beupon.com/.

  3. Thanks for this, I was testing myself. But usual, you read my mind! Brutal upload times are worth it, to avoid the hideous compression artefacts on skin, most noticeably.  I wish YT were a bit more honest about their special sauce!

Comments are closed.