In this tutorial, I will show you how to properly transcode videos using Handbrake. I’ve gone over all the settings in as simple and concise a manner as possible, without sacrificing the finer details (no pun intended 😉 ). Hope you find it useful.
- 1. General Info about Handbrake and Videos
- 2. Picture Tab
- 3. Filters Tab
- 4. Video Tab
- 5. Audio Tab
- 6. Subtitles Tab
- 7. Chapters Tab
- 8. Presets
- 9. Recommended Settings
- 10. Anamorphic Revisited
- 11. Closing Notes
General Info about Handbrake and Videos
Why Transcode Videos?:
Well, there could be many different reasons for this. Few that come to mind, off the top, are:
- Incompatibility of the video codec with your device.
- Uploading a video with a low bandwidth connection.
- Reducing file size to save your device memory.
In the words of its developer:
“HandBrake is a GPL-licensed, multiplatform, multithreaded video transcoder.”
What needs to be noted here is that Handbrake is a video transcoder. It wasn’t, isn’t and quite probably never will be a “Video Converter”. I have heard the terms container and codec, converter and encoder (or transcoder) misunderstood and used interchangeably countless times. So, I feel it would be best if I clear that up first.
- Container: This is your actual video file format. If your file name is xxx.yyy, then yyy is the container. For example, mp4, avi, mkv, 3gp, flv are all container formats, and in no way signifies the codec used.
- Codec: A video file basically comprises of two things. The audio that you hear, and the video that you see. Codec (COder-DECoder), simply put, is the program using which data streams are encoded for storage on a device, and decoded for playback. The video and audio streams are encoded using different codecs and are held together in the container format. For example; aac, mp3, wma are audio codecs; and x264, xvid, VP8 are video codecs.
- Transcoding: Encode using a different codec from the one with which the video is currently encoded.
- Converting: Changing the container format of the video file, with or without transcoding.
So, from this it is evident that most video converters are transcoders as well (though in most cases, devoid of many of the features offered by standalone video transcoders like Handbrake), while video transcoders may or may not offer conversion.
Handbrake currently supports two output container formats: MKV and MP4. So, it wouldn’t be right classifying it as a video converter per se, but it most certainly is a video transcoder. And quite a good one at that.
Now enough of all this blabbering! Let’s jump right on to using Handbrake.
First, let’s have a look at the window:
To add a file to transcode, simply drag and drop it to the window. Or, you can click on “Source” and browse to the file location to add it. Then set the destination and the output file name. If Batch transcoding (transcoding more than 1 file) is what you’re after, then after you’ve set all the required parameters for transcoding, click “Add to Queue” and add another file. Click “Show Queue” to view all the files in queue to be encoded.
Click on “Preview” to view a 10 second(can be changed) preview of how your output would look like.
Choose either MP4 or MKV container according to your requirements. Tick the “Web Optimized” check box if you want to upload the video to a website.
Now we’ll see the various settings offered by handbrake.
This tab contains all the settings that you’ll need to modify the Resolution and Aspect Ratio (Width / Height) of your video.
Anamorphic is the property of scaling the width of a video by a factor in order to correct its Aspect Ratio.This setting is a bit complicated to explain. So, I feel it’s best if I explain it in a later part. For now, just understand this;
If your video doesn’t appear squished on your device, and you want to keep its resolution as it is, keep this option to Strict and let Handbrake handle the rest.
If your video doesn’t appear squished on your device, and you want to reduce its resolution, keep this option to loose and reduce the resolution. Keeping it to none with “Keep Aspect Ratio” enabled will work too. But if the video source itself is anamorphic, then that property will be lost.
Most video encoders divide each video frame into macroblocks, which can be said to be an array of pixels. A macroblock generally consists of 16×16 pixels. This means that both the width and the height of the video would have to be divisible by 16. The downside here is that you’d almost never get a perfect resolution and aspect ratio. For example, imagine a video that has an aspect ratio of 1.84 and is 640 pixels wide. The standard resolution for such a video would be 640×348 (approximately). But since the height and width both must be divisible by 16, the resolution would be reduced to 640×336, thereby creating an effective aspect ratio of 1.9. By using the Modulus option, you get to decide the multiplying factor for the resolution, at the expense of some overhead. By setting the value of modulus to 2, you would be able to preserve the aspect ratio of the 640×348 video as it is, as the height and width now just needs to be divisible by 2. But to achieve this, 4 additional horizontal pixels would be padded and encoded (348 is not divisible by 16. Next closest number divisible by 16 is 352. 352-348=4). But these would get cropped off during playback, and in most cases won’t be visible.
You can use this setting to crop off a part of your video file. Just set this to Custom, with all settings 0, if you don’t want to do so. You can also leave it to Automatic. But in some very rare cases, Handbrake will crop off a portion of your video file even when not needed, or it may miss a portion to be cropped. So, as the saying goes, Better be safe than sorry!
This tab contains settings that you’ll need if you are dealing with a noisy and/or distorted source file. Before encoding the video, Handbrake would run it through these filters to rectify the source.
Detelecine, Deinterlace and Decomb:
Only worry about these settings if your source is a broadcast content(analog broadcast content, to be precise).
Interlacing is the process of dividing each frame into two fields, with each field containing alternate horizontal lines of the frame, making it suitable for broadcast (For more info, see: Interlaced Video). By this, the content can be broadcasted at twice the frame rate as that of progressively scanned video (For more info, see: Progressive Video), without any additional bandwidth. The downside to this is, you’ll get combing artefacts if you try viewing this on your computer monitor.
So, in order to rectify this, you’ll need to enable either the “Deinterlacing” or the “Decomb” Option. The difference between these two is that while Deinterlacing would deinterlace each and every frame of the video, Decomb would check which parts of the video have combing artefacts and would fix just those frames. I recommend using the Decomb option in default mode, as Deinterlacing could reduce the video quality in case the frame isn’t entirely interlaced. But if your video seems to be interlaced entirely (rarely does this happen), using Deinterlacing at Fast setting can save time on your encode. It’s always better to keep these settings off if your video isn’t interlaced.
Notice how the frame is Divided into two fields, one containing the odd lines and the other containing the even lines. In scenes with fast motion or in which the camera position is changed quickly, both the odd and even fields can be seen separately, which is called Combing Effect. This effect can be seen clearly in the above frame.
The combing artefacts are removed, while keeping quality loss to a minimum.
Telecining is the process of converting a video shot in one frame rate into a frame rate that is suitable for broadcasting. Extra frames need to be added to such videos. There are two ways by which this could be achieved.
- Duplicating certain (not all) fields (interlaced frames), called Hard Telecine.
- Showing those fields a bit longer than usual by repeating them during playback, called Soft Telecine.
Hard telecined video needs to be Detelecined before viewing it on a computer. You can tell if a video is hard telecined or not by analysing it frame by frame. If you obtain a pattern of frames with combing artefacts and then some without it, I’d say you’ve got a Hard Telecined Video. For example, one pattern, commonly observed in NTSC content, is 2 interlaced frames and 3 normal frames (or 2 duplicated fields in 8 fields). For PAL content, in very rare cases, this pattern is 2 interlaced frames and 23 normal frames (or 2 duplicated fields in 48 fields).
Just leave this filter on default for such videos. Else keep it off.
If you’ve got excess grain or blur in your video, you can use this option to reduce it, but at the expense of loss of finer details. Handbrake version 0.10 and above has added support for NLmeans denoising filter, which although takes more time in encoding, gives better results than hqn3d filter(the one used in pre 0.10 versions). If you don’t mind the extra time, use this in ultralight (or light if your video is too grainy) preset. Otherwise, use hqn3d in weak preset. Keep this option off if you if you feel your video is fine as it is.
The grain is reduced, but there is a noticeable loss of detail(for instance, the wrinkles).
This filter can be used to remove visible sharp edges between adjacent macroblocks. Only use this option as a last resort. Even the smallest changes in this can affect the quality drastically. For all intents and purposes, I recommend you to steer clear off this option. There is only so much one can do to rectify a bad source. But in case you really need to use this option, don’t exceed the setting of 5.
The sharp edges between macroblocks are clearly visible in this frame. These are called blocky artefacts.
The blocky artefacts are removed, but so are the details. Overall, the whole image looks softened.
This tab contains settings related to your Video encoder.
- x264(H.264/AVC Standard): Always choose this if your device supports it. It offers the best quality for the size.
- MPEG 4 Part 2(H.263 Standard): Faster encoding and better support for old devices than x264. But the quality will be lower.
- MPEG 2 Part 2(H.262 Standard): Faster encoding than MPEG 4. But the output file will be much larger and of inferior quality. Only use this if your device doesn’t support even MPEG 4.
- x265 (H.265/HEVC Standard): This is a relatively new encoder. It uses the H.265 standard, which is an improvement over the H.264 standard. x265 offers the same quality as x264 at much lower bitrates, i.e., the output file size will be much lower. But support for this encoder is quite minimal, especially in mobile devices. VLC(for Windows PC, that is) currently offers support for this codec, but I have seen playback issues with some x265 videos on mobile devices. So, I recommend you to check if your device supports this codec, before making the decision to use this.
- x264, MPEG4, MPEG2 and x265: Same as MP4.
- Theora(VP3): VP3 is a relatively old codec that was intended to compete with MPEG 4. Theora was evolved from this codec and it offers various improvements over its predecessor, On2’s VP3. However, it doesn’t compare to x264 in terms of quality at a given bit rate. But where Theora really triumphs is that it is truly open source and not subject to any patents. This in itself makes it a favourable choice to those who want to distribute content, as they aren’t required to pay any royalty fee. x264, though open source, is still subject to the patents held by MPEG consortium for the H.264 standard. And distributors of H.264 encoded content are, by law, required to pay a licensing fee.
- libvpx(VP8): libvpx can be said to be an improvement over the somewhat dated Theora encoder. It offers much better quality, and like Theora, is completely free. It still doesn’t offer the amazing quality of x264, but it has become successful in closing that gap. And I mean BY A LOT. So, it’s a great alternative if you want to distribute content.
Framerate is the number of frames displayed per second (fps). Keep this option to same as source unless, for some reason, you need to change it.
x264 Exclusive Settings:
x264 Preset: By using this slider you can adjust the level of tradeoff between encoding speed and filesize and/or quality. The extreme left setting will finish encoding quicker but the filesize will be larger for the quality. The extreme right setting will take much longer to encode, but it will offer the lowest filesize for the quality.
x264 Tune: Options of None, Film, Animation, Grain, Still Image, PSNR, SSIM, Fast Decode are provided. Choose any one of these options according to your requirements. (For example, Film if your source is a movie, Grain if you want to retain grain, etc. PSNR and SSIM will offer you maximum quality the way a computer will see it, and is not generally recommended to use.)
H.264 Profile: Four profile options are provided: Main, Baseline, High, Auto.
- Main: Less CPU intensive, Fast Encode, Fast Decode (Playback), Large Filesize.
- Baseline: More CPU Intensive, Slower Encode, Slower Decode (Playback), Lower Filesize.
- High: Most CPU Intensive, Slowest Encode, Slowest Decode (Playback), Lowest Filesize.
- Auto: Selects the Profile most suited for your settings automatically.
H.264 Level: Each H.264 level provides a set of constraints like max bit rate, frame size, etc for encoding. For the full list of constraints for each level, see: H.264 Levels
Handbrake offers two methods for Encoding Video: Constant Quality and Average Bitrate.
Constant Quality: In this method, you have no control over the output file size. For most cases, this is the better option of the two. The output file is most likely to be of better quality and lower size using this method. In this method you can control the quality of the video by using the quality slider. The extreme right value (lowest number) represents the highest possible quality (lossless, output will be bigger than the source if the source itself is lossy), while the extreme left value(highest number) represents the lowest quality (extremely lossy).
Average Bitrate: Unless you REALLY know what you’re doing, don’t use this option. This option gives you control over the file size, but at the expense of quality. All you need to do is take what your estimate is of the output file size (in kb), divide it by the duration of the video(in seconds), and enter it in the box labelled “Avg bitrate(kbps)”. However, the problem here is that, more often than not your estimated file size will be either too large or too low.
If you use this setting, do remember to check the 2-pass Encoding and Turbo First Pass check boxes. The reason for this is not every portion of the video has the same bitrate (thus, the term “Average”). Some portions require higher bitrate (fast action scenes), while some appear fine at lower bitrates (scenes with less motion). So, if 2-Pass encoding is turned on, Handbrake will encode the video a second time, allocating bits to different parts of the video in a much better way than the first time.
But obviously, this will require much more time than a single pass encode. This is rectified by turning on Turbo First Pass, which will encode the first time much quicker and less efficiently (since the actual output will be that of the second pass, the first encode can be thought of as redundant). It still requires more time than a single pass encode, but the overall time will be much lesser than what it would be if this option is kept off.
This tab contains settings related to your audio encoder.
- libav AAC: Encodes your audio to AAC using ffmpeg’s libav codec library.
- FDK AAC/AAC-LC: Encodes your audio to AAC-LC using the FDK Encoder. Generally much better results are obtained using FDK than by using libav.
- FDK HE-AAC: Encodes your audio to HE-AAC using the FDK encoder. More suited for lower bitrate audio files (<80kbps) for streaming.
- LAME MP3: Encodes your audio to the extremely popular MP3 format using the LAME encoder. Higher bitrates are needed for achieving the same quality as AAC-LC.
- libav AC3: Encodes your audio to AC3 using ffmpeg’s libav codec library.
- Passthru(AAC, MP3, AC3, DTS, DTS- HD): These would pass through the source audio settings as it is to the output file.
- Passthru(Auto): This setting will sense your source format, and pass through your source audio settings as it is to the output file. Use this option if you don’t want to transcode your audio.
- Libav AAC , FDK AAC/AAC-LC, FDK HE-AAC, LAME MP3, libav AC3, Passthru(All): Same as MP4.
- Vorbis: Vorbis can be said to be the audio equivalent of Theora. It is a free and open source codec that isn’t subject to any patents. Audio encoded in Vorbis is almost identical to AAC, and can be used as a viable alternative to AAC to distribute content.
- libav FLAC: 16 bit and 24 bit FLAC options are available by using ffmpeg’s libav codec library. These options are lossless, so the filesize will increase by a lot.
Options of Dolby ProLogic II, Dolby Surround, Mono, Stereo, 5.1ch, 6.1ch, 7.1ch, None and Automatic are provided. Choose any one of these options according to your requirements.
Number of Audio samples per second. Keep this setting at auto for best results.
Dynamic Range Compression. This setting is used to alter the difference between the lowest and loudest sounds in the audio file. Use this setting at greater than 0 if you feel the lower volume parts in the audio file are too low in volume, while the louder parts are too loud. Generally, a value between 1 and 2 is sufficient for most files. At default, this value is kept at 0 (DRC OFF).
This setting is used to increase the volume of the entire audio file. The value should be in dB. Never keep this setting at more than 10 dB. It will distort your audio at the really loud places. To calculate this value: Suppose you need 2 times the volume of your source file in your output. Then:
You can also add an additional audio track by using the “Add Track” option. This is particularly useful if you have an audio track in your preferred language, and would like to add it to your video.
Similarly, you can also delete existing tracks that you don’t need.
You can add Subtitle tracks to your video file by clicking on “Import SRT”. Your subtitle needs to be in SRT format for this to work.
Handbrake can softcode(mux) or hardcode(embed) the Subtitle track to your Video, according to your wish. Softcode means that the subtitle file won’t be “written” to your video, whereas in hardcode, it is. The advantage of softcode is that you can turn the subtitles OFF whenever it is not required, or switch to another subtitle track in a different language. The disadvantage is, it won’t be displayed if the device does not support the subtitle format.
You can also adjust the offset time for the subtitle, which would delay or advance the start time of the subtitle track, according to your requirement.
You can use the options provided in this tab to edit existing chapter markers in your source file, import existing chapters from a csv file to your output file, or export the chapters in your source file to a csv file.
Handbrake has numerous built in presets which you could use to simplify your encoding task. You can also create your own custom preset by clicking the “Add” button, or remove existing presets by clicking “Remove”.
I’ll only provide the recommended settings for Constant Quality method, as it’s just not possible to provide the average bitrate without having a look at the video. The average bitrate differs a lot from video to video, and I don’t think it is right to give you a “safe” bitrate, which could leave you with a file that is much larger than required.
For Mobile Devices:
- Container: MP4; Resolution: Height: 640 (Keep AR);
- Video Codec: x264; Preset: Very Fast; Tune: Film; Profile: Auto; RF: >=24;
- Audio Codec: AAC; Audio Bitrate: =<160.
For HDTVs (Or Monitors):
- Container: MP4; Resolution: Height: 720 (>27″ screens) 1080 (27″ and above screens) (Keep AR);
- Video Codec: x264; Preset: Fast; Tune: Film; Profile: Auto; RF: Between 18 and 20;
- Audio Codec: AAC; Audio Bitrate: >=160.
HTML 5 supports embedding video and audio onto an html page using <video> and <audio> tags. The advantage of this is that you don’t need a plugin (like flash) to play video on your browser. This means the video will load much quicker, and will use less system resources.
The formats supported till now by HTML5 are:
- H.264 video and AAC audio in MP4 container, licensing fee needs to be paid for content distribution, fully supported by Handbrake.
- VP3 video with vorbis audio in Ogg container, no licensing fee, Ogg container not supported by Handbrake.
- VP8 Video with Vorbis audio in webm container, no licensing fee, webm container not supported by Handbrake.
I’ve only provided the formats at least partially supported by Handbrake. For the full list, see: HTML5 Supported Media Formats
Your best bet to legally distribute paid content on your webpage would be to transcode your file to VP8 video and vorbis audio in Matroska(MKV) container, and to convert it to webm format using a 3rd party converter.
Take note that these settings that I’ve given are not foolproof. It is quite possible ymmv. It all depends on your source file. It is always a good practice to see what happens when you encode using a slightly different setting.
That’s the reason I’ve given you these settings. So that you have a starting point, from where on you could tweak the settings according to your requirements.
If you haven’t dozed off till now, well, good job! Now it’s time to reap your metaphorical reward (remember, I told you I’d explain Anamorphic in detail in a later part. This is the “later part”!).
Things could get a bit complicated here, but I’ll try to keep it as simple as possible.
Quite a few times, you may come across a video file that will be displayed in a squished or stretched form in your computer. You check the resolution and the Aspect Ratio of the video, but that seems correct. So, what is the problem?
In order to fully understand this, you need to know about Display Aspect Ratio (DAR), Storage/Frame Aspect Ratio (SAR/FAR) and Pixel Aspect Ratio (PAR). So, here goes:
- Display Aspect Ratio (DAR): This is a flag in the video file that tells the display device what Aspect Ratio to display the Video at. Most commonly this value is either 4:3 (for SD content) or 16:9(for HD or Widescreen content).
- Storage/Frame Aspect Ratio (SAR/FAR): This is the actual Aspect Ratio of your video file, not taking into consideration the PAR. This is the value that you’ll get when you divide the width and height data of your video file obtained from the Media Info in your video Player.
- Pixel Aspect Ratio (PAR): Pixel, or picture element, is the smallest element in an image. But the harsh truth is, this element is not always a square. For computer graphics, it is a square, but for analog broadcast content, it needs to be rectangular. Pixel Aspect Ratio is a ratio that defines the shape of each pixel.
The math between these three values is:
DAR = SAR x PAR
Most analog broadcast content are not in 4:3(Standard Definition) or 16:9(Widescreen) aspect ratio. The resolution of NTSC content is 720×480(AR=1.5) and that of PAL content is 720×576(AR=1.25).
Now, imagine what would happen if PAL or NTSC content is viewed on a computer monitor (or any digital display, for that matter). As monitors generally have an aspect ratio of 4:3 or 16:9 these images would look distorted horizontally.
In order to compensate for this, NTSC contents are scaled horizontally by a factor of about 0.9(or 1.2 for widescreen) to obtain a resolution of approximately 640×480(854×480 for widescreen), while PAL contents are scaled horizontally by a factor of 1.07(or 1.45 for widescreen) to obtain a resolution of approximately 768×576(or 1024×576 for widescreen). This factor is known as Pixel Aspect Ratio (PAR), as it can be said that each pixel is scaled by this factor to fit the display screen.
Anamorphic is the property of scaling the width of a video by a factor (PAR) in order to correct its Aspect Ratio.
To apply anamorphic property to a video:
- Set the Anamorphic Option to Custom.
- Then you’ll be able to tweak the PAR, Source Resolution and the display width values.
- The resolution shown in the Width and Height boxes will be the actual resolution of your output. The Aspect Ratio that you get from this resolution is the SAR. The resolution that you get by scaling the width by the PAR value is the Resolution at which the video file will be displayed on your screen. The Aspect Ratio that you get from this resolution is the DAR.
- Keep changing the PAR and viewing the preview, till you obtain an output preview that is satisfactory.
Anamorphic is also widely used to preserve the resolution of widescreen movies in DVDs. This is what the tag “Enhanced for Widescreen” means in a DVD. Films used to be shot at an aspect ratio of 4:3 or 1.33. From there, this value underwent a series of changes, from 1.66, 2.59, 2.35, 1.85, 2.20, 2.76, etc. Even today, there is no standard Aspect ratio at which films are supposed to be shot, and much of it depends on the choice of the director. There are three ways to accommodate such films on a standard display:
- Stretch the video to fit on the screen, while preserving the Aspect Ratio. So, for wider Aspect Ratios the sides of the picture gets cropped off, while for taller Aspect ratios the top and bottom of the picture gets cropped off. This method is called Pan and Scan.
- For wider aspect ratios, movies are encoded with black bars on the top and bottom of the frame. This is called letterboxing. And for taller Aspect Ratios, black bars are added to the sides of the frame. This is called Pillarboxing. This method was popular before anamorphic. It isn’t required now as modern displays and DVD players add black spaces by itself to fix the Aspect Ratio.
Both these methods are rendered useless now with the advent of Anamorphic.
- By using anamorphic property, the PAR of the movie is adjusted to view it in both 4:3 as well as 16:9 displays. This method is the one that is most widely used now. Pan and scan crops off a part of the frame, while Letterboxing/Pillarboxing reduces the effective resolution, as part of the resolution is comprised of just black lines. So, anamorphic in this sense, offers the best of both worlds. It preserves the Resolution and the Aspect Ratio while keeping the video frame intact.
The SAR Output. The frame appears squished.
Black bars are added to the top and bottom of the frame while playback, to compensate for the wider Aspect Ratio of 2.35(letterboxing).
You’ll need to crop off the bars if you want to convert a pillarboxed/letterboxed source to anamorphic.
I’ll be ending this tutorial here.
For the “Advanced” tab, I’ll be making a separate post. Part 2 Coming soon!