Copyright: © 2001 B.Beyeler. All Rights Reserved.


Contents
Table of Contents

• About bbMPEG

• The Main Window

• General Settings

• Input and Output File Settings

• Load and Save Settings

• Video Stream Settings

• Advanced Video Settings

• Audio Stream Settings

• Program Stream Settings

• How to multiplex existing files

• What is multiplexing?


About bbMPEG

bbMPEG version 1.24 beta. By Brent Beyeler, released as freeware.

bbMPEG is an MPEG audio/video encoder and multiplexor. It can be used as a plug-in for Adobe Premiere 5.x or with the programs AVI2MPG2 or AVI2MPG2_VFW (provided). It can generate MPEG-1 or MPEG-2 video streams, MPEG-1 layer 1 or 2 audio streams and MPEG-1 or MPEG-2 program streams.

bbMPEG requires either Win95, Win98 or WinNT. It may work with Win3.1 if Win32s is installed. It also requires either Adobe Premiere 5.x, the AVI2MPG2 program included with bbMPEG or another program designed for this DLL (the source includes an example program that demonstrates how to use the DLL). The last thing it requires is a Pentium processor.

MPEG video compression courtesy of the MPEG Software Simulation Group.

MPEG audio compression courtesy of the MPEG/Audio Software Simulation Group.

MPEG multiplexing courtesy of Christoph Moar's MPLEX software.

Please send questions or comments to:

beyeler@home.com

Visit bbMPEG's web page at:

http://members.home.net/beyeler/bbmpeg.html

Disclaimer and Agreement.

This software is supplied subject to the following conditions. By using the software, you agree to these conditions.

This software is provided 'as is', with no warranty of any kind, including but not limited to any implied warranty of merchantability or fitness for any particular purpose.

In no event shall the author be liable for any damages whatsoever arising out of use or inability to use this software, even if the author has been advised of the possibility of such damages.

If you cannot agree to the above conditions please remove the software from your computer immediately.


The Main Window

Messages

Any non fatal messages and the verbose output messages are displayed here.

Run in batch mode

Check to run in batch mode. When enabled, encoding/multiplexing is started without having to press the Start button and when finished, bbMPEG exits. Thisoption can be changed while encoding.

Save messages

Save all the messages to a text file.

Start button

Click to start encoding or multiplexing.

Suspend button

Click to suspend encoding or multiplexing. This is useful if you need your computer back for awhile. Suspending just displays a dialog box asking if you want to resume or cancel encoding.

Cancel/Ok button

Click the cancel button to abort encoding, this is only used before encoding has started. Click the Ok button to exit, this is only used after encoding has finished or has been aborted.

Settings button

Click to change the encoding and multiplexing settings.


General Settings

MMX Modes

Select an MMX mode to use (a * next to the mode means the mode was detected). You can force a particular mode by selecting one that was not detected but if the processor does not actually support the mode, bbMPEG will generate an Invalid Opcode exception when video encoding is started. Off disables all MMX modes, MMX enables MMX modes on all processors that support it (Intel, AMD, etc.), and SSE enables the use of SSE instructions on processors that support them (PIII and Athlon). These modes do not affect the MPEG output in any way, selecting Off will generate the exact same file as selecting one of the other modes. Currently, MMX code is used in the motion estimation and RGB to YUV conversion routines. SSE code is only used in some of the motion estimation routines.

Use Floating Point

This options enables floating point routines when checked, otherwise scaled integer routines are used. The floating point routines are slower but more accurate, whereas the scaled integer routines are faster but less accurate. Currently, the only routine this option affects is the RGB to YUV conversion. This option will affect the MPEG output, although it might be quite hard to tell the difference.

Verbose Display

Check to display additional information in the Message window while encoding or multiplexing.

Encode Video

Check to encode a video stream. If there is no video available this option will be disabled. Disable this to multiplex an existing video stream.

Encode Audio

Check to encode an audio stream. If there is no audio available this option will be disabled. Disable this to multiplex an existing audio stream.

Multiplex Video

