# MediaWare Solutions MPEG SDK

    MPEG SDK --> MpegDecoder

class MpegDecoder

An MpegDecoder knows how to navigate and decode an MPEG stream.

It uses the global singleton object error defined in Basic.h for error reporting. When an error occurs during of of its operations, an error will be pushed and error.empty() will be false. The error can then be retrieved by error.pop().

Source:
  MpegDecoder.h:38

##

MpegDecoder
  [public] Default constructor.
MpegDecoder
  [public] Construct a MpegDecoder for the given file.
~MpegDecoder
  [public] Destructor.

##

currentPCMBiteFrame
  [public] Return the closest video frame number corresponding to the most recent PCMBite resulting from getPCMBite() or getNextPCMBite().
getBGRImage
  [public] Return an array of 24 bit unsigned chars containing the pixels of the given image, scaled and in the format of BGR.
getBGRXImage
  [public] Return an array of 32 bit unsigned chars containing the pixels of the given image, scaled and in the format of BGRX.
getFilename
  [public] Return the complete pathname with filename.
getFrameNumber
  [public] Return the frame number for the given timecode.
getFrameRate
  [public] Return the frame rate of the MPEG.
getFramesPerSecond
  [public] Return the number of frames/sec for the MPEG.
getImageHeight
  [public] Return the height of the frames returned by getRGBImage() etc.
getImageWidth
  [public] Return the width of the frames returned by getRGBImage() etc.
getLastFrame
  [public] Return the number of frames in the MPEG.
getMpegHeaderInfo
  [public] Static method to return an MpegHeaderInfo object containing all the information about a particular MPEG file.
getMpegInfo
  [public] Return an MpegInfo object containing the information about the current MPEG.
getMpegInfo
  [public] Static method to return an MpegInfo object containing all the information about a particular MPEG file.
getNextPCMBite
  [public] Return the next PCMBite or 0 if there is none.
getNFrames
  [public] Return total number of frames.
getPCMBite
  [public] Return the first PCMBite after video frame frame.
getRGBImage
  [public] Return an array of 24 bit unsigned chars containing the pixels of the given image, scaled and in the format of RGB.
getRGBXImage
  [public] Return an array of 32 bit unsigned chars containing the pixels of the given image, scaled and in the format of RGBX.
getTimeCode
  [public] Return the SMPTE timecode for the given frame number.
getTotalTime
  [public] Return total time in seconds.
getXBGRImage
  [public] Return an array of 32 bit unsigned chars containing the pixels of the given image, scaled and in the format of XBGR.
getXRGBImage
  [public] Return an array of 32 bit unsigned chars containing the pixels of the given image, scaled and in the format of XRGB.
gop
  [public] Return information about the GOP containing the given frame.
hasAudio
  [public] Does this MPEG contain an audio stream.
hasVideo
  [public] Does this MPEG contain a video stream.
isIFrame
  [public] Whether the given frame is an I frame.
isIorPFrame
  [public] Whether the given frame is an I or a P frame.
nextIFrame
  [public] Get the frame number of the next I frame following the given frame.
nextIOffset
  [public] Get offset of the next I frame.
nextIorPFrame
  [public] Get the frame number of the next I or P frame following the given frame.
openFile
  [public] Open a new file with this decoder and reset all variables.
picFrameNum
  [public] Get the frame number of the first picture after offset.
picOffset
  [public] Get the Offset of the picture with the given frame number.
picture
  [public] Return information about the specified frame.
prevIFrame
  [public] Get the frame number of the previous I frame to the given frame.
prevIOffset
  [public] Get offset of the previous I frame.
prevIorPFrame
  [public] Get the frame number of the previous I or P frame to the given frame.
saveToBMP
  [public] Save the given frame to file in BMP format at the given zoom factor.
saveToJPEG
  [public] Save the given frame to file in JPEG format at the given zoom factor.
saveToTIFF
  [public] Save the given frame to file in TIFF format at the given zoom factor.
saveToWAV
  [public] Save the audio clip between first_frame and last_frame to a file in WAV format.
sequence
  [public] Return information about the sequence containing the given frame.
setAuxFilesPath
  [public] Set the path for loading and saving of auxiliary files (e.g. .mpf and .idx).
setDeinterlace
  [public] Set whether to deinterlace the image when retrieving an image from an MPEG-2 video.
setUseAspectRatio
  [public] Set whether to use the video's aspect ratio when retrieving an image from an MPEG-2 video.

