Dali : MPEG Video -- C API

[ Header Files | Types | Constants | Sequence Header Allocation Primitives | Sequence Header Manipulations | Sequence Header Query Primitives | Sequence Header Initialization Primitives | GOP Header Allocation Primitives | GOP Header Manipulation Primitives | GOP Header Query Primitives | GOP Header Initialization Primitives | Picture Header Allocation Primitives | Picture Header Manipulation Primitives | Picture Header Query Primitives | Picture Header Initialization Primitives | MpegPic Decoding Primitives | MpegPic Encoding Primitives | Motion Vector Search | Video Index Allocation Primitives | Video Index Query Primitives | Video Index Manipulation Primitives | Misc Primitives | See Also ]

Header Files

#include <dvmmpeg.h>

Type Definitions

MpegSeqHdr

The MpegSeqHdr structure contains all of the parameters contained in the sequence header of an MPEG stream.

    typedef struct MpegSeqHdr {
        short width;
        short height;
        short mb_width;
        short mb_height;
        int bitrate;
        int vbv_buffer_size;
        char pel_aspect_ratio;
        char picture_rate;
        char constrained;
        char default_qt;
        unsigned char iqt[64];
        unsigned char niqt[64];
    } MpegSeqHdr;    
  
width
the width of each frame
height
the height of each frame
mb_width
the width of each frame in macroblocks
mb_height
the height of each frame in macroblocks
bitrate
the bitrate of the Mpeg video stream, in units of 400 bits/second
vbv_buffer_size
buffer size needed by a decoder to decode a frame. At least this many bytes should be present in a bitstream to guarantee that the bitstream contains an entire encoded frame.
pel_aspect_ratio
index to aspect ratio table. This table is shown below
Index Aspect Ratio
0 RESERVE
1 1.000
2 0.6735
3 0.7031
4 0.7615
5 0.8055
6 0.8437
7 0.8935
8 0.9375
9 0.9815
10 1.0255
11 1.0695
12 1.1250
13 1.1575
14 1.2015
15 RESERVE

picture_rate
Frame rate, as an index into the picture rate table.
Index Aspect Ratio
0 RESERVE
1 23.976
2 24
3 25
4 29.97
5 30
6 50
7 59.94
8 60
9 RESERVE
10 RESERVE
11 RESERVE
12 RESERVE
13 RESERVE
14 RESERVE
15 RESERVE

