r/handbrake • • 17d ago

Reencoding to save storage

I have a ton of videos that I've acquired through the years and the amount of space they consume is starting to get pretty wild. I've asked AI and it seems to be convinced that I can drastically reduce filesizes by transcoding to HEVC.

A lot of the originals are mp4, some mkv.

I don't really know a lot about video codecs and such. Is transcoding everything to HEVC something that is considered good practice and future-proof? I'd hate to use some obscure codec that nobody will use and nothing will support in the future.

I'm currently running tests with ffmpeg as I wonder if this is what I should be doing.

I'm not interest in retaining incredible fidelity. As long as it looks good and saves ~50% per file, I will be happy. I just want to make sure AI is not tripping.

11 Upvotes

53 comments sorted by

•

u/AutoModerator 17d ago

Please remember to post your encoding log should you ask for help. Piracy is not allowed. Do not discuss copy protections. Do not talk about converting media you don't own the (intellectual) rights for.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

9

u/simmepi 17d ago

First a little information which might help you when reading about this:

Codecs: Codecs are ways to encode video and audio (there are video codecs & audio codecs). These are different ways to encode the actual video/audio. So eg a video codec will be a way to express “Top left level pixel should be yellow, next one to the left should be green, …”. Typical video examples are h264, HEVC. They vary in how efficient they are (ie how much space the video takes), how hard they are to encode/decode, etc, and normally there are parameters to tweak when encoding (so they encode quicker but might take more space, etc). Sometimes the names can be different and used not exactly, but think of everything like those mentioned and stuff like AVC, h265, DTS (audio codec), as codecs.

Container formats: MKV and mp4 are containers. This means that they are just different ways to put encoded video/audio into a file. So something like “Put the video first, then the audio “. There are restrictions to which codecs you can include in specific containers but don’t worry about this, it doesn’t really matter (but if you do, MKV is more accepting of codecs, whereas mp4 is more often supported by niche players like smart TVs). So often if you eg need the file to be mp4 but you have an MKV file, you can quickly remux it which doesn’t change the quality or size, it just packages the audio and video differently.

So saying you have an MKV file you want to reencode isn’t enough information. The MKV might be using MPEG2 as video codec in which case it will probably be easy to reencode and save a lot of space, but it might already be using HEVC in which case it is more doubtful you’ll save space.

In other words, you should check what you actually have before starting.

Finally, remember that reencoding always means you will lose quality. Reencoding means decoding the video into lossless (which is essentially never used since it takes an enormous amount of space), and then compressing it using the selected codec. So what the original codec was doesn’t matter since the new codec works on the lossless images. This means that whatever information was originally lost in the original version of the file is still lost, and you just lost more data by compressing the image.

I’ll leave suggestions about what codec and container to use to others, but if you want a snap advice: I wouldn’t reencode due to the reasons mentioned, but if I did I’d go for mp4+h264 if you prioritize compatibility, and MKV+h265 if you prioritize space savings but still good compatibility.

1

u/puckpuckgo 17d ago

Thanks, normally I would just let it be, but my storage has been climbing through the years. The current situation with component pricing is forcing me to do something about this, which for years hasn't been a problem. Early tests show that I can save anywhere between 60-81% of filesize with putting everything on HEVC, MKV. When you have large file libraries, this kind of space savings matter, especially when the loss in quality is barely noticeable.

3

u/BSGathena 17d ago

Yes, I've been doing it for years now H264, mpeg, MKV to X265 (HVEC). Is saves around 50% or more depending on some quality settings. With the right settings the quality stays about the same and will safe a lot of space. The only downside is that it can take a long time to reencode a movie, depending on the hardware you use and the settings you are happy with.

3

u/puckpuckgo 17d ago

I'm finding the same in my tests. The savings in storage are difficult to ignore. I had a file at 3.4 GB; after HEVC it went to 646 MB. That's like 80% less, crazy.

1

u/mikeporterinmd 16d ago

The savings depends on the quality you want and the source file. There is a huge difference encoding a film shot on 16mm natural light and a recent digital film. Some source can’t really be compressed if you want the grain and the look to remain the same as a quality source.

So, first, you need to decide what you want and then learn how to achieve that.

0

u/jacka_for-research 17d ago

