Subscribe to AfterDawn's weekly newsletter.
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.
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.
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.
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.
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
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.
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
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.
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.
1. Select Chapter Point
- Select the chapter point you wish to enter a name for by clicking on it in the chapter list.
- Enter the name you wish to give this chapter.
Step 5 - Save Chapter File(s)
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.
- 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.
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 (hh:mm:ss.ms) and the second provides the name assigned1.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Open the Bitrate Calculator by selecting it from the Tools menu.
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.
- 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.
- 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.
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.
- 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.
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.
Last updated: 13 August 2012