The VideoEncoder class supports encoding a series of images to a video format, and then writing the video to disk. More...
#include <common/common.hh>
Public Member Functions | |
VideoEncoder () | |
Constructor. More... | |
virtual | ~VideoEncoder () |
Destructor. More... | |
bool | AddFrame (const unsigned char *_frame, const unsigned int _width, const unsigned int _height) |
Add a single frame to be encoded. More... | |
bool | AddFrame (const unsigned char *_frame, const unsigned int _width, const unsigned int _height, const std::chrono::steady_clock::time_point &_timestamp) |
Add a single timestamped frame to be encoded. More... | |
unsigned int | BitRate () const |
Get the bit rate. More... | |
std::string | Format () const |
Get the encoding format. More... | |
bool | IsEncoding () const |
True if the enoder has been started, false otherwise. More... | |
void | Reset () |
Reset to default video properties and clean up allocated memory. More... | |
bool | SaveToFile (const std::string &_filename) |
Write the video to disk param[in] _filename File in which to save the encoded data. More... | |
bool | Start (const std::string &_format="mp4", const std::string &_filename="", const unsigned int _width=1280, const unsigned int _height=720, const unsigned int _fps=25, const unsigned int _bitRate=0) |
Start the encoder. More... | |
bool | Stop () |
Stop the encoder. More... | |
The VideoEncoder class supports encoding a series of images to a video format, and then writing the video to disk.
VideoEncoder | ( | ) |
Constructor.
|
virtual |
Destructor.
bool AddFrame | ( | const unsigned char * | _frame, |
const unsigned int | _width, | ||
const unsigned int | _height | ||
) |
Add a single frame to be encoded.
[in] | _frame | Image buffer to be encoded |
[in] | _width | Input frame width |
[in] | _height | Input frame height |
bool AddFrame | ( | const unsigned char * | _frame, |
const unsigned int | _width, | ||
const unsigned int | _height, | ||
const std::chrono::steady_clock::time_point & | _timestamp | ||
) |
Add a single timestamped frame to be encoded.
[in] | _frame | Image buffer to be encoded |
[in] | _width | Input frame width |
[in] | _height | Input frame height |
[in] | _timestamp | Timestamp of the image frame |
unsigned int BitRate | ( | ) | const |
Get the bit rate.
std::string Format | ( | ) | const |
Get the encoding format.
bool IsEncoding | ( | ) | const |
True if the enoder has been started, false otherwise.
void Reset | ( | ) |
Reset to default video properties and clean up allocated memory.
This will also delete any temporary files.
bool SaveToFile | ( | const std::string & | _filename | ) |
Write the video to disk param[in] _filename File in which to save the encoded data.
bool Start | ( | const std::string & | _format = "mp4" , |
const std::string & | _filename = "" , |
||
const unsigned int | _width = 1280 , |
||
const unsigned int | _height = 720 , |
||
const unsigned int | _fps = 25 , |
||
const unsigned int | _bitRate = 0 |
||
) |
Start the encoder.
This should be called once. Add new frames to the video using the AddFrame function. Use SaveToFile when the video is complete.
[in] | _width | Width in pixels of the output video. |
[in] | _height | Height in pixels of the output video. |
[in] | _format | String that represents the video type. Supported types include: "avi", "ogv", mp4", "v4l2". If using "v4l2", you must also specify a _filename. |
[in] | _bitRate | Bit rate to encode the video. A value of zero will cause this function to automatically compute a bitrate. |
[in] | _filename | Name of the file that stores the video while it is being created. This is a temporary file when recording to disk, or a video4linux loopback device like /dev/video0 when the _format is "v4l2". If blank, a default temporary file is used. However, the "v4l2" _format must be accompanied with a video loopback device filename. |
bool Stop | ( | ) |
Stop the encoder.
The SaveToFile function also calls this function.