## mpegvideoparser mpegvideoparser — Convenience library for mpeg1 and 2 video bitstream parsing. |

## Synopsis

    #include <gst/codecparsers/gstmpegvideoparser.h>

    enum                GstMpegVideoPacketTypeCode;
    enum                GstMpegVideoPacketExtensionCode;
    enum                GstMpegVideoLevel;
    enum                GstMpegVideoProfile;
    enum                GstMpegVideoPictureType;
    enum                GstMpegVideoPictureStructure;
    struct              GstMpegVideoSequenceHdr;
    struct              GstMpegVideoSequenceExt;
    struct              GstMpegVideoPictureHdr;
    struct              GstMpegVideoGop;
    struct              GstMpegVideoPictureExt;
    struct              GstMpegVideoQuantMatrixExt;
    struct              GstMpegVideoTypeOffsetSize;
    GList *             gst_mpeg_video_parse                (const guint8 *data,
                                                             gsize size,
                                                             guint offset);
    gboolean            gst_mpeg_video_parse_sequence_header
                                                            (GstMpegVideoSequenceHdr *params,
                                                             const guint8 *data,
                                                             gsize size,
                                                             guint offset);
    gboolean            gst_mpeg_video_parse_picture_header (GstMpegVideoPictureHdr *hdr,
                                                             const guint8 *data,
                                                             gsize size,
                                                             guint offset);
    gboolean            gst_mpeg_video_parse_picture_extension
                                                            (GstMpegVideoPictureExt *ext,
                                                             const guint8 *data,
                                                             gsize size,
                                                             guint offset);
    gboolean            gst_mpeg_video_parse_gop            (GstMpegVideoGop *gop,
                                                             const guint8 *data,
                                                             gsize size,
                                                             guint offset);
    gboolean            gst_mpeg_video_parse_sequence_extension
                                                            (GstMpegVideoSequenceExt *seqext,
                                                             const guint8 *data,
                                                             gsize size,
                                                             guint offset);
    gboolean            gst_mpeg_video_parse_quant_matrix_extension
                                                            (GstMpegVideoQuantMatrixExt *quant,
                                                             const guint8 *data,
                                                             gsize size,
                                                             guint offset);

## Description

Provides useful functions for mpeg videos bitstream parsing.

## Details

### enum GstMpegVideoPacketTypeCode

    typedef enum {
      GST_MPEG_VIDEO_PACKET_PICTURE      = 0x00,
      GST_MPEG_VIDEO_PACKET_SLICE_MIN    = 0x01,
      GST_MPEG_VIDEO_PACKET_SLICE_MAX    = 0xaf,
      GST_MPEG_VIDEO_PACKET_USER_DATA    = 0xb2,
      GST_MPEG_VIDEO_PACKET_SEQUENCE     = 0xb3,
      GST_MPEG_VIDEO_PACKET_EXTENSION    = 0xb5,
      GST_MPEG_VIDEO_PACKET_SEQUENCE_END = 0xb7,
      GST_MPEG_VIDEO_PACKET_GOP          = 0xb8,
      GST_MPEG_VIDEO_PACKET_NONE         = 0xff
    } GstMpegVideoPacketTypeCode;

Indicates the type of MPEG packet

`GST_MPEG_VIDEO_PACKET_PICTURE` | Picture packet starting code
`GST_MPEG_VIDEO_PACKET_SLICE_MIN` | Slice min packet starting code
`GST_MPEG_VIDEO_PACKET_SLICE_MAX` | Slice max packet starting code
`GST_MPEG_VIDEO_PACKET_USER_DATA` | User data packet starting code
`GST_MPEG_VIDEO_PACKET_SEQUENCE` | Sequence packet starting code
`GST_MPEG_VIDEO_PACKET_EXTENSION` | Extension packet starting code
`GST_MPEG_VIDEO_PACKET_SEQUENCE_END` | Sequence end packet code
`GST_MPEG_VIDEO_PACKET_GOP` | Group of Picture packet starting code
`GST_MPEG_VIDEO_PACKET_NONE` | None packet code

