class mola::VideoRecorder

Overview

Records frames rendered off-screen (an OpenGL framebuffer object of a fixed size, independent of the window size and visibility) to a video file, by piping raw RGBA to an ffmpeg process. The wall clock time (UNIX, seconds) of each frame is written to <output>.times.txt, one line per frame, to align the video with other logs (e.g. when editing it). Every rendered frame becomes one video frame at fps : the render loop should run at that rate (if it is slower, the video plays faster than real time, but without repeated frames).

All methods must be called from the thread owning the OpenGL context.

#include <VideoRecorder.h>

class VideoRecorder
{
public:
    // typedefs

    typedef std::function<void(mrpt::system::VerbosityLevel, const std::string&)> Logger;

    // structs

    struct Params;

    // construction

    VideoRecorder(Params p);
    VideoRecorder(const VideoRecorder&);
    VideoRecorder(VideoRecorder&&);

    // methods

    VideoRecorder& operator = (const VideoRecorder&);
    VideoRecorder& operator = (VideoRecorder&&);
    void begin_frame();
    void end_frame(int windowWidth, int windowHeight);
    void close();
    bool failed() const;
    std::size_t frames_written() const;
    double effective_fps() const;
};

Construction

VideoRecorder(Params p)

Parameters:

std::invalid_argument

on non-positive sizes or rate.

Methods

void begin_frame()

Binds the off-screen framebuffer (created on first use): draw the frame next. On failure (see failed()), the window framebuffer stays bound.

void end_frame(int windowWidth, int windowHeight)

Records the frame drawn since begin_frame(), binds the window framebuffer again and copies the frame into it, scaled to the given window framebuffer size, as a preview.

void close()

Finishes the video (waits for ffmpeg) and releases the GL objects.

bool failed() const

True once recording failed (no ffmpeg, write error…): nothing is recorded.

double effective_fps() const

Frames per second actually rendered so far.