##

MpegDecoder

    public MpegDecoder ( ) ;

Default constructor.

Constructs a MpegDecoder with no file. Most functions except the openFile function will push an error.

MpegDecoder

    public MpegDecoder ( const string & filename ,
                         CallBack cb = 0 ) ;

Construct a MpegDecoder for the given file.

  Parameters:

    filename | name of the MPEG file to open
    cb | callback to use when openning a video-only stream which requires generating of an index table for navigation

MpegDecoder

    public ~ MpegDecoder ( ) ;

Destructor.

##

setAuxFilesPath

    public static void setAuxFilesPath ( const string & aux_path ) ;

Set the path for loading and saving of auxiliary files (e.g. .mpf and .idx).

Auxiliary files are searched in the following order:

     1. aux_path (if set)
     2. where the mpeg file is
     3. where the program is executing from
     4. $TMP in win32 or /tmp in UNIX

If aux_path is set to "NULL", auxiliary files will not be used.

openFile

    public void openFile ( const string & filename ,
                           CallBack cb = 0 ) ;

Open a new file with this decoder and reset all variables.

  Parameters:

    filename | name of the MPEG file to open
    cb | callback to use if an index table needs to be generated

hasVideo

    public bool hasVideo ( ) const ;

Does this MPEG contain a video stream.

hasAudio

    public bool hasAudio ( ) const ;

Does this MPEG contain an audio stream.

getMpegInfo

    public const MpegInfo & getMpegInfo ( CallBack cb = 0 ) ;

Return an MpegInfo object containing the information about the current MPEG.

The MPEG is only ever queried once about its information, and the result stored internally for reuse.

getMpegHeaderInfo

    public static MpegHeaderInfo getMpegHeaderInfo ( const string & pathname ) ;

Static method to return an MpegHeaderInfo object containing all the information about a particular MPEG file.

getMpegInfo

    public static MpegInfo getMpegInfo ( const string & pathname ,
                                         CallBack cb = 0 ) ;

Static method to return an MpegInfo object containing all the information about a particular MPEG file.

getFilename

    public const string & getFilename ( ) const ;

Return the complete pathname with filename.

getLastFrame

    public int getLastFrame ( ) ;

Return the number of frames in the MPEG.

Exception:
  mws.exception.MWSException if there was an error in the code

getFrameNumber

    public int getFrameNumber ( const TimeCode & timecode ) const ;

Return the frame number for the given timecode.

getTimeCode

    public TimeCode getTimeCode ( int frame ) const ;

Return the SMPTE timecode for the given frame number.

getFrameRate

    public float getFrameRate ( ) ;

Return the frame rate of the MPEG.

getFramesPerSecond

    public float getFramesPerSecond ( ) ;

Return the number of frames/sec for the MPEG.

getImageWidth

    public int getImageWidth ( float zoom = 1 . 0 ) ;

Return the width of the frames returned by getRGBImage() etc.

Note that image width is affected by the zoom factor and whether useAspectRatio() was set to true or false.

getImageHeight

    public int getImageHeight ( float zoom = 1 . 0 ) ;

Return the height of the frames returned by getRGBImage() etc.

Note that image height is affected by the zoom factor and whether useAspectRatio() was set to true or false.

getTotalTime

    public float getTotalTime ( ) ;

Return total time in seconds.

getNFrames

    public int getNFrames ( ) ;

Return total number of frames.

picOffset

    public fpos_t picOffset ( int frame ) const ;

Get the Offset of the picture with the given frame number.

picFrameNum

    public int picFrameNum ( fpos_t offset ) const ;

Get the frame number of the first picture after offset.

Return -1 if not found.

prevIOffset

    public fpos_t prevIOffset ( fpos_t offset ) const ;

Get offset of the previous I frame.

Return 0 if not found.

nextIOffset

    public fpos_t nextIOffset ( fpos_t offset ) const ;

Get offset of the next I frame.

Return 0 if not found.

setUseAspectRatio

    public void setUseAspectRatio ( bool flag ) ;

Set whether to use the video's aspect ratio when retrieving an image from an MPEG-2 video.

If set to true, getRGBImage() etc will shape the output image so that its width and height has the same ratio as the aspect ratio nominated in the MPEG. If set to false, the extracted image has the same width and height ratio as the pixels in the video. The default setting is false.

setDeinterlace

    public void setDeinterlace ( bool flag ) ;

Set whether to deinterlace the image when retrieving an image from an MPEG-2 video.

