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:
- What is Video Compression
- The Difference between Lossy and Lossless Compression
- Inter-frame vs Intra-frame Compression
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):
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):
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):
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?