### enum GstMpegVideoPacketExtensionCode

    typedef enum {
      GST_MPEG_VIDEO_PACKET_EXT_SEQUENCE         = 0x01,
      GST_MPEG_VIDEO_PACKET_EXT_SEQUENCE_DISPLAY = 0x02,
      GST_MPEG_VIDEO_PACKET_EXT_QUANT_MATRIX     = 0x03,
      GST_MPEG_VIDEO_PACKET_EXT_PICTURE          = 0x08
    } GstMpegVideoPacketExtensionCode;

Indicates what type of packets are in this block, some are mutually exclusive though - ie, sequence packs are accumulated separately. GOP & Picture may occur together or separately.

`GST_MPEG_VIDEO_PACKET_EXT_SEQUENCE` | Sequence extension code
`GST_MPEG_VIDEO_PACKET_EXT_SEQUENCE_DISPLAY` | Sequence Display extension code
`GST_MPEG_VIDEO_PACKET_EXT_QUANT_MATRIX` | Quantization Matrix extension code
`GST_MPEG_VIDEO_PACKET_EXT_PICTURE` | Picture coding extension

### enum GstMpegVideoLevel

    typedef enum {
     GST_MPEG_VIDEO_LEVEL_HIGH      = 0x04,
     GST_MPEG_VIDEO_LEVEL_HIGH_1440 = 0x06,
     GST_MPEG_VIDEO_LEVEL_MAIN      = 0x08,
     GST_MPEG_VIDEO_LEVEL_LOW       = 0x0a
    } GstMpegVideoLevel;

Mpeg-2 Levels.

`GST_MPEG_VIDEO_LEVEL_HIGH` | High level (HL)
`GST_MPEG_VIDEO_LEVEL_HIGH_1440` | High 1440 level (H-14)
`GST_MPEG_VIDEO_LEVEL_MAIN` | Main level (ML)
`GST_MPEG_VIDEO_LEVEL_LOW` | Low level (LL)

### enum GstMpegVideoProfile

    typedef enum {
      GST_MPEG_VIDEO_PROFILE_422                 = 0x00,
      GST_MPEG_VIDEO_PROFILE_HIGH                = 0x01,
      GST_MPEG_VIDEO_PROFILE_SPATIALLY_SCALABLE  = 0x02,
      GST_MPEG_VIDEO_PROFILE_SNR_SCALABLE        = 0x03,
      GST_MPEG_VIDEO_PROFILE_MAIN                = 0x04,
      GST_MPEG_VIDEO_PROFILE_SIMPLE              = 0x05
    } GstMpegVideoProfile;

Mpeg-2 Profiles.

`GST_MPEG_VIDEO_PROFILE_422` | 4:2:2 profile (422)
`GST_MPEG_VIDEO_PROFILE_HIGH` | High profile (HP)
`GST_MPEG_VIDEO_PROFILE_SPATIALLY_SCALABLE` | Spatially Scalable profile (Spatial)
`GST_MPEG_VIDEO_PROFILE_SNR_SCALABLE` | SNR Scalable profile (SNR)
`GST_MPEG_VIDEO_PROFILE_MAIN` | Main profile (MP)
`GST_MPEG_VIDEO_PROFILE_SIMPLE` | Simple profile (SP)

### enum GstMpegVideoPictureType

    typedef enum {
      GST_MPEG_VIDEO_PICTURE_TYPE_I = 0x01,
      GST_MPEG_VIDEO_PICTURE_TYPE_P = 0x02,
      GST_MPEG_VIDEO_PICTURE_TYPE_B = 0x03,
      GST_MPEG_VIDEO_PICTURE_TYPE_D = 0x04
    } GstMpegVideoPictureType;

Picture type.

`GST_MPEG_VIDEO_PICTURE_TYPE_I` | Intra-coded (I) frame
`GST_MPEG_VIDEO_PICTURE_TYPE_P` | Predictive-codec (P) frame
`GST_MPEG_VIDEO_PICTURE_TYPE_B` | Bidirectionally predictive-coded (B) frame
`GST_MPEG_VIDEO_PICTURE_TYPE_D` | D frame

