class mrpt::vision::CVideoFileWriter

An output stream which takes a sequence of images and writes a video file in any of a given of compatible formats.

The output file is open when calling “open”, and it’s closed at destructor or after calling “close”.

Example of usage:

CVideoFileWriter  vid;
vid.open("test.avi",15,TPixelCoord(320,200), "MJPG");
CImage  img(320,200);
vid << img;
vid.close;

There are two methods for adding frames to the video:

  • The operator <<: Which will raise an exception on any error.

  • The method writeImage, which does not raise any exception on errors.

This class is a wrapper for OpenCV’s CvVideoWriter.

#include <mrpt/vision/CVideoFileWriter.h>

class CVideoFileWriter
{
public:
    // structs

    struct Impl;

    // construction

    CVideoFileWriter();

    //
methods

    bool open(
        const std::string& out_file,
        double fps,
        const mrpt::img::TImageSize& frameSize,
        const std::string& fourcc = std::string(""),
        bool isColor = true
        );

    void close();
    bool isOpen() const;
    const CVideoFileWriter& operator << (const mrpt::img::CImage& img);
    bool writeImage(const mrpt::img::CImage& img);
};

Construction

CVideoFileWriter()

Default constructor, which does not open any file.

Methods

bool open(
    const std::string& out_file,
    double fps,
    const mrpt::img::TImageSize& frameSize,
    const std::string& fourcc = std::string(""),
    bool isColor = true
    )

Open a file for writing the video.

If fourcc is left as an empty string a default codec will be seleceted (e.g. “IYUV”).

Other valid values for “fourcc” are: “PIM1” -> MPEG1, “MJPG” -> Motion JPEG, “XVID”, etc…

Parameters:

out_file

The video file to create for output.

fourcc

The video codec, as a string. See notes below. fps The video FPS (frames per seconds).

frameSize

The size of the video frames. All subsequent images must be of this size.

isColor

Set to false to create a grayscale video.

Returns:

false on any error, true on success.

void close()

Finish the file writing and close the file output.

bool isOpen() const

Return true if already successfully open with open() and not closed yet.

const CVideoFileWriter& operator << (const mrpt::img::CImage& img)

Write image to the video file.

Parameters:

std::exception

On any error

bool writeImage(const mrpt::img::CImage& img)

Write image to the video file (method function, alternative to the operator <<).

Returns:

false on any error