AVI to a DVD Compliant MPEG-2 File Using QuEnc

Original Page URL: http://www.digital-digest.com/articles/AVI_to_DVD_Compliant_MPEG2_QuEnc_Guide_page1.html
Author/Publisher:
Date Added: Jul 25, 2008
Date Updated: Jul 25, 2008


This guide serves a very basic purpose. It will tell you how to convert your AVI file into a DVD compliant MPEG-2 video stream (and AC3 audio file) for use in more complex DVD authoring tools that do not have their own encoder (for example, DVD-lab Pro). We will encode the MPEG-2 using QuENC, and the audio component to AC3 using Aften.

Please note that this guide is not a AVI to DVD guide, because the DVD authoring part is not covered. It merely gets your DVD compliant MPEG-2/AC3 streams for which you can use with various DVD authoring tools. This guide was written mainly for use with DVD-lab Pro (guide still to be written).

This guide is aimed at more advanced users, which would typically be the type of users that would need to do something like this. You should have good knowledge of bitrates (and be able to do bitrate calculations), command line tools and things of this nature (but even these areas will be covered, albeit only briefly). Beginners can use one of our complete AVI/Video to DVD guides, as these authoring tools which are aimed at home users will usually include their own MPEG-2 encoder.

By the end of this guide, you should have a separate video and audio stream ready to use in DVD authoring tools like DVD-lab Pro without further re-encoding. There are also some additional instructions for performing 3:2 pulldown for 24 fps material and multiplexing instructions (incase your DVD authoring tool does not support demuxed stream input) using FFmpeg.

Software you'll need (all freeware):

Step 1: Installation

Download and install Avisynth - just follow the installer, nothing too complicated. QuEnc's installer is also quite simple, just choose a directory where you want it installed and all the files are extracted to there. MediaInfo can be installed by downloading and following the installer.

If you are planning on using QuEnc to encode the audio, then you can skip all the way to step 5. Otherwise, you will need to install an AVI demuxing tool and some audio tools. Download and install AVI-Mux GUI by extracting everything in the ZIP file to a folder on your hard-drive. BeSweet can be installed simply by downloading the ZIP package and extracting the files to a folder on your hard-drive. BeLight can be similarly installed, and when you run BeLight for the first time, it will ask you to locate the BeSweet executable and do that by going to where you extracted the BeSweet package. AftenGUI's install again only requires you to extract the contents of the ZIP file. Installation of all the required components and tools is now complete.

Step 2: Source File Inspection

In this step, we examine the source AVI file and basically determine whether it is NTSC or PAL. Start MediaInfo and load in your video file, and the details about the video will be shown, including the framerate (fps).

MediaInfo: Video Details


As a rule, files that are 23.976, 24, 29.97 or 30 frame per second are NTSC. While PAL video is at 25 FPS. Multiples of these frame rates (eg. 15 FPS and 60 FPS => NTSC) are sometime used as well. For the example file I'm using for this guide, the framerate is 23.976, which makes the file NTSC. Also take note of the AVI's other attributes, such as resolution (which will be important later on) and audio type (encoding, channels, frequency ... although other tools we use later on will tell us this as well).

Step 3: Demux the AVI file's audio stream

In this step, we will demux the AVI file to extract the audio stream from it. We can technically skip all these audio instructions and use QuEnc to encode our audio as well (skip straight to Step 5), but this method gives us better audio encoding quality and support. We will use AVI-Mux GUI to demux the audio component of the AVI file. Start AVI-Mux and drag your source AVI into the "open file ..." section. Click on the now listed file and click on the "generate data source from files" button to scan the AVI file. The streams in the AVI file should now show up down below. Some information about the audio file will be displayed, including the type of audio file (MP3, AC3 ...), the number of channels (2ch, 6ch ...) and the frequency (44 KHz, 48 KHz) - take notice of these settings because they will become important later on. For now, left click on the audio stream to highlight it, and then right click to select the "Extract Binary" option to extract the audio stream from the AVI file into a separate file.

AVI-Mux GUI: Extract Binary


AVI-Mux GUI will process the file and extract the audio and when it has finished, you can close AVI-Mux GUI. If the extracted audio stream was an AC3 file, and it was 48 KHz, then this file is most likely DVD compliant already and it will be ready to use in your DVD project (the file probably came originally from a DVD, even). In this case, you can skip the rest of the steps in regards to the audio, and skip to the video encoding instructions. However, if the audio stream isn't an AC3 file or if you're not sure if the AC3 file is DVD compliant, then you can always re-encode the file to be sure, and so let's continue with these instructions.

