In todayâs market, the datahoarderâs âstorage is cheapâ excuse aged like fine milk on the sun during an european heatwave.
From SSDs to HDDs, People are so desperate theyâre resorting to Blu Rays and DVDs for storage (at least for reasonable prices), and i shouldnât be here explaining why Read-only-memories and cold storage has their huge limitations and could not be for you.
This article is for everybody with decently-enough-sized collections of videos : Be it courses, movies, TV Shows, and anything else you mightâve paid a premium to keep instead of renting and hoping they arenât gonna disappear tomorrow without any notification. Iâve come here to tell you something that most redditors would put me on a cross for : You should probably consider re-encoding your videos if youâre tight on space and money. (but there will be catches, YMMV)
Hereâs the thing : If you got a bunch of courses which consist of mostly still images and lots of other stuff you really want to keep but does not have huge sentimental value or donât have the intention to âtruly enjoyâ on a movie night, you probably donât need the full heft of those videos.
Itâs true : Storage can be bought indefinitely but video quality can never be recovered (and donât you dare consider AI upscaling for that as itâs truly horrid and inefficient). Thatâs why iâm not telling you to re-encode the video of your childâs first words, but you probably do not need some sort of home-theater-tier video quality for the 12-season TV series you watch on your phone when youâre eating a meal alone, paying 30-50$/TB to store it.
Before you get into the rabbit hole of encoders, encoder settings and all that, iâm gonna preface by saying that itâs not a guaranteed to get good enough results for huge savings, as the cost per GB saved compared to GB bought wildly varies by :
- current price and availability of storage
- price of electricity in your country (which may not only vary by your physical location, but, depending on the country, also the time of the day in which the electricity is being used)
- the hardware you already have for encoding those videos (iâm not making you buy new stuff, that would defeat the whole purpose)
So you will have to do your calculations. What i can tell you off the bat is that, if you have a single PC at your disposal that has an NVIDIA GPU, you should probably, seriously consider re-encoding. And yes, I AM bummed that an NVIDIA graphics card is the best option for something, especially considering the prices for those too, but it doesnât take a good one to be able to do this, and if you do your calculations, you might not even need it.
The core of the process is simple : Iâm using ab-av1, an incredibly handy tool that uses ffmpeg and VMAF to automatically gauge how much a given video can be encoded while still being within a given âvisual qualityâ, and reducing its size as much as possible.
This not only reduces your need to manually tweak encoder settings and re-encode dozens of times, staring at a monitor looking for artifacts and going insane, to see which settings may suit you best.
Wanna have some pretty good results and save a lot of space? --min-vmaf 95 will serve you well.
Wanna have some extra headroom just in case for more complex scenes and high-movement scenarios, with not much more storage getting used up? bump it up to a --min-vmaf 96 and again, youâre probably gonna be more than good.
The NVIDIA graphics card comes in handy for one thing : efficient and decent enough hardware encoding. Even though software encoding, which runs solely on the CPU, may produce better results and smaller files, it doesnât make a ton of sense for our use case : Weâre trying to save money. If youâre gonna spend a half hour encoding a video with a huge CPU hitting its maximum TDP and burning through 300W of power to shrink a file by a handful of gigabytes, you couldâve probably bought storage for the price of all that electricity you just used, even in todayâs ransom-tier pricing.
This means that hardware encoding is the most sensible strategy in our case : very cheap, decent enough, and also very fast, as an added bonus.
The best-case scenario (which i think is pretty over the top and not accessible to most people) is a 40-series or over RTX card. These have support for hardware encoding for the AV1 format, which although not universally supported, is still pretty well supported on fairly modern devices, and is VERY efficient compared to other solutions (takes around half the compute time as the second-best option for an even smaller output file size.)
The flags used were thus :
--min-vmaf 96 --preset p7 -e av1_nvenc
- In this use case, i got :
- pretty consistently ~1/3 of the original file size as an output,
- ~1 minute of pre-processing time of CPU execution to use VMAF and detect which CRF would suit the video best for a 1GB video (around 150W used by the CPU only for 1 minute)
- ~2 minutes of actual encoding to encode the ~1GB video into a ~333MB one. (Around 20W used by the GPU + ~50W for the semi-idle CPU. )
- This comes up to around 0.00267/GB (average american electricity pricing) âŹ0.0042/GB (for the average European one), or 2-4\/TB (saved).
Even if you donât have that, HEVC NVENC (ran with flags --min-vmaf 96 --preset p7 -e hevc_nvenc) is still more than good enough and cheap enough to justify. By consuming ~double of the electricity (same amount of electricity spent per minute, but double the time), it still comes at a very reasonable 4-8$/TB saved.
And if you donât have that either⊠please do your calculations first. Consider that hardware encoding will most likely be your best bet for power efficiency and dollars spent per terabyte saved, and run some tests of your own, taking into account the average time spent to encode ~1hr of original video, the energy spent per hour of encoding, the space savings your encoder averages to, and how much money storage is right now.
Since I personally found these savings to be more than enough to justify the time and electricity spent, i obviously had to make my own, small, gradio wrapper with a very simple queuing system to encode entire directories and automatically handle re-encoding my current or future libraries (since finding out about re-encoding, knowing i can store 2-3x the amount of things i used to, let me shift from a mindset of âi will store this only if iâm 100% sure i really really need itâ to âyou know, it would be a real shame if i someday lost all the content from this creator/blogger/website. Maybe i should save the things i liked most for a rainy dayâ.) My little gradio interface lets me drag everything i want into a folder, not have to worry about a thing, and after a while, everything will be organized the same way it came, preserving the same folder structure, with a clear separation between non-encoded files and encoded ones.
- the output folder generates the same directory tree as the input folder has.
- OPTIONALLY original files can be automatically deleted after their encode is done
- files that are already well-encoded or that do not pass the base VMAF to begin with can be skipped and/or moved to the âprocessedâ folder directly, without re-encoding them unnecessarily.
- i chose to âsplitâ the processed/unprocessed lines for two main reasons :
- Less ambiguity when browsing files
- Freedom to stream while encoding (if an encoded file and a non-encoded one share the same folder, we run the risk of mistakenly streaming a file that is mid-encode, then once the encoding for that file is done, it gets deleted mid-stream and you have to go back and play the encoded one, hoping you remember where you were at. Having an âencodedâ folder as your main media library folder on Plex/Jellyfin/etc.. lets you be sure that 100% of the time, when youâre streaming, youâre streaming an encoded file, which saves on bandwith too.)