AfterDawn Blu-ray Encoding Tutorial Lesson 1
Prepare Source Video
With all the video tools available today, encoding H.264 video is relatively simple even if you known next to nothing about the format. However, encoding to meet the strict requirements imposed by Blu-ray standards requires a little more thought. If you are using a hobbyist Blu-ray authoring tool like multiAVCHD, this isn't something you need to worry about. If, on the other hand, you are authoring Blu-ray discs with a prosumer tool like DVD-Logic EasyBD, Adobe Encore or Sony DVD Architect, or if you just want to ensure universal Blu-ray player compatibility, you need to be much more careful about what settings and options you use.
Fortunately all the software you need for this is readily available for free.1 The encoder we will be using for this is x264, the most popular H.264 encoder in the world for its combination of price (free) and features. Among those features are settings to ensure Blu-ray compliance. Even if you can afford tens of thousands of dollars for video encoding software, x264 will produce results comparable or superior to the most expensive H.264 encoders for most footage.
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.
While it is not possible to provide instructions for opening every possible type of video file, we will cover most common types, and even a few that aren't so common. If you need instructions for a particular video file, whether it is included here or not, simply post a request to the official discussion thread (open in new window) for this guide in our forums. We will try to help out, and may also add the instructions here.
Step 1 - Install and Configure Software
The bare minimum software required for this lesson is MeGUI and AviSynth. Depending on your source files, additional software may be required for decoding your video. In addition you will need MediaInfo for analyzing your source files to determine what additional preparation may be necessary before opening them with AviSynth. Most files will need to be indexed, which can be accomplished using tools provided in MeGUI. In rare cases you may also need to download a plugin to extend AviSynth's capabilities further.
MeGUI and AviSynth
In most cases MeGUI and AviSynth are all you actually need for this process. One or both of them will be used throughout this tutorial so you might as well install them first.
MeGUI does not have to be installed. Simply extract the contents of the Zip file into a dedicated folder and it's ready to go. If you are using Windows Vista or higher, it's generally recommended that you install software to folders other than Program Files or Program Files (x86).2
For demonstration purposes we will be using a folder called Programs for 64-bit software and Programs (x86) for 32-bit programs. At various points along the way you may need to know where software like AviSynth is installed on your own computer. When in doubt, start by looking in the Program Files or Program Files (x86) folders on your C: drive. If you are still stuck feel free to post a question on our forums and someone should be able to help you out.
Once you have extracted MeGUI's files to the folder of your choice, run MeGUI.exe (depending on your Windows settings you may not see .exe in the name).
Immediately MeGUI will check to see if AviSynth is installed. If not, you will be presented with the option to install it. Make sure to click the Yes button unless you plan to install it on your own. Without AviSynth you will not be able to do any encoding using MeGUI.
Once MeGUI has determined that AviSynth is installed, it will immediately begin downloading other programs which it uses internally as well as updating itself. After all the other updates have download you will see a message about the Nero AAC encoder and be presented you with instructions for installing it manually. This is not required for video encoding, or any Blu-ray related task, but it can be annoying. You can either get used to dismissing the message, and occasionally other error messages about a missing component, or follow its instructions to get rid of it.
Rather than answering Yes when prompted to restart MeGUI, you can click the No button and simply close it for now.
Haali Media Splitter
Haali Media Splitter is technically optional, however it is highly recommended if any of your source files are in a Matroska or MP4 container (file). This also applies to sources which originate from any type of Transport Stream files, including the BDAV (M2TS) files used on Blu-ray, AVCHD, and on some DVRs. If, for whatever reason, you prefer not to install this program, it generally won't cause any problems.
|Haali Media Splitter|
The configuration options for Haali Media Splitter can only be accessed during installation. If you decide to change them later you will have to uninstall and reinstall it. Fortunately this is a quick and painless process. Generally speaking, the default configuration is fine. There's no real advantage to enabling either AVI or MPEG-PS support since Windows handles these just fine.
However, if you use a media player like Media Player Classic - Home Cinema, you should probably uncheck the option to associate .mka and .mkv files with Windows Media Player. In any case it will not affect x264 encoding.
You will be using MediaInfo to collect information about your source files. It provides a lot of information which can come in handy later on, but for the purposes of this tutorial all we are concerned with is identifying the video encoding and container for each source file. Generally speaking, if your files come from the same device or process you shouldn't need to repeat this process every time. For example, your digital camera should give you files encoded the same way and stored in the same container every time. However, any time you run into problems opening a new source it's a good idea to return to this step.
MediaInfo comes in both 32-bit and 64-bit versions. If you have a 64-bit version of Windows, either should work equally well. However, if you are running 32-bit Windows you will have to use the 32-bit version of MediaInfo.
Run the installer once it finishes downloading. After MediaInfo is installed, run it once to set the default Output Format to Tree. This will maximize the information it can provide us about our source files.
Analyze Video File
Now we are ready to take a look at our source video files to determine whether what, if any, processing is necessary prior to encoding to H.264. But first it's important to know what you are looking for.
For the most part there are only two pieces of information you need to know at this point - the container format and video encoding standard. When your video is encoded, it must first be extracted from the container and then decoded into a series of individual pictures.
Locate your file in Windows Explorer and right-click on it. Select MediaInfo from the context menu to analyze it. The information from MediaInfo will, in nearly every case, tell you everything you need to know about both the container and video encoding if you know how to read it. If you were to learn every possibility that could easily be so time consuming as to not be worth the trouble. Rather than trying to include that level of detail here, I will instead focus on the most common combinations used in digital camcorder and DTV applications, as well as some more unusual formats which will be used for other Blu-ray tutorials in the future.
1. Container details
- This section of the window provides information about the entire file, primarily the container format being used. In some cases this information, by itself, is enough to determine the steps required to open your video in AviSynth.
2. Video Encoding
- The Video section, particularly the information in the top few fields, tells you what decoder will be required to read the frames extracted from your container..
If the format listed in the Video section is MPEG Video, check for another Format line in the theGeneral section listing MPEG-PS, MPEG-TS, BDAV, or MPEG Video. If any of those is listed, you will be using DGIndex to prepare your source in MeGUI. If the General section lists some other format besides those listed above for your MPEG-2 video, DGIndex most likely will not open it because it will not know how to parse the container and therefore will not be able to tell where the video frames begin and end.
HDV in QuickTime
If your MPEG-2 video originated from a HDV camcorder or was produced via professional editing, the General section may list a Format profile of QuickTime. In that case, you can open it in MeGUI without any additional pre-processing, but will need to use the process listed below for QuickTime files in place of DGIndex.
When regular digital cameras (as opposed to digital camcorders) began offering rudimentary video capabilities, Apple's QuickTime container and MJPEG (Motion JPEG) video encoding became a defacto standard. As DSLRs, which typically have quite good video capabilities, have largely replaced traditional camcorders for video, QuickTime has generally been phased out in favor of AVCHD. However some lower end digital cameras, particularly those from Nikon, have upgraded the video encoding to H.264, but retained the QuickTime container. Regardless of the video encoding used, QuickTime files are easy to spot if you pay attention to the General section. The filename should end with .MOV in addition to the Format, Format Profile, and Codec ID shown on the right.
Since QuickTime is an Apple container originally designed for the Mac, while AviSynth is built around Microsoft's Video for Windows (VfW) framework, they are not natively compatible. However, thanks to a plugin called FFMS2 which uses the platform independent FFmpeg libraries to open video files, this is easily dealt with. In fact, it works essentially the same way as using DGIndex with MPEG-2 files, except that the format listed in the Video section can be almost anything. One notable exception is when ICOD or Intermediate Codec is listed as the video format. ICOD is a proprietary format used by some Apple software for editing. There is currently no Windows software, even outside AviSynth, which is capable of decoding ICOD video. If you somehow end up with ICOD video, you will not be able to encode it in MeGUI (or any other Windows program). Fortunately there are also no cameras which produce ICOD video, so unless your video file comes from a professional video editor who uses a Mac this should never come up.
H.264 (MPEG-4 AVC) Video In A Transport Stream Container
One final common situation to look at is MPEG-4 AVC video (aka H.264) in a MPEG-2 Transport Stream (MPEG-2 TS) container. Transport streams are the standard MPEG container for DTV broadcasts, used in both ATSC and DVB. Additionally, BDMV, the format used for commercial Blu-ray discs, and the camcorder format known as AVCHD use a container called BDAV based on MPEG-2 TS. As with QuickTime files, AVC in a TS file can be opened using FFMS2. However, as a rule this is considered somewhat risky due to the incomplete state of both TS demuxing and AVC decoding in FFmpeg, you should instead preprocess these sources with MeGUI's HD streams extractor. This will repackage your video stream in a Matroska (MKV) file, which works better with FFmpeg. This is still an imperfect solution because FFmpeg is known to occasionally have problems decoding interlaced AVC video. However, it is still a superior option to leaving your video in a TS container.
There are commercial solutions capable of decoding these streams. Donald Graft sells an indexer and AviSynth decoder for decoding H.264 using the CUDA interface on nVidia GPUs which is integrated into MeGUI. He also developed a similar solution which uses the (payware) DiAVC decoder. However that tool is neither release quality nor integrated into MeGUI. Alternatively, either DiAVC or the (also payware) CoreAVC decoder could be used via DirectShow, but to avoid devoting too much time on a limited use case, we won't cover those solutions here. Just be aware that it's a situation you may need to deal with if you work with a lot of interlaced H.264 video. Fortunately most modern video is progressive and MPEG-4 AVC allows video streams which are nominally interlaced, but contain progressive frames.
Raw YUV Video
The last type of video to look at in this tutorial is not one that's produced by devices like consumer cameras or DVRs. It is included only for its relevance in a future tutorial series on Blu-ray authoring, where it will be used for encoding videos from the open source Blender project. The format is YUV4MPEG, which is used for RAW video streams which are uncompressed except for being converted to the YUV colorspace used in MPEG encoding.
RawSource AviSynth plugin
Although AviSynth is also based around the same MPEG colorspace as YUV4MPEG video, it is designed to rely on other software to determine where each frame begins and ends. Traditionally this was handled by Windows, or more recently add-ons like FFMS2. However, that plugin cannot open YUV4MPEG files and a Windows codec is not requred. Instead you will need to download the RawSource plugin. Unlike the other AviSynth plugins used in this tutorial, RawSource is not provided by MeGUI. Fortunately it's just barely more work to add a plugin manually.
|RawSource AviSynth plugin|
As with most AviSynth plugins, RawSource comes in a Zip file. Although there are several files included in the download, all you need to install is the DLL file which you can simply copy to your AviSynth plugins folder. The location of this folder will depend on where you installed AviSynth. Fortunately AviSynth's Start Menu folder includes a link to open that folder in case you're not sure where it is. In the AviSynth 2.5 folder you should have an entry which says Plugin Directory. Click that shortcut and copy rawsource.dll to the folder which opens up. By putting the DLL file in this folder you ensure it will load automatically so you don't have to remember (or know how to) load it manually.
Create AviSynth script
Now that you have the plugin installed, the only thing left is to create a text file using Notepad with just a single line in it to load your video file. Save the script in the same folder as the video file, making sure to change the extention Notepad automatically suggests to .avs, and you are finished. From this point on you can use the AVS file to substitute for the actual video file. In other words, when you open your video file in MeGUI's AVS Script Creator, instead of loading YourVideoFileName.y4m you will load the AVS script instead.
Extract Streams From TS Files
The HD Streams Extractor in MeGUI is primarily oriented toward preparing Blu-ray sources for encoding, but it works nearly as well with any sort of MPEG TS (transport stream) file. It is particularly useful for AVCHD sources thanks to their use of BDMV (Blu-ray Movie) style playlists. It also has the advantage of being able to recognize and extract pretty much any type of stream, whether video, audio, or subpicture, you may have.
There are essentially two ways to use the HD Streams Extractor. If your source is a Blu-ray (BDMV) or AVCHD disc you have previously authored, or perhaps which has been authored for you by your camera or camcorder, you can let the streams extractor tool examine your files and select titles based on run length. If you have a lot of short videos you need to encode, as is often the case with home video footage, this probably won't be a particularly useful way to go.
Fortunately there's another option, and this method has the added advantage that it works with any TS or M2TS file regardless of whether it is authored as a Blu-ray or AVCHD disc. You can simply select the video files directly and avoid MeGUI's selection criteria altogether.
Rather than wasting your time with an incredibly lengthy explanation for what is actually a very intuitive and straight forward process, I have decided to simply provide two videos which we produced last year. If you only have transport streams rather than authored BDMV or AVCHD files the first video will not apply at all. Even if you are extracting from authored discs, if you intend to keep everything it will only be useful for identifying the specific playlist and M2TS file(s) for each clip.
The second video exclusively covers operations within the HD Streams Extractor, although once again there will likely be information you are not concerned with as it explains how to deal with streams which are only found on studio authored Blu-ray discs. However, it should explain everything you need to know to use the tool effectively
Once you have extracted the video streams you wish to encode, the next step is to index your newly created Matroska (MKV) files using MeGUI's File Indexer.
Creating An AviSynth Script
MeGUI's AVS Script Creator is a (mostly automated) tool for creating AviSynth Scripts for encoding. In the next lesson we will look at some of the more advanced operations you may want to perform in your script, but for right now we will concentrate on simply opening a video file. If you have more than one file, obviously you will need to perform this step for each one.
The button to the right of the Video Input field will open a dialog where you can browse for and select your video file. If you created an AVS file in a previous step make sure to select that instead of the actual video file. In most cases you will automatically be prompted with options to either index your file or use DirectShow to open it. As the description below explains, DirectShow should be avoided whenever possible.
1. Open video with DirectShow
- The simplest method for opening many types of video files in AviSynth is using a DirectShow decoder you may already have installed in Windows. However, while DirectShow is perfectly fine for playing video files, it has some quirks which make it generally inferior for use in this process. In particular, if you plan to do any sort of editing which requires random access, even something as simple as cutting out a series of frames, it is notoriously unreliable. However, if you find that you can't open your video any other way you may want to try it as a last resort.
2. Index your file
- The preferred method for opening most video files in AviSynth is via an index created either with FFIndex or DGIndex. This option will open the File Indexer so you can perform that step. After the index is created it will automatically be used to create an AviSynth script (AVS file) which will then open in the script creator. If your video file is in a transport stream (TS or M2TS file) and the video encoding format is anything other than MPEG-2 make sure you use the HD Streams Extractor to move it to a Matroska (MKV) file first.
1. Open file
- The file you selected in the AVS Script Creator will automatically be loaded here. If you have multiple files to index you may prefer to load each of them (one at a time of course) before exiting the File Indexer. This button can be used to select a file to index manually.
2. Demuxing Audio
- By default any audio streams in your file will be demuxed when the index is created. Make sure at least one audio stream is set to be demuxed so you can use it in your Blu-ray project.
3. Close File Indexer
- If this button is checked the File Indexer will automatically close after a job is queued. If you want to create more than one indexing job without closing the window, make sure to uncheck this button.
4. Queue Indexing Job
- Use this button to creat the indexing job and add it to MeGUI's job queue.
Preview Your AviSynth Script & Continue To Lesson 2
Once your video file has been selected and any indexing jobs completed, a preview window will appear, displaying a frame from the middle of your video. You are now ready to continue to Lesson 2 where you will learn how to create an AviSynth script to encode your video with x264.
Last updated: 21 August 2012