MPEG-2 features

The following features are supported for MPEG-2:

Info

The "info" feature for MPEG-2 exports some information about the picture type and the macroblock types. This feature is purely informative, no changes here will be applied back when transplicating.

TODO: string:
Picture type. This can either be:

  • "I" for I-frames
  • "P" for P-frames
  • "B" for B-frames

TODO: boolean:

  • true for interlaced frame (note: I have never seen a file that has this set to true)
  • false for non-interlaced frame

TODO: string: (optional when interlaced is true)

  • top for top field.
  • bottom for bottom field;

TODO:

  • null if the macroblock was skipped
  • a string, where each letter in the string corresponds to a certain macroblock feature:
    • 'I' for an intra macroblock (I, P, and B frames)
    • 'q' for macroblocks that change the quantization scale (I, P, and B frames)
    • 'c' for macroblocks that change the DCT coefficients (P and B frames)
    • 'f' for forward motion vectors (P and B frames)
    • 'b' for backward motion vectors (B frames)

Quantized DCT coefficients

The "q_dct" feature for MPEG-2 exports the quantized coefficients of the DCT transform that are encoded in the bitstream.

TODO: number:

  • The DC coefficient for this block.

TODO: number:

  • An AC coefficient for this block (from 1 to 63), in the zig-zag scan order.

TODO: (informative) number:

  • The count of vertical blocks per macroblock for each component.

TODO: (informative) number:

  • The count of horizontal blocks per macroblock for each component.

TODO: (informative) number:

  • The index for the Quantization Table for each plane, as defined in the "dqt" feature.

Quantized DCT coefficients (with DC delta)

The "q_dct_delta" feature for MPEG-2 is similar to the "q_dct" feature, but the DC coefficient is expressed as a delta value from the previous DC coefficient.

Note that the previous DC coefficient is not necessarily the one from the block immediately to the left since there might be multiple blocks inside a macroblock, which will be encoded in a raster scan order (left to right, top to bottom) per-macroblock.

TODO: number:

  • The DC coefficient delta for this block.

TODO: number:

  • An AC coefficient for this block (from 1 to 63), in the zig-zag scan order.

TODO: (informative) number:

  • The count of vertical blocks per macroblock for each component.

TODO: (informative) number:

  • The count of horizontal blocks per macroblock for each component.

TODO: (informative) number:

  • The index for the Quantization Table for each plane, as defined in the "dqt" feature.

Quantized DCT coefficients (DC only)

The "q_dc" feature for MPEG-2 is similar to the "q_dct" feature, but only the DC coefficients are available.

TODO: number:

  • The DC coefficient for this block.

TODO: (informative) number:

  • The count of vertical blocks per macroblock for each component.

TODO: (informative) number:

  • The count of horizontal blocks per macroblock for each component.

TODO: (informative) number:

  • The index for the Quantization Table for each plane, as defined in the "dqt" feature.

Quantized DCT coefficients (DC delta only)

The "q_dc_delta" feature for MPEG-2 is similar to the "q_dc" feature, but the DC coefficient is expressed as a delta value from the previous DC coefficient.

TODO: number:

  • The DC coefficient delta for this block.

TODO: (informative) number:

  • The count of vertical blocks per macroblock for each component.

TODO: (informative) number:

  • The count of horizontal blocks per macroblock for each component.

TODO: (informative) number:

  • The index for the Quantization Table for each plane, as defined in the "dqt" feature.

Motion vectors

The "mv" feature for MPEG-2 exports the motion vectors that are encoded in the bitstream.

There may be "forward" and "backward" motion vectors.

TODO: MV:

  • null if there is no motion vector for this macroblock
  • an Array with two numbers, the first being horizontal and the second being vertical.

TODO: (informative) fcode:

  • fcode is an Array with two numbers, the first being horizontal and the second being vertical.
  • This field is informative. It tells you the fcode that was encoded for this frame. This can be used to calculate the minimum and maximum values allowed for the motion vectors.
  • For MPEG-2, the motion vector range is calculated by:
    const min_val = -(1<<(3 + fcode));
    const max_val =  (1<<(3 + fcode))-1;
    

TODO: string:

  • The "overflow" field will instruct FFglitch on what to do when it imports motion vector values that overflow the limit defined by fcode. Possible values are:
    • "assert": exits FFglitch on overflow.
    • "truncate": truncates motion vector values within range (I suggest using this one).
    • "ignore": does nothing (allows overflow).
    • "warn": warns once, but then ignores.

Motion vectors (delta only)

The "mv_delta" feature for MPEG-2 is similar to the "mv" feature, but the motion vectors are expressed as a delta value from the previous motion vector.

There may be "forward" and "backward" motion vectors.

TODO: MV_delta:

  • null if there is no motion vector delta for this macroblock
  • an Array with two numbers, the first being horizontal and the second being vertical.

TODO: (informative) fcode:

  • fcode is an Array with two numbers, the first being horizontal and the second being vertical.
  • This field is informative. It tells you the fcode that was encoded for this frame. This can be used to calculate the minimum and maximum values allowed for the motion vectors.
  • For MPEG-2, the motion vector range is calculated by:
    const min_val = -(1<<(3 + fcode));
    const max_val =  (1<<(3 + fcode))-1;
    

TODO: string:

  • The "overflow" field will instruct FFglitch on what to do when it imports motion vector values that overflow the limit defined by fcode. Possible values are:
    • "assert": exits FFglitch on overflow.
    • "truncate": truncates motion vector values within range (I suggest using this one).
    • "ignore": does nothing (allows overflow).
    • "warn": warns once, but then ignores.

Quantization scale

The "qscale" feature for MPEG-2 exports the quantization scale value for slices/macroblocks.

TODO

NOTE: this feature is not very thread-friendly in its current state in FFglitch. It will change in the future.

Macroblock

The "mb" feature for MPEG-2 exports the bytestream of each macroblock as a string value.

Macroblocks are mostly self-sufficient, so it might be possible to reorder them and still have a valid bitstream.

TODO: macroblock:

  • null if the macroblock was skipped.
  • a string with the hexadecimal representation of the bytestream for this macroblock

TODO: (informative) number:

  • the size in bits of the macroblock. This is used by FFglitch to properly align the bitstream when transplicating. Do not change these values.