Check to multiplex a video stream into the program stream. If this option is checked and the Encode Video option is checked the video that is encoded will be multiplexed into the program stream, or, if the Encode Video option is not checked, the video stream specified by the MPEG Video Stream temp file on the Input/Output File Settings page will be multiplexed into the program stream. Note that you can multiplex just a video stream into a program stream by checking this option and unchecking the Multiplex Audio option.

Multiplex Audio

Check to multiplex an audio stream into the program stream. If this option is checked and the Encode Audio option is checked the audio that is encodedwill be multiplexed into the program stream, or, if the Encode Audio optionis not checked, the audio stream specified by the MPEG Audio Stream temp fileon theInput/Output File Settings page will be multiplexed into the program stream. Note that you can multiplex just an audio stream into a program stream by checking this option and unchecking the Multiplex Video option.

Start Second

Enter a start time, in seconds, at which point the multiplexer will start writing data to the output MPEG file. Use this option with the End second option to have the multiplexor only output a certian time range of the video/audio to the output file. The actual starting frame is the next I frame after the start time. If both the starting and ending times are zero, the entire time range is output. Note that any seconds cut from the front of the movie are still multiplexed, they are just not written to the output file.

For example, if you have a movie that is 55 seconds long but you really only want the part of the movie that starts at the 10 second mark and ends at the 45 second mark, you would enter 10 in the Start second field and 45 in the End second field. Then only the middle 35 seconds of the movie would be output, the first 10 seconds and the last 10 seconds of the input video/audio would be left out.

End Second

Enter an end time, in seconds, at which point the multiplexor will stop writing data to the output MPEG file. This also stops the multiplexing operation, see the Start second description for usage information. The actual last frame is the last frame before the next I frame which is after the end time.

Max Size (MB)

Enter a maximum output file size in megabytes (1048576 bytes), this will split the output file into several files if the output is bigger than the maximum.

For example, if the total output file size is going yo be 1GB and this option is set to 640, the result will be two files one ~640MB and the other ~360MB. The files will be named using the output filename with 00, 01, 02 ... appended before the file extension (name00.mpg, name01.mpg name02.mpg ...).

Reset Clocks

Enable this option to restart the clocks (PTS/DTS/SCR timestamps) after starting a new file while using the start/stop time or max size options. This is normally enabled for all MPEG types except DVD.

Set Broken Link Flag In GOP

Enable this option to set a flag at the start of a new file, indicating the first few B frames cannot be decoded due to the splitting action. This is normally enabled for all MPEG types except DVD.

Write Sequence/Program End Codes

Enable this option to write sequence and program end codes at the end of a split file. This is normally enabled for all MPEG types except DVD.


Input/Output File Settings

MPEG Program Stream file

This is the filename of the output of the multiplex process.

MPEG Video Stream temp file

If video encoding is enabled, this is the filename of the output from the video encoder. If this option is checked the file is not deleted after multiplexing. The temp files are only deleted if multiplexing completes normally and this option is not checked.

If video encoding is disabled, this is the filename of the input video stream for multiplexing. It can be either an MPEG-1 or an MPEG-2 video stream.

MPEG Audio Stream 1 temp file

If audio encoding is enabled, this is the filename of the output from the audio encoder. If this option is checked the file is not deleted after multiplexing. The temp files are only deleted if multiplexing completes normally and this option is not checked.

If audio encoding is disabled, this is the filename of the input audio stream for multiplexing. It can be either an MPEG Layer 1 or 2 audio stream or an AC3 audio stream.

MPEG Audio Stream 2 file

This is the filename of an input audio stream for multiplexing as the secondary audio track. It can be either an MPEG Layer 1 or 2 audio stream or an AC3 audio stream.

Intra Quant Matrix file

This option specifies a file containing a custom intra quantization matrix to be used instead of the default matrix specified in ISO/IEC 13818-2. This file has to contain 64 integer values (range 1...255) separated by white space (blank, tab, or newline), one corresponding to each of the 64 DCT coefficients. They are ordered line by line, i.e. v-u frequency matrix order (not by the zig-zag pattern used for transmission). The three included intra matrix filesare: intra.mat - the default matrix as a starting point for customization,intra-ni.mat - for natural images and intra-cg.mat - for computer graphics.