constrained
true if this stream uses contrained parameters. Using constrained parameters implies that the following constraints are met:
  • width ≤ 768
  • height ≤ 576
  • mb_width*mb_height ≤ 396
  • frame_rate ≤ 30 frames/second
  • mb_width*mb_height*frame_rate ≤ 396*25
  • all motion vectors ≤ ±128
  • vbv_size ≤ 40*1024 bytes
  • bit_rate ≤ 1856000 bits/second
  • default_qt
    indicates if iqt and niqt use default values, or are specified in the bitstream. 0 if both tables use default values, 1 if only iqt is defined in the bitstream, 2 if only niqt is defined, 3 if both are defined.
    iqt[64]
    intra-quantization table
    niqt[64]
    non-intra quantization table.

    MpegGopHdr

    The MpegGopHdr structure contains all of the parameters contained in the GOP header of an MPEG stream.

        typedef struct MpegGopHdr {
            char drop_frame_flag;      
            char time_code_hours;
            char time_code_minutes;
            char time_code_seconds;
            char time_code_pictures;
            char closed_gop;
            char broken_link;
        } MpegGopHdr; 
      
    
    drop_frame_flag, time_code_hours, time_code_minutes, time_code_seconds , time_code_pictures
    These fields correspond the the fields defined in the IEC standard 461 ("time and control codes for video tape recorders"). The code refers to the first picture in the group of pictures that has a temporal_reference of zero.

    The drop_frame_flag is 1 only if the pic rate is 29.97Hz. If drop_frame_flag = 0 then pictures are counted assuming rounding to the nearest integral number of pictures per second. If If drop_frame_flag = 1 then picture numbers 0 and 1 at the start of every minute except minutes 0, 10, 20, 30, 40, 50 are ommitted from the count.

    closed_gop
    If closed_gop = 1, then this GOP is encoded without vectors pointing to pictures in previous GOP. Closed_gop = 0 otherwise.
    broken_link
    if broken_link = 1, then the first B-frame that follows the first I-frame in this GOP cannot be decoded because the other frame used for prediction is not available. This can be used to avoid decoding pictures that cannot be correctly decoded due to editing.

    MpegPicHdr

    The MpegPicHdr structure contains all of the parameters contained in the picture header of an MPEG stream.

        typedef struct MpegPicHdr {
            short temporal_reference;
            char  type;
            unsigned short vbv_delay;
            char  full_pel_forward_vector;
            char  forward_r_size, forward_f;
            char  full_pel_backward_vector;
            char  backward_r_size, backward_f;
        } MpegPicHdr; 
      
    
    temporal_reference
    an integer associated with each picture, start from 0 for first (in display order) picture of each GOP, increase by one modulo 1024 for every picture (in display order).
    type
    indicates the type of encoding for this picture : could be I_FRAME, P_FRAME, B_FRAME or D_FRAME.
    full_pel_forward_vector
    If this slot is 1, the forward motion vectors are in full-pixel units. If this slot is 0, the forward motion vectors are in half-pixel units.
    forward_r_size
    Used internally for decoding motion vectors from the bitstream. See MPEG-1 Video standard for details.
    forward_f
    Used internally for decoding motion vectors from the bitstream. See MPEG-1 Video standard for details.
    full_pel_backward_vector
    If this slot is 1, the backward motion vectors are in full-pixel units. If this slot is 0, the backward motion vectors are in half-pixel units.
    backward_r_size
    Used internally for decoding motion vectors from the bitstream. See MPEG-1 Video standard for details.
    backward_f
    Used internally for decoding motion vectors from the bitstream. See MPEG-1 Video standard for details.

    MpegVideoIndex

    The MpegVideoIndex structure is essentially a table to organize MpegVideoIndexElements. More information about MpegVideoIndexElements can be found below.

        typedef struct MpegVideoIndex {
            MpegVideoIndexElement *table;
            int numElements;
            int maxElements;
        } MpegVideoIndex;
      
    
    table
    an array of maxElements to store indices into a MPEG video.
    numElements
    the number of MpegVideoIndexElements stored in the MpegVideoIndex.
    maxElements
    the maximum number of MpegVideoIndexElements that can be stored in the MpegVideoIndex.

    MpegVideoIndexElement

    The MpegVideoIndex structure contains all information necessary to decode either an individual frame, or a group of frames starting from an arbitrary frame in the MPEG video stream.

        typedef struct MpegVideoIndexElement {
            char refCount;
            char type;
            char pastOffset;
            char forOffset;
            int offset;
            int length;
        } MpegVideoIndexElement;  
      
    
    refCount
    the number of reference frames needed to decode the current frame
    type
    the type of encoding for this picture. One of the characters I_FRAME, P_FRAME, or B_FRAME.
    pastOffset
    the number of frames to skip going in reverse order to find the reference frame for the current frame (always 0 for I frames)
    forOffset
    the number of frames to skip in the forward direction to find the next reference frame for the current frame (always 0 for I and P frames)
    offset
    the bit offset of the bitparser from the start of MPEG video file (useful for skipping to pic hdrs of known frames)
    length
    the length (in bits) of the current frame in the encoded bitstream.

    Constants

    Picture Type

    Indicates the type of frame. Return values are I_FRAME, P_FRAME, B_FRAME, D_FRAME.

        #define I_FRAME 1
        #define P_FRAME 2
        #define B_FRAME 3
        #define D_FRAME 4
      
    

    Start Codes

    These codes represent the possible starting and ending codes for different structures in the MPEG stream. Values are: SEQ_START_CODE, SEQ_END_CODE, ISO_11172_END_CODE, PACK_START_CODE, SYS_START_CODE, PIC_START_CODE, GOP_START_CODE, EXT_START_CODE, USER_START_CODE, SLICE_MIN_START_CODE, SLICE_MAX_START_CODE, PACKET_MIN_START_CODE, PACKET_MIN_START_CODE

        #define SEQ_START_CODE 0x000001b3
        #define SEQ_END_CODE   0x000001b7
        #define ISO_11172_END_CODE 0x000001b9
        #define PACK_START_CODE 0x000001ba
        #define SYS_START_CODE 0x000001bb
        #define PIC_START_CODE 0x00000100
        #define GOP_START_CODE 0x000001b8
        #define EXT_START_CODE 0x000001b5
        #define USER_START_CODE 0x000001b2
        #define SLICE_MIN_START_CODE 0x00000101
        #define SLICE_MAX_START_CODE 0x000001af
        #define PACKET_MIN_START_CODE 0x0000001bc
        #define PACKET_MAX_START_CODE 0x0000001f0
        
    

    Return Codes

    These represent the possible return values from Dali MPEG functions. DVM_MPEG_OK is returned if all goes well. Error codes are: DVM_MPEG_NOT_FOUND, DVM_MPEG_INVALID_START_CODE, DVM_MPEG_INDEX_FULL

        #define DVM_MPEG_OK 0
        #define DVM_MPEG_NOT_FOUND -1
        #define DVM_MPEG_INVALID_START_CODE -2
        #define DVM_MPEG_INDEX_FULL 1
        
    

    Operators

    Sequence Header Allocation Primitives

    MpegSeqHdr *MpegSeqHdrNew ()

    void MpegSeqHdrFree (MpegSeqHdr *hdr)


    Sequence Header Manipulations

    int MpegSeqHdrFind (BitParser *bp)

    int MpegSeqHdrDump (BitParser *inbp, BitParser *outbp)

    int MpegSeqHdrSkip (BitParser *bp)

    int MpegSeqHdrParse (BitParser *bp)

    int MpegSeqHdrEncode (BitParser *bp)


    Sequence Header Query Primitives

    #define MpegSeqHdrGetWidth(MpegSeqHdr *hdr)
    #define MpegSeqHdrGetHeight(MpegSeqHdr *hdr)
    #define MpegSeqHdrGetAspectRatio(MpegSeqHdr *hdr)
    #define MpegSeqHdrGetBitRate(MpegSeqHdr *hdr)
    #define MpegSeqHdrGetPicRate(MpegSeqHdr *hdr)
    #define MpegSeqHdrGetBufferSize(MpegSeqHdr *hdr)
    #define MpegSeqHdrGetIQT(MpegSeqHdr *hdr)
    #define MpegSeqHdrGetNIQT(MpegSeqHdr *hdr)


    Sequence Header Initialization Primitives

    #define MpegSeqHdrSetWidth(MpegSeqHdr *hdr, int x)
    #define MpegSeqHdrSetHeight(MpegSeqHdr *hdr, int x)
    void MpegSeqHdrSetAspectRatio(MpegSeqHdr *hdr, double x)
    void MpegSeqHdrSetPicRate(MpegSeqHdr *hdr, double x)
    #define MpegSeqHdrSetBitRate(MpegSeqHdr *hdr, int x)
    #define MpegSeqHdrSetBufferSize(MpegSeqHdr *hdr, int x)
    #define MpegSeqHdrSetConstrained(MpegSeqHdr *hdr, int x)
    void MpegSeqHdrSetIQT(MpegSeqHdr *hdr, int *qTable)
    void MpegSeqHdrSetNIQT(MpegSeqHdr *hdr, int *niqTable)
    void MpegSeqHdrSetDefaultIQT(MpegSeqHdr *hdr)
    void MpegSeqHdrSetDefaultNIQT(MpegSeqHdr *hdr)


    GOP Header Allocation Primitives

    MpegGopHdr *MpegGopHdrNew ();

    void MpegGopHdrFree (MpegGopHdr *hdr)


    GOP Header Manipulation Primitives

    int MpegGopHdrFind (BitParser *bp)

    int MpegGopHdrDump (BitParser *inbp, BitParser *outbp)

    int MpegGopHdrSkip (BitParser *bp);

    int MpegGopHdrParse (BitParser *bp, MpegGopHdr *);

    int MpegGopHdrEncode (MpegGopHdr *hdr, BitParser *bp);


    GOP Header Query Primitives

    #define MpegGopHdrGetClosedGop(MpegGopHdr *hdr)
    #define MpegGopHdrGetBrokenLink(MpegGopHdr *hdr)


    GOP Header Initialization Primitives

    #define MpegGopHdrSetDropFrameFlag(MpegGopHdr *hdr, int x)
    #define MpegGopHdrSetHours(MpegGopHdr *hdr, int x)
    #define MpegGopHdrSetMinutes(MpegGopHdr *hdr, int x)
    #define MpegGopHdrSetSeconds(MpegGopHdr *hdr, int x)
    #define MpegGopHdrSetPictures(MpegGopHdr *hdr, int x)
    #define MpegGopHdrSetClosedGop(MpegGopHdr *hdr, int x)
    #define MpegGopHdrSetBrokenLink(MpegGopHdr *hdr, int x)


    Picture Header Allocation Primitives

    MpegPicHdr *MpegPicHdrNew ();

    void MpegPicHdrFree (MpegPicHdr *hdr);


    Picture Header Manipulation Primitives

    int MpegPicHdrFind (BitParser *bp);

    int MpegPicHdrDump (BitParser *inbp, BitParser *outbp);

    int MpegPicHdrSkip (BitParser *bp);

    int MpegPicHdrParse (BitParser *bp, MpegPicHdr *hdr);

    int MpegPicHdrEncode (MpegPicHdr *, BitParser *);


    Picture Header Query Primitives

    #define MpegPicHdrGetTemporalRef(MpegPicHdr *hdr)
    #define MpegPicHdrGetType(MpegPicHdr *hdr)


    Picture Header Initialization Primitives

    #define MpegPicHdrSetTemporalRef(MpegPicHdr *hdr, int x)
    #define MpegPicHdrSetType(MpegPicHdr *hdr, int x)
    #define MpegPicHdrSetVBVDelay(MpegPicHdr *hdr, int x)
    #define MpegPicHdrSetFullPelForward(MpegPicHdr *hdr, int x)
    void MpegPicHdrSetForwarddFCode(MpegPicHdr *hdr, int x) #define MpegPicHdrSetFullPelBackward(MpegPicHdr *hdr, int x)
    void MpegPicHdrSetBackwardFCode(MpegPicHdr *hdr, int x)


    MpegPic Decoding Primitives

    int MpegPicDump (BitParser *inbp, BitParser *outbp)

    int MpegPicSkip (BitParser *inbp)

    int MpegPicIParse (BitParser *bp, MpegSeqHdr *seqHdr, MpegPicHdr *picHdr, ScImage *scY, ScImage *scU, ScImage *scV)

    int MpegPicPParse (BitParser *bp, MpegSeqHdr *seqHdr, MpegPicHdr *picHdr, ScImage *scY, ScImage *scU, ScImage *scV, VectorImage *fmv)

    int MpegPicBParse (BitParser *bp, MpegSeqHdr *seqHdr, MpegPicHdr *picHdr, ScImage *scY, ScImage *scU, ScImage *scV, VectorImage *fmv, VectorImage *bmv)


    MpegPic Encoding Primitives

    void MpegPicIEncode (MpegPicHdr *picHdr, ScImage *scY, ScImage *scU, ScImage *scV, ByteImage *qScale, int *sliceInfo, int sliceInfoLen, BitParser *bp)

    void MpegPicPEncode (MpegPicHdr *picHdr, ScImage *scY, ScImage *scU, ScImage *scV, VectorImage *fmv, ByteImage *qScale, int *sliceInfo, int sliceInfoLen, BitParser *bp)

    void MpegPicBEncode (MpegPicHdr *picHdr, ScImage *scY, ScImage *scU, ScImage *scV, VectorImage *fmv, VectorImage *bmv, ByteImage *qScale, int *sliceInfo, int sliceInfoLen, BitParser *bp)


    Motion Vector Search

    void BytePMotionVecSearch (MpegPicHdr *picHdr, ByteImage *y, ByteImage *prevY, ByteImage **intermediates, VectorImage *fmv)

    void ByteBMotionVecSearch (MpegPicHdr *picHdr, ByteImage *currY, ByteImage *prevY, ByteImage *nextY, ByteImage **interPrev, ByteImage **interNext, int *sliceInfo, int sliceInfoLen, VectorImage *fmv, VectorImage *bmv)

    void ByteComputeIntermediates (ByteImage *original, ByteImage **intermediates)


    Video Index Allocation Primitives

    MpegVideoIndex *MpegVideoIndexNew (int size);

    void MpegVideoIndexFree (MpegPicHdr *hdr);


    Video Index Query Primitives

    #define MpegVideoIndexGetType(index, fnum) index->table[fnum].type
    #define MpegVideoIndexGetNext(index, fnum) index->table[fnum].forOffset
    #define MpegVideoIndexGetPast(index, fnum) index->table[fnum].pastOffset
    #define MpegVideoIndexGetOffset(index, fnum) index->table[fnum].offset
    #define MpegVideoIndexGetLength(index, fnum) index->table[fnum].length
    #define MpegVideoIndexNumRefs(index, fnum) index->table[fnum].refCount


    Video Index Manipulation Primitives

    void MpegVideoIndexParse (BitParser *bp, MpegVideoIndex *index);

    void MpegVideoIndexEncode (MpegVideoIndex *index, BitParser *bp);

    int MpegVideoIndexFindRefs (MpegVideoIndex *index, MpegVideoIndex *result, int frameNum);

    int MpegVideoIndexTableAdd (MpegVideoIndex *index, int frameNum, int bitOffset, char ftype, int flength, int past, int next);

    void MpegVideoIndexResize (MpegVideoIndex *index, unsigned int newSize);


    Misc Primitives

    int MpegGetCurrStartCode(BitParser *bp)

    int MpegAnyHdrFind(BitParser *bp)

    int MpegSeqEndCodeEncode(BitParser *bp)


    See Also

    BitImage , BitImageScan API , ByteGeom Package API


    Last updated : Saturday, November 14, 1998, 07:50 PM