
VCodecUniversal C++ library
v1.0.0
Table of contents
- Overview
- Versions
- Library files
- VCodecUniversal class description
- Build and connect to your project
- Portability
- Simple example
- Test application
Overview
The VCodecUniversal C++ library provides video encoding and decoding of H264, HEVC (H.265) and JPEG with one class for all platforms. The library does not encode or decode itself: it uses the codec libraries VCodecWmf, VCodecNv, VCodecLibva, VCodecV4L2, VCodecImxVpu, VDecoderH264, VDecoderH265, VDecoderJPEG and VEncoderJPEG. CMake builds the codec libraries that can be built for the target system (see Build and connect to your project) and reports them; at run time the library selects for every stream the first codec library of Table 1 that works on the computer. The VCodecUniversal class implements the VCodec interface, the public header VCodecUniversal.h includes only standard C++ headers and VCodec.h. The library is written in C++17 and is supplied as source code only.
VCodecUniversal is general-purpose software: it is not tied to any sector or application, and the developer of a program decides what the program does with it.
Table 1 - Codec libraries in the order of use. A codec library is used only if CMake built it and it works on the computer.
| System | Encoding H264 | Encoding HEVC | Encoding JPEG | Decoding H264 | Decoding HEVC | Decoding JPEG |
|---|---|---|---|---|---|---|
| Windows | VCodecWmf | VCodecWmf | VCodecWmf | VCodecWmf | VCodecWmf | VCodecWmf |
| Linux | VCodecNv, VCodecLibva (order: CUSTOM_3), VCodecImxVpu, VCodecV4L2 | VCodecNv, VCodecLibva (order: CUSTOM_3), VCodecV4L2 | VCodecLibva, VCodecV4L2, VEncoderJPEG | VCodecNv, VCodecLibva (order: CUSTOM_3), VCodecV4L2, VDecoderH264 | VCodecNv, VCodecLibva (order: CUSTOM_3), VCodecV4L2, VDecoderH265 | VCodecNv, VCodecLibva (order: CUSTOM_3), VCodecV4L2, VDecoderJPEG |
| Other systems | - | - | VEncoderJPEG | VDecoderH264 | VDecoderH265 | VDecoderJPEG |
The codec libraries:
- VCodecWmf - Windows: VCodecUniversal encodes and decodes H264 and HEVC with the hardware codecs of the GPU when they are available, and with the software codecs of Microsoft Media Foundation otherwise. VCodecWmf selects the codec itself, in this order: NVIDIA GPU (NVENC/NVDEC), Intel GPU (Quick Sync), AMD GPU (AMF), software codec. The order is chosen by the vendor of the GPU, not by the type of the GPU (dedicated or integrated). JPEG is always encoded and decoded with the software codec of Windows Imaging Component (WIC).
- VCodecNv - Linux: hardware encoder (NVENC) and decoder (NVDEC) of NVIDIA GPUs. VCodecNv is used if the GPU driver works (the library loads libcuda.so.1, initializes it, needs at least one GPU and the decoder library libnvcuvid.so.1 or the encoder library libnvidia-encode.so.1). VCodecNv decodes JPEG images with NVDEC; it is not used for JPEG encoding (it has no hardware JPEG encoder).
- VCodecLibva - Linux: hardware codecs of GPUs with a VA-API driver (Intel GPUs). VCodecLibva is used for a format if the VA-API driver of the first DRM device with a working VA display (/dev/dri/renderD128, /dev/dri/card0, /dev/dri/renderD129, /dev/dri/card1) has the profile and the entry point of the format, and for decoding only for streams that it decodes (4:2:0; H264 with 8 bits, HEVC with 8 or 10 bits).
- VCodecImxVpu - Linux on i.MX8M Mini: Hantro H1 hardware H264 encoder.
- VCodecV4L2 - Linux: hardware codecs with a V4L2 memory-to-memory driver (NVIDIA Jetson, Raspberry Pi 4 and others).
- VDecoderH264, VDecoderH265, VDecoderJPEG, VEncoderJPEG - software codecs of all systems except Windows. There is no software H264 and HEVC encoder.
VCodecNv is not a part of the RapidPixel SDK: in the SDK VCodecUniversal uses the other codec libraries of Table 1 (on Linux VCodecLibva first). VCodecNv is used only if the project adds it, for example a stand alone build with the VCodecNv repository next to VCodecUniversal.
The drivers of VCodecNv and VCodecLibva are checked once per process (the first frame that needs them). The codec libraries are selected by the first frame of a stream: encoding - the first frame of a compressed format and frame size; decoding - the first key frame of a compressed format; also after the command RESET and after a change of CUSTOM_3. A codec library that can not process the stream is replaced by the next one of Table 1:
- Encoding: a codec library that fails on the first frame (no hardware, a format or a frame size that the hardware does not support) is replaced, the next one encodes the same frame.
- H264 and HEVC decoding: VCodecNv, VCodecV4L2 and VCodecWmf that fail before they give the first picture are replaced; the next codec library decodes the stream from this key frame (or from the next one). VCodecLibva and the software decoders also return FALSE when they need more data, so they are not replaced.
- JPEG: an image that a hardware codec refuses is processed by the software codec (VDecoderJPEG, VEncoderJPEG). A hardware codec that refused an image before it processed one is not used for the next images.
- The last codec library of the list is never replaced: the frames that it can not process are failures.
The codec library that processed the last frame is returned by getParam(VCodecParam::TYPE) (see getParam method).
Encoding and decoding time of VCodecUniversal on Windows 11 (Intel Core i7-13700H, NVIDIA GeForce RTX 4050 Laptop GPU; VCodecWmf, which selects the NVIDIA GPU; NV12, test pattern, 5000 kbps, 30 fps; test data streams for decoding; time of a frame without the first frame, which also selects and creates the codec; a process without power throttling, as a program in the foreground: Windows 11 can throttle a process in the background, then decoding of H264 and HEVC with VCodecWmf takes about 60 msec per frame):
| codec / resolution | 1920x1080 encoding | 1920x1080 decoding | 1280x720 encoding | 1280x720 decoding | 640x480 encoding | 640x480 decoding |
|---|---|---|---|---|---|---|
| H264 | ~3.2 msec | ~7.5 msec | ~1.7 msec | ~7.6 msec | ~0.9 msec | ~7.6 msec |
| HEVC | ~3.9 msec | ~7.5 msec | ~2.1 msec | ~7.7 msec | ~1.1 msec | ~7.6 msec |
| JPEG | ~6.5 msec | ~5.3 msec | ~2.8 msec | ~2.4 msec | ~1.0 msec | ~0.9 msec |
Encoding and decoding time on Linux (Ubuntu 24.04 in WSL 2 on the same computer; VCodecNv, which is not a part of the RapidPixel SDK, for H264 and HEVC and for JPEG decoding, VEncoderJPEG for JPEG encoding):
| codec / resolution | 1920x1080 encoding | 1920x1080 decoding | 1280x720 encoding | 1280x720 decoding | 640x480 encoding | 640x480 decoding |
|---|---|---|---|---|---|---|
| H264 | ~3.5 msec | ~2.7 msec | ~2.0 msec | ~1.7 msec | ~1.1 msec | ~0.9 msec |
| HEVC | ~4.1 msec | ~2.0 msec | ~2.3 msec | ~1.2 msec | ~1.1 msec | ~0.8 msec |
| JPEG | ~1.3 msec | ~1.4 msec | ~0.5 msec | ~0.8 msec | ~0.2 msec | ~0.4 msec |
Decoding time of the software codecs (CUSTOM_3 = 2, one thread, the same computer, Linux):
| codec / resolution | 1920x1080 | 1280x720 | 640x480 |
|---|---|---|---|
| H264 | ~1.9 msec | ~0.8 msec | ~0.4 msec |
| HEVC | ~4.5 msec | ~1.9 msec | ~0.7 msec |
| JPEG | ~1.2 msec | ~0.6 msec | ~0.2 msec |
Versions
Table 2 - Library versions.
| Version | Release date | What’s new |
|---|---|---|
| 1.0.0 | 12.11.2026 | - First version. - The test streams (H264, HEVC and JPEG) are not in the repository: the user supplies them (see Test data), the test application skips the checks that need a missing file. |
Library files
The library is supplied as source code only. The user is provided with a set of files in the form of a CMake project (repository). The repository structure is shown below:
CMakeLists.txt ------------------- Main CMake file of the library (finds the codec libraries).
example -------------------------- Folder with simple example of VCodecUniversal usage.
CMakeLists.txt --------------- CMake file for example application.
main.cpp --------------------- Source code file of example application.
static --------------------------- Folder with static project resources.
vcodecuniversal_web_logo.png - Web logo used in README.
test ----------------------------- Folder with codec test application.
CMakeLists.txt --------------- CMake file for codec test application.
main.cpp --------------------- Source code file of codec test application.
src ------------------------------ Folder with source code of the library.
CMakeLists.txt --------------- CMake file of the library.
VCodecUniversal.cpp ---------- C++ implementation file of the public class.
VCodecUniversal.h ------------ Header file which includes VCodecUniversal class declaration.
VCodecUniversalVersion.h ----- Header file which includes version of the library.
VCodecUniversalVersion.h.in -- CMake service file to generate version file.
impl ------------------------- Internal implementation details.
CodecChain.cpp ----------- Codec libraries of a stream and the codec in use.
CodecChain.h ------------- Codec chain class declaration.
CodecLibrary.cpp --------- Order of the codec libraries, codec objects and parameters.
CodecLibrary.h ----------- Codec library functions declaration.
HardwareCheck.cpp -------- Check of the GPU drivers of VCodecNv and VCodecLibva.
HardwareCheck.h ---------- Check functions declaration.
StreamParser.cpp --------- Parser of the H264, HEVC and JPEG headers.
StreamParser.h ----------- Parser declaration.
VCodecUniversalImpl.cpp -- Implementation of the codec.
VCodecUniversalImpl.h ---- Implementation class declaration.
VCodecUniversal class description
VCodecUniversal class declaration
The VCodecUniversal class is declared in the VCodecUniversal.h file (namespace rapidpixel; the names are also available in the namespace cr::video through VCodec.h). The methods are thread-safe: calls from several threads are serialized. A frame that is passed to a method must not be accessed by another thread until the method returns. The constructor throws std::bad_alloc if memory is not available. The copy and the move operations of the class are deleted. Class declaration:
class VCodecUniversal : public VCodec
{
public:
/// Get library version.
static std::string getVersion();
/// Class constructor.
VCodecUniversal();
/// Class destructor.
~VCodecUniversal() override;
/// Copy and move operations are deleted.
VCodecUniversal(const VCodecUniversal&) = delete;
VCodecUniversal(VCodecUniversal&&) = delete;
VCodecUniversal& operator=(const VCodecUniversal&) = delete;
VCodecUniversal& operator=(VCodecUniversal&&) = delete;
/// Transcode (encode or decode) video frame.
bool transcode(Frame& src, Frame& dst) override;
/// Set parameter value.
bool setParam(VCodecParam id, float value) override;
/// Get parameter value.
float getParam(VCodecParam id) override;
/// Execute command.
bool executeCommand(VCodecCommand id) override;
private:
/// Implementation of the codec.
std::unique_ptr<VCodecUniversalImpl> m_impl{nullptr};
};
getVersion method
The getVersion() method returns a string of the current version of the VCodecUniversal class. Method declaration:
static std::string getVersion();
The method can be used without a VCodecUniversal class instance:
std::cout << "VCodecUniversal class version: "
<< rapidpixel::VCodecUniversal::getVersion() << std::endl;
Console output:
VCodecUniversal class version: 1.0.0
transcode method
The transcode(…) method is intended to encode and decode video frames (Frame class). The direction (encode or decode) is determined by the fourcc fields of the src and dst frames: if src is NV12 and dst is a compressed format (H264, HEVC, JPEG), the library encodes; if src is compressed and dst is NV12, the library decodes. Other combinations of the pixel formats are rejected. One object can encode and decode alternately: the encoder and the decoder are separate. Method declaration:
bool transcode(Frame& src, Frame& dst);
| Parameter | Value |
|---|---|
| src | Source video frame (see Frame class description). For encoding: must have raw pixel format NV12, data must be not nullptr, width and height must be even and in the range 2 - 8192 and size must be not less than width * height * 3 / 2. For decoding: must have compressed format H264, HEVC or JPEG, data must point to one access unit of an Annex B byte stream (NAL units with start codes; H264, HEVC) or to one JPEG image (starting with the SOI marker), and size must be its length in bytes. A frame with size 0 (data can be nullptr) gets a picture that the decoder holds at the end of a stream (see below). width and height are not used for decoding. |
| dst | Result video frame (see Frame class description). For encoding: must have compressed format H264, HEVC or JPEG. For decoding: must have raw pixel format NV12. A frame with a size that differs from the size of the result is reallocated: for encoding the size of the result is the size of src, for decoding it is the size of the decoded picture. A frame that is not reallocated must have a buffer of the size that the Frame constructor allocates for its size and pixel format. frameId and sourceId are copied from src. |
Returns: Encoding: TRUE if the encoder accepted the frame. If TRUE is returned and dst.size is 0, the encoder holds the frame: the coded data comes with a next frame (VCodecWmf; VCodecV4L2 on NVIDIA Jetson with the pipeline of the encoder). Decoding: TRUE if dst holds a decoded picture, FALSE if no picture is returned (the decoder needs more data, the stream waits for a key frame, the data is damaged or not supported). FALSE is also returned for invalid frames or pixel formats, if no codec library can process the frame and if memory is not available. The content of dst is not defined if FALSE is returned. The library cannot check that a non-nullptr data pointer is valid for size bytes: the pointer must be valid.
Decoding details:
- H264 and HEVC: the library reads the parameter sets, the first fields of the slice headers and the types of the SEI messages of the stream (base layer). Decoding starts with the first key frame whose parameter sets are known: an IDR picture or a picture of intra slices (H264), an IRAP picture (HEVC) or a picture with a recovery point SEI message. The access units before it are skipped (FALSE). The library keeps the parameter sets of the stream (also after the command RESET) and puts them in front of the first access unit that a decoder gets: a stream can send them once. A picture whose parameter sets are not known or not valid is not given to a decoder (FALSE).
- The size of the picture is read from the stream (H264 and HEVC: the cropped size of the sequence parameter set; JPEG: the frame header) and must not be larger than 8192 x 8192 pixels: a stream with a larger size is rejected before a decoder gets it. NV12 needs even sizes: a picture with an odd width or height (JPEG; H264 4:4:4) is extended by one column or row by VCodecNv, VDecoderH264 and VDecoderJPEG and cropped by VCodecLibva and VCodecV4L2; VCodecWmf does not decode it.
- The pictures that a decoder holds at the end of a stream (streams with B-frames) are taken with source frames of size 0 with the same compressed format, one picture per call, until the method returns FALSE. VCodecLibva, VDecoderH264 and VDecoderH265 give them; the other codec libraries do not hold pictures or give them with the next frames.
- The samples of the decoded pictures are the samples of the stream (no range conversion), except for VCodecLibva, which converts limited range pictures to full range.
Warning: Hardware decoders use the graphics driver. A damaged or crafted stream can make a driver block inside the decoder: the call does not return then (it was observed with the Microsoft H264 decoder on an Intel GPU, see VCodecWmf). The library cannot interrupt the call. An application that decodes streams from an untrusted source should decode them in a separate process, or use the software codecs only (CUSTOM_3 = 2, not Windows).
setParam method
The setParam(…) method is designed to set new video codec parameter values. Method declaration:
bool setParam(VCodecParam id, float value);
| Parameter | Description |
|---|---|
| id | Video codec parameter ID according to VCodecParam enum. |
| value | Video codec parameter value. |
Returns: TRUE if the parameter was set or FALSE if not. An unknown ID, NaN, infinity and a value outside of the range of the parameter (see Table 3) are rejected: the parameter is not changed. The fractional part of a value is cut off; LOG_LEVEL, BITRATE_MODE, H264_PROFILE and CUSTOM_3 accept only integer values, FPS keeps fractions. TYPE can not be set. The value is given at once to the codecs in use; a codec library with a smaller range uses the nearest value of its range (see Table 3). If a codec in use refuses the value, FALSE is returned and the parameter is not changed.
The VCodec.h file of the VCodec library defines IDs for parameters (VCodecParam enum) and IDs for commands (VCodecCommand enum). VCodecParam declaration:
namespace rapidpixel
{
enum class VCodecParam
{
/// [read/write] Log level: 0 - Disable, 1 - Console, 2 - File,
/// 3 - Console and file.
LOG_LEVEL = 1,
/// [read/write] Bitrate, kbps. For H264 and H265 codecs.
BITRATE_KBPS,
/// [read/write] Minimum bitrate, kbps. For variable bitrate mode.
MIN_BITRATE_KBPS,
/// [read/write] Maximum bitrate, kbps. For variable bitrate mode.
MAX_BITRATE_KBPS,
/// [read/write] Bitrate mode: 0 - constant bitrate, 1 - variable bitrate.
BITRATE_MODE,
/// [read/write] Quality 0-100%. For JPEG codecs.
QUALITY,
/// [read/write] FPS. For H264 and H265 codecs.
FPS,
/// [read/write] GOP size. For H264 and H265 codecs.
GOP,
/// [read/write] H264 profile: 0 - Baseline, 1 - Main, 2 - High.
H264_PROFILE,
/// [read/write] Codec type. Depends on implementation.
TYPE,
/// [read/write] Custom parameter 1. Depends on implementation.
CUSTOM_1,
/// [read/write] Custom parameter 2. Depends on implementation.
CUSTOM_2,
/// [read/write] Custom parameter 3. Depends on implementation.
CUSTOM_3
};
}
Table 3 - Video codec parameter descriptions for VCodecUniversal.
| Parameter | Access | Description |
|---|---|---|
| LOG_LEVEL | read / write | Log level: 0 - Disable, 1 - Console, 2 - File, 3 - Console and file. Default: 0. VCodecUniversal writes no log: the value is given to the codec libraries, which write their messages with the Logger library (VCodecNv, VCodecLibva, VCodecV4L2, VCodecImxVpu, VEncoderJPEG). With 0 the codec libraries write no messages; the GPU drivers and system components can write their own messages (for example the JPEG decoder of Windows Imaging Component, used by VCodecWmf, writes messages about damaged JPEG images to the error stream). |
| BITRATE_KBPS | read / write | Bitrate, kbps. Range: 1 - 1,000,000. Default: 5000. For H264 and HEVC encoding. Ranges of the codec libraries: VCodecWmf 1 - 100,000, VCodecLibva 100 - 1,000,000, VCodecImxVpu 100 - 60,000 (the nearest value is used). |
| MIN_BITRATE_KBPS | read / write | Minimum bitrate of the variable bitrate mode, kbps. Range: 0 - 1,000,000 (0 - no minimum). Default: 0. Used by VCodecNv and VCodecLibva (values 1 - 99 are taken as 100); VCodecWmf, VCodecV4L2 and VCodecImxVpu have no minimum bitrate. |
| MAX_BITRATE_KBPS | read / write | Maximum (peak) bitrate of the variable bitrate mode, kbps. Range: 0 - 1,000,000. Default: 0 (the peak is BITRATE_KBPS; a value lower than BITRATE_KBPS has the same effect). Used by VCodecWmf, VCodecNv and VCodecLibva (values 1 - 99 are taken as 100). |
| BITRATE_MODE | read / write | Bitrate mode: 0 - constant bitrate, 1 - variable bitrate. Default: 0. Used by VCodecWmf, VCodecNv and VCodecLibva; VCodecV4L2 and VCodecImxVpu use the mode of the hardware encoder. |
| QUALITY | read / write | JPEG quality. Range: 0 - 100 (0 is taken as 1, the lowest quality). Default: 80. For JPEG encoding. |
| FPS | read / write | Frame rate. Range: 1 - 1000, fractions are kept (29.97). Default: 30. For H264 and HEVC encoding. VCodecWmf uses 1 - 240 (integer). |
| GOP | read / write | GOP size (period of key frames), frames. Range: 1 - 10,000. Default: 30. For H264 and HEVC encoding. VCodecWmf uses 1 - 1000. |
| H264_PROFILE | read / write | H264 profile: 0 - Baseline, 1 - Main, 2 - High. Default: 0. For H264 encoding. |
| TYPE | read only | Codec library that processed the last frame (the last call that returned TRUE): 0 - none (before the first frame and after RESET), 1 - VCodecWmf, 2 - VCodecNv, 3 - VCodecLibva, 4 - VCodecV4L2, 5 - VCodecImxVpu, 6 - VDecoderH264, 7 - VDecoderH265, 8 - VDecoderJPEG, 9 - VEncoderJPEG. setParam(…) returns FALSE. |
| CUSTOM_1 | read / write | Not used: any finite value is stored (default 0). |
| CUSTOM_2 | read / write | Number of threads of the software codecs (VDecoderH264, VDecoderH265, VDecoderJPEG, VEncoderJPEG and the software JPEG decoder of VCodecNv): 0 - automatic, 1 - one thread (default), 2 - 32 threads. If a codec can not start all threads, FALSE is returned, the value is stored and the codec works with fewer threads. |
| CUSTOM_3 | read / write | Order of the codec libraries (Linux, Table 1): 0 - VCodecNv (NVIDIA GPU) before VCodecLibva (Intel GPU) (default), 1 - VCodecLibva before VCodecNv, 2 - software codecs only (no hardware codec is used). A new value releases the encoder and the decoder: the next frames select the codec libraries again. Windows: 0 and 1 are accepted and have no effect (VCodecWmf selects the GPU), 2 is rejected (no software codecs). |
getParam method
The getParam(…) method is designed to obtain video codec parameter values. Method declaration:
float getParam(VCodecParam id);
| Parameter | Description |
|---|---|
| id | Video codec parameter ID according to VCodecParam enum (see Table 3). |
Returns: Parameter value (the value that was set; TYPE - the codec library that processed the last frame) or -1 if the parameter is not supported.
executeCommand method
The executeCommand(…) method is designed to execute video codec commands. Method declaration:
bool executeCommand(VCodecCommand id);
| Parameter | Description |
|---|---|
| id | Video codec command ID according to VCodecCommand enum. |
Returns: TRUE if the command was accepted or FALSE if not (an unknown ID is rejected; MAKE_KEY_FRAME: the encoder in use refused the command).
The VCodec.h file of the VCodec library defines IDs for parameters (VCodecParam enum) and IDs for commands (VCodecCommand enum). VCodecCommand declaration:
enum class VCodecCommand
{
/// Reset.
RESET = 1,
/// Generate key frame. For H264 and H265 codecs.
MAKE_KEY_FRAME
};
Table 4 - Video codec command descriptions for VCodecUniversal.
| Command | Description |
|---|---|
| RESET | Releases the encoder and the decoder: the next frames select the codec libraries again (a decoder starts with the next key frame). The parameters and the parameter sets of the decoded H264 or HEVC stream are kept. TYPE is 0 after the command. |
| MAKE_KEY_FRAME | The next encoded H264 or HEVC frame is a key frame (the command is given to the encoder in use). It is accepted without an encoder (the first frame of an encoder is a key frame) and for JPEG (every JPEG frame is a key frame). |
Build and connect to your project
Prerequisites and System Requirements
The library is built with CMake 3.13 or newer and a C++17 compiler: Windows - Microsoft Visual C++ (Visual Studio 2022 was used), Linux - GCC or Clang. CMake builds a codec library if its repository folder exists and its build requirements are met (see Build stand alone):
| Codec library | System | Build requirements | Run time requirements |
|---|---|---|---|
| VCodecWmf | Windows | Windows SDK (Media Foundation, Direct3D 11, Windows Imaging Component) | Windows 11; GPU drivers; HEVC: hardware HEVC codec of the GPU or the “HEVC Video Extensions” package |
| VCodecNv | Linux | Headers nvEncodeAPI.h, nvcuvid.h and cuviddec.h of the Video Codec SDK 12.0 or newer: in a folder Video_Codec_SDK* or Video_Codec_Interface* next to the repository folders, in a system include folder, or set by the CMake cache variable VIDEO_CODEC_SDK_INCLUDE_DIR; folders VDecoderJPEG, VEncoderJPEG, Logger | NVIDIA GPU driver with the libraries libcuda.so.1, libnvidia-encode.so.1, libnvcuvid.so.1 (see VCodecNv) |
| VCodecLibva | Linux | libva and libva-drm with headers (sudo apt-get install libva-dev); folder Logger | VA-API driver of the GPU (for example intel-media-va-driver), access to the device /dev/dri/renderD128 |
| VCodecV4L2 | Linux | Kernel header linux/videodev2.h; folder Logger | V4L2 memory-to-memory codec devices |
| VCodecImxVpu | Linux | Hantro H1 encoder package of the board (h264encapi.h in hantro_enc, library libhantro_h1); folder Logger | i.MX8M Mini, access to /dev/mxc_hantro_h1 |
| VDecoderH264, VDecoderH265, VDecoderJPEG, VEncoderJPEG | all except Windows | - | - |
Build stand alone
The repository does not contain sub-repositories. The libraries VCodecUniversal depends on must be placed in the same folder as VCodecUniversal: Frame and VCodec (always), the codec libraries that the target system can use and Logger (used by VCodecNv, VCodecLibva, VCodecV4L2 and VCodecImxVpu). Copy their folders, for example from the folder modules of the RapidPixel SDK. The folder of VCodecNv (VCodecNv is not a part of the RapidPixel SDK) is placed next to the other folders. A codec library whose folder does not exist is not built. The folder structure must be:
<work folder>
VCodecUniversal
Frame
VCodec
Logger
VCodecWmf
VCodecNv
VCodecLibva
VCodecV4L2
VCodecImxVpu
VDecoderH264
VDecoderH265
VDecoderJPEG
VEncoderJPEG
Typical commands to build the library, the test application and the example (on Windows only Frame, VCodec and VCodecWmf are needed):
cd VCodecUniversal
cmake -B build -S .
cmake --build build --config Release
If VCodecUniversal is the top-level CMake project, the main CMakeLists.txt file checks every codec library (system, CMake option, folder, build requirements), reports the result and adds the folders ../Frame, ../VCodec, ../Logger (if needed) and the codec libraries in the order of their mutual dependencies before the library itself. If the folder ../Frame or ../VCodec does not exist CMake stops with an error. CMake reports the codec libraries, for example on Linux:
-- VCodecUniversal: VDecoderJPEG - built
-- VCodecUniversal: VEncoderJPEG - built
-- VCodecUniversal: VDecoderH264 - built
-- VCodecUniversal: VDecoderH265 - built
-- VCodecUniversal: VCodecNv - built
-- VCodecUniversal: VCodecLibva - built
-- VCodecUniversal: VCodecV4L2 - built
-- VCodecUniversal: VCodecImxVpu - not built: Hantro H1 encoder headers and library not found
-- VCodecUniversal: VCodecWmf - not built: Windows only
-- VCodecUniversal: codec libraries in use: VCodecNv, VCodecLibva, VCodecV4L2, VDecoderH264, VDecoderH265, VDecoderJPEG, VEncoderJPEG
The compiled library is located in build/src (Windows: build/src/Release/VCodecUniversal.lib), the example and test executables in build/bin (Windows: build/bin/Release/).
CMake options
Table 5 - CMake options of the repository. In the options below ${PARENT} is the prefix defined by the top-level project (empty if VCodecUniversal is the top-level project).
| Option | Default | Description |
|---|---|---|
| ${PARENT}_VCODECUNIVERSAL | ON | Build the library. |
| ${PARENT}_VCODECUNIVERSAL_TEST | ON (stand alone), OFF (included in other project) | Build the test application. |
| ${PARENT}_VCODECUNIVERSAL_EXAMPLE | ON (stand alone), OFF (included in other project) | Build the example. |
| ${PARENT}_SUBMODULE_CACHE_OVERWRITE | ON | Forced rewriting of the options above in the CMake cache. The top-level project sets it to OFF when it includes VCodecUniversal as a sub-repository. |
| CMAKE_BUILD_TYPE | Release (if not specified) | Build type. |
| VCODECUNIVERSAL_USE_VCODECWMF, VCODECUNIVERSAL_USE_VCODECNV, VCODECUNIVERSAL_USE_VCODECLIBVA, VCODECUNIVERSAL_USE_VCODECV4L2, VCODECUNIVERSAL_USE_VCODECIMXVPU, VCODECUNIVERSAL_USE_VDECODERH264, VCODECUNIVERSAL_USE_VDECODERH265, VCODECUNIVERSAL_USE_VDECODERJPEG, VCODECUNIVERSAL_USE_VENCODERJPEG | ON | Use the codec library if the project has it. OFF: the library does not use the codec library (stand alone: CMake does not build it). |
| VIDEO_CODEC_SDK_INCLUDE_DIR | found by CMake | Folder of the headers of the Video Codec SDK (VCodecNv). |
Connect to your project
If you want to connect the VCodecUniversal library to your CMake project as source code, you can follow these steps. VCodecUniversal does not add its dependencies when it is included in another project: your project must add Frame, VCodec and the codec libraries that it wants VCodecUniversal to use (with Logger for VCodecNv, VCodecLibva, VCodecV4L2 and VCodecImxVpu, and VDecoderJPEG and VEncoderJPEG for VCodecNv). VCodecUniversal uses the codec libraries that the project has (their targets are looked up when the build files are generated, so the order in which your project adds them does not matter) and reports them. Add only the codec libraries that can be built for the target system (see Prerequisites and System Requirements). For example, if your repository has the following structure:
CMakeLists.txt
src
CMakeLists.txt
yourLib.h
yourLib.cpp
Create folder 3rdparty in your repository and copy the folders of the libraries Frame, VCodec, Logger, the codec libraries and VCodecUniversal there (for example from the folder modules of the RapidPixel SDK). The folder of VCodecNv (VCodecNv is not a part of the RapidPixel SDK) is placed next to the other folders. The new structure of your repository (Linux computer with an NVIDIA GPU):
CMakeLists.txt
src
CMakeLists.txt
yourLib.h
yourLib.cpp
3rdparty
Frame
VCodec
Logger
VDecoderJPEG
VEncoderJPEG
VDecoderH264
VDecoderH265
VCodecNv
VCodecV4L2
VCodecUniversal
Create a CMakeLists.txt file in the 3rdparty folder. The CMakeLists.txt should contain (the libraries are added in the order of their dependencies):
cmake_minimum_required(VERSION 3.13)
################################################################################
## 3RD-PARTY
## dependencies for the project
################################################################################
project(3rdparty LANGUAGES CXX)
################################################################################
## SETTINGS
## basic 3rd-party settings before use
################################################################################
# To inherit the top-level architecture when the project is used as a submodule.
SET(PARENT ${PARENT}_YOUR_PROJECT_3RDPARTY)
# Disable self-overwriting of parameters inside included subdirectories.
SET(${PARENT}_SUBMODULE_CACHE_OVERWRITE OFF CACHE BOOL "" FORCE)
################################################################################
## CONFIGURATION
## 3rd-party submodules configuration
################################################################################
SET(${PARENT}_SUBMODULE_FRAME ON CACHE BOOL "" FORCE)
if (${PARENT}_SUBMODULE_FRAME)
SET(${PARENT}_FRAME ON CACHE BOOL "" FORCE)
SET(${PARENT}_FRAME_TEST OFF CACHE BOOL "" FORCE)
endif()
SET(${PARENT}_SUBMODULE_VCODEC ON CACHE BOOL "" FORCE)
if (${PARENT}_SUBMODULE_VCODEC)
SET(${PARENT}_VCODEC ON CACHE BOOL "" FORCE)
endif()
SET(${PARENT}_SUBMODULE_LOGGER ON CACHE BOOL "" FORCE)
if (${PARENT}_SUBMODULE_LOGGER)
SET(${PARENT}_LOGGER ON CACHE BOOL "" FORCE)
SET(${PARENT}_LOGGER_EXAMPLE OFF CACHE BOOL "" FORCE)
endif()
SET(${PARENT}_SUBMODULE_VDECODERJPEG ON CACHE BOOL "" FORCE)
if (${PARENT}_SUBMODULE_VDECODERJPEG)
SET(${PARENT}_VDECODERJPEG ON CACHE BOOL "" FORCE)
SET(${PARENT}_VDECODERJPEG_EXAMPLE OFF CACHE BOOL "" FORCE)
endif()
SET(${PARENT}_SUBMODULE_VENCODERJPEG ON CACHE BOOL "" FORCE)
if (${PARENT}_SUBMODULE_VENCODERJPEG)
SET(${PARENT}_VENCODERJPEG ON CACHE BOOL "" FORCE)
SET(${PARENT}_VENCODERJPEG_TEST OFF CACHE BOOL "" FORCE)
SET(${PARENT}_VENCODERJPEG_EXAMPLE OFF CACHE BOOL "" FORCE)
SET(${PARENT}_VENCODERJPEG_BENCHMARK OFF CACHE BOOL "" FORCE)
endif()
SET(${PARENT}_SUBMODULE_VDECODERH264 ON CACHE BOOL "" FORCE)
if (${PARENT}_SUBMODULE_VDECODERH264)
SET(${PARENT}_VDECODERH264 ON CACHE BOOL "" FORCE)
SET(${PARENT}_VDECODERH264_EXAMPLE OFF CACHE BOOL "" FORCE)
endif()
SET(${PARENT}_SUBMODULE_VDECODERH265 ON CACHE BOOL "" FORCE)
if (${PARENT}_SUBMODULE_VDECODERH265)
SET(${PARENT}_VDECODERH265 ON CACHE BOOL "" FORCE)
SET(${PARENT}_VDECODERH265_EXAMPLE OFF CACHE BOOL "" FORCE)
endif()
SET(${PARENT}_SUBMODULE_VCODECNV ON CACHE BOOL "" FORCE)
if (${PARENT}_SUBMODULE_VCODECNV)
SET(${PARENT}_VCODEC_NV ON CACHE BOOL "" FORCE)
SET(${PARENT}_VCODEC_NV_TEST OFF CACHE BOOL "" FORCE)
SET(${PARENT}_VCODEC_NV_EXAMPLE OFF CACHE BOOL "" FORCE)
endif()
SET(${PARENT}_SUBMODULE_VCODECV4L2 ON CACHE BOOL "" FORCE)
if (${PARENT}_SUBMODULE_VCODECV4L2)
SET(${PARENT}_VCODEC_V4L2 ON CACHE BOOL "" FORCE)
SET(${PARENT}_VCODEC_V4L2_TEST OFF CACHE BOOL "" FORCE)
SET(${PARENT}_VCODEC_V4L2_EXAMPLE OFF CACHE BOOL "" FORCE)
endif()
SET(${PARENT}_SUBMODULE_VCODECUNIVERSAL ON CACHE BOOL "" FORCE)
if (${PARENT}_SUBMODULE_VCODECUNIVERSAL)
SET(${PARENT}_VCODECUNIVERSAL ON CACHE BOOL "" FORCE)
SET(${PARENT}_VCODECUNIVERSAL_TEST OFF CACHE BOOL "" FORCE)
SET(${PARENT}_VCODECUNIVERSAL_EXAMPLE OFF CACHE BOOL "" FORCE)
endif()
################################################################################
## INCLUDING SUBDIRECTORIES
## Adding subdirectories according to the 3rd-party configuration
################################################################################
if (${PARENT}_SUBMODULE_FRAME)
add_subdirectory(Frame)
endif()
if (${PARENT}_SUBMODULE_VCODEC)
add_subdirectory(VCodec)
endif()
if (${PARENT}_SUBMODULE_LOGGER)
add_subdirectory(Logger)
endif()
if (${PARENT}_SUBMODULE_VDECODERJPEG)
add_subdirectory(VDecoderJPEG)
endif()
if (${PARENT}_SUBMODULE_VENCODERJPEG)
add_subdirectory(VEncoderJPEG)
endif()
if (${PARENT}_SUBMODULE_VDECODERH264)
add_subdirectory(VDecoderH264)
endif()
if (${PARENT}_SUBMODULE_VDECODERH265)
add_subdirectory(VDecoderH265)
endif()
if (${PARENT}_SUBMODULE_VCODECNV)
add_subdirectory(VCodecNv)
endif()
if (${PARENT}_SUBMODULE_VCODECV4L2)
add_subdirectory(VCodecV4L2)
endif()
if (${PARENT}_SUBMODULE_VCODECUNIVERSAL)
add_subdirectory(VCodecUniversal)
endif()
The file 3rdparty/CMakeLists.txt adds the folders to your project and excludes test applications and examples from compiling. On Windows the file adds only Frame, VCodec, VCodecWmf (${PARENT}_VCODECWMF, ${PARENT}_VCODECWMF_TEST, ${PARENT}_VCODECWMF_EXAMPLE) and VCodecUniversal; VCodecLibva (${PARENT}_VCODEC_LIBVA, ${PARENT}_VCODEC_LIBVA_TEST, ${PARENT}_VCODEC_LIBVA_EXAMPLE) and VCodecImxVpu (${PARENT}_VCODEC_IMX_VPU, ${PARENT}_VCODEC_IMX_VPU_TEST, ${PARENT}_VCODEC_IMX_VPU_EXAMPLE) are added in the same way on Linux computers that have their build requirements. Next, you need to include the folder 3rdparty in the main CMakeLists.txt file of your repository. Add this string at the end of your main CMakeLists.txt:
add_subdirectory(3rdparty)
Next, you have to include the VCodecUniversal library in your src/CMakeLists.txt file:
target_link_libraries(${PROJECT_NAME} VCodecUniversal)
Done! CMake reports the codec libraries that VCodecUniversal uses (-- VCodecUniversal: codec libraries in use: ...; with CMake older than 3.19 the report lists the codec libraries that the project added before VCodecUniversal). If a project does not add Frame and VCodec, its build stops with the error Frame.h: No such file or directory or VCodec.h: No such file or directory (Windows: Cannot open include file).
Portability
The library itself has no system or CPU specific code except the check of the GPU drivers of VCodecNv and VCodecLibva (Linux, compiled only with these codec libraries): it has no SIMD intrinsics and no CPU specific compiler options, and the codec libraries choose their own CPU and GPU code. The library does not serialize integers or floats; the parser of the stream headers reads the bytes of the streams one by one and does not depend on the byte order of the CPU. Windows: the library uses VCodecWmf only and was built and tested for x64 with Visual Studio 2022 (MSVC 19.36) on Windows 11. Linux: the library was built without warnings by GCC 12 and 13 and Clang 15 and 18 for x86-64 (Release and Debug) and by GCC 13 and Clang 18 for aarch64 (cross compilation); it was tested on x86-64 (Ubuntu 24.04 in WSL 2: VCodecNv with an NVIDIA GPU and the software codecs) and on aarch64 under emulation (software codecs). VCodecLibva and VCodecV4L2 were built and tried, but the test computer has no hardware for them (the library replaced them by the next codec libraries); VCodecImxVpu was not built (no Hantro H1 encoder package). Other systems (for example macOS) can use the software codecs only; they were not tested.
Simple example
The example shows the whole use of the library: one VCodecUniversal object, frames and one method transcode(…) for encoding and decoding. The pixel formats of the frames define what the method does: NV12 to H264 encodes, H264 to NV12 decodes. The application does not select a codec: the library uses the hardware codec of the computer (see Table 1), so the same code works on Windows and Linux. The example encodes 100 images to H264, writes the compressed data to the file out.h264 (a video player plays it) and decodes each frame back. HEVC and JPEG are encoded and decoded in the same way, with Fourcc::HEVC or Fourcc::JPEG as the format of the compressed frame. H264 and HEVC encoding needs a hardware encoder: on a computer without it the example prints “No H264 encoder on this computer” (JPEG is encoded on every computer).
#include <cstdint>
#include <fstream>
#include <iostream>
#include "VCodecUniversal.h"
int main()
{
// One codec for encoding and decoding. It selects the hardware codec of
// the computer itself, or a software codec if there is no hardware codec.
rapidpixel::VCodecUniversal codec;
codec.setParam(rapidpixel::VCodecParam::BITRATE_KBPS, 5000.0f);
codec.setParam(rapidpixel::VCodecParam::FPS, 30.0f);
// Frames: source image, compressed data (H264, HEVC or JPEG) and decoded
// image.
rapidpixel::Frame image(1280, 720, rapidpixel::Fourcc::NV12);
rapidpixel::Frame compressed(1280, 720, rapidpixel::Fourcc::H264);
rapidpixel::Frame decoded(1280, 720, rapidpixel::Fourcc::NV12);
std::ofstream file("out.h264", std::ios::binary);
for (int n = 0; n < 100; ++n)
{
// Put your image here. The example draws moving stripes.
for (int i = 0; i < image.size; ++i)
{
image.data[i] = static_cast<uint8_t>(i + n);
}
// Encode: NV12 -> H264.
if (!codec.transcode(image, compressed))
{
std::cout << "No H264 encoder on this computer" << std::endl;
return 1;
}
file.write(reinterpret_cast<char*>(compressed.data), compressed.size);
// Decode: H264 -> NV12. The size is 0 if the encoder holds the image.
if (compressed.size > 0 && codec.transcode(compressed, decoded))
{
std::cout << "Frame " << n << ": " << compressed.size
<< " bytes -> " << decoded.width << "x"
<< decoded.height << std::endl;
}
}
return 0;
}
Console output on Windows (the sizes of the compressed frames depend on the encoder):
Frame 0: 5031 bytes -> 1280x720
Frame 1: 5910 bytes -> 1280x720
Frame 2: 14517 bytes -> 1280x720
...
Frame 99: 15475 bytes -> 1280x720
Test application
The test application (test/main.cpp) for the VCodecUniversal C++ library has four modes: Manual encoder test, Auto test (the time of encoding and decoding and the codec library for all codecs and resolutions), Parameter & API tests (version, default values and ranges of the parameters, commands, pixel formats, invalid frames, invalid JPEG headers, frames before the first key frame, crafted H264 and HEVC parameter sets with sizes and values that are not valid, corruption campaign of damaged streams) and Encoding & decoding tests (JPEG round trip, decoding of the test streams, start of decoding with the kept parameter sets, encoding and decoding of all formats, changes of the encoder parameters, software codecs with one and four threads, order of the codec libraries, end of a stream with B-frames, changes of the frame size and of the format, frame IDs, creation and destruction of many codecs, use from several threads). The mode is selected in the menu or with a command line argument: --manual (or 1), --auto (or 2, an optional second argument 0, 1 or 2 sets CUSTOM_3), --param (or 3), --codec (or 4) or --all (the Parameter & API tests, the Encoding & decoding tests and the Auto test). The application returns 0 if all checks passed, 1 if a check failed and 2 if the argument is unknown. The tests write no files: the application checks that the run directory is not changed. The Manual encoder test writes the file with the encoded frames. A format that no codec library of the computer can encode or decode is reported and skipped (for example H264 encoding on a computer without hardware encoder). The checks that need a test data file that is missing are skipped: the application prints SKIPPED with the name of the file and its folder, the skipped checks do not fail the run (see Test data). To run the application:
cd build/bin
./VCodecUniversalTest
After starting, you will see the mode selection menu:
========================================
VCodecUniversal v1.0.0 test
========================================
========================================
SET MODE
========================================
1 - Manual encoder
2 - Auto test
3 - Parameter & API tests
4 - Encoding & decoding tests
0 - Exit
>
The Parameter & API tests and the Encoding & decoding tests print one line per test and the codec libraries that were used, for example on Linux with an NVIDIA GPU (--codec):
JPEG round trip: OK
Decoding of the test streams:
Decoders: H264: VCodecNv HEVC: VCodecNv JPEG: VCodecNv
OK
Start of decoding: OK
Encoding:
Encoders: H264: VCodecNv HEVC: VCodecNv JPEG: VEncoderJPEG
OK
Encoder parameters: OK
Software codecs: OK
Order of the codec libraries:
H264 decoders by CUSTOM_3: 1: VCodecNv 0: VCodecNv 2: VDecoderH264
OK
End of a stream with B-frames: OK
Dynamic changes: OK
Frame IDs: OK
Life cycle of the codec: OK
Threads: OK
Checks: 114, skipped: 0, result: PASSED
Manual encoder mode
Allows to select a codec (H264, HEVC, or JPEG), use default parameters or enter custom ones (resolution, frame count, bitrate/GOP/FPS for H264/HEVC and profile for H264, or quality for JPEG), and encode a test video pattern. The test pattern consists of 8 colored vertical bars with a scrolling brightness wave and a white square bouncing diagonally. Encoded output is saved to out.h264, out.hevc, or out.jpeg. For JPEG, only the last encoded frame is kept in the file. The summary shows the codec library that encoded the frames.
Auto test mode
Runs encoding and decoding tests for all 3 codecs (H264, HEVC, JPEG) across 3 resolutions (1920x1080, 1280x720, 640x480) with 100 frames each and shows the codec library of every test. Decoding uses the test data files of the folder test/data (see Test data): a missing file is shown as NO DATA. The average time does not include the first frame (it also selects and creates the codec). Summary of the auto test on Linux (--auto 0):
Codec Res | Encode | Decode
H264 1920x1080 | 3.45 ms 100/100 VCodecNv | 2.65 ms 100/100 VCodecNv
H264 1280x720 | 2.02 ms 100/100 VCodecNv | 1.69 ms 100/100 VCodecNv
H264 640x480 | 1.12 ms 100/100 VCodecNv | 0.94 ms 100/100 VCodecNv
HEVC 1920x1080 | 4.14 ms 100/100 VCodecNv | 2.02 ms 100/100 VCodecNv
HEVC 1280x720 | 2.26 ms 100/100 VCodecNv | 1.23 ms 100/100 VCodecNv
HEVC 640x480 | 1.14 ms 100/100 VCodecNv | 0.75 ms 100/100 VCodecNv
JPEG 1920x1080 | 1.25 ms 100/100 VEncoderJPEG | 1.43 ms 100/100 VCodecNv
JPEG 1280x720 | 0.52 ms 100/100 VEncoderJPEG | 0.78 ms 100/100 VCodecNv
JPEG 640x480 | 0.17 ms 100/100 VEncoderJPEG | 0.37 ms 100/100 VCodecNv
Test data
The test streams are not in the repository: to run the checks that need them, create the folder test/data and put the files of Table 6 in it. Without a file the checks that need it are skipped, for example:
Decoding of invalid frames: SKIPPED: Frames before the first key frame: no file test_640x480.h264 in the folder /path/to/VCodecUniversal/test/data
OK
The summary line gives the number of skipped parts of the tests, for example Checks: 207, skipped: 23, result: PASSED (--all on Linux without hardware codecs and without the files of Table 6). The Auto test shows NO DATA for a missing file.
Table 6 - Test data files supplied by the user.
| File | Content | Tests that use the file |
|---|---|---|
| test_1920x1080.h264, test_1280x720.h264, test_640x480.h264 | H264, Constrained Baseline profile, 4:2:0, 100 frames. Frames 0 and 60 are IDR pictures with SPS and PPS, the other frames are P-frames (no B-frames). | Decoding of the test streams, Auto test. test_640x480.h264 also: Decoding of invalid frames (frames before the first key frame), Crafted streams, Corruption campaign, Start of decoding, Software codecs, Order of the codec libraries, Dynamic changes, Life cycle of the codec. |
| test_1920x1080.hevc, test_1280x720.hevc, test_640x480.hevc | HEVC, Main profile, 4:2:0, 100 frames. Frames 0, 30, 60 and 90 are IDR pictures with VPS, SPS and PPS, the other frames are P-frames (no B-frames). | Decoding of the test streams, Auto test. test_640x480.hevc also: Corruption campaign, Start of decoding, Software codecs, Dynamic changes. |
| test_1920x1080.jpeg, test_1280x720.jpeg, test_640x480.jpeg | JPEG, 100 frames: baseline JPEG images, 4:2:0. | Decoding of the test streams, Auto test. test_640x480.jpeg also: Corruption campaign, Software codecs. |
| test_176x144_bframes.h264 | H264, High profile, 4:2:0, 176x144, 16 frames: an IDR picture, then P-frames and B-frames (the decoder holds pictures at the end of the stream). | End of a stream with B-frames. |
A test data file has the number of frames (32-bit number), then for every frame its size in bytes (32-bit number) and its data: one access unit of an Annex B byte stream (NAL units with start codes, in decoding order) or one JPEG image. The numbers are little-endian. The size of the pictures is the size in the file name.
The files can be made from the test pattern of FFmpeg with the encoders libx264, libx265 and mjpeg and with Python 3. Save the script below as pack.py in the build folder. It writes the frames of a stream (the packets that FFprobe finds in it) to a test data file and creates the folder of the file:
import os
import struct
import subprocess
import sys
# Test data file: number of frames, then the size and the data of every frame
# (32-bit little-endian numbers). A frame is a packet of the stream (FFprobe).
stream, result = sys.argv[1], sys.argv[2]
data = open(stream, 'rb').read()
sizes = [int(size) for size in subprocess.run(
['ffprobe', '-v', 'error', '-show_entries', 'packet=size', '-of', 'csv=p=0',
stream], capture_output=True, check=True, text=True).stdout.split()]
if sum(sizes) != len(data):
sys.exit('The packets do not cover the stream')
os.makedirs(os.path.dirname(os.path.abspath(result)), exist_ok=True)
with open(result, 'wb') as file:
file.write(struct.pack('<I', len(sizes)))
position = 0
for size in sizes:
file.write(struct.pack('<I', size) + data[position:position + size])
position += size
Then run the commands below in the build folder (checked with FFmpeg 6.1). On Windows write the commands of the loop once for every size and use python instead of python3.
for size in 1920x1080 1280x720 640x480; do
ffmpeg -y -f lavfi -i testsrc=size=$size:rate=30 -frames:v 100 -pix_fmt yuv420p -c:v libx264 -profile:v baseline -g 60 -sc_threshold 0 stream.264
python3 pack.py stream.264 ../test/data/test_$size.h264
ffmpeg -y -f lavfi -i testsrc=size=$size:rate=30 -frames:v 100 -pix_fmt yuv420p -c:v libx265 -g 30 -bf 0 -x265-params open-gop=0:scenecut=0 stream.265
python3 pack.py stream.265 ../test/data/test_$size.hevc
ffmpeg -y -f lavfi -i testsrc=size=$size:rate=30 -frames:v 100 -pix_fmt yuvj420p -c:v mjpeg -q:v 2 stream.mjpeg
python3 pack.py stream.mjpeg ../test/data/test_$size.jpeg
done
ffmpeg -y -f lavfi -i testsrc=size=176x144:rate=30 -frames:v 16 -pix_fmt yuv420p -c:v libx264 -profile:v high -g 16 -bf 3 -x264-params b-adapt=0 stream.264
python3 pack.py stream.264 ../test/data/test_176x144_bframes.h264