### enum GstMpegVideoPictureStructure

    typedef enum {
        GST_MPEG_VIDEO_PICTURE_STRUCTURE_TOP_FIELD    = 0x01,
        GST_MPEG_VIDEO_PICTURE_STRUCTURE_BOTTOM_FIELD = 0x02,
        GST_MPEG_VIDEO_PICTURE_STRUCTURE_FRAME        = 0x03
    } GstMpegVideoPictureStructure;

Picture structure type.

`GST_MPEG_VIDEO_PICTURE_STRUCTURE_TOP_FIELD` | Top field
`GST_MPEG_VIDEO_PICTURE_STRUCTURE_BOTTOM_FIELD` | Bottom field
`GST_MPEG_VIDEO_PICTURE_STRUCTURE_FRAME` | Frame picture

### struct GstMpegVideoSequenceHdr

    struct GstMpegVideoSequenceHdr {
      guint16 width, height;
      guint8  aspect_ratio_info;
      guint8  frame_rate_code;
      guint32 bitrate_value;
      guint16 vbv_buffer_size_value;

      guint8  constrained_parameters_flag;

      guint8  intra_quantizer_matrix[64];
      guint8  non_intra_quantizer_matrix[64];

      /* Calculated values */
      guint   par_w, par_h;
      guint   fps_n, fps_d;
      guint   bitrate;
    };

The Mpeg2 Video Sequence Header structure.

guint16 `width`; | Width of each frame
guint16 `height`; | Height of each frame
guint8 `aspect_ratio_info`; |
guint8 `frame_rate_code`; |
guint32 `bitrate_value`; | Value of the bitrate as is in the stream (400bps unit)
guint16 `vbv_buffer_size_value`; |
guint8 `constrained_parameters_flag`; | `TRUE` if this stream uses contrained parameters.
guint8 `intra_quantizer_matrix`[64]; | intra-quantization table
guint8 `non_intra_quantizer_matrix`[64]; | non-intra quantization table
guint `par_w`; | Calculated Pixel Aspect Ratio width
guint `par_h`; | Calculated Pixel Aspect Ratio height
guint `fps_n`; | Calculated Framrate nominator
guint `fps_d`; | Calculated Framerate denominator
guint `bitrate`; | the real bitrate of the Mpeg video stream in bits per second, 0 if VBR stream

### struct GstMpegVideoSequenceExt

    struct GstMpegVideoSequenceExt {
      /* mpeg2 decoder profile */
      guint8 profile;
      /* mpeg2 decoder level */
      guint8 level;

      guint8 progressive;
      guint8 chroma_format;

      guint8 horiz_size_ext, vert_size_ext;

      guint16 bitrate_ext;
      guint8 vbv_buffer_size_extension;
      guint8 low_delay;
      guint8 fps_n_ext, fps_d_ext;
    };

The Mpeg2 Video Sequence Extension structure.

guint8 `profile`; | mpeg2 decoder profil
guint8 `level`; | mpeg2 decoder level
guint8 `progressive`; | `TRUE` if the frames are progressive `FALSE` otherwize
guint8 `chroma_format`; | indicates the chrominance format
guint8 `horiz_size_ext`; | Horizontal size
guint8 `vert_size_ext`; | Vertical size
guint16 `bitrate_ext`; | The bitrate
guint8 `vbv_buffer_size_extension`; | Vbv vuffer size
guint8 `low_delay`; | `TRUE` if the sequence doesn't contain any B-pictures, `FALSE` otherwize
guint8 `fps_n_ext`; | Framerate nominator code
guint8 `fps_d_ext`; | Framerate denominator code

### struct GstMpegVideoPictureHdr

    struct GstMpegVideoPictureHdr {
      guint16 tsn;
      guint8 pic_type;

      guint8 full_pel_forward_vector, full_pel_backward_vector;

      guint8 f_code[2][2];
    };

The Mpeg2 Video Picture Header structure.

