ViSP  2.6.2
vpFFMPEG Class Reference

#include <vpFFMPEG.h>

Public Types

enum  vpFFMPEGColorType { COLORED, GRAY_SCALED }
 

Public Member Functions

 vpFFMPEG ()
 
 ~vpFFMPEG ()
 
int getWidth () const
 
int getHeight () const
 
unsigned long getFrameNumber () const
 
void setBitRate (const unsigned int bit_rate)
 
bool openStream (const char *filename, vpFFMPEGColorType color_type)
 
bool initStream ()
 
void closeStream ()
 
bool acquire (vpImage< vpRGBa > &I)
 
bool acquire (vpImage< unsigned char > &I)
 
bool getFrame (vpImage< vpRGBa > &I, unsigned int frameNumber)
 
bool getFrame (vpImage< unsigned char > &I, unsigned int frameNumber)
 
bool openEncoder (const char *filename, unsigned int width, unsigned int height, CodecID codec=CODEC_ID_MPEG1VIDEO)
 
bool saveFrame (vpImage< vpRGBa > &I)
 
bool saveFrame (vpImage< unsigned char > &I)
 
bool endWrite ()
 

Detailed Description

This class interfaces the FFmpeg library to enable the reading of video files.

Here an example which explains how to use the class.

#include <visp/vpConfig.h>
#include <visp/vpImage.h>
#include <visp/vpRGBa.h>
#include <visp/vpFFMPEG.h>
int main ()
{
#ifdef VISP_HAVE_FFMPEG
vpImage<vpRGBa> I; //The image to stores the frames
vpFFMPEG ffmpeg;
//Initialization
ffmpeg.openStream("video.mpeg",vpFFMPEG::COLORED);
ffmepg.initStream();
//Video reading
int frameIndex = 0;
ffmpeg.getFrame(I,frameIndex); //Here the first frame (index 0) is read.
#endif
}

If you want to open the video as a gray scaled video, you can use the following example.

#include <visp/vpConfig.h>
#include <visp/vpImage.h>
#include <visp/vpFFMPEG.h>
int main ()
{
#ifdef VISP_HAVE_FFMPEG
vpImage<unsigned char> I; //The image to stores the frames
vpFFMPEG ffmpeg;
//Initialization
ffmpeg.openStream("video.mpeg",vpFFMPEG::GRAY_SCALED);
ffmepg.initStream();
//Video reading
int frameIndex = 0;
ffmpeg.getFrame(I,frameIndex); //Here the first frame (index 0) is read.
#endif
}

Definition at line 154 of file vpFFMPEG.h.

Member Enumeration Documentation

Enumerator
COLORED 
GRAY_SCALED 

Definition at line 157 of file vpFFMPEG.h.

Constructor & Destructor Documentation

vpFFMPEG::vpFFMPEG ( )

Basic constructor.

Definition at line 67 of file vpFFMPEG.cpp.

vpFFMPEG::~vpFFMPEG ( )

Basic destructor.

Definition at line 86 of file vpFFMPEG.cpp.

References closeStream().

Member Function Documentation

bool vpFFMPEG::acquire ( vpImage< vpRGBa > &  I)

Gets the Next frame in the video.

Parameters
I: The vpImage used to stored the video's frame.
Returns
It returns true if the frame could be read. Else it returns false.

Definition at line 328 of file vpFFMPEG.cpp.

References COLORED, GRAY_SCALED, and vpTRACE.

Referenced by vpVideoReader::acquire().

bool vpFFMPEG::acquire ( vpImage< unsigned char > &  I)

Gets the Next frame in the video.

Parameters
I: The vpImage used to stored the video's frame.
Returns
It returns true if the frame could be read. Else it returns false.

Definition at line 425 of file vpFFMPEG.cpp.

References COLORED, GRAY_SCALED, and vpTRACE.

void vpFFMPEG::closeStream ( )

Deallocates all the FFMPEG parameters.

Definition at line 578 of file vpFFMPEG.cpp.

References COLORED, endWrite(), and GRAY_SCALED.

Referenced by ~vpFFMPEG().

bool vpFFMPEG::endWrite ( )

Ends the writing of the video and close the file.

Returns
It returns true if the file was closed without problem

Definition at line 763 of file vpFFMPEG.cpp.

References vpTRACE.

Referenced by vpVideoWriter::close(), and closeStream().

