[ Previous | Next | Contents | Glossary | Home | Search ]
Ultimedia Services Version 2 for AIX: Programmer's Guide and Reference

H.263 Encoder

The UMSH263Encoder compresses video frames to the H.263 video format.

To learn more about the UMSH263Encoder, see:

For introductory information, see Programming with Video Codec Objects.

File Format

The output format conforms to the H.263 Standard.

Algorithm Overview

The UMSH263Encoder object implements the International Telecommunication Union (ITU) Recommendation for Low Bitrate Video Coding, referenced as H.263, which is part of the H.324 Recommendation. The UMS object implements all required portions of the Recommendation, but only some of the optional modes. In addition, the UMSH263Encoder object allows the compressed frame to be packetized, for use with Real-time Transport Protocol (RTP).

The UMSH263Encoder object supports video image compression for the following image sizes: SubQCIF (128x96 pixels), QCIF (176x144), and CIF (352x288). The object supports frame rates from 30 frames-per-second down to 1 frame-per-second, both with and without rate control. Intra frames may be inserted at any time, but for maximum compression it is recommended that Intra frames be inserted at a rate of once every 30 frames. Inserting Intra frames more often than once every 10 frames can cause the rate control target to be exceeded.

Rate Control Overview

The H263 Encoder uses a combination of within frame quality adjustments, using the quantization factor, and frame skipping, to track the target bit rate. In general, the encoder is slightly biased toward frame quality, at the expense of frame rate. A very low bit rate could result in frame rates as low as 1 fps. The encoder attempts to track the target frame rate while keeping the bit rate at or below the target bit rate. If the bit rate begins to exceed the target, frames are skipped. This rate control design results in a frame rate that varies with image content.

The frame rate control is implemented with the frame_incr variable, which is passed into the encoder with each frame to be compressed. The encoder changes the frame_incr value to adjust the encoded frame rate. The application might also change the frame_incr variable when frames must be skipped because the encoder cannot keep up with the input frame rate.

The frame_incr value is based on an assumed source frame rate of 30 fps. Source frames are input frames to be compressed by the encoder. The frame_incr variable is initially set to one by the application, and passed into the encoder. After the frame is compressed, frame_incr is set by the encoder to the source frame offset, from the frame just compressed. The offset represents the next source frame to be compressed. For example, frame_incr is set to one, a call is made to compress_frame and the encoder, after compressing the first frame, estimates a target frame of 10 fps will fit in the target bit rate. The encoder then sets frame_incr to 3 and returns the compressed frame to the application. The application then skips the next two frames and supplies the fourth frame to the encoder, leaving frame_incr set to 3. The application should either leave frame_incr unchanged or increase the value.

The frame_incr variable is the link between the application and the encoder that specifies the relative frame position. When set by the application, it specifies the current frame's relative offset from the previously encoded frame in units of source frames. When set by the encoder, frame_incr specifies the offset to the next source frame to be encoded. The offset is always relative to the previously encoded frame.

If the user wants to achieve very high frame quality, at the expense of frame rate, then the maximum quantization level can be set to a low value. This results in more bits being allocated to each frame (higher quality), and, depending on the bit rate setting and image content, a lower frame rate.

The rate control algorithm is designed to operate best with a relatively high ratio of Inter to Intra frames. If Intra frames are inserted more often than about 1 every 15 frames, then the bit rate might be exceeded. This is because the encoder has been given two objectives that may conflict: 1) a low bit-rate target and 2) higher-quality frames (Intra frames typically use 3-10 times the number of bits as Inter frames).

RTP Packets

The UMSH263Encoder object can break the compressed frame into smaller pieces, suitable for sending that data using Real-time Transport Protocol (RTP) packets. RTP is a networking protocol defined the Internet Engineering Task Force. There is a payload format specification defined for the H.263 video data that allows that compressed data to be sent using the Real-time Transport Protocol. This feature can be enabled by setting the packet size, in bytes, and then calling the get_packet_info method after the frame is compressed. Each call to the get_packet_info method returns the RTP header information, along with packet boundary information. This allows each packet's data to be extracted from the compressed frame and sent individually.

Encoding H.263 Video

To encode H.263 video, follow these steps:

  1. Set up the source for the video.
  2. Create the UMSH263Encoder object.
  3. Change any necessary default settings for image_size, input image format, quantization factor, or maximum motion displacement using the corresponding set methods.
  4. Call the encoder's get_max_buffer_size method to determine the required buffer size for the compressed frame.
  5. Allocate memory for the input and output buffers. Initialize the SOM sequence data structures associated with the input and output buffers.
  6. Capture the image frame and write the frame to the image buffer.
  7. Call compress_frame, setting the frame_type variable to either an Intra frame (I-frame) or Inter frame (P-frame) and setting the frame_incr variable to the correct frame offset. For the first frame in a sequence, the frame_type must be Intra and the frame_incr must be set to 1.

Default Settings

The UMSH263Encoder object default settings are:

FrameRate is set to 10 fps
RateControl is ON
ImageFormatIn is set to YUVPlanar
ImageSize is set to QCIF
MotionDisplacement is set to 7
MaxQuant is set to 31
PacketSize is set to 0 (OFF)

Tips for Using the H.263 Encoder

The following tips provide important information for using the H.263 encoder:

For introductory information, see Programming with Video Codec Objects.

[ Previous | Next | Contents | Glossary | Home | Search ]