ViSP  2.6.2
vpVideoWriter Class Reference

#include <vpVideoWriter.h>

Public Member Functions

 vpVideoWriter ()
 
 ~vpVideoWriter ()
 
void setFirstFrameIndex (const unsigned int firstFrame)
 
void resetFrameCounter ()
 
unsigned int getCurrentFrameIndex () const
 
void setBitRate (const unsigned int bit_rate)
 
void setCodec (const CodecID codec)
 
void setFileName (const char *filename)
 
void open (vpImage< vpRGBa > &I)
 
void open (vpImage< unsigned char > &I)
 
void saveFrame (vpImage< vpRGBa > &I)
 
void saveFrame (vpImage< unsigned char > &I)
 
void close ()
 

Detailed Description

Class that enables to write easily a video file or a sequence of images.

The following example shows how this class is really easy to use. It enable to write an image sequence. The images are stored in the folder "./image" and are named "image0000.jpeg", "image0001.jpeg", "image0002.jpeg", ...

#include <visp/vpConfig.h>
#include <visp/vpVideoWriter.h>
int main()
{
//Initialize the writer.
writer.setFileName("./image/image%04d.jpeg");
writer.open(I);
for ( ; ; )
{
//Here the code to capture or create an image and stores it in I.
//Save the image
writer.saveFrame(I);
}
writer.close();
return 0;
}

The other following example explains how to use the class to write directly an mpeg file.

#include <visp/vpConfig.h>
#include <visp/vpVideoWriter.h>
#ifdef VISP_HAVE_FFMPEG
int main()
{
//Set up the bit rate
writer.setBitRate(1000000);
//Set up the codec to use
writer.setCodec(CODEC_ID_MPEG1VIDEO);
writer.setFileName("./test.mpeg");
writer.open(I);
for ( ; ; )
{
//Here the code to capture or create an image and stores it in I.
//Save the image
writer.saveFrame(I);
}
writer.close();
return 0;
}
#else
int main() {}
#endif

Definition at line 131 of file vpVideoWriter.h.

Constructor & Destructor Documentation

vpVideoWriter::vpVideoWriter ( )

Basic constructor.

Definition at line 54 of file vpVideoWriter.cpp.

vpVideoWriter::~vpVideoWriter ( )

Basic destructor.

Definition at line 71 of file vpVideoWriter.cpp.

Member Function Documentation

void vpVideoWriter::close ( )

Deallocates parameters use to write the video or the image sequence.

Definition at line 279 of file vpVideoWriter.cpp.

References vpFFMPEG::endWrite(), vpException::notInitialized, and vpERROR_TRACE.

unsigned int vpVideoWriter::getCurrentFrameIndex ( ) const
inline

Gets the current frame index.

Returns
Returns the current frame index.

Definition at line 200 of file vpVideoWriter.h.

void vpVideoWriter::open ( vpImage< vpRGBa > &  I)

Sets all the parameters needed to write the video or the image sequence.

Parameters
I: One image with the right dimensions.

Definition at line 108 of file vpVideoWriter.cpp.

References vpException::fatalError, vpImage< Type >::getHeight(), vpImage< Type >::getWidth(), vpException::ioError, vpImageException::noFileNameError, vpFFMPEG::openEncoder(), vpFFMPEG::setBitRate(), and vpERROR_TRACE.

void vpVideoWriter::open ( vpImage< unsigned char > &  I)

Sets all the parameters needed to write the video or the image sequence.

Parameters
I: One image with the right dimensions.

Definition at line 156 of file vpVideoWriter.cpp.

References vpException::fatalError, vpImage< Type >::getHeight(), vpImage< Type >::getWidth(), vpException::ioError, vpImageException::noFileNameError, vpFFMPEG::openEncoder(), vpFFMPEG::setBitRate(), and vpERROR_TRACE.

void vpVideoWriter::resetFrameCounter ( )
inline

Reset the frame counter and sets it to the first image index.

By default the first frame index is set to 0.

Definition at line 193 of file vpVideoWriter.h.

void vpVideoWriter::saveFrame ( vpImage< vpRGBa > &  I)

Saves the image as a frame of the video or as an image belonging to the image sequence.

Each time this method is used, the frame counter is incremented and thus the file name change for the case of an image sequence.

Parameters
I: The image which has to be saved

Definition at line 206 of file vpVideoWriter.cpp.

References vpException::notInitialized, vpFFMPEG::saveFrame(), vpERROR_TRACE, and vpImageIo::write().

void vpVideoWriter::saveFrame ( vpImage< unsigned char > &  I)

Saves the image as a frame of the video or as an image belonging to the image sequence.

Each time this method is used, the frame counter is incremented and thus the file name change for the case of an image sequence.

Parameters
I: The image which has to be saved

Definition at line 245 of file vpVideoWriter.cpp.

References vpException::notInitialized, vpFFMPEG::saveFrame(), vpERROR_TRACE, and vpImageIo::write().

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

Sets the bit rate of the video when writing.

Parameters
bit_rate: the expected bit rate.

By default the bit rate is set to 500 000.

Definition at line 210 of file vpVideoWriter.h.

void vpVideoWriter::setCodec ( const CodecID  codec)
inline

Sets the codec used to encode the video.

Parameters
codec: the expected codec.

By default the 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.

Definition at line 221 of file vpVideoWriter.h.

void vpVideoWriter::setFileName ( const char *  filename)

It enables to set the path and the name of the files which will be saved.

If you want to write a sequence of images, $ filename $ corresponds to the path followed by the image name template. For exemple, if you want to write different images named image0001.jpeg, image0002.jpg, ... and located in the folder /local/image, $ filename $ will be "/local/image/image%04d.jpg".

Parameters
filename: filename template of an image sequence.

Definition at line 87 of file vpVideoWriter.cpp.

References vpImageException::noFileNameError, and vpERROR_TRACE.

void vpVideoWriter::setFirstFrameIndex ( const unsigned int  firstFrame)
inline

Enables to set the first frame index.

Parameters
firstFrame: The first frame index.

Definition at line 186 of file vpVideoWriter.h.