AfterDawn Blu-ray Encoding Tutorial


AfterDawn Blu-ray Encoding Tutorial Lesson 3
Chapter Points and Bitrate

This is the third lesson in the AfterDawn Blu-ray Encoding Tutorial. In part one you learned how to analyze your video file to determine the container and video encoding used, as well as how to use the tools included with MeGUI to open it using AviSynth. In Lesson 2 you learned how to use the AVS Script Creator and AVS Cutter to produce a script (AVS file) containing instructions for processing your video and cutting it if necessary. You should now have an AviSynth script ready for encoding. But before you jump into that step you will want to do a little bit of planning to determine the bitrate you will use for your encoding job and, if necessary, create a file telling x264 where you need chapter points at in your finished video file.

The Complete AfterDawn Blu-ray Encoding Tutorial

Creating assets for Blu-ray authoring is relatively easy, but not necessarily simple. To make it easier to learn we have divided this tutorial into several individual lessons, each of which addresses a single step in the process. At the top and bottom of each lesson is a navigation menu where you can jump to any other lesson in the series. You can easily return to a previous section for review or skip over any future section. It is recommended that you read the entire series at least the first time through.

Lesson 1 - Prepare Source Video

In the first lesson you will learn how to analyze your source video, ensuring AviSynth will be able to decode it properly, and also formulate a plan for making any changes which may be required. In most cases this will also involve creating an index, which is a sort of map to the contents of a video.

Lesson 2 - Create AviSynth Script

In the second lesson you will learn to use MeGUI's AVS Script Creator tool to provide instructions for loading your source video and performing any required processing. This may include resizing video to the desired resolution and either deinterlacing or bobbing interlaced video to make it progressive.

Lesson 3 - Create Chapter File and Calculate Bitrate

In lesson three you wil learn how to create a file specifying chapter points and calculate the correct bitrate for your encoded video.

Lesson 4 - Encode Video

In lesson four you will learn about the proper settings for encoding your video.

Lesson 5 - Encode AC-3 Audio

In lesson five you will learn how to encode your audio to AC-3 format using MeGUI and either the Aften encoder or FFmpeg. When you complete this step you will have Blu-ray compliant audio files.

Lesson 6 - Advanced Bitrate Calculation

In lesson six you will learn more advanced techniques for calculating bitrate when you are authoring a Blu-ray disc from multiple video files.

Lesson 7 - Advanced Audio Processing

In this lesson you will learn how to use Audacity to combine individual audio files to produce either an uncompressed (LPCM) or Dolby Digital (AC-3) audio stream

Lesson 8 - Convert Text Subtitles To Images

In Lesson 9 you will become familiar with the process of converting subitles from the text-based SRT, SSA, and ASS formats to Blu-ray compliant SUP or BDN XML format.

Lesson 9 - Prepare A Still Menu Background

After completing Lesson 10 you should be able to create a single frame video file for use as the background for a Blu-ray still menu. You will also be able to extract a video frame as a regular still image file (such as a PNG or JPEG) and how to convert those common files into single frame, Blu-ray compliant video streams.

Lesson 10 - Make Menu Buttons With GIMP

This lesson will teach you the basics of making your own buttons for Blu-ray menus using the free image editor GIMP. It also includes tips on how to add elements necessary for a functional Blu-ray menu to a still image and assemble a mockup so you know what your menu will look like before you start the authoring process.

Official AfterDawn Blu-ray Encoding Tutorial feedback thread

We have created a dedicated discussion in our forums (open in new window) for feedback on this tutorial. We would love to hear your whatever thoughts you have. Tell us what you liked or what you didn't like. Let us know if there was something you didn't understand or even something that was just plain wrong. We strive for 100 percent accuracy in our guides, but nobody's perfect. Any help you can give us in getting a little closer to that goal is appreciated. Our goal is to help you out, and anything we can change to do a better job of that is an improvement.

Lesson 3 Objectives

  • Learn about Blu-ray chapters and how they relate to H.264 (MPEG-4 AVC) encoding
  • Create a chapter file for x264 using MeGUI's Chapter Creator
  • Determine the optimal bitrate for encoding a single video file