guint16 `tsn`; | Temporal Sequence Number
guint8 `pic_type`; | Type of the frame
guint8 `full_pel_forward_vector`; | the full pel forward flag of the frame: 0 or 1.
guint8 `full_pel_backward_vector`; | the full pel backward flag of the frame: 0 or 1.
guint8 `f_code`[2][2]; | F code

### struct GstMpegVideoGop

    struct GstMpegVideoGop {
      guint8 drop_frame_flag;

      guint8 hour, minute, second, frame;

      guint8 closed_gop;
      guint8 broken_link;
    };

The Mpeg Video Group of Picture structure.

guint8 `drop_frame_flag`; | Drop Frame Flag
guint8 `hour`; | Hour (0-23)
guint8 `minute`; | Minute (O-59)
guint8 `second`; | Second (0-59)
guint8 `frame`; | Frame (0-59)
guint8 `closed_gop`; | Closed Gop
guint8 `broken_link`; | Broken link

### struct GstMpegVideoPictureExt

    struct GstMpegVideoPictureExt {
      guint8 f_code[2][2];

      guint8 intra_dc_precision;
      guint8 picture_structure;
      guint8 top_field_first;
      guint8 frame_pred_frame_dct;
      guint8 concealment_motion_vectors;
      guint8 q_scale_type;
      guint8 intra_vlc_format;
      guint8 alternate_scan;
      guint8 repeat_first_field;
      guint8 chroma_420_type;
      guint8 progressive_frame;
      guint8 composite_display;
      guint8 v_axis;
      guint8 field_sequence;
      guint8 sub_carrier;
      guint8 burst_amplitude;
      guint8 sub_carrier_phase;
    };

The Mpeg2 Video Picture Extension structure.

guint8 `f_code`[2][2]; |
guint8 `intra_dc_precision`; | Intra DC precision
guint8 `picture_structure`; | Structure of the picture
guint8 `top_field_first`; | Top field first
guint8 `frame_pred_frame_dct`; | Frame
guint8 `concealment_motion_vectors`; | Concealment Motion Vectors
guint8 `q_scale_type`; | Q Scale Type
guint8 `intra_vlc_format`; | Intra Vlc Format
guint8 `alternate_scan`; | Alternate Scan
guint8 `repeat_first_field`; | Repeat First Field
guint8 `chroma_420_type`; | Chroma 420 Type
guint8 `progressive_frame`; | `TRUE` if the frame is progressive `FALSE` otherwize
guint8 `composite_display`; |
guint8 `v_axis`; |
guint8 `field_sequence`; |
guint8 `sub_carrier`; |
guint8 `burst_amplitude`; |
guint8 `sub_carrier_phase`; |

### struct GstMpegVideoQuantMatrixExt

    struct GstMpegVideoQuantMatrixExt {
     guint8 load_intra_quantiser_matrix;
     guint8 intra_quantiser_matrix[64];
     guint8 load_non_intra_quantiser_matrix;
     guint8 non_intra_quantiser_matrix[64];
     guint8 load_chroma_intra_quantiser_matrix;
     guint8 chroma_intra_quantiser_matrix[64];
     guint8 load_chroma_non_intra_quantiser_matrix;
     guint8 chroma_non_intra_quantiser_matrix[64];
    };

The Quant Matrix Extension structure

### struct GstMpegVideoTypeOffsetSize

    struct GstMpegVideoTypeOffsetSize {
      guint8 type;
      guint  offset;
      gint   size;
    };

A structure that contains the type of a packet, its offset and its size

guint8 `type`; | the type of the packet that start at `offset`
guint `offset`; | the offset of the packet start in bytes, it is the exact, start of the packet, no sync code included
gint `size`; | The size in bytes of the packet or -1 if the end wasn't found. It is the exact size of the packet, no sync code included

### gst_mpeg_video_parse ()

    GList *             gst_mpeg_video_parse                (const guint8 *data,
                                                             gsize size,
                                                             guint offset);

Parses the MPEG 1/2 video bitstream contained in `data` , and returns the detect packets as a list of GstMpegVideoTypeOffsetSize.

