If you’re like me, you probably have a serious issue with digital hoarding, refuse to delete anything and methodically collect and categorize all the things.
We need help, yes.
In the meantime, there’s the option of substituting your carefully hand-encoded AVC video files and give them the ol' modernization treatment with our new best friend, HEVC.
If you’re confused at this point, here’s a short glossary:
- AVC: Advanced Video Codec (or x264 for the specific encoder): The video codec used in pretty much all modern video.
- HEVC: High Efficiency Video Coding (or x265 for the specific encoder): The new(er) kid on the block and successor to AVC.
Your standard run-of-the-mill video file that obviously fell from a truck will usually come in either an mp4 or mkv container with AVC video and some kind of audio.
If you want to reduce the file size of the video and keep the quality reasonably high, re-encoding the file into HEVC seems to be a valid plan. Obviously it would be technically better to rip the source medium again into HEVC directly instead of transcoding an existing lossily-encoded file, but… yeah, that would be more work and less bashscriptable.
On a side note, if you want a little primer on video compression, I heartily recommend Tom Scott’s video on a related issue.
Anyway, long story short:
so I took the first episode of Farscape, which I had conveniently lying around in a neat little matroska-packaged AVC+DTS combo, cut out 15 minutes, and then re-encoded this 15 minute clip in a bunch of ways.
Why? Well, initially I wanted to figure out how best to transcode my existing Farscape rips to save the most space while maintaining a reasonable amount of quality, so I did the scientific(ish) thing and created a bunch of samples.
And yes, HEVC encoding without proper hardware support is a pain and I spent way too much CPU time on this little project, but soon™ we will have reached the point were HEVC is the new de-facto standard and when that point comes I will be ready.
Look, I’m not an expert on video encoding, I’m not familiar with the internals of the encoders, which means I know shit about the standards and the software implementations. I’m just some guy who wanted to save disk space and decided to do some testing in the process.
I re-encoded the aforementioned video clip using the following settings:
- Codecs: x264 and x265
- CRF: 1, 17, 18, 20, 21, 25, 26, 51
- Presets: placebo, slower, medium, veryfast, ultrafast
The result is 80 files of varying quality and size.
Judging file size is pretty straight-forward: Just compare the file sizes. Magic.
As for quality, that’s a difficult one, and since I lack a proper testing setup and about three dozen people to judge the subjective quality of each clip, I’ll just be using the SSIM as calculated by comparing each clip with the original clip, and see how far that gets me.
So to start, here are the first five rows:
To start of, here’s some tables:
That’s… accurate, yet not very visually stimulating.
Needs more plot.
Okay, let’s zoom in a little by ignoring CRF 51 and CRF 01, as they’re silly anyway.
Hm, yes, quite.
Now a breakdown to compare codecs across presets:
As you might have noticed, absolute file sizes might not be as interesting and/or generalizable as relative size changes, so here we go:
To start, let’s do the raw data table thing again:
Please note that I had to multiply the SSIM values by 100 to get them to display as something other than a flat 1 because rounding is hard, apparently.
Also, yes I know the “sum” column/row doesn’t make sense, but it’s the default and I couldn’t be bothered to try to remove it.
And now, the plotty thing.
Now let’s do that thing again where we compare all the CRF by preset cells in a grid, but now using SSIM as a metric:
Well that’s not very enlightening, is it?
I’ve tried log scales on this one, but it didn’t really help.
Let’s look at the subset of reasonable CRFs:
Well if there’s a lesson here, it seems that ultrafast is probably not the way to go.
Let’s take another look, ignoring the ultrafast data.
Keep in mind that this is not a scientific study.
The results might be limited to my version of HandBrake (
1.0.7 (2017040900)), or it might be limited to re-encoding a lossily-encoded file, or it might be limited to encoding SD content and behave slightly differently with 4k content. My point is: I don’t know. I have no idea how generalizable these results are, but with the limited amount of certainty I can muster, I’ll give you this:
- Don’t use ultrafast. veryfast is fast as well, and apparently better(ish)
- Also, don’t use placebo. Why would you even do that to yourself1.
- Keep your CRF around the 20’s. Seems reasonable.
Note: If you have anything else you want to try with the data, you can grab it here.
If I do this again, I will track the encoding time. Seriously, don’t to placebo. ↩︎