The buffered recorder class creates the video file from the images. More...
#include <recorder.h>
Public Member Functions | |
DISALLOW_COPY_AND_ASSIGN (Recorder) | |
Copy and assign of the class is not allowed. | |
unsigned int | countBuffered () |
Counts the currently buffered images. More... | |
unsigned int | getMissedFrames () |
Returns the count of the missed frames. More... | |
unsigned int | getRecordedFrames () |
Returns the recorded frames. More... | |
bool | isOpen () |
Returns the initialization status of the recorder. More... | |
bool | isTerminated () |
Retrieves the recorder status. More... | |
bool | open (const std::string &filename, int fourcc, double fps, cv::Size frameSize, bool isColor=true) |
Opens the video recorder. More... | |
RecorderStats | push (const cv::Mat &image) |
Pushes the new image to the buffer. More... | |
bool | repush () |
Repushes the last image again to the buffer. More... | |
void | stop () |
Softly stops the recording. More... | |
Static Public Member Functions | |
static void | detach (std::unique_ptr< Recorder > &&ptr) |
Detaches the recorder. More... | |
The buffered recorder class creates the video file from the images.
This is basically just a wrapper around cv::VideoWriter so that there is a simple buffer that allows multithreading. The class should only be used for one video file recording and then deleted. Once the recorder is succesfully opened, it cannot be re-opened even after termination.
When the recorder is to be opened, it is provided with all necessary information for the video file creation. The images are added to the buffer with push(). Recorder will write the contents of the buffer to the video file with the initialized parameters, and will continue to do so until it is terminated. Recorder can be stopped with stop() in order to finish writing the buffer contents. This allows it to flush the buffer contents and close the file properly.
Method isTerminated() can be used to check when Recorder has finished flushing the buffer after stop() signal. If Recorder object is destroyed before termination is successful, it will also destroy the rest of the buffer contents, thus leading into lost video frames. The destruction of Recorder should not leave video files corrupted, as it tries to close the files properly.
unsigned int cavapa_gui::Recorder::countBuffered | ( | ) |
Counts the currently buffered images.
|
inlinestatic |
Detaches the recorder.
It adds the recorder to a cleanup list that holds unfinished records, and let's them flush their buffer peacefully. The recorders on this list are destroyed on flushDetached() call, unless they have not yet terminated.
ptr | The recorder to be detached. |
unsigned int cavapa_gui::Recorder::getMissedFrames | ( | ) |
Returns the count of the missed frames.
The missed frames tell the amount of the frames that have been lost due to file writing errors. Most likely the file has no longer been open when the frames were supposed to be written.
unsigned int cavapa_gui::Recorder::getRecordedFrames | ( | ) |
Returns the recorded frames.
|
inline |
Returns the initialization status of the recorder.
bool cavapa_gui::Recorder::isTerminated | ( | ) |
Retrieves the recorder status.
bool cavapa_gui::Recorder::open | ( | const std::string & | filename, |
int | fourcc, | ||
double | fps, | ||
cv::Size | frameSize, | ||
bool | isColor = true |
||
) |
Opens the video recorder.
The parameters are the same as in cv::VideoWriter, and are passed directly to cv::VideoWriter::open.
filename | The name of the output video file. |
fourcc | The 4-character code of codec. |
fps | The framerate of the created video. |
frameSize | The size of the video frames. |
isColor | If it is not false, the encoder will expect and encode color frames. |
RecorderStats cavapa_gui::Recorder::push | ( | const cv::Mat & | image | ) |
Pushes the new image to the buffer.
image | The new OpenCV image. All the images buffered must match in size, otherwise the video file gets broken. |
bool cavapa_gui::Recorder::repush | ( | ) |
Repushes the last image again to the buffer.
void cavapa_gui::Recorder::stop | ( | ) |
Softly stops the recording.
This allows the recorder to write the rest of the frames to the buffer. Recorder cannot be restarted after this. If the recorder is deleted before the buffer has finished writing, the frames will be lost forever. Use terminated() to see when the buffer has finished flushing.