bool vpFFMPEG::getFrame ( vpImage< vpRGBa > &  I,
unsigned int  frame 
)

Gets the $ frame $ th frame from the video and stores it in the image $ I $.

Parameters
I: The vpImage used to stored the video's frame.
frame: The index of the frame which has to be read.
Returns
It returns true if the frame could be read. Else it returns false.

Definition at line 275 of file vpFFMPEG.cpp.

References COLORED, GRAY_SCALED, and vpTRACE.

Referenced by vpVideoReader::getFrame().

bool vpFFMPEG::getFrame ( vpImage< unsigned char > &  I,
unsigned int  frame 
)

Gets the $ frame $ th frame from the video and stores it in the image $ I $.

Parameters
I: The vpImage used to stored the video's frame.
frame: The index of the frame which has to be read.
Returns
It returns true if the frame could be read. Else it returns false.

Definition at line 372 of file vpFFMPEG.cpp.

References COLORED, GRAY_SCALED, and vpTRACE.

unsigned long vpFFMPEG::getFrameNumber ( ) const
inline

Gets the video's frame number.

Returns
The value of the video's frame number.

Definition at line 224 of file vpFFMPEG.h.

int vpFFMPEG::getHeight ( ) const
inline

Gets the video's height.

Returns
The value of the video's height.

Definition at line 217 of file vpFFMPEG.h.

int vpFFMPEG::getWidth ( ) const
inline

Gets the video's width.

Returns
The value of the video's width.

Definition at line 210 of file vpFFMPEG.h.

bool vpFFMPEG::initStream ( )

This method initializes the conversion parameters.

It browses the video and lists all the frame. It sets the number of frame in the video.

Returns
It returns true if the method was executed without any problem. Else it returns false.

Definition at line 217 of file vpFFMPEG.cpp.

References COLORED, GRAY_SCALED, and vpTRACE.

Referenced by vpVideoReader::open().

bool vpFFMPEG::openEncoder ( const char *  filename,
unsigned int  width,
unsigned int  height,
CodecID  codec = CODEC_ID_MPEG1VIDEO 
)

Allocates and initializes the parameters depending on the video to write.

Parameters
filename: Path to the video which has to be writen.
width: Width of the image which will be saved.
height: Height of the image which will be saved.
codec: Type of codec used to encode the video.

By default codec is set to CODEC_ID_MPEG1VIDEO. But you can use one of the CodecID proposed by ffmpeg such as : CODEC_ID_MPEG2VIDEO, CODEC_ID_MPEG2VIDEO_XVMC, CODEC_ID_MPEG4, CODEC_ID_H264, ... (More CodecID can be found in the ffmpeg documentation).

Of course to use the codec it must be installed on your computer.

Returns
It returns true if the paramters could be initialized. Else it returns false.

Definition at line 642 of file vpFFMPEG.cpp.

Referenced by vpVideoWriter::open().

bool vpFFMPEG::openStream ( const char *  filename,
vpFFMPEGColorType  color_type 
)

Allocates and initializes the parameters depending on the video and the desired color type.

Parameters
filename: Path to the video which has to be read.
color_type: Desired color map used to open the video. The parameter can take two values : COLORED and GRAY_SCALED.
Returns
It returns true if the paramters could be initialized. Else it returns false.

Definition at line 101 of file vpFFMPEG.cpp.

References COLORED, GRAY_SCALED, and vpTRACE.

Referenced by vpVideoReader::open().

bool vpFFMPEG::saveFrame ( vpImage< vpRGBa > &  I)

Saves the image I as frame of the video.

Parameters
I: the image to save.
Returns
It returns true if the image could be saved.

Definition at line 718 of file vpFFMPEG.cpp.

References vpTRACE.

Referenced by vpVideoWriter::saveFrame().

bool vpFFMPEG::saveFrame ( vpImage< unsigned char > &  I)

Saves the image I as frame of the video.

Parameters
I: the image to save.
Returns
It returns true if the image could be saved.

Definition at line 742 of file vpFFMPEG.cpp.

References vpTRACE.

void vpFFMPEG::setBitRate ( const unsigned int  bit_rate)
inline

Sets the bit rate of the video when writing.

Parameters
bit_rate: the expected bit rate.

Definition at line 231 of file vpFFMPEG.h.

Referenced by vpVideoWriter::open().