Creative work

Which Codec is best to render video for YouTube in Blender?

This is a systematic test and review of the quality differences when using different settings in Blender VSE, so that you can find the FFMPEG Codec settings best to render video in Blender.

What options do you have?

With FFMPEG video as a rendering option in Blender, you get several container choices, but the relevant ones for our purpose of generating YouTube videos are these:

Containers:

  • MPEG4 = .mp4 (Tip: use this for reels and other stuff you want to upload from your phone)
  • Matroska = .mkv (my personal favorite)
  • Webm = .webm
  • Quicktime = .mov

Codec options:

  • MPEG4 (divx) (This is the worst, do not use this, ever!)
  • H.264 (this is okay for most purposes)
  • (Webm container with) VP9 (Google Alternative to H.265) (also okay)

Output Quality:

  • Lossless
  • Perceptually lossless

Everything after that, I won’t even list, because it is all eye-cancer-inducing.

Encoding speed:

  • choose “slowest” if you can render over night and want a small file
  • choose “realtime” if you want it asap

Audio:

Use AAC or MP3 with the same bit rate as your original file. If you don’t know how to look that up just open the file in VLC player and look at the info menu. It’s somewhere in there. I honestly most of the time just use MP3 and 320 kbps, cause that is already insane and I have never even met a person who could tell the difference between that and 128 kbps.

What problems can occur?

Color banding

In general, a problem that I have encountered a lot (and also read about on multiple sources) are color banding effects of “fringes”. Color banding is the correct term. It is a phenomenon that occurs when you compress a video or an image. Neighboring areas are lumped together into one color to make the palette—and therefore the file—smaller. More colors = more information = more disk space needed. At least for the formats we are talking about here. (There are ones where this doesn’t matter, but since you are not an image processing nerd writing your thesis using this knowledge, don’t worry about it.)

Bad news: Color banding occurs in all files that are available in Blender VSE, at least all that I have rendered on my debian.

If you want to avoid color banding, do this:

  • export every frame as a PNG file
  • render audio (with the native quality your audio has into the same file format)
  • combine PNGs and audio with an external tool, not in blender / with ffmpeg

Yes, as of 2022, this is the “solution”. Otherwise you just have to live with sub-optimal output—or use the tricks I will show you in this article.

Cave!

There are no true lossless options. The only proven lossless output in blender is PNG or raw (both do not include audio). “Lossless” always results in huge files, but with little to no benefit to the visual perception.

Which FFMPEG encoding leads to the fewest color banding effects?

000 original image exported via PNG render
The original image (from PNG). You can see a few fringes or bands, which is due to the fact that I wanted to save disk space while hiking a 110 km trail. I wanted to shoot as much video as possible and not worry about a full memory card (and also not bring a lot of cards that I might then lose somewhere in the wilderness etc.)

Honest answer would be: “None, get a windows PC and install Premiere Pro and do everything with that, cause Open Source Codecs and rendering software is trash.” But I am trying to help you, because I have myself sifted through countless useless Stackexchange posts. So here is my test run:

I analyzed part of a cross-section of the first frame from a short video I rendered with these different settings and compared it to the original. My conclusion is: Nothing but PNG output (images, not video, there is no “PNG video”) looks like the original. And you can tell. You clearly see bands in both “lossless” and “perceptually lossless” video output. However, this might not be much of a problem, if you don’t film large areas of similar color with a slow gradient, e.g. skies, building walls or other, preferably light, surfaces. But since I film skies a lot, it annoys me.

Now here is the output I generated with different settings:

All of these snapshots are from videos created with different rendering settings. Can you tell the difference? I can’t, but I know there are slight differences. And even this is a little bit of a lost cause, I still want the least shitty result…

A systematic overview of the best FFMPEG codecs to render video in Blender

So here is a table of the options I used and the images, in addition to the median over the absolute deviation from the original value by pixel. In case you are now thinking: Value? But this is an RGB image. Yes, you are right. I converted it to grayscale, which is absolutely okay and sufficient for this example. It always comes down to value in the end, I could’ve just taken a channel mean or anything else really, but this is not my job, so you do that, if you got nothing better to do, and then brag about it on your own blog.