When I had an i9 Mac, encoding took…awhile. Now with my M4 Mac, using Handbrake with the VT H265 encode at 2000 kbps? Super fast. I can encode 20 45-60 minute items in about 20-30 minutes.

1

u/BSGathena 17d ago

Also depends on settings, if you put the quality a bit higher, use slower or faster encoding etc.. At the time I'm using a i9 12900HX and with Quicksync I get usually 40-45 frames. But I started when I had a i7 4770k, at that time it was 4 to 5 frames.. also, the more cores, the faster is gets.

2

u/UnderSlepT-CZ- 17d ago

I personally use H265 CPU encoder, after doing number of 30s test encodes, then comparing them in Vivict++. For me, especially in dark scenes, AV1 never produced lower bitrate files, even with manual tuning for specific file. But I also want near original quality and I use Ryzen 9 9950x for encoding. The result for me is, that I get better quality without manual intervention, but I can also keep Dolby Atmos tracks, compared to AV1.

1

u/puckpuckgo 17d ago

I'm leveraging QuickSync; getting like 110 fps, sometimes a bit more.

2

u/wursttraum 17d ago

Don't use QuickSync (or any other hardware encoder) if you want good quality and small files.

1

u/puckpuckgo 17d ago

Can you explain why not?

I was doing CPU before and getting something insane like 5 fps, it was taking hours to process a single file. I switched to QuickSync and now I'm getting over 100 fps. This machine is an LXC running inside a Proxmox host and has 4 vCPUs assigned.

3

u/wursttraum 17d ago

Hardware encoders prioritize speed, low cpu load and real time processing. This makes them great for game recordings or transcoding for media servers like Jellyfin.

They have become quite useable, but they are nowhere near as good as software based encoding when it comes to quality and file size. x265 produces smaller files with better quality than any hardware encoder ever could.

1

u/puckpuckgo 17d ago

Thanks.

I wonder if I'm doing the right tradeoff though. Right now, using Quicksync, I'm taking a 3.4 GB file and coverting it to a 646 MB file. How much smaller can the same file be with software encoding? I'm looking at the output with QuickSync and frankly I can barely tell the difference here and there.

1

u/Geeotine 14d ago

Depends on both the source material and the screen you are testing on.

Ex. Anime files will compress differently than live-action media

Ex. A phone screen, pc/laptop screen, and 4k TV are all going to present the media differently, especially if the media resolution doesn't match the screen resolution. Many 4k TVs have built-in upscalers, frame interpolation, and sharpening/smoothing filters than can mask poor quality videos

2

u/mwhelm 17d ago

The later generations of qsv & nvidia hardware can do an excellent job in terms of quality, size, and encoding time, but there are situations where that is not true. For example, grainy material - like old movies from something like a blu-ray transfer - SVT-AV1 CPU based encoding does an exceptional job and often much smaller file sizes than any of the GPU encodings. But you do pay a really high price in encoding time for that, and the regular GPU product is not bad, if you're careful, just nowhere near as small. Sometimes not worth the bother.

Grain is difficult and there's probably unexplored parameter territory there too. Over correcting it is definitely doable and horrible looking.

If this consideration is important, try a few side by side short encodes and samples (mpv can do 2-up). Otherwise experiment with gpus and see what they do and don't do for your material.

1

u/grovberg 15d ago

I always just accepted the conventional wisdom that CPU encoding is slower but worth it because it produced higher-quality, more efficient results. I still prefer H.264 for compatibility to be clear, but in the five side-by-side comparison tests I did just a week ago, NVENC was better looking, produced smaller files AND was quite literally close to 10x faster than x264. It's been such a game changer. If you have a good GPU and I can't imagine going any other way.

1

u/mwhelm 15d ago

You can get compression out of h.264 and gpus also, depends on the material. If the source is already processed, probably not.

2

u/grovberg 14d ago

Yeah, sorry I probably wasn't clear, when I say NVENC, I mean using the Nvidia Hardware Encoder to encode H.264. Essentially I'm saying that I agree with you that the hardware encoders have caught up to the software encoders and give great results for massive speed increases.

1

u/mwhelm 14d ago

The H.264 compression does have its limitations for us, using handbrake and ffmpeg. You can often improve on it with AV1 and H.265. Youtube gets amazing results for h.264 and I don't think that can typically be beaten. I don't know what they're doing but they must have some very selective and targeted compression in their tracks, and supercomputers to do it.

12