The default is false.

getRGBImage

    public const unsigned char * getRGBImage ( int frame ,
                                               float zoom = 1 . 0 ) const ;

Return an array of 24 bit unsigned chars containing the pixels of the given image, scaled and in the format of RGB.

getBGRImage

    public const unsigned char * getBGRImage ( int frame ,
                                               float zoom = 1 . 0 ) const ;

Return an array of 24 bit unsigned chars containing the pixels of the given image, scaled and in the format of BGR.

getXRGBImage

    public const unsigned char * getXRGBImage ( int frame ,
                                                float zoom = 1 . 0 ) const ;

Return an array of 32 bit unsigned chars containing the pixels of the given image, scaled and in the format of XRGB.

getXBGRImage

    public const unsigned char * getXBGRImage ( int frame ,
                                                float zoom = 1 . 0 ) const ;

Return an array of 32 bit unsigned chars containing the pixels of the given image, scaled and in the format of XBGR.

getRGBXImage

    public const unsigned char * getRGBXImage ( int frame ,
                                                float zoom = 1 . 0 ) const ;

Return an array of 32 bit unsigned chars containing the pixels of the given image, scaled and in the format of RGBX.

getBGRXImage

    public const unsigned char * getBGRXImage ( int frame ,
                                                float zoom = 1 . 0 ) const ;

Return an array of 32 bit unsigned chars containing the pixels of the given image, scaled and in the format of BGRX.

getPCMBite

    public const PCMBite * getPCMBite ( int frame ) ;

Return the first PCMBite after video frame frame.

A PCMBite consists of N channels of M 16-bit samples. N is obtained from the function PCMBite::nch() and M is obtained from the function PCMBite::getNumSamples(). The data in each channel is obtained with operator[](int ch).

Normally, a single call to getPCMBite(frame) is followed by a series of getNextPCMBite() and currentPCMBiteFrame() calls in a loop.

getNextPCMBite

    public const PCMBite * getNextPCMBite ( ) ;

Return the next PCMBite or 0 if there is none.

currentPCMBiteFrame

    public int currentPCMBiteFrame ( ) const ;

Return the closest video frame number corresponding to the most recent PCMBite resulting from getPCMBite() or getNextPCMBite().

saveToWAV

    public void saveToWAV ( int first_frame ,
                            int last_frame ,
                            const string & filename ,
                            CallBack cb = 0 ) ;

Save the audio clip between first_frame and last_frame to a file in WAV format.

If last_frame is -1, the audio clip is between first_frame and the end of the stream.

isIFrame

    public bool isIFrame ( int frame ) const ;

Whether the given frame is an I frame.

Returns false if the current MPEG is invalid or frame is out of range.

isIorPFrame

    public bool isIorPFrame ( int frame ) const ;

Whether the given frame is an I or a P frame.

Returns false if the current MPEG is invalid or frame is out of range.

nextIFrame

    public int nextIFrame ( int frame ) const ;

Get the frame number of the next I frame following the given frame.

Return -1 if not found.

prevIFrame

    public int prevIFrame ( int frame ) const ;

Get the frame number of the previous I frame to the given frame.

Return -1 if not found.

nextIorPFrame

    public int nextIorPFrame ( int frame ) const ;

Get the frame number of the next I or P frame following the given frame.

Return -1 if not found.

prevIorPFrame

    public int prevIorPFrame ( int frame ) const ;

Get the frame number of the previous I or P frame to the given frame.

Return -1 if not found.

sequence

    public string sequence ( int frame ) const ;

Return information about the sequence containing the given frame.

gop

    public string gop ( int frame ) const ;

Return information about the GOP containing the given frame.

picture

    public string picture ( int frame ) const ;

Return information about the specified frame.

saveToBMP

    public void saveToBMP ( int frame ,
                            const string & filename ,
                            float zoom = 1 . 0 ) const ;

Save the given frame to file in BMP format at the given zoom factor.

saveToJPEG

    public void saveToJPEG ( int frame ,
                             const string & filename ,
                             float zoom = 1 . 0 ) const ;

Save the given frame to file in JPEG format at the given zoom factor.

saveToTIFF

    public void saveToTIFF ( int frame ,
                             const string & filename ,
                             float zoom = 1 . 0 ) const ;

Save the given frame to file in TIFF format at the given zoom factor.

Copyright © 2000 Mediaware Solutions Pty Ltd
All rights reserved

Click here to return to the top of the page.