Video Encoding
DVDs use MPEG-2 encoding of video data. The mjpegtools suite include a collection of handy utilities designed to be used together. First there is a number of input tools that let us take source materials in different form and turn it into a stream of YUV data that can be piped into mpeg2enc, the MPEG-2 video encoder.
As a sample we may want to encode a single JPEG image to be used in a slideshow or as menu system background:
$> jpeg2yuv -n 50 -I p -f 25 -j image.jpg \
| mpeg2enc -f 8 -o video.m2v
The jpeg2yuv decompress a JPEG file and output a YUV stream. The tool can also work on sequences of JPEG files for animations. The lav2yuv do the same except it take AVI and Quicktime MJPEG as input, it also work with DV video stored in “Type 2 AVI” files.
The mpeg2enc take those YUV streams and encode them as MPEG-2 video. It’s a good idea to use the m2v suffix for files only containing MPEG-2 video streams.
Note that the files created contain streams, this mean that you can simply concatenate the contents of these files to make a larger one that play each clip after another. This may come handy if you’re doing a slideshow.
It’s important to use as high quality source material as possible, otherwise MPEG encoding artifacts may become highly pronounced.
Audio Encoding
The DVD specification allows for the use of AC-3, MPEG or PCM encoded audio streams. Most DVDs contain AC-3 encoded Dolby Digital soundtracks while MPEG-2 and PCM soundtracks are more rare on commercial releases.
Two additional optional formats can be provided, DTS and SDDS, that require appropriate decoders and are not supported by all players. Discs with those audio formats are required to also include at least a AC-3 (Dolby Digital) audio track.
Discs containing NTSC video must use PCM or AC-3 on at least one track, while PAL/SECAM video discs must use PCM, MPEG audio or AC-3 on at least one track. Additional tracks may be in any format.
A DVD can contain up to eight different audio tracks.
PCM
PCM is just your plain uncompressed audiosamples, the same format as CDs, and can contain 1 to 8 channels. The samplerate can either be 48 or 96 kHz with 16, 20 or 24 bits/sample. The maximum bit rate is 6.144 Mbps, which limits sample rates and bit sizes when there are 5 or more channels.
MPEG
MPEG audio is multi-channel digital audio using lossy compression of audiosources with sample rate of 48 kHz at 16 or 20 bits can contain 1 to 5.1 channels. Both MPEG-1 and MPEG-2 formats are supported. The variable bit rate is 32 to 912 kbps, with 284 kbps being the normal average rate.
The mjpeg tools contain a mp2enc that encodes WAV files into MPEG-2 format. However it’s not a very high quality encoder and only there for completeness of the suite. A much better tool would be the tooLAME encoder.
Here is a simple way to create a burst of silence that might be usefull when doing menus with no sound:
$> dd if=/dev/zero bs=4 count=number-of-samples \
| toolame -b 128 -s 48 /dev/stdin output.m2a
At 48kHz, PAL has 1920 audio samples per frame and NTSC 1601.6 samples.
Note that we use the m2a suffix for files containing only the MPEG-2 audio stream.
However the regular tooLAME encoder can’t handle multichannel audio, only mono or stereo, for that we need a special version from the same author called mctooLAME that can encode multi-channel MPEG-2 streams.
First you have to create an AIFF file containing your six channels. We can use the pcm2aiff utility to do that.
$> pcm2aiff input_file -c5 -r1
It take six input PCM files with the appropriate suffixes and output an AIFF file that can be feed into mctooLAME.
$> mctoolame -m s -n d -L your_6ch_file.aiff output.m2a
The options set stereo channel mode, dual surround mode, and turn on LFE.
AC-3
Dolby Digital us multi-channel digital audio that use lossy AC-3 encoding of audiosources with sample rates of 48 kHz at up to 24 bits and can contain 1 to 5.1 discreet audio channels. The bitrate is 64 to 448 kbps, with 384 or 448 being the normal rate for 5.1 channels and 192 kbps for stereo.
The ffmpeg tool contain a AC-3 encoder. However, I don’t know if it’s able to encode 5.1 soundtracks.
There’s apparently also a software-suite for creation of AC3 soundtracks in development called “AC3 Project” (see the “Tools” section).
Multiplexing Audio and Video
Multiplexing is the art of “twinning” together different data streams, will it be video, audio or other data, into one data stream.
The mjpegtools contain a multiplexer called mplex. The following create one MPEG stream from one MPEG-2 video stream and audio stream.
$> mplex -f 8 -o output.mpg video.m2v audio.m2
If the audio track is longer than the video clip then the final clip is extended to cover the rest of the audio. So in most cases you want all the tracks to be multiplexed match up in length.
Just as you can multiplex together several alternative audio tracks it’s also possible to do the same with video streams. Each video “track” are then referred to as an “angle”.
Note that we use the mpg suffix for multiplexed MPEG files containing different data streams.
Remember that the DVD specification limit each MPEG file to not exceed 1GB in size.
4 comments
Considering you’ve copied some of this from the Linux Journal article by Ian Pointer, you might consider attributing it properly.
Agreed, especially in view of the link to this page you’ve added in a comment to the LJ article!
Here’s is the link to the above-mentioned Linux Journal article:
http://www.linuxjournal.com/article/6953
That link is already included in the post above if you read the fourth paragraph a little bit closer…
Post a comment