Veracious Network More than just a game, it's a community!

Handbrake Video Transcoding

Handbrake (https://handbrake.fr/) is a very powerful utility for transcoding videos, but can be overwhelming with its barrage of options. To try to make heads and tails of it, I did some testing with a 1 minute video (1:12 exactly), from a 1080p Blu-ray source.

Before I get into the details though, it must be noted that Handbrake is designed to work with unencrypted video sources. As of the Digital Millennium Copyright Act, circumventing encryption on commercial disks, (even for the purpose of personal backups of purchased disks), is illegal in the United States.

Even listing steps on how a user can Make MKV files from encrypted disks could risk legal action. As such, I will not mention what utility you can use to easily Make MKV files from encrypted disks, but a savvy user can find what two packages to download and compile (or just install for Windows) to achieve this.

For the purpose of this document, it is assumed that you are dealing with unencrypted video sources (either DVD, Blu-Ray, video cameras, phones, digital files, etc), that you have the legal right to transcode.


Transcoding (converting a video from one source to another), is helpful to allow video files to be compatible on various devices, reducing the filesize to save space, or to pick and choose what items to include.

Handbrake Main Window

| Container | Encoder | Quality | Framerate | Bitrate | Passes | Preset | Speed | Filesize | |-------------|--------------|----------|------------|--------------------|----------------------------|-----------|---------|-----------| | MPEG-4 | H.264 | RF 22 | 30 FPS | Constant Quality | Single | Fast | 86 FPS | 33 MB | | Matroska | H.265 10-bit | RF 22 | 30 FPS | Constant Quality | Single | slow | 20 FPS | 24 MB | | Matroska | VP9 | CQ 22 | 30 FPS | Bitrate 4500kbps | Multi-Pass | medium | 5 FPS | 44 MB | | MPEG-4 | AV1 | RF 25 | 23.9 FPS | Constant Quality | Single | 11 | 150 FPS | 29 MB | | Matroska | AV1 | RF 25 | 23.9 FPS | Bitrate 1024kbps | Multi-Pass, Turbo Analysis | 11 | 172 FPS | 11 MB | | Matroska | AV1 | RF 25 | 23.9 FPS | Bitrate 2048kbps | Multi-Pass, Turbo Analysis | 11 | 153 FPS | 18 MB | | Matroska | AV1 | RF 25 | 23.9 FPS | Bitrate 2048kbps | Multi-Pass, Turbo Analysis | 1 | .92 FPS | 19 MB | | Matroska | AV1 | RF 25 | 23.9 FPS | Bitrate 2048kbps | Single | 11 | 153 FPS | 21 MB |

I wanted to know what encoder, frame rate, and settings to use for my specific file, so I did a few conversions to check the speed and resulting filesize. Please note, your needs and preferences will be different, so feel free to use different options.

Quick Overview of Runs

If you're looking at encoding speed, sticking with a codec supported by your GPU will be the best bet. Since I have an AMD 7900XTX, the AV1 encoder was the fastest for me, but it's not as widely supported as H.264 or VP9. If widest compatibility is needed, H.264 would be the best bet, but AV1 works well enough for me.

If you're looking at resulting filesize, running multiple passes and keeping the A/V bitrates as low as you're comfortable with will provide the smallest results. H.265 is notable for its good compression without quality loss.

Container?

Saying you have an 'MP4' file does not mean anything to the actual codec of the contents; this is just the container.

Using MPEG-4 is widely used as it's well supported, but I personally prefer Matroska containers since the format is fully open source and they can contain subtitles, images, multiple audio and video tracks, etc.

This way I can embed the subtitles and alternate audio tracks into a single file, without worrying about losing them.

Filters

Filter selection can make a huge difference in the overall quality of the rendered video. Notably for interlaced videos, the option to deinterface can be important.

If you get artifacts in the rendered video, try adjusting the filters.

Video Codec / Encoder

Handbrake Video Codec Selection

Most encoding uses the CPU (such as H.264 or VP9), but some graphics cards can handle them and H.265 as well. With my 7900XTX, I am limited to AV1 if I wanted to use GPU rendering. This increased the encoding speed from (at best), 86 FPS up to about 150 FPS. AV1 is supported well enough by Jellyfin, so I opted for this codec.

Selecting multi-pass vs a single pass reduces overall filesize but does increase the amount of time encoding takes. For me this is a worth while trade off, (as I can just queue the encoding tasks to be done while I do something else).

Setting the Preset to a lower value (for a slower encoding, theoretically for a higher quality video), seemed pointless, so I left it at default.

Dropping the bitrate to 1Mbps produces a small file, but does have noticeable quality degradation at 1080p, so I opted for 2Mbps instead. This resulted in a 25 minute video being encoded at 388MB with AAC audio or 608MB when raw DTS audio is used.

Audio Codec

Handbrake Audio Codec Selection

Selecting "Passthrough" preserves original audio quality, but will increase the filesize by a fair amount. In my test video, one of the audio channels was DTS 2-channel encoded at 1.5Mbps. Selecting this would consume 192Kb per second, or 11.25MB per minute of video.

Re-encoding the audio down to AAC or Vorbis will reduce the filesize by compressing the audio. Stick to 160kbps bitrate or better.

For videos which only ship with 5.1 Dobly Digital audio, I will generally encode both the 6-channel stream and add a 2-channel stereo stream as well. Some platforms do not handle 5.1 audio well, (ie: they will have very quiet dialogue but loud sound effects).

Handbrake Audio Track Name

I will also take the time to name the audio tracks appropriately, so that they are easily identifiable in the player. This is less important if there is only one stream, but more beneficial if there are additional languages or versions.

Subtitles

Handbrake Subtitle Selection

For subtitles, I like to always include all raw subtitles directly from the source file. Same naming convention as audio tracks if there are multiple subtitles, (ie: English, Spanish, etc).

Handbrake Subtitle Track Name

To preserve the original video, (and not all people prefer subtitles), I will always deselect "Burn into video". This places a tiny additional load on the player, but allows the user to turn off subtitles if they wish.

Meta Data

Handbrake Meta Data

The last tab in Handbrake is for embedded meta data of the video. This is where it can be named, tagged, and given a release date. Most players, (including Jellyfin), can read this meta data when playing the media.

Testing

It is recommended to encode a short snippet of video to test your settings before encoding the entire video. You can render the full video, but if you need to go back and modify a setting, you will need to wait for the entire video to be encoded again.

If you are encoding a single video with no chapters, you can set the Range to Seconds and specify the start and end times. This will allow you to encode a small portion of the video to test your settings.

Quick Settings

My personal preferred settings, (again, feel free to adjust to your liking):