I.263 video frames

There are three kinds of video frames. To distinguish between them we need to know their size.
FRAMESIZE == 0 - this is a drop frame. Display the previously decoded frame.
FRAMESIZE == 8 - if in PB-frames mode such frame is needed to display the P-Pictures. The input data should be treated as follows:

unsigned char temporalReference;

unsigned char unused[7];

My code below shows how to decode such frames properly. If NOT in PB-frames mode this frame shall be treated as DROP frame.

FRAMESIZE > 8 - shall be treated as usual I.263 frame.

Picture Layer

Data for each picture consists of a picture header followed by data for Group of Blocks, eventually followed by an end-of-sequence code and stuffing bits.

An 8-bit number which can have 256 possible values. It is formed by incrementing its value in the previously transmitted picture header by one plus the number of non-transmitted pictures (at 29.97 Hz) since the previously transmitted one. The arithmetic is performed with only the eight LSBs. In the optional PB-frames mode, TR only addresses P-pictures; for the temporal reference for B-pictures refer to the field "Temporal Reference for B-pictures (TRB)" below.

Type Information (PTYPE)

Marker (1 bit)

This bit should always be set to "1" in order to avoid startcode emulation.

The following bits are present if the CSFMT extension (see above) is present and extended PAR is indicated therein. When present, EPAR consists of:

Pixel Aspect ratio width (8 bits)

The natural binary representation of the PAR width; "0" is forbidden.

Pixel Aspect ratio height (8 bits)

The natural binary representation of the PAR height; "0" is forbidden.

Quantizer Information (PQUANT) (5 bits)

A fixed length codeword of 5 bits which indicates the quantizer QUANT to be used for the picture until updated by any subsequent GQUANT or DQUANT. The codewords are the natural binary representations of the values of QUANT which, being half the step sizes, range from 1 to 31.

Continuous Presence Multipoint (CPM) (1 bit)

A codeword of 1 bit that signals the use of the optional Continuous Presence Multipoint mode (CPM); “0” is off, “1” is on. This mode is not supported in I.263 and should be off.

Temporal Reference for B-pictures (TRB) (3 bits)

TRB is present if the PB-frame mode is on (see above) and indicates the number of non-transmitted pictures (at 29.97 Hz) since the last P- or I-picture and before the B-picture. The codeword is the natural binary representation of the number of non-transmitted pictures plus one. The maximum number of non-transmitted pictures is 6.

Quantization information for B-pictures (DBQUANT) (2 bits)

DBQUANT is present if the PB-frame mode is on (see above). In the decoding process a quantization parameter QUANT is obtained for each macroblock. With PB-frames QUANT is used for the P-block, while for the B-block a different quantization parameter BQUANT is used. QUANT ranges from 1 to 31.

Extra Insertion Information (PEI) (1 bit)

A bit which when set to "1" signals the presence of the following optional data field. This data field has no meaning in I.263 and should be ignored.

Group of Blocks Layer

Data for each Group of Blocks (GOB) consists of a GOB header followed by data for macroblocks. Each GOB contains one row of macroblocks. For the first GOB in each picture (with number 0), no GOB header shall be transmitted. For all other GOBs, the GOB header may be empty, depending on the encoder strategy.

GOB Header

This header may be present or not. For the first GOB in each picture (with number 0), no GOB header shall be transmitted. The decoder must search the 256 input bits for the GOB start code. The GOB Header has the following format:

Group of Block Start Code (GBSC) (17 bits)

A word of 17 bits. Its value is 0000 0000 0000 0000 1. GOB start codes may be byte aligned.

Group Number (GN) (5 bits)

A fixed-length codeword of 5 bits. The bits are the binary representation of the number of the Group of Blocks. For the GOB with number 0, the GOB header including GSTUF, GBSC, GN, GFID and GQUANT is empty; group number 0 is used in the PSC.

GOB Frame ID (GFID) (2 bits)

A fixed-length codeword of 2 bits. GFID shall have the same value in every GOB header of a given picture. Moreover, if PTYPE as indicated in a picture header is the same as for the previous transmitted picture, GFID shall have the same value as in that previous picture. However, if PTYPE in a certain picture header differs from the PTYPE in the previous transmitted picture header, the value for GFID in that picture shall differ from the value in the previous picture.

Quantizer Information (GQUANT) (5 bits)

A fixed-length codeword of 5 bits which indicates the quantizer QUANT to be used for the remaining part of the picture until updated by any subsequent GQUANT or DQUANT. The codewords are the natural binary representations of the values of QUANT which, being half the step sizes, range from 1 to 31.

Macroblock Layer

Data for each macroblock consists of a macroblock header followed by data for blocks.

Macroblock Header

The Macroblock Header has the following format:

Coded macroblock indication (COD) (1 bit)

A bit which when set to "0" signals that the macroblock is coded. If set to "1", no further information is transmitted for this macroblock; in that case the decoder shall treat the macroblock as an INTER macroblock with motion vector for the whole block equal to zero and with no coefficient data. COD is only present in pictures for which PTYPE indicates ‘INTER’, for each macroblock in these pictures.

Macroblock type & Coded block pattern for chrominance (MCBPC)

A variable length codeword giving information about the macroblock type and the coded block pattern for chrominance. For a description of codewords for this field please refer the section 5.3.2 of the H.263 standard.

Macroblock mode for B-blocks (MODB) (Variable length)