IndexSnapshotPlotContainerCodecQualitySpeedSize MB
001Matroska (mkv)VP9losslessrealtime73.9
002Matroska (mkv)VP9perceptually losslessgood17.5
003Matroska (mkv)H.264percecptually losslessgood8.2
004Matroska (mkv)H.264losslessrealtime71.6
005Matroska (mkv)H.264constant bitraterealtime2.9
006Quicktime (mov)H.264losslessrealtime71.6
007MPEG4 (mp4)MPEG4lossless (lmfao)realtime2.0
Comparison of different rendering settings with FFMPEG in Blender. Which ones are best to render video for YouTube?

Different export settings for the different FFMPEG codecs to render video in blender

Which Codec looks most visually pleasing?

Theoretically, the smoothest looking curve should be the visually most pleasing… but well, you tell me… I really can’t say. I see fringes in all of them and I don’t really find any of them okay. The last one has definitely a lot of lost information but it is smooth, in a way, mathematically though… not really. In my opinion, from the lossy options, webm/PV9 was best. It is, after all, the Google version of H.265 (which is unavailable with FFMPEG/Blender) atm. So I will use this in the future, I think.

“Lossless” export is also possible, but will lead to non-playable video, aka a huge lag. I had the idea of just doing that, and letting YouTube do the encoding for me. They do that when you upload a video, but this might also result in more losses. I wasn’t feeling eager to try that, to be honest. So I didn’t. But feel free to check that out. My guess would be that you get a laggy YouTube video doing that.

My solution to reduce color banding without messing with the Codec

I personally don’t have the perfectionism in me to worry about three fringy frames. I don’t think there is one best codec to render video in Blender. So what I will do is just flatten the value curve, and therewith the relative distances between these unwanted steps in the cross-section will be flattened as well. That leads to a smaller depth of whatever surface it is applied to. E.g. if you have a sky with a gradient, like in my example, you will lose some of the 3D look of that sky. It will look more moody and less far away, less cloudy etc. To me that does not matter much, because it was a moody day and it matches the color grading. But if you have a gradient that you want to show off, “swallowing it” is not really an option. I would say, you should also look into your camera options and choose a higher quality format. That alone has worked pretty well for me with my Sony already. Because due to the smaller sampling rate the footage is kinda “bandy” already. And that can only get worse after rendering it a second time.

You might not see it well in these sample images. But when I looked at the final footage, it really did make a difference. After all these bands look most annoying when you move the camera “across” the gradient and it changes. That results in the bands moving and it looks very cheap and sad. So that effect can definitely be reduced drastically by applying a profile like the above.

median plot
Medians of absolute distances of values from the different codecs / settings to the original. The larger the difference to the original curve the poorer the quality should be. Median was used because it’s not as sensitive to outliers.

Conclusion: What is the best codec to render video in Blender?

Right now, there is no optimal or best FFMPEG codec to render video in Blender. They are all flawed. If you don’t have the option to use other codecs or proprietary software, this is what you have to deal with. H.265 could be a solution in the future, but I do not have much hope here, because blender VSE is not the most important part of blender. (VP9 also seems to be a decent alternative!) But yeah, VSE… It’s more like the unwanted step child of the 3D animation editor… And FFMPEG is notoriously outdated and a bit primitive. So if you are desperate to get good video quality, but for free, get DaVinci resolve and stop messing around with FFMPEG and its sad sad Blender module. 🙂

You Might Also Like

2 Comments

  • Reply
    zedfirenze
    September 26, 2023 at 9:22 pm

    My goodness this a beautiful article and you really gave me the solution to a problem I was having all throughout today. Thought I was tripping because no one talked about this, but thankfully now I know. I’ll just take my image sequence into davinci resolve and see how that looks.

    • Reply
      Undine Almani
      September 27, 2023 at 12:37 am

      Thank you 🤍 I thought I was tripping too for quite some time 😅

    Leave a Reply