Easy3D 2.5.3
VideoEncoder Class Reference

A class that encodes video frames (e.g., images) into a video file. More...

#include <easy3d/video/video_encoder.h>

Public Types

enum  PixelFormat { PIX_FMT_RGB_888 , PIX_FMT_BGR_888 , PIX_FMT_RGBA_8888 , PIX_FMT_BGRA_8888 }
 The supported pixel format/storage of the video frames. More...
 

Public Member Functions

 VideoEncoder ()
 Constructor.
 
 ~VideoEncoder ()
 Destructor.
 
bool start (const std::string &file_name, int framerate, int bitrate)
 
bool encode (const unsigned char *data, int width, int height, PixelFormat pixel_format)
 
bool end ()
 

Static Public Member Functions

static bool is_size_acceptable (int width, int height)
 Returns whether the image size (width, height) is acceptable.
 

Detailed Description

A class that encodes video frames (e.g., images) into a video file.

The output format is automatically guessed according to the file extension. Below is an example of usage:

VideoEncoder encoder;
encoder.start(output_file, 30, 100 * 1024 * 1024); // 30 fps, 100 Mbit/s
for (std::size_t i = 0; i < image_files.size(); ++i) {
std::vector<unsigned char> data;
int w, h, c;
if (ImageIO::load(file_name, data, w, h, c, 0, false))
encoder.encode(data.data(), w, h, VideoEncoder::PIX_FMT_RGBA_8888);
}
encoder.end();
static bool load(const std::string &file_name, std::vector< unsigned char > &data, int &width, int &height, int &channels, int requested_channels=0, bool flip_vertically=true)
Load image data from a file. The following formats are supported JPG/JPEG, PNG, BMP,...
Definition: image_io.cpp:41
@ PIX_FMT_RGBA_8888
packed BGR 8:8:8, 24bpp, BGRBGR...
Definition: video_encoder.h:69
VideoEncoder()
Constructor.
Definition: video_encoder.cpp:418

Member Enumeration Documentation

◆ PixelFormat

The supported pixel format/storage of the video frames.

Enumerator
PIX_FMT_BGR_888 

packed RGB 8:8:8, 24bpp, RGBRGB...

PIX_FMT_RGBA_8888 

packed BGR 8:8:8, 24bpp, BGRBGR...

PIX_FMT_BGRA_8888 

packed RGBA 8:8:8:8, 32bpp, RGBARGBA...

packed BGRA 8:8:8:8, 32bpp, BGRABGRA...

Member Function Documentation

◆ encode()

bool encode ( const unsigned char *  data,
int  width,
int  height,
PixelFormat  pixel_format 
)

Encode one frame to the video stream.

Parameters
dataThe input image data. It is a 1D array of 'unsigned char' which points to the pixel data. The pixel data consists of 'height' rows of 'width' pixels, with each pixel has one of the following structures. The correspondences between these structures and pixel/OpenGL formats are: RGB 8:8:8, 24bpp <—> PIX_FMT_RGB_888 <—> GL_RGB BGR 8:8:8, 24bpp <—> PIX_FMT_BGR_888 <—> GL_BGR RGBA 8:8:8:8, 32bpp <—> PIX_FMT_RGBA_8888 <—> GL_RGBA BGRA 8:8:8:8, 32bpp <—> PIX_FMT_BGRA_8888 <—> GL_BGRA
Returns
true on successful.

◆ end()

bool end ( )

Finish encoding all the frames.

Note
It must be called after encoding all frames.

◆ start()

bool start ( const std::string &  file_name,
int  framerate,
int  bitrate 
)
Parameters
file_nameThe name of the output video file, e.g., "C:/result.mp4". The output format is automatically guessed according to the file extension.

The documentation for this class was generated from the following files: