MPEG SDK --> 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().
MpegDecoder
MpegDecoder
~MpegDecoder
currentPCMBiteFrame
getBGRImage
getBGRXImage
getFilename
getFrameNumber
getFrameRate
getFramesPerSecond
getImageHeight
getImageWidth
getLastFrame
getMpegHeaderInfo
getMpegInfo
getMpegInfo
getNextPCMBite
getNFrames
getPCMBite
getRGBImage
getRGBXImage
getTimeCode
getTotalTime
getXBGRImage
getXRGBImage
gop
hasAudio
hasVideo
isIFrame
isIorPFrame
nextIFrame
nextIOffset
nextIorPFrame
openFile
picFrameNum
picOffset
picture
prevIFrame
prevIOffset
prevIorPFrame
saveToBMP
saveToJPEG
saveToTIFF
saveToWAV
sequence
setAuxFilesPath
setDeinterlace
setUseAspectRatio
public MpegDecoder ( ) ;
Default constructor.
Constructs a MpegDecoder with no file. Most functions except the openFile function will push an error.
public MpegDecoder ( const string & filename ,
CallBack cb = 0 ) ;
Construct a MpegDecoder for the given file.
| 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 |
public ~ MpegDecoder ( ) ;
Destructor.
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.
public void openFile ( const string & filename ,
CallBack cb = 0 ) ;
Open a new file with this decoder and reset all variables.
| filename | name of the MPEG file to open |
| cb | callback to use if an index table needs to be generated |
public bool hasVideo ( ) const ;
Does this MPEG contain a video stream.
public bool hasAudio ( ) const ;
Does this MPEG contain an audio stream.
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.
public static MpegHeaderInfo getMpegHeaderInfo ( const string & pathname ) ;
Static method to return an MpegHeaderInfo object containing all the information about a particular MPEG file.
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.
public const string & getFilename ( ) const ;
Return the complete pathname with filename.
public int getLastFrame ( ) ;
Return the number of frames in the MPEG.
public int getFrameNumber ( const TimeCode & timecode ) const ;
Return the frame number for the given timecode.
public TimeCode getTimeCode ( int frame ) const ;
Return the SMPTE timecode for the given frame number.
public float getFrameRate ( ) ;
Return the frame rate of the MPEG.
public float getFramesPerSecond ( ) ;
Return the number of frames/sec for the MPEG.
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.
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.
public float getTotalTime ( ) ;
Return total time in seconds.
public int getNFrames ( ) ;
Return total number of frames.
public fpos_t picOffset ( int frame ) const ;
Get the Offset of the picture with the given frame number.
public int picFrameNum ( fpos_t offset ) const ;
Get the frame number of the first picture after offset.
Return -1 if not found.
public fpos_t prevIOffset ( fpos_t offset ) const ;
Get offset of the previous I frame.
Return 0 if not found.
public fpos_t nextIOffset ( fpos_t offset ) const ;
Get offset of the next I frame.
Return 0 if not found.
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.
public void setDeinterlace ( bool flag ) ;
Set whether to deinterlace the image when retrieving an image from an MPEG-2 video.
The default is false.
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.
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.
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.
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.
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.
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.
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.
public const PCMBite * getNextPCMBite ( ) ;
Return the next PCMBite or 0 if there is none.
public int currentPCMBiteFrame ( ) const ;
Return the closest video frame number corresponding to the most recent PCMBite resulting from getPCMBite() or getNextPCMBite().
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.
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.
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.
public int nextIFrame ( int frame ) const ;
Get the frame number of the next I frame following the given frame.
Return -1 if not found.
public int prevIFrame ( int frame ) const ;
Get the frame number of the previous I frame to the given frame.
Return -1 if not found.
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.
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.
public string sequence ( int frame ) const ;
Return information about the sequence containing the given frame.
public string gop ( int frame ) const ;
Return information about the GOP containing the given frame.
public string picture ( int frame ) const ;
Return information about the specified frame.
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.
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.
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.
Click here to return to the top of the page.