VOutputV4L2 C++ library v1.0.0

C++ library provides video output based on V4L2 API for Linux OS

Overview

VOutputV4L2 C++ library provides video output based on V4L2 API for Linux OS. The library provides simple interface without complexity of V4L2 API. The library allows the user to create his own video processing pipeline and record the results to a virtual video device (v4l2 loopback) which is used by any other programs (ffmpeg, gstreamer etc.) as a video source. VOutputV4L2 class depends on open source libraries: Frame (describes video frame structure and pixel formats) and Logger (provides method to write logs). Library interface:

class VOutputV4L2
{
public:
    /// Open device e.g "/dev/video4".
    bool open(std::string device);
    /// Write data to device.
    bool write(Frame& frame);
    /// Set log level.
    void setLogLevel(cr::utils::PrintFlag flag);
    /// Close device.
    void close(void);
};

How to use

Below is a simple example. The program opens the virtual video device /dev/video4 in the system, captures video frames from video file test.mp4 in an infinite loop and writes BGR video to video device.

#include <iostream>
#include <opencv2/opencv.hpp>
#include "VOutputV4L2.h"

int main(void)
{
    // Open video device.
    cr::video::VOutputV4L2 videoOutput;
    if(!videoOutput.open("/dev/video4"))
        return -1;

    // Open video file.
    cv::VideoCapture videoSource;
    if (!videoSource.open("test.mp4"))
        return -1;

    // Get frame size.
    int width = (int)videoSource.get(cv::CAP_PROP_FRAME_WIDTH);
    int height = (int)videoSource.get(cv::CAP_PROP_FRAME_HEIGHT);

    // Init frames.
    cv::Mat inputFrameBgr(cv::Size(width, height), CV_8UC3);
    cr::video::Frame srcFrame(width, height, cr::video::Fourcc::BGR24);

    while (true)
    {
        // Capture next video frame.
        videoSource >> inputFrameBgr;
        if (inputFrameBgr.empty())
        {
            // Set first video frame position in video file.
            videoSource.set(cv::CAP_PROP_POS_FRAMES, 1);
            continue;
        }

        // Copy bgr frame into srcFrame data.
        memcpy(srcFrame.data, inputFrameBgr.data, srcFrame.size);

        // Put frame into output device.
        if(!videoOutput.write(srcFrame))
            std::cout << "Can't write frame" << std::endl; 
    }
    return 1;
}

Downloads

VOutputV4L2 C++ library programmer’s manual: DOWNLOAD

Price and Terms

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