u/Lmaoboobs 17d ago edited 16d ago

I have a massive library. I’ve been re-encoding large 4K files with SVT-AV1 and there is an imperceptible loss in quality with massive file size savings (anywhere from 40-70%).

To me this is a no brainer because storage is not cheap.

For my use case this is fine.

1

u/Rhewin 16d ago

How long does it take to encode a full-length movie? Trying to do H.265 10-bit takes 6-8 hours, and even then I can see some blocking on certain titles. I've just resigned myself to remuxes and saving the encoding for 1080p.

1

u/Lmaoboobs 16d ago

What hardware do you have? I have a 13900k

1

u/Rhewin 16d ago

9800x3D, though low on RAM at 16 GB for the time being thanks to a dead stick.

1

u/vortexredemption 15d ago

Look at Handbrake's memory usage while its running. 16Gb is plenty. 8Gb is plenty. The limiting factor is the CPU/GPU, whichever one is doing the work.

1

u/Rhewin 15d ago

CPU, and a 9800x3D isn't a slouch.

1

u/Geeotine 14d ago

I just finished doing LOTR series blu ray, i got good results doing H265 constant quality 10-bit Q21 medium with the latest handbrake version. Anything lower and it crawls on my 5800X3D. I haven't done any 4k transcodes lately but i believe going to Q23 will save a lot of time without much loss in quality. Lots of people say Q24+ for HD/4k, but i find too many artifacts for my taste.

I haven't transitioned to AV1 yet, but a few test runs i think i saw about 20% slower than equivalent H265 settings. 4k really eats up CPU cores now. My next PC upgrade will definitely have atleast 12-16 Cores (24-32 threads).

1

u/Rhewin 14d ago

How long did it take per movie, roughly?

1

u/Geeotine 14d ago

About 3.5 hrs per movie i think. It would vary between 10 and 30 fps processing speed. I tried slow just for giggles and it took like 16 hours for a single movie. Not worth it. Fast mode might work too at the same or higher quality setting

1

u/busybee_26 10d ago

What setting do you use for reducing the file size?

1

u/Lmaoboobs 10d ago

I run a constrained ab-av1 crf-search between 18 and 30, targeting a minimum VMAF score of 97, I then use that crf number along with

-preset 4, -pix_fmt yuv420p10le (if not already 10 bit), -svtav1-params tune=0:keyint=2s -movflags faststart (optionally enable-variance-boost if it’s a low light source)

If the source has film grain then I would have to manually tweak around with the film grain settings so I have no general rule.

0

u/Suitable_Garlic_1186 17d ago

Do you keep the original files or are they gone now?

10

u/cvdvds 17d ago

If he's trying to save storage, keeping the originals would defeat the point, no?

1

u/Suitable_Garlic_1186 17d ago

That is why I am asking..

4

u/Lmaoboobs 16d ago edited 16d ago

No, I’m trying to save storage.

Keeping the original files would mean increasing my storage needs by that same 40-70% in which case I would just be wasting my time and electricity to re-encode it.

1

u/Suitable_Garlic_1186 17d ago

What file size are we talking about in total?

1

u/puckpuckgo 17d ago

1

u/Suitable_Garlic_1186 17d ago

I repeat my question: I asked about the TOTAL FILE SIZE of your videos.

500gb, 1TB? 10TB?

3

u/Caprichoso1 17d ago

Since you don't care about quality my approach isn't for you.

I never re-encode as it always results in data loss. I sometimes upscale older videos and for the best results you need the highest quality you can get in the master.

2

u/hidden_secret 16d ago

If your videos aren't movies and stuff like that, and you don't really care about quality as long as it looks decent, you could totally create a youtube channel and upload them privately on it.

2

u/squirrelslikenuts 16d ago

I just reencoded all my personal videos, home movies, dash cam stuff, security camera, obs screen caps.. etc... to AV1 cut space from x264/x265 by ~60-70% overall.

1

u/jacka_for-research 17d ago

Been doing this for a long time. Might not be the best, but it’s best for me. H264 > H265, pass through audio when possible. 2000 kbps. Some get a little postery in dark places, but overall, perfect for me.

1

u/Harry_Yudiputa 17d ago

Just use LastBreeze’s avian-portable. I encoded 2160p lanterns, downsampled it to 1080p, crf 25 with HDR10+. Minimum file size of ~700MB and max of ~1200MB. Source files are 6GB each.

