VSourceV4L2 C++ library v2.0.1

Low-latency video capture C++ library based on Linux V4L2 API. Provides simple interface for easy integration in C++ projects without complexity of V4L2 API.

Overview

VSourceV4L2 C++ library provides video capture and video source (V4L2 compatible video sources: MPIPI CSI cameras, USB cameras) control function based on Linux V4L2 API. The library supports stepwise and discrete devices. The library inherits interface from open source VSource interface class. VSource.h file contains data structures VSourceParams class, VSourceCommand enum, VSourceParam enum and includes VSource class declaration. VSourceParams class contains video source params and methods to encode and decode video source params. VSourceCommands enum contains IDs of commands supported by VSource class. VSourceParam enum contains IDs of params supported by VSource class. VSource class depends on libraries: open source Frame library (contains video frame structure and pixel formats) and open source ConfigReader library (provides methods to work with JSON structures (read/write)). Also VSourceV4L2 depends on open source Logger library which provides method to write logs. The library provides auto detection of supported resolution, format and fps. If particular devices doesn't support requested pixel format, resolution or fps, the library will set most appropriate parameters. Library interface:

class VSourceV4L2 : public VSource {
public:
    /// Open video source.
    bool openVSource(std::string& initString);
    /// Init video source by params structure.
    bool initVSource(VSourceParams& params);
    /// Get open status.
    bool isVSourceOpen();
    /// Close video source.
    void closeVSource();
    /// Get new video frame.
    bool getFrame(Frame& frame, int32_t timeoutMsec = 0);
    /// Set video source param.
    bool setParam(VSourceParam id, float value);
    /// Get video source param value.
    float getParam(VSourceParam id);
    /// Get video source params structure.
    VSourceParams getParams();
    /// Execute command.
    bool executeCommand(VSourceCommand id);
};

How to use

Below is a simple example of the program. The program opens the first video device in the system and captures video frames in an infinite loop.

#include <iostream>
#include "VSourceV4L2.h"

int main(void) {
    // Open video device.
    cr::video::VSource* source = new cr::video::VSourceV4L2();
    if (!source->openVSource("/dev/video0"))
        return -1;
    // Init frame.
    cr::video::Frame frame;
    // Main loop.
    while (true) {
        // Wait new frame 1000 msec.
        if (!source->getFrame(frame, 1000))
            continue;
        // Show info about frame.
        std::cout << "New frame " << frame.frameId <<
        " (" << frame.width << "x" << frame.height << ") cycle time: " <<
        (int)source->getParam(cr::video::VSourceParam::CYCLE_TIME_MKS) <<
        " mksec" << std::endl; 
    }
    return 1;
}

Downloads

VSourceV4L2 C++ library programmer’s manual: DOWNLOAD

Price and Terms

The VSourceV4L2 C++ library is supplied under a license in source code. Library pricing is available upon request info@constantrobotics.com