Tuesday, December 26, 2023

Video Encoding - H265 vs NVidia Enc vs CPU vs 1080p vs 720p vs...

Datatalk.

Goodie. There are so many (good) video codecs these days that it is hard to pick one... Or not?

There are some very decent explanations of the different formats on the Internet... but, as usual, I just had to figure it out and see for myself ๐Ÿ˜‡


H265 vs. the rest

Again, I'm not as knowledgeable as the sites below. These are just my own notes.


Some good sources:

... and I'm not going to duplicate their work ๐Ÿ˜‡. These are my personal notes, findings and settings...


To store movies

  1. H265 / HEVC
  2. AV1
  3. H264

(That's AV1, as in AV ONE, not AVI, as in AV I, we're talking codecs here, not containers such as AVI, MP4 or MKV.)

AV1 should be on equal terms with H265, but several sources claim it still denoises a little too much. (It's removing grain from 'classic' movie recordings. How much, and if that's a real problem is up to you.)

The other disadvantage of AV1 is that not all (hardware) players support it (but on a PC most players do, and if you have troubles try VLC). Of course, if you use a transcoding server like Plex then it's not a problem at all.

Denoising in VP9 is way too aggressive, which is why I left it out.


To stream stuff

  1. AV1
  2. VP9
  3. H265
  4. H264

AV1 is the best, but not everything supports it yet, and AV1 is slower when encoding.

VP9 is supported by any and all browsers and lots more stuff, but sometimes you might run into problems. 

H265 is fairly standard these days, but can be slower in encoding. Lots of hardware these days support hardware H265 encoding, which is faster but typically results in higher data rates / larger files.

H264 may be older and larger, but it's supported by almost anything. If you run into some compatibility issues it might be your best option.


To play back stuff

Devices like the Shield may not support all formats natively (the Shield, for example, does VP9, H265, H264 4K 60 fps, H265 4K 60fps 10-bit color, VP8 1080p 60fps) but an app like Kodi appears to be able to soft-decode some additional formats.

The Shield does play anything H265 it seems.

If your player is a PC, then Kodi does everything.

So, in general, go for H265 unless your player can't handle it. Check out Kodi if you need software decoding, or Plex if you want to transcode stuff.


Hardware encoding and file sizes

NVidia offers hardware H265 encoding. I used a GTX1060 with NVidea hardware encoding, as well as H265 software encoding, both through Handbrake, and tried some movie fragments and anime episodes.

When it came to panning etc. all codecs worked fine. VP9 made cinematic stuff look a little plasticky. H265 and AV1 were both the slowest encoders.

To achieve the same quality the hardware NVidia H265 encoder produced files of two to three times the size as the software encoders, even at higher quality settings.


Downscale... As small as possible? (720p vs 1080p)

Is it worth it to go down to 720p instead of 1080p? Sometimes... If your source material is (older) TV serials or anime, then it might be. Note that Handbrake typically won't upscale, so don't worry too much about that.

720p results in a roughly 30..50% smaller file. Never upscale when resampling as the files get larger and the quality doesn't get any better. Remember that 480p is the equivalent of ol' NTSC!

In general: stick to 1080p, or whatever the source was. Handbrake is smart enough not to upscale stuff.


Source dependent

The optimal settings strongly depend on type and quality of the source, so the settings below are just 'average' settings that worked well on a range of files. You can get much better better results by tuning the settings to your individual files, but that's too much effort ๐Ÿ˜


Anime

For anime the following settings worked fine (for me):

Handbrake / Preset: Fast 1080p 30fps

Summary / Format: MKV

Summary / Format / Passthru Common Metadata: No 

Dimensions / Resolution: 1080p or 720p

720p results in a roughly 30..50% smaller file. Never upscale when resampling as the files get larger and the quality doesn't get any better. Remember that 480p is the equivalent of ol' NTSC!

1080p was fine for most anime files (which typically are already at 1080p or less) as the files stayed well below 300 MB. 

Video / Video / Video Encoder: H265 10 bit

The hardware encoders produce (by default) files between 2 and 3 times as large. If you want a similar file size (at the cost of some quality) you can set Video / Quality to 25. It seems the NVidia encoder and the software encoder use the quality slider in a somewhat different way. 

Note that the regular H265 encoder produces 8 bit code, which is the way to go if you want the smallest file sizes, but it doesn't handle banding that well. I found 8 bit unacceptable on H264 and H265 files.

You may also opt for H264, which encodes a lot faster, but it was just a little worse quality wise, and the files got a little bigger, so I accepted the slower encoding of H265.

 My default: software, H265, 10 bit 