Step 4: Convert the audio file to a DVD compliant AC3 file

Now that we've got our MP3 (or AC3, or WAV or even Ogg) file, we will now convert it to a DVD compliant AC3 file. What we will actually do first to to get our audio file into WAV format (either stereo, or multi-channel), and then use Aften/AftenGUI to encode that into an DVD compliant AC3. Why the need to go to a WAV file first? Mainly because BeLight's Aften support is a bit buggy, but it works great for getting audio files to WAV. But why not just use any old MP3/AC3 to WAV tool? Well, BeLight supports generating multi-channel WAV files which AftenGUI supports.

Start BeLight and if this is the first time you've used it, you will be asked to locate the BeSweet executable file. Once that's done, from the "File" menu, add in your audio file. Click on the "WAV/PCM" tab. If your audio file is 5.1 channels, then select the "16 Bits 5.1 Wave" option. Otherwise, select "16 Bits Stereo Wave". To the left of that, make sure "Output Sampling Rate" is checked and "48000" Hz is selected. Press "Start Processing" to begin the conversion (there are more options to configure in BeLight, but I'll leave that to you to do more research on - the options there are enough for a guide of its own). After a while, you should have a WAV file in the same folder as your input audio file. We will now convert this WAV file to AC3 using AftenGUI.

BeLight: WAV Creation


Start AftenGUI. Press the "Add" button to load in your newly created WAV file. Just like BeLight, there are all sorts of options that you can configure, such as invididual channel levels, but for most cases you just need to ensure the CBR Mode is selected and that the bitrate you want is selected. For stereo files, a bitrate of 192 or 256 kbps is enough. For 5.1 channel files, a bitrate of 384 or 448 is required. By default, the output location will be the same place as the input, but you can change this if needed. When you're done with the settings, press "Encode" to encode the AC3 file - when Aften finishes encoding, you'll get a dialog box telling you so.

Aften: AC3 encoding


That's it for the audio part. We begin working on the video part next, which surprisingly, is actually easier.



Step 5: AviSynth Script Creation

We will now use QuEnc to transcode our AVI files to a DVD compliant MPEG-2 stream. However, QuEnc only accepts AviSynth scripts inputs, not AVI files directly. This is not a problem at all though, because AviSynth scripts are basically just text files that one can create with any text editor. What is more difficult, it working out the aspect ratio and resolution settings, which due to DVD's way of storing and displaying video, can be somewhat confusing. Doom9 has a guide which explains the process quite well, but what I have done here, and it's a first for a guide here on Digital Digest, is to provide a function that will generate the AviSynth script for you with all the resizing parameters filled in based on your source file's input size.

To use this function, simply enter in the local path to your video file (eg. C:\temp\Borat\Borat-fixed.avi), the source resolution in width/height, whether it's NTSC or PAL (as determined all the way back in Step 1) and whether you want an anamorphic encoding or not.

The last point need to be expanded upon further before we proceed. Since most AVI inputs are using square pixels, there's only a little bit to be gained from anamorphic encoding unless your input video exceeds the DVD resolution (720x480 for NTSC and 720x576 for PAL) or if your input video uses high bitrates and you don't want to lose valuable available bitrates by using too much of it on the black borders. But it makes very little difference to encoding time and authoring (if your DVD authoring tool supports anamorphic video, which it should), so it might be worth the effort. If your input video is already anamorphic, then do not select the "Encode Anamorphic?" option.

Once you generate your AviSynth script, simply copy it into your favourite text editor and save the file with the .avs extension. This script is now ready to use in QuEnc in the next step. Note that if you decided to use QuEnc to encode your audio as well, then change the part of the script where it says "audio=false" to "audio=true".

Step 6: QuEnc MPEG-2 Encoding

Start QuEnc. Load in your AVS script that was generated in the last step. Make sure the "Codec" setting is set to "MPEG-2". For your bitrate settings, you will need to calculate the bitrate to use so the size of the file fits into your DVD project. This involves the length of your video, the bitate already used by the video, the amount of space you will use for menus and other videos on the disc. But if you already known the amount of space your video file will occupy (and the video length, of course), the bitrate of your audio file(s), then the calculation is (if you are using QuEnc to encode the audio too, then don't minux the "Total Audio Bitrate" as the bitrate entered here will include the audio's bitrate):

((Amount of available Space in MB minus menus and other videos) * 1024 * 8 / (Number of Seconds of Video)) - (Total Audio Bitrate)

For example: ((3800 MB) * 1024 * 8 / (120 min * 60 sec)) - (2 x 448) = 3427 kbps

There are many bitrate calculators available to use if you're having trouble. When you have arrived at the bitrate you want to use, enter it into the box. I like to select all the other options (use VBR, High Quality, Use Trellis Quant and 2 Pass Encoding). These are all settings that will improve quality when enabled, but will slow down encoding quite a bit (so for fast, no nonsense encoding where quality isn't paramount, deselect all these settings).

