Can't fit anymore anime on your homeserver? Lets save some space!

More and more people are running their own homeservers with services like Plex to be able to stream video content to their devices. But there is a cost, storage.

Can't fit anymore anime on your homeserver? Lets save some space!
Photo by Alan Alves / Unsplash

More and more people are running their own homeservers with services like Plex to be able to seamlessly stream video content to their devices either remotely or within their homes. Whilst I think this is a great thing to do and can make enjoying content easier, there is a cost that comes with this, storage. Ripping blu-rays means taking 20GB to 100GB+ worth of content for a single series or movie, how can we save some space?

As most people know encoding or compression is used everywhere from your YouTube videos, photos on Instagram to movies on Netflix. The question is how can we use it properly?

This guide is geared towards the generic user who just wants some smaller files and doesn't mind slight artifcating on scenes that are not noticable in typical viewing (see note at bottom of page). I understand there are hardcore encoders out there who are all for producing the best results with tiny sizes, but this is far more advanced than your average user needs to know.

FFmpeg

I am going to provide a very basic guide to encode cartoon/anime content, assuming its ripped from Blu-Ray or any "raw source" (raw is a loose term, but in this context I mean it to be original).

Getting started

To begin with we need ffmpeg, for use with windows I recommend gyan.dev's builds here or if you want a direct link to the files. If you are on Linux and do not have it already installed, please check the ffmpeg guide for the distro you are using. This guide is going to assume you are on Windows, but basic understanding of Linux will be enough to apply everything here across.

Open the .zip file, enter ffmpeg-x.x-essentials_build\bin and move FFmpeg.exe to a folder of your choice and open command prompt (CMD) in that folder.

Our base FFmpeg command

We'll begin by having a base command, this is the standard command (aka arguments) we will use for all our encoding.

ffmpeg -i "{INPUT FILE NAME}" -c:v libx265 -pix_fmt yuv420p10le -preset slow {SETTINGS} -c:s copy -c:a libopus -b:a 384K -map 0 "{OUTPUT FILE NAME}"

Base arguments

What's in it?

  • -c:a libopus and -b:a 384K.
    • Audio codec to OPUS, to keep it short, it's a codec which better distributes bitrate in comparison to say AAC.
    • Audio bitrate to 384K. Typically you would do 128K x channels but as this is attempting to be a generic guide, this is that plus overhead for multi channel.
  • -c:v libx265
    • x265 (HEVC) is a more efficient video codec than x264, not all old devices support it, but I am making the assumption you are using plex with basic transcoding avaliable for converting video for old devices.
  • -pix_fmt yuv420p10le
    • This sets it to 10Bit, modern devices support it but older ones may require transcoding if not.
  • -c:s copy and -map 0
    • Copies any subtitle tracks
  • -preset slow
    • Uses the slow preset, this is the optimal setting.
    • You can use veryslow if you have a high performance PC and don't mind the wait but only provides benefit at CRF 23+

Settings

These replace the {SETTINGS} placeholder in the base command. All of the below settings can have the quality improved just by lowering the CRF values to between 18-21.

If you are a heavy mobile viewer, you could just use the generic settings and change the CRF to 24. You could even lower the resolution to 720p as the high pixel density (Pixels Per Inch) with small displays will make it hard to notice.

Generic

This setting is what I would apply to most animated content.

-crf 21.5 -x265-params "bframes=8:psy-rd=1.5:psy-rdoq=2.2:aq-mode=3"

You can add :limit-sao and use this for everything but also see below.

Grainy, complex animations

Best example would be newest Blade of the Immortal

-crf 19 -x265-params "no-sao:bframes=8:psy-rd=1.5:psy-rdoq=3:aq-mode=3:ref=6"

Grainy content is hard to encode without causing artifacts, you can reduce psy-rdoq to improve the handling of grain and lower the crf to 18 if you are not happy with the results. If you want more detailed tuning I recommend checking out

Slice of Life / Simple Content

You can just use the Generic settings but if you want to save even more space, why not! Banding is more commnon with this but, again, the assumption is that it doesn't matter.

-crf 23.5 -x265-params "bframes=8:psy-rd=1:aq-mode=3:aq-strength=0.8:deblock=1,1"

Example Generic Command

ffmpeg -i "Input.mkv" -c:v libx265 -pix_fmt yuv420p10le -preset slow -crf 21.5 -x265-params "bframes=8:psy-rd=1.5:psy-rdoq=2.2:aq-mode=3" -c:s copy -c:a libopus -b:a 384K -map 0 "Ouput.mkv"

Alternative Detailed Guides

Note: This guide is not meant to please the encoding groups who spend time inspecting videos with a fine toothpick to find a 5x5 pixel square that is slightly off color. For this level I recommend seeing guide.encode.moe

If you are looking for more a more in-depth guide I really recommend you check out this post. It goes over all the settings in thorough detail, it will let you really tweak settings to get the most out of your encoding. I have changed the settings to be storage focused than transparent quality, as for most users, they are used to the awful video quality of sites such as Kissanime.

Even the above linked post just scratches the surface of what tools are avaliable.