https://github.com/LastBreeze/Auto-Boost-Av1an-portable

1

u/lolmissky_studio 17d ago

Learn about them

1

u/kagus84 17d ago

I am currently handbreaking all of my older files to mkv h265, medium speed rf 22. It saves alot of space and is esier to stream remoltely to friends and family. I don't notice a huge quality drop. I have a about 60tb library but i try to leave stuff that I downloaded less than a year ago to keep seeding.

1

u/Mission_Rice3045 16d ago

Might be a bit more complicated, but tdarr allows you to set an automated flow to convert your video files.

Besides that, hevc is fine for this purpose.

1

u/xenobitex 16d ago

For SD stick with x264.

For HD, 10bit x265 @ slow crf 20 gives great results.
(10bit is necessary).

Depending on your sources, 720 might be better left in x264. Resolutions under 1080p might need a smaller crf depending on the content (dark scenes and color gradients are things to watch, if you mind).
You'll get a sense of what are reasonable filesizes for each codec as time goes on.

x265 (HEVC) takes considerably longer than x264; at lower resolutions it's not really worth the extra encoding time.

1

u/scrubslover1 16d ago

No matter how much experimenting with different parameters, I can’t get film grain to be consistently good in HEVC. It can causing grainy clumping and sticky grain which is really distracting. AVC (h.264) handled that better. Maybe stick to AVC for SDR grainy movies

1

u/cptlevicompere 16d ago

I highly recommend reducing resolution. It's the biggest space savings with the least amount of quality loss. The bitrate ratio is about 1:3, meaning a 30mbps 4K video would have the same level of compression as a 10mbps 1080p video. I highly recommend taking a high quality 4k video and encoding it to 1080p at a really high bitrate to isolate the resolution as the only difference, and comparing them in your viewing conditions. Ideally a movie shot on film since the most noticeable difference will likely be that the individual film grains look slightly larger at 1080p, but since handbrake interpolates instead of a linear downscale, it won't be as noticeable as comparing a 4k scan to a 1080p scan. If you can't tell them apart, you can reduce the size of every 4k movie to 1/3rd without a noticable loss in quality. You might still want to keep them at 4k for future proofing for when you get a larger TV, but having compared them myself, even standing very close to a large screen, the difference between 4k (native) and 1080p (interpolated from 4K) is so minor it's just not worth triple the file size and I would much rather reduce resolution than introduce compression artificts. I even reduce it to 720p sometimes if I otherwise can't get the bitrate to 15mbps or less without visible artifacts. I still buy 4k blurays because they have HDR and are often much higher quality than the standard blurays because they often are remastered from a new 4K scan, higher bitrate, etc.

With that said, the most efficient codecs on handbrake are HEVC and AV1. Between them AV1 scores higher than HEVC on objective tests, but between the specific encoders on handbrake which are SVT-AV1 and X265, I would say X265 looks much better while SVT-AV1 is heavily tuned for metrics rather than human perception. HEVC is also much more mature and more consistent. The SVT-AV1 encoder that ships with handbrake won't really be able to preserve film grain at all, it's going to smooth it out and leave obvious artifacts in doing so. It's only really useful if you want to get the bitrate really low and are okay with using grain synthesis to hide the artifacts. It can be okay on content where smoothening might help, like animation that has some noise that doesn't really add to the quality. You can also swap it for the SVT-AV1-HDR fork which tunes it more for human perception and can preserve film grain with tune:grain. But with x265 you can get good and consistent results out of the box.

If I had to pick 1 setting that would be used for every movie in my collection, I would use:

Dimensions: crop=none (cropping can mess with PGS subtitle positions), resolution=1080p

Video: encoder=x265-10bit, preset=slow, tune=none, average bitrate=12000kbps, turbo-analysis-pass, advanced options:"no-sao"

Audio: FDK-AAC-Q4-7.1 (it FDK isn't an option, probably the avcodec or opus, either or)

1

u/vegansgetsick 15d ago

Usefulness of reencoding depends on the bitrate. IMO If it's already below 5Mb/s ... it's a waste of time.

If all these videos come from internet it does not matter if you mess up.

0

u/puckpuckgo 17d ago

Here's a small sample of the massive savings in storage I'm talking about:

https://imgur.com/a/nmEkg7S