QuEnc: Settings


Now, click on the "Advanced" button. Let's go through the settings that might need changing in this section.

QuEnc: Advanced Settings


The "Extreme & Slow" setting can be selected if you want maximum quality at the cost of encoding speed. "GOP" and "Max B-Frame" settings should remain at 12 and 2. "Forced Closed GOP" should not be used unless you are encoding the multi-angle part of the DVD. "Scene Detection" places an I-Frame at scene changes, which might be useful for placing chapter stops at these places.

Select "16:9 Aspect Ratio" if you decided to use anamorphic encoding in Step 5 (or if your source video was already anamorphic). Otherwise, select 4:3 Aspect Ratio. We'll leave the GUI settings alone since it has nothing to do with encoding.

Over on the other side, change the DC Precision setting to "10".

Change the "Max Bitrate" to a value that is 9800 kbps minus your audio bitrate. For example, if you have one audio file at 384 kbps, then the max bitrate should be 9800 - 384 = 9416 kbps. If you have two audio tracks, two at 448 and another at 192, then the max bitrate would be 9800 - 448 - 448 - 192 = 8712 kbps. If you are using QuEnc to encode the audio as well, you can enable "Auto Max Bitrate" to let QuEnc determine the max bitrate automatically.

The other options here can be left alone. Skip to the bottom, and the "Mux Profile" setting can be changed. If you want a single MPG file that includes audio (if using QuEnc to encode the audio), then choose the "DVD" profile or "Separate Passes" if you want individual video/audio files (good for authoring tools like DVD-Lab Pro). If you've followed this guide and already encoded your audio, then you will only have the "No Audio" profile. If you did decide to encode the audio using QuEnc, then you can select the output audio format: AC3 @ 192/256 kbps for stereo and 384/448 kbps for 5.1ch is recommended.

Press "Apply" to apply the advanced settings and return to the main QuEnc screen.

Press "Encode" to start the video (and audio) encoding). When QuEnc finishes, you will have a DVD compliant MPEG-2 video stream (M2V), an AC3 file or a MPEG-2 file that includes both streams.

The next steps provide instructions for performing 3:2 pulldown on 23.976/24 FPS video which is needed for making NTSC DVDs, and also instructions on how to multiplex your separate M2V/AC3 files into a MPEG-2 (MPG) file for certain DVD authoring tools that only accept this type of input.



Appendix A: 3:2 Pulldown with DGPulldown

This step is required if your source file is a 23.976/24 FPS video and you intend to make a NTSC DVD which stores the video at 29.97 FPS. We will use a handy little tool called DGPulldown which does just this for us with the minimum of fuss. Some DVD authoring tools such as DVD-lab Pro will actually include this function within the program itself and will be activated whenever you load in a file requiring pulldown, so for people planning on using these types of tools, you can skip this step.

Download and install DGPulldown by extracting the contents of the ZIP file to a folder on your hard-drive. Start DGPulldown and under the "Source ES" section, load in your MPEG-2 file. Select an output location/filename and ensure the "23.976 -> 29.97" option is selected. Press "Convert" to start the conversion and that's all there is to it.

DGPulldown


Appendix B: MPEG-2 Multiplexing using FFmpeg

FFmpeg is a small command line tool that allows you to encode MPEG-2 files, as well as do basic multiplexing. Download the latest daily snapshot of ffmpeg compiled for Windows and extract the .7z package using WinRAR or the freeware 7-Zip tool to extract the contents to a folder on your computer. Start a Windows command prompt (Start -> Run -> cmd) and navigate to the folder containing ffmpeg.exe (for example: "cd c:\temp\FFmpeg-svn-14277"). Type in the following command to multiplex your video and audio files:

ffmpeg -i drive:\path\to\input.m2v -i drive:\path\to\input.ac3 -vcodec copy -acodec copy output.mpg

(change the input path and output path/filename as needed)



About Digital Digest | Help | Privacy | Submissions | Sitemap

© Copyright 1999-2011 Digital Digest. Duplication of links or content is strictly prohibited.