AfterDawn Blu-ray Encoding Tutorial Lesson 9
All the previous lessons in our Blu-ray encoding tutorial have focused on regular content, which obviously is the primary purpose for making a Blu-ray disc. On the other hand a Blu-ray disc is more than that. If all you wanted to do was play your video you probably wouldn't need to bother with the Blu-ray authoring process. Most Blu-ray players are perfectly capable of playing most, if not all, the same content (often with fewer restrictions) when it's just copied to a disc or solid state (USB) storage device.
While it's possible your primary interest in Blu-ray may simply be universal compatibility with Blu-ray players, there's another good reason for making an actual Blu-ray (BDMV) disc. In addition to compatibility it gives you the option to add menus. Just like any other Blu-ray content, menus require you to create assets encoded in particular formats. In fact for the most part they are more similar to regular titles than different.
In this lesson you will learn how to use the same tools already covered in many of the previous lessons, such as MeGUI, AviSynth, and x264, to extract individual frames from a video file and encode them for use as the backgrounds in still menus. Additionally you will get directions for extracting those stills as PNG (compressed bitmap) images for use in designing menus. Prior
Preparing For This Lesson
Before you attempt to follow the steps in this lesson you should make sure to familiarize yourself with at least lessons 1, 2, and 4 which cover the process of loading sources, creating AviSynth scripts, and using the x264 video encoder. The steps outlined below build on the steps in those lessons. If you don't feel comfortable with those steps in the process, you may want to re-read them now, or at least be prepared to review them as you follow along with this lesson.
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.
Despite the apparent differences between menus and regular titles on a Blu-ray disc, on a basic level they are fundamentally the same. In fact you could say that a menu is really just another title with an interactive graphics layer displayed over the top of it. Logically then, before you start thinking about the interactive part, you need to prepare the title itself.
So what exactly does that mean? Even though a still menu only needs a single image, that doesn't mean it's not a video stream. In fact what you will be learning to do in this lesson is create a video stream consisting of just a single frame. You will use MeGUI's AviSynth Script Creator for this, not unlike what you did in Lesson 2 when you were preparing to encode an entire title. This video stream will then be encoded with x264, once again in basically the same way you encoded your title in Lesson 4, except that the settings will be focused almost exclusively on optimal quality since bitrate shouldn't be an issue with just one frame.
Creating Your AviSynth Script
Just like when you encoded your content in previous lessons, you will need to create an AviSynth script to use as a source for encoding with x264. Hopefully you still have any intermediary files required for opening your video in AviSynth, such as an index file created by either DGIndex or FFIndex all the way back in Lesson 1. In fact, you should go ahead and create an AviSynth script for the video you are extracting your still menu background from before proceeding any further.
Selecting A Single Frame
At this point you should have a basic script that looks something like this when you look on the Script tab.
Progressive Frames Only
It's important, at this point, to think about whether your source video is progresive or interlaced. A still menu needs to be progressive. If your source is interlaced this means deciding exactly how you will extract progressive content from it, and there are basically three possibilities.
- Just because your video is interlaced, it doesn't automatically mean there aren't any progressive images in it. Images used for things like titles may be progressive even when the rest of the video is progressive. If the image you are planning to use for your menu background comes from such a frame you can probably just use one of MeGUI's standard deinterlacing methods (ie one which doesn't include bobbing) to combine the two fields into a single progressive image. In other cases even that isn't necessary, although it's generally safe to deinterlace these sources anyway.
- The frame you want may not look any good deinterlaced. Maybe it has jagged edges or blurred details, both of which are classic artifacts from deinterlacing. As an alternative you could try bobbing, or bob deinterlacing, the video. As you should recall from Lesson 2, bobbing turns each field into an entire frame. This should eliminate jagged edges, but may result in other artifacts since every other line is interpolated (a sort of educated guess) by AviSynth.
3. Separate Fields & Resize
- Since you are only interested in keeping a single image for your menu background, there's an even simpler alternative to bobbing which may be preferable. You could simple separate the interlaced fields into separate images and then resize to a 1280×720. This is similar to bobbing except that it doesn't require as much detail to be interpolated, and therefore may produce better results for some sources. It will also result in a menu background with a lower resolution (interlaced content must be 1920×1080 or 1440×1080), but that shouldn't be a problem as long as you design your menu buttons accordingly. This also has the advantage of giving you control over the upscaling algorithm, which will be determined by the resizing filter you select.
Separating Fields & Resizing
You can find instructions for deinterlacing and bobbing in Lesson 2 (Click here to open in new window) but separating fields and resizing will require some manual editing via the Script tab. The resizing part, of course, can be done with MeGUI's standard options. We'll look at that first for review.
Enable Resize On The I/O Tab
Make sure the Resize box is checked and enter a resolution of 1280×720. If your original script produced 1440×1080 output you will also need to uncheck Clever (TM) anamorphic encoding. Also make sure Suggest resolution (mod16) is unchecked.
Select Resize Filter
Select the desired resize filter from the dropdown list on the Filters tab.
Add SeparateFields Filter To Script
Finally, on the Script tab, you will need to add a line above the resize filter which simply says, "SeparateFields()" and you're done. If you use the Preview button now you should get a frame which has half the picture (one interlaced field) from the original, but a resolution of 1280x720.
Resizing 1440×1080 to 1920×1080
Although 1440×1080 is a perfectly valid resolution for Blu-ray video, you may prefer to resize it to 1920×1080 for menu stills. If you choose not to do this your Blu-ray player will stretch it for you automatically on playback. But since you are only going to be encoding a single frame, there's no real disadvantage to resizing before encoding because the size difference in the final video stream should be negligible. This is particularly advantageous if you are going to output a PNG file to use as a background for designing your menu layout because it will show you an accurate representation of what it will look like on the screen.
Once again this will require some manual editing of your script because MeGUI's standard resizing controls don't allow you to resize to a higher resolution. Instead you can set it to resize to a lower resolution and edit MeGUI's automated entry manually.
First make sure to uncheck Anamorphic encoding and then activate the Resize feature. Make sure to set the resolution to something less than 1440&amult;1080 or else it won't be added to the script. As with the previous operation you can also select the Resize filter on the Filters tab.
Manually Edit Resize Filter
Now you can go to the Script tab and simply change the resolution for the resize filter. The number before the comma is the horizontal resolution. Change it to 1920. The second number is the vertical resolution. Set it to 1080.
Reduce Script To A Single Frame
Your script should now have any required changes made so it is time to find the frame you want to use for your menu background. Use the Preview AVS Script button to update (or open) the Preview window.
Use the slider at the bottom of the preview window to navigate through the video until you find the frame you want to use for your menu background. Make a note of the Current Position number at the top. You will need it in a moment to complete your script.
Return to the Script tab of the main AVS Script Creator window and add one last line at the end of your script. This line will add the 'Trim' filter using the format shown below.
The first number in parentheses will be the frame number you identified with the preview. The second number will always be -1, which tells AviSynth that only one frame is being included in the resulting clip.
Set Framerate To 24fps
Although many different framerates are Blu-ray compliant, depending of course on the resolution used, it's usually best if you stick with a single framerate for all still menus, regardless of whether it matches the original source or not. This will significantly simplify later steps, such as generating code for interactive graphics (button) streams. Once again you can do this by adding a simple
It's simplest to add this line to the end of your script. Otherwise it's possible some other filter could change the framerate later.
Save Your Script
Now you can save your script in the standard way discussed in Lesson 2. Keep in mind you will probably want to make sure you give it a name which indicates it is for a menu, rather than the original video. To customize the name you should do the following prior to saving.
On the I/O tab, just above the Preview and Save buttons, is a field which shows the name (and path) which will be used when the AVS file is saved. Click the browse button to the right of this field to change either the path or name.
Set the name in the File name field of the Save As dialog. Your AviSynth script will be saved with this name. This will avoid overwriting the AVS file for encoding the full video title and also help you identify it later if you need to re-open it for any reason.
Encoding A Single Frame h.264 File
Your single frame video clip can be encoded using the exact same steps outlined in Lesson 4. One significant difference, however, is that you don't really have to worry about bitrate restrictions because the output file will be so small. Instead you may prefer to switch to quality-based (CRF) encoding. The simplest way to do this is by creating new still menu encoding profiles based on the same standard profiles described in Lesson 4.
Still menu profile settings
Unlike normal video, where encoder settings may vary wildly from one source to another, it's generally safe to use the same settings for almost every still menu. The simplest way to start is copying the settings from an existing 1080p24 profile. If you don't have such a profile to copy, simply follow the instructions in Lesson 4 (Click here to open in new window) for creating one. Then make the following changes on the Main tab.
1. Set Encoding mode to Const. Quality
- Normally video for a Blu-ray disc is encoded using a bitrate-based strategy for optimal bitrate distribution between frames. Since your still menu has only one frame, it's almost impossible for size to be a problem. Instead you can use a quality-based (CRF) strategy to set the quality instead. The general rule of thumb for high definition video is using a CRF somewhere between 20 and 22 for near perfect quality. However I prefer to set it as high (lower numbers = higher quality) as 16 just to be safe.
2. Preset Placebo
- Presets are a tradeoff between encoding speed and quality. The general rule of thumb is that you should use the highest preset you can stand to wait for. For a single image this should always be Placebo. If this preset is too slow for a single frame, you should probably rethink whether your computer is suitable for Blu-ray video encoding.
Exporting Your Menu Background In PNG Format
Sometimes you need to have your menu background in actual image format. You might have a program which generates the background video for you automatically or maybe you want to edit the background in a graphics editing program. If you continue to the next lesson which covers the process of creating menu buttons you will find some ideas about when this may be useful. Conveniently AviSynth has another filter you can use to produce such a file and you can use it via MeGUI.
Step 1 - Open Your Still Menu AviSynth Script
In order to generate this image file, you will need to create an AviSynth script for a still menu (single image) using the instructions above. Assuming you need to encode your still as a video file in addition to exporting it as a still image, you can simply use the file you created above as your video source. When you browse for your file, make sure you have it set to see all files.
Step 2 - Convert To RGB24 Colorspace
While the color information in most video is in a format generically known as YUV, still images use a simpler type of color encoding called RGB. Before AviSynth can generate a still image file, it will need your video to be converted to RGB. It's also possible, although not likely, that your video is already in RGB format. If so this will not do any harm as it will simply be ignored by AviSynth.
Add this line to the end of your script. If your video uses some form of YUV color encoding, as most do, it will be converted to RGB for compatibility with various still image formats. If it is already in RGB format it will do nothing.
Step 3 - Use ImageWriter To Output An Image File
Next you need to add the ImageWriter filter to give AviSynth instructions for creating the image file. Make sure this is the last line in your AviSynth script.
1. Image File Name
- The text in between these quotes will be used to name your image file. The frame number will also be appended to the end. For example, if you use "Top Menu" the image file will be named Top Menu00000.
2. Image Format
- ImageWriter can export images in several different formats, including uncompressed bitmap (bmp), PNG compressed bitmap (png), JPEG (jpg). The text in parentheses determines what format of file will be output. You can find more details about ImageWriter's output options on the AviSynth website (Click here to open in new window).
Step 4 - Save And Preview
ImageWriter does its magic when AviSynth renders a file. Normally that means playing your script in a media player, but in this case you can accomplish the same thing by simply saving your script with the AVS Script Creator. Assuming you haven't changed the default option, your script will automatically be loaded for encoding in the main MeGUI window. When that happens the image file will also be created in the same folder as the AVS file.
Loading A PNG (or other image) File In AviSynth
AviSynth includes a built-in filter for opening normal graphics files such as PNG, BMP, or JPEG images. MeGUI, on the other hand, is not designed to make use of it. Instead you will need to create an AVS file outside MeGUI. This file will be used in place of a script created by the AVS Script Creator.
Locate Your Still Image File
Before you can create your AviSynth script to load your image file you will need to locate it in Windows Explorer. Depending on the type of file you are using for your background it may have a different file extension such as .bmp or .jpg (or .jpeg) or you may not see an extension at all.
Open Image File Properties
Next right-click on the filename and select Properties from the context menu. Almost all the way at the top of the General tab you will see the filename. Copy the entire name.
Create AviSynth script
As in the Leson 1 example, your script will be a simple text file containing a single line with instructions telling AviSynth what filter to use, and in this case also the number of the last frame.
1. ImageSource Filter
- This tells AviSynth to use the ImageSource filter. Make sure the opening parentheses you use here have a corresponding closing parentheses.
2. Image Filename
- The first argument (after the opening parentheses) is the filename surrounded by quotes. Make sure not to forget the quotes or else you will get an error when AviSynth tries to open it.
3. End Frame
- This last argument tells AviSynth that the last frame is number 0. Keep in mind that frame numbering starts with 0 so this means the first frame is also the last. Notice that there is a comma following the first argument (the filename in quotes) and the second. This is how AviSynth knows how to separate them so don't forget it.
Save Your Script
Save the script in the same folder as the video file, making sure to change the extension Notepad automatically suggests to .avs, and you are finished. Now you can open MeGUI, open this AVS file in the main window, and use the same instructions as before for encoding.
Continue To Lesson 10
While the background is essential, a menu isn't a menu without buttons. Designing the graphics to use for menu buttons can be both simple and easy with just a little planning. In the next lesson you will learn how to use the free image editing tool GIMP to create button images and use them in the process of designing menus. When you are done you will also know how to customize PNG menu backgrounds exported using the process you just learned and export still image files suitable for re-importing to encode still menu backgrounds.