I263

From MultimediaWiki
Jump to navigation Jump to search

General description

This codec is based on early drafts of the H.263 standard specification. It supports the following modes: Unrestricted Motion Vector mode, Advanced Prediction mode, PB frames mode, Improved PB frames mode (old version!) and Deblocking Filter mode.

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.

Picture Header

The Picture Header of I.263 has the following format:

  • Picture Start Code (PSC) (22 bits)

PSC is a 22 bit word. Its value is 0000 0000 0000 0000 1 00000. All picture start codes shall be byte aligned.

  • Temporal Reference (TR) (8 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.

  • H.263 ID (1 bit)

This bit should always be set to "0" for distinction from H.261.

  • Split screen indicator (1 bit)

This indicator is not used in I.263. Just skip this bit.

  • Document camera indicator (1 bit)

This indicator is not used in I.263. Just skip this bit.

  • Freeze Picture Release (1 bit)

Unused. Just skip this bit.

  • Source Format (3 bits)

Indicates the source format of the picture. Values "000" and "110" are forbidden. "111" indicates the extended PTYPE (see below).

  • Picture type (1 bit)

Picture Coding Type: “0” INTRA (I-picture), “1” INTER (P-picture).

  • Unrestricted Motion Vector mode indicator (1 bit)

Unrestricted Motion Vector mode: “0” off, “1” on.

  • Syntax-based Arithmetic Coding mode (SAC) indicator (1 bit)

Syntax-based Arithmetic Coding mode is not supported in I.263. Just skip this bit.

  • Advanced Prediction mode indicator (1 bit)

Advanced Prediction mode: “0” off, “1” on.

  • PB-frames mode indicator (1 bit)

PB-frames mode: “0” normal I- or P-picture, “1” PB-frame. If the Picture Type bit (see above) is set to “0”, this bit shall be set to “0” as well.


Extended PTYPE (EPTYPE):

These fields are present only if the Source Format field (see above) indicates the extended PTYPE.

  • Source Format (3 bits)

Values "000" and "111" are forbidden. "110" indicates that the custom source format (CSFMT) extension is present (see below).

  • Unknown flags (2 bits)

These bits should always be set to "0". They have no meaning. Just skip them.

  • Deblocking Filter mode indicator (1 bit)

Deblocking Filter mode: “0” off, “1” on.

  • Unknown flag (1 bit)

This bit should always be set to "0". It has no meaning. Just skip it.

  • Improved PB-frames mode indicator (1 bit)

Improved PB-frames mode: “0” off, “1” on. For a description of this mode see the Annex M below.

  • Unknown flags (5 bits)

These bits should always be set to "0". They have no meaning. Just skip them.

  • Unknown Marker (5 bits)

The value of these bits should always be set to "00001".


Custom source format (CSFMT) extension

This extension is present only if indicated by the Source Format field of the Extended PTYPE (EPTYPE) (see above).

  • Pixel Aspect Ratio code (4 bits)

Aspect ratios: "0001" - 1:1, "0010" - 12:11 (CIF 4:3), "0011" - 10:11 (525-type 4:3), "1111" - extended PAR (see below; probably never used because of an internal bug in the I.263 driver). Other values are forbidden.

  • Picture width (9 bits)

The width of the encoded picture = (value of this field + 1) * 4

  • Marker (1 bit)

Equal to "1" to prevent start code emulation.

  • Picture height (9 bits)

The height of the encoded picture = (value of this field + 1) * 4

Extended Pixel Aspect Ratio (EPAR)

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):

number of bits code CPBP MVDB
1 0
2 10 x
2 11 x x

MODB is coded differently for Improved PB-frames, as specified in Annex M (see below).

  • Coded Block Pattern for B-blocks (CBPB) (6 bits)

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:

- block1 belongs to a coded macro block (COD==0 || MB-type == INTRA) or

- block2 belongs to a coded macro block (COD==0 || MB-type == INTRA)

B shall be replaced by B1 and C shall be replaced by C1 where:

B1 = B + d1

C1 = C - d1

d1 = SIGN(d) * ( MAX( 0, |d|-MAX( 0, 2*|d| - QP))

d = (3A-8B+8C-3D) / 16

QP = quantization parameter of block 2.

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.

number of bits code CPBP MVDB Coding mode
1 0 Bidirectional prediction
2 10 x Forward prediction
3 110 x x Forward prediction
3 111 x Bidirectional prediction

Source Code

Open source implementation (GPL) by Maxim Poliakovski: http://multimedia.cx/I263Src.zip