Large values correspond to coarse quantization and consequently more noise at that particular spatial frequency.

For the intra quantization matrix, the first value in the file (DC value) is ignored. Use the Intra DC Precision setting on the Advanced Video Settings page to define the quantization of the DC value.

Non Intra Quant Matrix file

This option follows the same rules as described for the above Intra Quant Matrix option, but specifies the file for the NON-INTRA coded (predicted / interpolated) blocks. In this case the first coefficient of the matrix is NOT ignored.

The default matrix uses a constant value of 16 for all 64 coefficients. (a flat matrix is thought to statistically minimize mean square error). The two included inter matrix files are: inter.mat - an alternate matrix,used in the MPEG-2 test model and inter-cg.mat - for computer graphics.

Statistics Output file

This option specifies an output file for video encoding status and statistical information. The contents of this file are defined below.

Description of the macroblock type map:

The status information routine prints a two-character code for each macroblock in the picture currently being coded:

First character:

S: skipped
I: intra coded
0: forward prediction without motion compensation
F: forward frame/16x8 prediction (in frame/field pictures resp.)
f: forward field prediction
p: dual prime prediction
B: backward frame/16x8 prediction
b: backward field prediction
D: frame/16x8 interpolation
d: field interpolation

Second character:

space: coded, no quantization change
Q: coded, quantization change
N: not coded (only predicted)

Description of the mquant map:

The mquant map displays the dynamically changing quantization setting as determined by the rate control algorithm. Larger values correspond to coarser quantization. Not displayed values indicate same quantization as in the previous macroblock.


Load and Save Settings

Settings filename

Name of settings file that has been loaded.

Description

Text description of the current settings.

Save as Default

Click to save the current settings as the default startup settings.

Reset Defaults

Click to restore the 'factory' settings as the default startup settings.

Load Settings

Click to load the settings from an INI file.

Save Settings

Click to save the current settings to an INI file.


Video Stream Settings

PAL defaults

Check this option so when one of the Video Types listed below is selected, it will default to PAL settings instead of NTSC.

Video Type

Specify which type of MPEG video to encode.

MPEG-1 is ISO/IEC 11172-2 video, use it for smaller video (320x240) and near universal playback.

VideoCD is a subset of MPEG-1, use it to make VideoCD compatible MPEG-1 files. The input video should be either 352x240 (NTSC) or 352x288 (PAL), and the input audio should be 44.1 kHz, 16 bit, stereo to be VideoCD compliant.

MPEG-2 is ISO/IEC 13818-2 video, use it for larger video.

SVCD is subset of MPEG-2, use it to make SuperVCD compatible MPEG-2 files. The input video should be either 480x480 (NTSC) or 480x576 (PAL), and the input audio should be 44.1 kHz, 16 bit to be SVCD compliant.

DVD is a subset of MPEG-2, use it to make DVD compatible MPEG-2 files. The input video should be either 720x480, 704x480, 352x480, 352x240 for NTSC or 720x576, 704x576, 352x576, 352x288 for PAL. The input audio should be 48kHz 16-bit audio.

Pulldown

This field is only enabled if the video frame rate is set to 23.976 or 24 fps. If 2:3 or 3:2 pulldown is selected, the video will have the repeat_first_field flag set as needed so 29.97 or 30 fps video is generated upon playback. 2:3 pulldown sets the repeat flag every odd frame (1, 3, 5, ...), while 3:2 sets the repeat flag every even frame (0, 2, 4, ...).

Profile ID (MPEG-2 only)

Specifies the subset of the MPEG-2 syntax required for decoding the sequence. Currently only the High, Main and Simple profiles are supported. Typical uses are:

High Profile - production equipment requiring 4:2:2
Main Profile - 95 % of TVs, VCRs, cable applications
Simple Profile - Low cost memory, e.g. no B pictures

Level ID (MPEG-2 only)

Specifies coded parameter constraints, such as bitrate, sample rate, and maximum allowed motion vector range. Typical uses are:

High Level - HDTV production rates: e.g. 1920 x 1080 x 30 Hz
High 1440 Level - HDTV consumer rates: e.g. 1440 x 960 x 30 Hz
Main Level - CCIR 601 rates: e.g. 720 x 480 x 30 Hz
Low Level - SIF video rate: e.g. 352 x 240 x 30 Hz

Chroma Format

Specifies the resolution of chrominance data as follows:

4:2:0 - half resolution in both dimensions (most common format)
4:2:2 - half resolution in horizontal direction (High Profile only)

Frame Rate

Defines the frame rate (for interlaced sequences: field rate is twice the frame rate). Generally, this should be set to the incoming video frame rate, if it is not the video will playback slower or faster than normal.

Aspect Ratio

Defines the display aspect ratio.

Frame Intervals

I Frames (N) defines the distance between I frames (and 'Group of Pictures' headers). Common values are 15 for 30 Hz video and 12 for 25 and 24 Hz video.

P Frames (M) defines the distance between consecutive I or P frames. Usually set to 3. N has to be a multiple of M. M = 1 means no B frames in the sequence.

Enable VBR

If checked the encoder generates a constant quality variable bitrate videostream. The quality (macroblock quantization) is held constant and isspecified with the quality setting.

If not checked, a constant bitrate (more or less) video stream is generated, the bitrate is specified in the CBR bitrate field and the encoder changes the quality in an attempt to regulate the bitrate.

Quality

This is the macroblock quantization parameter. It directly affects the quality and size of the encoded video and ranges from 1 (best quality, highest bitrate) to 31 (least quality, lowest bitrate).

Auto Set CBR

Automatically set the constant bitrate, vbv buffer size and video buffer size based on the input frame size and the selected frame rate.

Max or CBR Bitrate

If the Enable VBR setting is not checked, this value specifies the target video bitrate in units of bits/sec. This setting will directly affect the video quality and file size. Low bit rates yield smaller files with lower quality, while higher bit rates yield larger files but better quality video.

If this value is zero, there is no bitrate limiting and the encoder will place (after encoding) the actual maximum bitrate into the stream.

Avg Bitrate

If the Enable VBR setting is enabled, the encoder attempts to generate anaverage bitrate close to this value, enter zero for no average bitrate.

If the Enable VBR setting is disabled, this value is not used.

Min Bitrate

If the Enable VBR setting is enabled, the encoder will decrease the macroblock quantization value to raise the bitrate if neccesary to keep the generated bitrate above this minimum, enter zero for no minimum bitrate.

If the Enable VBR setting is disabled, this value is not used.

Timecode of first frame

This value is used to set the timecode encoded into the first 'Group of Pictures' header. The format is based on the SMPTE style:

