Skip to main content

Video Formats and Codecs

Just like with images, choosing your video codec is a crucial performance and quality consideration. 

The main two video codecs

There are two dominant video codecs, an older one and a newer one, with their own pros and cons.

x264/AVC (older)

The x264 codec is fast to encode, but results in comparatively large filesizes for a given quality. It's also a lot cheaper to transcode videos to x264, as it requires a lot less processing power.

x265/HEVC (newer)

The x265 codec gives much superior quality for a given filesize, allowing for a video of the same quality as an x264-encoded one to be even 2-3 times smaller. This is a huge improvement, and especially important for the web, where CDN bandwidth for videos can easily get very high indeed.

There are two downsides to x265. Firstly, it takes a lot longer to encode; in the past compatibility was also a problem, but most browsers and video players support it now, and compatibility issues are a smaller and smaller problem for it. The second, and more relevant problem is that it's often massively more expensive to transcode videos to x265; you have to consider if the reduced CDN bandwidth costs are going to be worth that or not.

Constant Rate Factor (CRF)

This is a quality mechanism, specific to the x264 and x265 codecs. It's an arbitrary number from 0-51 representing the output quality for the processed video; 0 is effectively lossless, and 51 is the lowest quality. Beware: the default CRF settings for x264 and x265 are different, and they are not directly comparable!

The default CRF for x264 is 23, and the default CRF for x265 is 28. These are more or less equivalent in quality, as x265 achieves better quality and lower filesizes than x264, so you have to adjust the CRF you want depending on which one you are using, as a CRF of 23 does not represent the same quality level on x264 vs x265.

x264 vs x265: video transcoding tests

I did some brief testing to demonstrate the difference in transcoding time and resulting filesizes that result from using x264 vs x265, and produced a spreadsheet of results, which you can find here

Conclusion

In theory, using x265 would be a no-brainer; it's a lot more efficient for hosting videos. Unfortunately...

In practice, unless you are transcoding very few videos which will have huge view counts, the cost of transcoding to x265 is prohibitively expensive.