Overview
VSourceUniversal C++ library captures video from every video source that the RapidPixel SDK supports through one VSource interface: video files, network streams, V4L2 devices, cameras of libcamera and cameras, files and streams of Windows Media Foundation. The user gives only the source string (the init string of openVSource(...) or the field source of VSourceParams), the library selects the video source library that can open the source and creates it inside. Supported video sources:
(Linux and Windows) Video files: MP4, MOV, M4V, 3GP, AVI, Matroska (MKV), WebM, raw H.264, H.265 and Motion JPEG streams (codecs H.264, H.265, Motion JPEG, MPEG-4 Part 2, uncompressed BGR24).
(Linux and Windows) Network streams: RTSP, RTSPS, SDP-less RTP and SRTP, MPEG-TS over UDP (codecs H.264, H.265, JPEG), KLV and ONVIF® metadata.
(Linux) V4L2 video devices (USB cameras, capture cards, MIPI cameras with a V4L2 driver): raw formats, MJPEG, H.264, H.265.
(Linux) Cameras of libcamera (Raspberry Pi cameras, other cameras with a libcamera pipeline handler, USB cameras).
(Windows) Cameras, video files and HTTP / RTSP streams of Windows Media Foundation.
Documentation
Documentation: GO TO DOCUMENTATION
Simple interface
class VSourceUniversal : public VSource
{
public:
/// Get string of current library version.
static std::string getVersion();
/// Open video source.
bool openVSource(std::string& initString) override;
/// Init video source.
bool initVSource(VSourceParams& params) override;
/// Get open status.
bool isVSourceOpen() override;
/// Close video source.
void closeVSource() override;
/// Get new video frame.
bool getFrame(Frame& frame, int32_t timeoutMsec = 0) override;
/// Set video source param.
bool setParam(VSourceParam id, float value) override;
/// Get video source param value.
float getParam(VSourceParam id) override;
/// Get video source params structure.
void getParams(VSourceParams& params) override;
/// Execute command.
bool executeCommand(VSourceCommand id) override;
/// Decode and execute command.
bool decodeAndExecuteCommand(uint8_t* data, int size) override;
/// Get connection status.
bool isVSourceConnected();
/// Get the telemetry of the last frame.
bool getTelemetry(VSourceUniversalTelemetry& telemetry);
/// Set a custom video codec.
void setCodec(VCodec* codec);
/// Get the video source library.
VSourceUniversalLibrary getLibrary();
/// Check if a video source library is built.
static bool isLibraryAvailable(VSourceUniversalLibrary library);
};
Simple example
#include <iostream>
#include <string>
#include "SimpleUi.h"
#include "VSourceUniversal.h"
int main(int argc, char** argv)
{
// Open video source: a video file, a stream URL or a camera. The library
// is selected by the init string.
rapidpixel::VSourceUniversal source;
std::string initString = (argc > 1) ? argv[1] : "0;640;480";
if (!source.openVSource(initString))
{
// The init string is not printed: it can hold a password.
std::cout << "ERROR: can't open video source" << std::endl;
return -1;
}
// Create the window to display the video.
rapidpixel::SimpleUiWindow window("VSourceUniversal Video Display");
window.show();
rapidpixel::Frame frame;
rapidpixel::VSourceUniversalTelemetry telemetry;
int noFrameCount = 0;
while (window.isOpen() && noFrameCount < 10)
{
// Wait up to 1000 ms for new frame in BGR24 format: the frames of
// every source are decoded and converted by the library.
frame.fourcc = rapidpixel::Fourcc::BGR24;
if (!source.getFrame(frame, 1000))
{
++noFrameCount;
continue;
}
noFrameCount = 0;
const int lostFrames =
source.getTelemetry(telemetry) ? telemetry.lostFrames : 0;
// Draw the text on the captured frame and display it with SimpleUI.
rapidpixel::SimpleUiDraw::drawText(frame, 10, 10,
"Frame ID: " + std::to_string(frame.frameId) + " | Lost: " +
std::to_string(lostFrames) + " | Connected: " +
std::to_string(source.isVSourceConnected()),
rapidpixel::Color{0, 255, 0, 255}, 16);
window.render(frame);
if (window.waitKey(27, 1)) // ESC key to exit
{
return 0;
}
}
// The window was closed by the user.
if (!window.isOpen())
{
return 0;
}
std::cout << "ERROR: no frames from the video source" << std::endl;
return -1;
}