`data` : | The data to parse
`size` : | The size of `data`
`offset` : | The offset from which to start parsing
Returns : | a GList of GstMpegVideoTypeOffsetSize

### gst_mpeg_video_parse_sequence_header ()

    gboolean            gst_mpeg_video_parse_sequence_header
                                                            (GstMpegVideoSequenceHdr *params,
                                                             const guint8 *data,
                                                             gsize size,
                                                             guint offset);

Parses the `seqhdr` Mpeg Video Sequence Header structure members from `data`

`seqhdr` : | The GstMpegVideoSequenceHdr structure to fill. [out]
`data` : | The data from which to parse the sequence header
`size` : | The size of `data`
`offset` : | The offset in byte from which to start parsing `data`
Returns : | `TRUE` if the seqhdr could be parsed correctly, `FALSE` otherwize.

### gst_mpeg_video_parse_picture_header ()

    gboolean            gst_mpeg_video_parse_picture_header (GstMpegVideoPictureHdr *hdr,
                                                             const guint8 *data,
                                                             gsize size,
                                                             guint offset);

Parsers the `hdr` Mpeg Video Picture Header structure members from `data`

`hdr` : | The GstMpegVideoPictureHdr structure to fill. [out]
`data` : | The data from which to parse the picture header
`size` : | The size of `data`
`offset` : | The offset in byte from which to start the parsing
Returns : | `TRUE` if the picture sequence could be parsed correctly, `FALSE` otherwize.

### gst_mpeg_video_parse_picture_extension ()

    gboolean            gst_mpeg_video_parse_picture_extension
                                                            (GstMpegVideoPictureExt *ext,
                                                             const guint8 *data,
                                                             gsize size,
                                                             guint offset);

Parse the `ext` Mpeg Video Picture Extension structure members from `data`

`ext` : | The GstMpegVideoPictureExt structure to fill. [out]
`data` : | The data from which to parse the picture extension
`size` : | The size of `data`
`offset` : | The offset in byte from which to start the parsing
Returns : | `TRUE` if the picture extension could be parsed correctly, `FALSE` otherwize.

### gst_mpeg_video_parse_gop ()

    gboolean            gst_mpeg_video_parse_gop            (GstMpegVideoGop *gop,
                                                             const guint8 *data,
                                                             gsize size,
                                                             guint offset);

Parses the `gop` Mpeg Video Group of Picture structure members from `data`

`gop` : | The GstMpegVideoGop structure to fill. [out]
`data` : | The data from which to parse the gop
`size` : | The size of `data`
`offset` : | The offset in byte from which to start the parsing
Returns : | `TRUE` if the gop could be parsed correctly, `FALSE` otherwize.

### gst_mpeg_video_parse_sequence_extension ()

    gboolean            gst_mpeg_video_parse_sequence_extension
                                                            (GstMpegVideoSequenceExt *seqext,
                                                             const guint8 *data,
                                                             gsize size,
                                                             guint offset);

Parses the `seqext` Mpeg Video Sequence Extension structure members from `data`

`seqext` : | The GstMpegVideoSequenceExt structure to fill. [out]
`data` : | The data from which to parse the sequence extension
`size` : | The size of `data`
`offset` : | The offset in byte from which to start parsing `data`
Returns : | `TRUE` if the seqext could be parsed correctly, `FALSE` otherwize.

### gst_mpeg_video_parse_quant_matrix_extension ()

    gboolean            gst_mpeg_video_parse_quant_matrix_extension
                                                            (GstMpegVideoQuantMatrixExt *quant,
                                                             const guint8 *data,
                                                             gsize size,
                                                             guint offset);

Parses the `quant` Mpeg Video Quant Matrix Extension structure members from `data`

`quant` : | The GstMpegVideoQuantMatrixExt structure to fill. [out]
`data` : | The data from which to parse the Quantization Matrix extension
`size` : | The size of `data`
`offset` : | The offset in byte from which to start the parsing
Returns : | `TRUE` if the quant matrix extension could be parsed correctly, `FALSE` otherwize.