MODB is present for MB-type 0-4 if the PB frames mode is on and is a variable length codeword indicating whether CBPB is present (indicates that B-coefficients are transmitted for this macroblock) and/or MVDB is present. The the codewords for MODB are defined as follows (“x” means that the item is present in the macroblock):

CBPB is only present in PB-frames mode if indicated by MODB. CBPBN = 1 if any coefficient is present for B-block N, else 0, for each bit CBPBN in the coded block pattern.

Coded block pattern for luminance (CBPY) (Variable length)

Variable length codeword giving a pattern number signifying those Y blocks in the macroblock for which at least one non-INTRADC transform coefficient is transmitted. Please refer to section 5.3.5 of the H.263 standard for a description of this field.

Quantizer Information (DQUANT) (2 bits)

A two bit code to define change in QUANT. Please refer to section 5.3.6 of the H.263 standard for a description of this field.

Motion vector data (MVD) (Variable length)

MVD is included for all INTER macroblocks (in PB-frames mode also for INTRA macroblocks) and consists of a variable length codeword for the horizontal component followed by a variable length codeword for the vertical component. Please refer to section 5.3.7 of the H.263 standard for a description of codewords for this field.

Motion vector data (MVD 2-4) (Variable length)

The three codewords MVD 2-4 are included if indicated by PTYPE and by MCBPC, and consist each of a variable-length codeword for the horizontal component followed by a variable-length codeword for the vertical component of each vector. MVD 2-4 are only present when in Advanced Prediction mode (refer to Annex F). For a description of codewords for this field see the section 5.3.8 of the H.263 standard.

Motion vector data for B-macroblock (MVDB) (Variable length)

MVDB is only present in PB-frames mode if indicated by MODB and consists of a variable-length codeword for the horizontal component followed by a variable-length codeword for the vertical component of each vector. Please refer to section 5.3.9 of the H.263 standard for a description of codewords for this field.

Block Layer

Please refer to section 5.4 of the H.263 standard for a description.

Decoding Process

Please refer to section 6 of the H.263 standard for a description.

Annex D - Unrestricted motion Vector mode

Please refer to Annex D of the H.263 standard for a description.

Annex F - Advanced Prediction mode

Please refer to Annex F of the H.263 standard for a description.

Annex G - PB-frames mode

Please refer to Annex G of the H.263 standard for a description.

Annex J - Deblocking Filter mode

J.1 Introduction

This annex describes the use of a block edge filter within the coding loop. The main purpose of the block edge filter is to reduce blocking artifacts. The filtering is performed on 8x8 block edges and assumes that 8x8 DCT is used and that motion vectors may have either 8x8 or 16x16 resolution. The use of this mode is indicated in the picture header. In the PB-frame case the present option applies for B-frames as well as for the P- and I-frames.

J.2 Definition of the edge filter

The filter operations are performed along 8x8 block edges at the encoder as well as on the decoder side. Filtering is performed on the complete reconstructed image data but before the clipping described in paragraph 6.3.2 and before storing the data in the frame store for future prediction. No filtering is performed on frame and slice edges. Luminance as well as chrominance data is filtered.

If A,B,C and D are four pixel values on a line - horizontal or vertical - of the reconstructed picture, and A and B belong to one block called block1 whereas C and D belong to a neighboring block called block 2 which is to the right or below of block 1. Figure 1 shows examples for the position of these pixels.

IMAGE!!!! Can everyone show me how to place an image here?

One of the following conditions must be fulfilled in order to turn the filter on for a particular edge:

Figure 2 shows how the value of d is modified into d1 in order to make sure that only edges are filtered that presumably represent an artifact and not a natural edge. As a result of this modification, only those edge pixels that have a luminance step smaller than QP are filtered.

The definition of d1 may seem a little complicated, but it guarantees, that small mismatches will remain small and will not build up during the sequence. This could happen with a condition that simply switches the filter on or off, because a mismatch of only _1 could then cause the filter to be switched on or off unexpectedly resulting in large differences between coder and decoder.

Due to rounding effects, the order of edges where filtering is performed must be specified. Filtering along horizontal edges shall be performed before filtering along vertical edges.

Annex M - Improved PB-frames mode

M.1 - Introduction

This annex describes the improved PB-frames mode of I.263. The use of this mode is indicated in the extended PTYPE. Most parts of this option are similar to the PB-frame option defined in Annex G. The main difference is that the B-macroblock may have a separate vector for forward prediction. MVDB that in Annex G was used to enhance the downscaled forward and backward vectors for bidirectional prediction is used as vector data for forward prediction in this annex. All the differences are identified in this annex. When nothing is indicated, it means that the same procedure as described in Annex G is used.

M.2 - B-frame prediction modes

There are two different ways of coding a B-macroblock. The different coding modes are signaled by the parameter MODB. The B-macroblock coding modes are:

Bidirectional prediction

Prediction is done from the P-frames before and after the B-frame. This prediction is equivalent to the prediction defined in Annex G when MVD =0. Notice that in this mode, motion vector data (MVD) of the PB-macroblock must be included even if the P-macroblock is INTRA coded.

Forward prediction

The vector data contained in MVDB is used as a vector for forward prediction from the previous frame. Notice that no prediction is used for coding the forward vector.

M.3 - Calculation of vectors for bidirectional prediction of a B-macroblock

In case bidirectional prediction is used, the scaled forward and backward vectors are calculated as described in Annex G when MVD = 0.

M.4 - MODB table

A new table for MODB is needed. It indicates the possible coding modes for a B-block.