Video / Quality: Constant 22 

The actual effect of the Quality slider depends on the codec used to encode. Typically, lower is better, with larger file sizes. 

My default: 22 for the software H265 encoder.

Video / Encoder Options/ Encoder Preset: Medium

In my personal experience this would reduce some artifacts, at the cost of more pre-processing time and possibly a slightly larger file. YMMV.

In H264 Medium tends to give slightly smaller files than Fast, in H265 Medium tends to give slightly larger files than Fast. In general I preferred the results when using Medium. 

Audio / Source / select the track(s) you want

In most cases you can use AAC and mix down to Stereo.

If the source is already AC3 or another usable format you may opt for passthru or AC3.

If you want 5.2 you need either AC3 or passthru. For Atmos you always need passthru.

Subtitles / Tracks / select the track(s) you want

Subtitles / Burn-in: no (untick)

Subtitles / Default: yes (tick) if has a foreign audio track, no if it is an English dub

Some players appear to ignore the default tick, but whatever...


Resulting file sizes


Results on Anime

  • Source MKV - H265 1080p - 2.1 GB
  • File 1 - H265 1080p medium q 22 - 240 MB
  • File 4 - H265 720p medium q 22 - 156 MB
  • File 5 - H265 720p medium q 18 - 231 MB
  • File 2 - NVidia H265 1080p medium q 22 - 667 MB
  • File 3 - NVidia H265 1080p slow q 22 - 662 MB
  • File 6 - NVidia H265 720p slower q 25 - 272 MB
  • File 7 - NVidia H265 720p slower q 30 - 166 MB


In general anime compresses quite well. Even the 720p versions were watchable with some diminishing details, but with a resulting file size of < 250 MB downscaling isn't worth the effort.

There was little difference between q22 and q18 in quality. In general, I preferred 1080p quality 22 over 720p quality 18.

The NVidia hardware encoder uses a different scale for the quality slider. Even at quality 30 (which should be considerably worse than quality 22) it wasn't much worse than the CPU H265 at quality 22.

My personal experience contradicts many of the statements I found online, where they say the H265 hardware encoding is way worse. It's a little worse, yes, but not as much as expected.


Life Action

Life Action doesn't fare that well, at least when it comes to final file size. With similar settings Anime would compress down to 300 MB or less, whilst Life Action would give files close to 600.

Sometimes the resulting files are larger than the originals, in which case I keep the original files.

The following settings gave me reasonable good results in Handbrake:

Summary / Format: MKV

Summary / Format / Passthru Common Metadata: No 

Handbrake / Preset: Fast 1080p 30fps

Dimensions / Resolution: 1080p or 720p

Video / Video / Video Encoder: H265 10 bit

 If you plan to hold on to high quality rips of material with poor contrast, then you might opt for the 12 bit, though to be fair 10 bit fixes most banding and handles most grain.

Video / Quality: Constant 22 / 24

My target are files around 350..450 MB at H265. I compress everything larger than 500 MB at quality 22. If the resulting file is still larger than 500 MB I give it another go with quality set at 25.

I could win some more by compressing audio, but if it's already AC3 5.1 I typically go for a pass-through, as I often play back on my home theater setup.

Movies require something better like q 22 up to q18. 

I've seen quite a few compressed files at less than 300 MB with incredible quality, so there's a lot more that can be accomplished by tweaking the settings. In general though I was too lazy to keep fiddling with the settings๐Ÿ˜‡

Video / Encoder Options/ Encoder Preset: Medium

Audio / Source / select the track(s) you want

Either AAC, AC3, or passthru, depending on the source. I typically go for passthru if the source is AAC or AC3 (aka A52). There's not enough space to be gained by recompressing AC3 to AAC.

Subtitles / Tracks / select the track(s) you want

Some files come with multiple subtitle tracks. Figuring out which one does what takes a lot of time, so I include all the English and Dutch ones.

Subtitles / Burn-in: no (untick)

Subtitles / Default: yes (tick)

If the audio track isn't English I check the source, then set a suitable English or Dutch subtitle track as default.  


Handbrake generic settings

Your settings may differ, these are mine.

Tools / Preferences / Output files


Tools / Preferences / Advanced / System / Work Priority Level: Below Normal

I'd love to limit the number of threads instead, but haven't figured out yet how to do it from within the GUI.  I typically let Handbrake do its thing in the background whilst doing other stuff on my PC, so I set the priority level to Below Normal or even to Low.

Tools / Preferences / Advanced / Process Isolation: off

Default is on, but switching it off didn't seem to affect transcoding on my machine much.


 

No comments:

Post a Comment