hh:mm:ss:ff (hh=hour, mm=minute, ss=second, ff=frame (0..frame rate-1)


Advanced Video Settings

Color Primaries (MPEG-2 only)

Specifies the x, y chromaticity coordinates of the source primaries.

Transfer Characteristics (MPEG-2 only)

Specifies the opto-electronic transfer characteristic of the source picture.

Matrix Coefficients

Specifies the matrix coefficients used in deriving luminance and chrominance signals from the green, blue, and red primaries.

Video Format (MPEG-2 only)

Specifies the video format.

Intra DC Precision (MPEG-2 only)

Specifies the effective precision of the DC coefficient in MPEG-2 intra coded macroblocks. 10-bits usually achieves quality saturation.

Additional Settings

See Setting Description field when tree item is selected for description of setting.

Motion Vectors

The motion vector settings specify the maximum length of the motion vectors. If this length is set smaller than the actual movement of objects in the picture, motion compensation becomes ineffective and picture quality drops. If it is set too large, an excessive number of bits is allocated for motion vector transmission, indirectly reducing picture quality, too.

Automatically setting the motion vectors

To have the motion vectors automatically calculated, set the 'Auto set Vector Lengths' setting to 1, and then set the 'Horizontal and Vertical Pel Movement' settings to indicate by how many pixels a pixel will move from frame to frame.

Manually setting the motion vectors

All F Code values have to be in the range 1 to 9 which translate into maximum motion vector lengths as follows:

code	max search width/height
1	7
2	15
3	31
4	63
5	127
6	255
7	511
8	1023
9	2047

F Codes are specified individually for each picture type (P,Bn), direction (forward prediction, backward prediction) and component (horizontal, vertical). Bn is the n'th B frame surrounded by I or P frames

(e.g.: I B1 B2 B3 P B1 B2 B3 P ...).

P frame values have to be specified if N (N = # of frames in GOP) is greater than 1 (otherwise the sequences contains only I frames).

M - 1 (M = distance between I/P frames) sets of values have to specified for B frames. Each set defines values for forward prediction (i.e. from a past frame), and backward prediction (from a future frame).

Search widths and heights set the (half) width of the window used for motion estimation. The encoder currently employs exhaustive integer vector block matching. Execution time for this algorithm depends on the product of search width and search height and, too a large extent, determines the speed of the encoder. Therefore these values have to be chosen carefully.

Here is an example of how to set these values, assuming a maximum motion of 10 pels per frame in horizontal and 5 pels per frame in vertical direction and M=3 (I B1 B2 P):

Search Width and Height values:

forward	hor.	vert.	backward	hor.	vert.
I -> B1	10	5	B1 <- P	20	10
I -> B2	20	10	B2 <- P	10	5
I -> P	30	15

F Code values are then selected as the smallest ones resulting in a range larger than the search widths / heights:

P Frame:
Forward Horz F Code = 3
Forward Vert F Code = 2
Forward Search Width = 30
Forward Search Height = 15

B1 Frame:
Forward Horz F Code = 2
Forward Vert F Code = 1
Search Width = 10
Search Height = 5
Backward Horz F Code = 3
Backward Vert F Code = 2
Backward Search Width = 20
Backward Search Height = 10

B2 Frame:
Forward Horz F Code = 3
Forward Vert F Code = 2
Forward Search Width = 20
Forward Search Height = 10
Backward Horz F Code = 2
Backward Vert F Code = 1
Backward Search Width = 10
Backward Search Height = 5


Audio Stream Settings

Layer

Select MPEG audio layer 1 or 2.

Bit Rate

Specify an audio bitrate in units of Kbits/sec.

Set Private Bit

Check to set the private bit in the audio stream.

Copyrighted Material

Check to set the copyrighted material bit in the audio stream.

Original Material

Check to set the original material bit in the audio stream.

Error Protection

Check to generate CRC error protection in the audio stream. Usually needed for SuperVCD.

De-emphasis

Select a de-emphasis value for the audio stream.

Psychoacoustic Model

Select psychoacoustic model 1 or 2.

Mode

If the input audio is mono, no selections can be made. If the input audio is two channel, select Stereo, Joint Stereo or Dual Channel.


Program Stream Settings

Program stream types

MPEG-1

If checked, an MPEG-1 (ISO/IEC 11172-1) program stream is produced. It is made the default if the MPEG-1 video type is selected on the Video Settings page, and it is disabled if the video type selected is MPEG-2 or SVCD.

VCD

If checked, a VideoCD compatible program stream is produced. It is made the default if the VideoCD video type is selected on the Video Settings page, and it is disabled if the video type selected is not VideoCD.

MPEG-2

If checked, an MPEG-2 (ISO/IEC 13818-1) program stream is produced. It is made the default if the MPEG-2 video type is selected on the Video Settings page.

SVCD

If checked, a SVCD compatible program stream is produced. It is made the default if the SVCD video type is selected on the Video Settings page.

DVD

If checked, a DVD compatible program stream is produced. It is made the default if the DVD video type is selected on the Video Settings page.

VBR

Enable variable bitrate multiplexing. This generates program streams without any standalone padding packets and causes the SCR (System Clock Reference) to be evaluated after each video frame to see if it should be incremented more than usual (this effectively changes the mux rate).

Pad VCD audio

VCD audio sectors are specified to be 2304 bytes long. If this option is checked, the sectors are zero padded to 2324 bytes. Some VideoCD authoring software expects the padding to be present and some do not, if an authoring program does not accept files made with this option enabled, disable it and and it should be accepted.

Write program end code

Enable to write a program end code at the end of the program stream. Leave unchecked so program streams can be concatenated, although to do the job right, quite a few more things should be done to concatenate program streams.

Add SVCD scan offsets

Enable to embed SVCD scan offsets in User Data blocks after I frames. This option requires the Align Sequence Headers option to also be enabled.

Align sequence headers

If enabled, all video packets containing a sequence header are aligned to the start of the packet.

Use Private Stream 2

VOB files use Private Stream 2 packets to hold the system headers and PCI/DSI information. bbMPEG does not produce PCI/DSI info so the data is set to zeros. Some players do not like this, so this option can be cleared to generate Padding packets instead of Private Stream 2 packets.

Use computed bitrate

Use a calculated video bitrate (instead of the embedded video bitrate) as the basis for the mux rate. Not available when multiplexing VCD or SVCD streams and generally should not be enabled if VBR multiplexing is enabled.

Timestamps

Specify whether PTS and DTS timestamps are put on all frames, only I and P frames or just I frames.

Pulldown

Use this option to specify that the video stream is composed of 23.976 or 24 fps NTSC progressive video. Set this option to Auto to have the multiplexer automatically detect if pulldown is being used. This value is automatically set if the Pulldown option on the Video Settings page is set to 2:3 or 3:2 pulldown.

Forced mux rate

Specify a mux rate value in units of 50 bytes/sec. Set to zero to have the multiplexor compute a value.

Pack size

Specify the size (in bytes) of the packs in the program stream. SuperVCD and VideoCD are fixed at 2324 bytes while DVD is fixed at 2048 bytes.

PES packets per pack

Specify the number of PES packets per pack. This determines the size of the PES packets. Usually leave this set to one.

Video buffer size

Specify the video buffer size. This should be at least as big as the vbv buffer. Note that due to the units difference, the number here should be twice as big as the vbv buffer size number.

Audio 1 buffer size

Specify the audio buffer size for the primary audio track.

Audio 2 buffer size

Specify the audio buffer size for the secondary audio track.

Startup pack delay

Specifies the starting value of the SCR clock in milliseconds.

Video stream startup delay

Specify the number of milliseconds to delay the video stream.

Audio 1 stream startup delay

Specify the number of milliseconds to delay the primary audio stream.

Audio 2 stream startup delay

Specify the number of milliseconds to delay the secondary audio stream.


How to multiplex existing files

To mutliplex existing MPEG video and MPEG audio (or AC3) streams, just uncheck the Encode Video and Encode Audio options. Then on the Input and Output files page, use the OpenVS button to select the existing video file (usually a .m2v or .m1v file), and the OpenAS 1 button to select an existing audio file (usually a .mp2, .mpa or .ac3 file) for the primary audio track, and the OpenAS 2 button to select an existing audio file for the secondary audio track if desired. Use the OpenPS button to select an output file, click OK and then click the start button.

Note that you can uncheck the Encode Video and Encode Audio independently of  each other, so you could encode video, multiplex the encoded video and an existing audio file. Or, you could encode audio, multiplex the encoded audio and an existing video file.


What is multiplexing?

Multiplexing is a way to combine two or more elementary streams (audio or video stream) into a single stream (a program stream). To combine a video stream with an audio stream, the two streams are multiplexed (or interleaved) together in the form of packets (chunks of video or audio data) with timing information to indicate when the packets are to be displayed or played. When you convert an AVI to an MPEG file with bbMPEG, the encoded video stream is put into a temporary file (usually a .m2v or .m1v file) and the encoded audio stream is also put into a temporary file (usually a .mp2 file). If multiplexing is not performed, the result of the conversion process will be the two temporary file, one video file and one audio file. To combine these two files into a single file, they need to be multiplexed together into a single file (usually a .m2p or .mpg file).

Note that some players will play the audio (.mp2) or video (.m2v or .m1v) files by themselves, but some players require a program stream (the output of the multiplexor). You can actually put just a video or just an audio stream into a program stream, by multiplexing only one stream instead of two.