A class that encodes video frames (e.g., images) into a video file.
More...
#include <easy3d/video/video_encoder.h>
|
| VideoEncoder (const std::string &file_name, int framerate=30, int bitrate=8 *1024 *1024) |
| Constructor to initialize the video encoder.
|
|
| ~VideoEncoder () |
| Destructor to clean up resources.
|
|
bool | encode (const unsigned char *image_data, int width, int height, PixelFormat pixel_format) |
| Encodes one frame to the video stream.
|
|
|
static bool | is_size_acceptable (int width, int height) |
| Checks if the image size (width, height) is acceptable.
|
|
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:
for (std::size_t i = 0; i < image_files.size(); ++i) {
std::vector<unsigned char> data;
int w, h, c;
}
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.
Definition image_io.cpp:41
VideoEncoder(const std::string &file_name, int framerate=30, int bitrate=8 *1024 *1024)
Constructor to initialize the video encoder.
Definition video_encoder.cpp:595
@ PIX_FMT_RGB_888
Packed RGB 8:8:8, 24bpp, RGBRGB...
Definition video_encoder.h:76
@ PIX_FMT_RGBA_8888
Packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition video_encoder.h:78
◆ PixelFormat
The supported pixel formats for the video frames.
Enumerator |
---|
PIX_FMT_RGB_888 | Packed RGB 8:8:8, 24bpp, RGBRGB...
|
PIX_FMT_BGR_888 | Packed BGR 8:8:8, 24bpp, BGRBGR...
|
PIX_FMT_RGBA_8888 | Packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
|
PIX_FMT_BGRA_8888 | Packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
|
◆ VideoEncoder()
VideoEncoder |
( |
const std::string & | file_name, |
|
|
int | framerate = 30, |
|
|
int | bitrate = 8 * 1024 * 1024 ) |
|
explicit |
Constructor to initialize the video encoder.
- Parameters
-
file_name | The name of the output video file, e.g., "D:/result.mp4". The output format is automatically guessed according to the file extension, which can be:
- mp4: MPEG-4 Part 14;
- mpeg: MPEG-1 Systems / MPEG program stream;
- avi: Audio Video Interleaved;
- mov: QuickTime / MOV; If it can't be guessed this way then "mp4" is used by default.
|
framerate | The frame rate (normally between 25 and 60, default is 30 fps). |
bitrate | The bit rate (default is 8 Mbits/sec). |
◆ encode()
bool encode |
( |
const unsigned char * | image_data, |
|
|
int | width, |
|
|
int | height, |
|
|
PixelFormat | pixel_format ) |
Encodes one frame to the video stream.
- Parameters
-
image_data | The input image data as a 1D array of 'unsigned char' pointing to the pixel data. The pixel data consists of 'height' rows of 'width' pixels, with each pixel has one of the following structures. |
width | The video width (must be a multiple of 8). |
height | The video height (must be a multiple of 8). |
pixel_format | The pixel format. Correspondences between image 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 success, false otherwise.
◆ is_size_acceptable()
static bool is_size_acceptable |
( |
int | width, |
|
|
int | height ) |
|
inlinestatic |
Checks if the image size (width, height) is acceptable.
- Parameters
-
width | The width of the image. |
height | The height of the image. |
- Returns
- True if the size is acceptable, false otherwise.
The documentation for this class was generated from the following files:
- G:/3_code/Easy3D/easy3d/video/video_encoder.h
- G:/3_code/Easy3D/easy3d/video/video_encoder.cpp