Understanding The Requirements For Chapter Points

Most frames in a H.264 stream cannot be properly decoded into full pictures until other frames have been decoded first. In order to plan for a chapter point you must be know, ahead of time, that no frame before the beginning of the chapter will have to be decoded. For example, let's say you want a chapter to start at frame 1000. That frame will have to be an I-Frame, meaning it can be decoded by itself. But if the next few frames refer to other frames before the chapter point, you may see a split second of garbage until you reach a frame which doesn't need those previous frames.

H.264 chapter point diagram -

This isn't a problem if your chapter points all come at the beginning of a video stream, which may be the case, depending on your source. For example, if you are making a Blu-ray disc from a large number of short home movies from your camcorder, every chapter may actually be a separate file. A single Blu-ray title is nothing more than a playlist which may play a single video file or dozens. If each chapter starts a new video file you don't have to do any planning for chapter points before you encode the video.

However, if you need to put a chapter point in the middle of a video file, you need to let the x264 encoder know where those points are so it can make sure you don't have unplayable frames after you seek to that point. That can be done via a special text file which is essentially just a list of chapter points. Conveniently, MeGUI even has a tool, or perhaps more accurately a combination of tools, which you can use to automate the process in just a few simple steps.

Step 1 - Open Your AviSynth Script

By default, when you save an AVS file (AviSynth Script) it will automatically be opened in the main MeGUI window to be used in other tools. Additionally, a preview window will open where you can see the script's output. Both the AVS script being listed in the Video Encoding section of the main MeGUI window and the video loaded in the preview window are important for this process.

Open AVS file in MeGUI -

MeGUI's Chapter Creator will use the AviSynth script (AVS file) for your video to generate a preview and gather information about the characteristics (particularly framerate) for determining things like the timecodes associated with specific frames. That requires the script first be selected as a source in the main MeGUI window. If you have just exited the AVS Script Creator tool it should be loaded automatically. Otherwise use this button to open it now. Once it is opened a preview window should automatically appear. You can close this window as the Chapter Creator has its own preview window.

Step 2 - Open The Chapter Creator & Preview Window

Open the MeGUI Chapter Creator -

The Chapter Creator can be opened from the Tools menu. The settings here will automatically be linked to the AVS file you have loaded in the main MeGUI window.

Open preview window in MeGUI's Chapter Creator -

Once the Chapter Creator appears, click the Preview Button to open a special window where you can visually identify the locations for your chapter points and add them automatically.

Step 3 - Select Chapter Points

Finding chapter points in MeGUI's video preview window -

1. Adjust Preview Size

You can make the preview window larger or smaller using these buttons. Considering 1920×1080 video will fill most computer monitors, this is often very helpful.

2. Navigation Slider

The simplest way to select a chapter point is simply dragging the navigation slider until you reach it. At the very least it's a useful way to get close to the desired frame before using other controls to fine tune the location.

3. Fine Tuning

The left and right (single) arrow buttons will navigate just one frame in either direction. The double arrows can be used to jump 15 frames, or the Play button will play the video.

4. Select Frame

If you already know what frame you want to use for your chapter point you can use this button to jump directly to it.

5. Set Chapter Point

Once the frame where you want the next chapter to begin is shown in the preview window, use this button to add it to the list in the Chapter Creator window.

6. Frame Number

One of the required steps for setting chapter points is creating a QP file to let the x264 video encoder know to encode the first frame of each chapter as an IDR frame. This is what ensures it can be decoded if your Blu-ray player jumps to it. In theory the Chapter Creator can generate this file for you automatically. In practice it doesn't select the right frames unless your video has a framerate of exactly 25fps. Otherwise, you should use Notepad (or whatever text editor you prefer) to create the file for yourself. As you select chapter points in this preview window you should add the frame number for each one to your text file followed by the letter K. Make sure each chapter point is on a separate line. It should look like the example below.

QPF file in Notepad -

Once you have set all the desired chapter points, close the Preview window to return to the main Chapter Creator dialog where your chapter points should all be listed.

Step 4 - Name Chapters

As an optional step, you can add names to your chapter points. This could be intended just for your own personal reference or it might be something you import during Blu-ray authoring. If all you are using the Chapter Creator for is generating a QP File for x264 encoding it won't even be saved in the resulting file.

Name chapters in MeGUI Chapter Creator -

1. Select Chapter Point

Select the chapter point you wish to enter a name for by clicking on it in the chapter list.

2. Rename

Enter the name you wish to give this chapter.

Step 5 - Save Chapter File(s)

Saving chapter files in MeGUI -

MeGUI can produce three different types of chapter file, only two of which are relevant to Blu-ray encoding or authoring. Once you have selected you chapter points and named them if desired you can create these files using the Save button. If you need to save both files you should make sure 'and close' isn't checked. Otherwise the Chapter Creator will close before you get a chance to save a second time.

MeGUI Chapter Creator Save dialog -

1. QPF

Select this option if you are saving a file to tell x264 which frames need to be used for chapter points. As mentioned previously, automated QP file generation currently only works if your video has a framerate of 25fps. Otherwise use the alteranate instructions detailed above for creating the file in Notepad and the intructions below for saving it.
MeGUI Chapter Creator text file format

2. Text File

MeGUI Chapter Creator text files use two lines to describe each chapter. The first lists the chapter number and timecode for the first frame in hours, minutes, seconds, and milliseconds ( and the second provides the name assigned1.

1 Even if MeGUI's standard text file output for chapters isn't exactly what you need for your authoring program, you may find that it's close enough to be used with some minor editing. For example, maybe your program uses timecodes with fractional seconds in a format other than milliseconds or the word 'Chapter' in front of the chapter numbers removed. Those are simple enough changes to make with Notepad. If you aren't sure what format you need, it's probably best to go ahead and save both a Text and QPF file so you have both the timecodes and frame numbers recorded for every chapter.

Saving A QPF File in Notepad

If you have a video source with a framerate other than 25fps you should be manually creating your QPF files using the method listed above. Once you have all the chapter points listed in the appropriate format, you can save your file with an extension of .QPF. This will make it easy to load later via MeGUI's x264 settings dialog.

Saving a x264 QP File in Notepad -

By default Notepad will save every file with an extension of .txt, but as long as you have a relatively recent version of Windows (Windows XP or newer) you can override this behavior by simply providing an alternate extension as part of the filename when you save your file. If you forget this step, you may have to jump through some hoops to change the extension, depending on how you have Windows Explorer configured.

Change txt file extension for QP file in Windows Explorer -

Changing The File Extension For An Existing Chapter (QP) File

If you can see the .TXT file extension, you can change it to .QPF by simply right-clicking on the file and selecting Rename from the context-menu.

Change file extension via Windows Explorer rename -

The filename will automatically be highlighted for editing. Hightlight just the last three letters (txt) and change them to qpf. Hit the Enter key on your keyboard and you will be asked if you are sure you want to change the extension. Make sure to answer Yes.

Change Windows Explorer settings to show file extensions -

Displaying File Extensions

If you don't see the file extension, you will need to change Windows' settings before you can change the extension of an existing file. Select Folder Options from the Tools menu.

Turn off Hide File Extensions option in Windows Explorer -

Go to the View tab of the Folder Options dialog and uncheck Hide extensions for known file types. Now you should be able to change the extension as detailed above.

Considerations For Chapter Point Selection

How, or even whether, you set chapter point locations is entirely up to you, but here are some things you may want to think about. Sometimes there are obvious chapter locations based on the source video. If your source is a TV capture with spots where commercials were inserted for broadcast, those same points tend to be good choices for chapters. In other cases maybe you just want to add a chapter every five minutes or ten minutes just for the pragmatic purpose of being able to quickly skip past large portions of video.

Obvious examples like TV captures aside, in the end your selection of chapter points, at least for longer clips, will likely come down to the importance you place on authoring. If you see the creation of a Blu-ray disc as purely functional - nothing more than a way to produce something you can play on any standalone Blu-ray player, simply choosing a regular interval between chapters is probably as good as anything else. If, instead, you see a Blu-ray disc as a separate creative product, you may find it worthwhile to put more planning into chapter placement, perhaps beginning even before you get into the encoding process. Ultimately it comes down to a question of priorities and personal preferences which you will have to figure out for yourself.

Calculating Bitrate

Encoding video for Blu-ray is a lossy process. That means that the video you encode will not be a perfect copy of the source, but rather an approximation. Ideally it will be transparent, meaning the differences between the source and encoded video is invisible to the human eye, but almost without exception you will lose details from the original.

Quality Based Encoding

There are essentially two different strategies x264 can use for encoding your video. The first is quality-based encoding. This means the encoder attempts to maintain the same quality throughout your video regardless of resulting file size. The problem with this approach is the size of the resulting video streams is unpredictable while the space available is anything but. If you choose to encode using x264's constant quality mode you could easily end up with files far too large to fit on even a Blu-ray disc.

Additionally, in order to insure every BDMV (Blu-ray Movie) disc will play on every Blu-ray player, there are limitations placed on the encoder which may limit quality even when the files you are authoring are far smaller than the destination media.

Bitrate Based Encoding

More often, and certainly whenever you are looking to fit as much content as possible on your disc, it will be preferable to use a Bitrate-based encoding strategy. This involves selecting an average bitrate for your encoded video which may or may not produce the highest quality possible. It will, however, result in predictable file sizes so you can guarantee all your content will fit on whatever media your authored disc will be burned to.

In order to help you encode your video at the highest quality possible without exceeding the capacity of your disc, you will need to calculate the bitrate which will produce as big a video file as possible without exceeding the available space on the disc it will be written to later. This is more complicated than you might think and requires some additional information you may not know now, and even some you may never know. In fact bitrate is something you may end up thinking about from the earliest planning stages for your Blu-ray disc just so you can be sure to have all the necessary facts when you get to this point.

Factors Limiting Bitrate

The most obvious factor you must consider when deciding on your video bitrate is the size of the disc you will be writing to eventually. This could range from something as small as a single layer DVD (4.37GB) to a dual layer DVD (8.54GB) to a single or even dual layer Blu-ray disc with 25GB or 50GB of space. Obviously the most important thing to remember is that your video must fit on the disc itself.

Audio & Subtitle Streams

Although the vast majority of the time required for preparing assets and authoring a Blu-ray disc will likely be spent on the video, it is far from the only thing you will be putting on your disc. For starters there are the other streams which accompany the video. Depending on the source of your video, you will have one or more audio streams and possibly one or more subpicture or text subtitle streams as well. In some cases you may even have secondary video streams which are displayed on top of the primary video.

Container Overhead

On top of all that, you have container overhead. In order to make it possible to play multiple streams (such as both video and audio) simultaneously they must be combined, or muxed, into a container file. In the case of Blu-ray the container is BDAV, better known by its file extension of M2TS. This is a variation on the MPEG-2 Transport Stream (TS) file format which is designed around both error resiliency and combining multiple programs (ie video streams) together. A container adds overhead on top of the size of the streams it holds.

Authoring Overhead

In addition to the streams and containers, the authoring process uses up additional space of its own. Fortunately, unless you are using features like BD-J (Java) for your menus or some type of special features this is pretty much insignificant. If you wanted to err on the side of caution you could figure 50MB for this, but in reality it will likely be less than 1MB.


On top of that, there is menu overhead. In part this is more authoring overhead, but since Blu-ray menus are essentially just additional titles which happen to have interactive elements, this can also introduce additional video, audio, and subpicture streams which must be accounted for.

Actual Disc Space

Finally, you should consider the issue of media limitations. While mass produced discs are literally stamped out of metal, recordable discs are made by burning data into one or more layers of dye on the disc's surface. While the entire surface of a stamped disc is essentially the same from a quality perspective, it is generally considered a good idea to avoid burning all the way to the edge of a recordable disc because that's where inconsistencies in dye application may become a factor.

Exactly how much blank space you leave at the end of a disc is up to you, including the option of filling it to capacity, I personally try to leave at least 100MB free for DVD media. Blu-ray media is much newer, and therefore the tolerances of blank media isn't as well established. However, you should probably leave at least as much blank space as for a DVD, and maybe as much as two to five times that much just to be safe.

MeGUI's Bitrate Calculator

Obviously it's not realistic to expect you to calculate all the possible factors to figure out what bitrate you should use for encoding, which is why MeGUI has a bitrate calculator to do the job for you. You will still need to add a little information of your own, some of which you may need to estimate, but with just a little experience you should be able to get very accurate bitrate settings from it. As with the Chapter Creator, you will want to make sure your AVS file is loaded in the Video Encoding section of the main MeGUI window before you start the Bitrate Calculator.

Starting the MeGUI Bitrate Calculator -

Open the Bitrate Calculator by selecting it from the Tools menu.

MeGUI Bitrate Calculator Blu-ray settings -

1. Title Length

This is the length of the title passed from the main window to the Bitrate Calculator.

2. Frame Information

This is the framerate and number of frames passed from the main MeGUI window to the Bitrate Calculator.

3. Resolution

The resolution is also passed to the Bitrate Calculator from the main MeGUI window.

4. Video Encoding

Make sure x264 is selected.

5. Select Audio Stream

By default a single audio stream is listed. If it is already encoded in the form which will be used on your Blu-ray disc, you can use this button to select the file. MeGUI will examine it and subtract the appropriate amount from the number of bits available.

6. Video Encoding Details

If an audio stream hasn't been encoded yet, the Bitrate Calculator can still account for the space it will use if you enter the format and bitrate manually.

7. Add Stream or File

You can add an audio stream to be figured into the disc space calculations using this button.

8. Container

Set the container to M2TS. This is very important as it has more overhead than either MKV or MP4 and the calculations will be off if the wrong container is selected.

9. Target Size

This should be the size of the media you are planning to burn your Blu-ray files to when they are authored. Although there are entries for DVD and BD media in the list, they do not include allowances to avoid burning to the edge of the disc. To figure this in, and also to include your own allowances for menus, you should choose Select Custom Size instead.
Set custom size for Blu-ray discs in MeGUI's Bitrate Calculator -

In this example I have taken the value listed for single layer BD-R discs, subtracted 500MB to avoid burning to the edge. You might also subtract another 50MB to account for some still menus or a larger amount, such as 500MB or even 1000MB for motion (video) menus.

10. Bitrate

This is the bitrate calculated by MeGUI. You can make a note of this number to apply it manually or you can just let MeGUI apply it for you automatically.

11. Apply Settings

Clicking this button lets MeGUI know you are satisfied with the calculated bitrate and the window will close.

MeGUI applying the calculated bitrate -

Once you apply the settings from the Bitrate Calculator, MeGUI will automatically ask if you wish to set the encoder to x264 in automated 2 pass (bitrate-based) mode. If you prefer to apply the settings manually you can answer no here.

Since encoder settings is the subject of the next lesson, we won't continue any further with the operation right now. In fact, if you are reading this tutorial for the first time and following along with your own encoding job, you may prefer to jump straight into Lesson 4 and return to read more on this subject later. It may very well take you months, or even years, to fine tune your own strategy and you are best off taking the time to understand what you're doing and why.

Improved Bitrate Calculation For Menus

The strategy described above for figuring in menu overhead is reasonably good, but you may want to use more precise numbers to optimize the bitrate calculated. Rather than using a generic allowance you could, instead, encode the menus ahead of time so you know precisely how much space they will require. In fact, if you want to make sure your bitrate calculations are as accurate as possible your best bet is to prepare all your audio, subtitle, and menu assets before you tackle the video.

Continue To Lesson 4

All the necessary planning for encoding your video is now done. Finally you can setup an encoding job (one for each video source) to create the H.264 video streams you will be authoring to create your Blu-ray disc. In the next lesson you will get instructions for configuring the x264 encoder to obtain Blu-ray compliant output.

AfterDawn Blu-ray Encoding Tutorial

Written by: Rich Fiscus
Last updated: