Overview
The VCodecContour C++ library is a video codec for very narrow channels such as serial ports and radio modems: a Full HD video becomes a stream of a few kilobits per second (for example 19200 bits per second). The decoded video looks like the picture of an old 8-bit video game: areas of flat colors of a palette of 16 colors with smooth boundaries along the outlines of the objects of the frame (fields, roads, the horizon, the sky, vehicles). The picture follows the video frame by frame, also in a fast flight: an operator who lost the main video link keeps the motion and the orientation. Encoding / decoding time on different platforms (only 2 CPU cores usage):
| Platform | CPU | Encoding | Decoding | ------------------------------------------------------------------ | MediaTek Genio 720 | On 2×A78 2.6GHz | 3.1 ms | 2.3 ms | | Intel Atom x7835RE | 8x86, 3.6GHz | 3.1 ms | 2.3 ms | | Raspberry Pi 5 | 4×A76, 2.4GHz | 4.1 ms | 3.1 ms | | NVIDIA Jetson Orin NX | 8×A78AE, 2.0GHz | 5.2 ms | 5.1 ms | | Raspberry Pi 4 | 4×A72, 1.8GHz | 9.8 ms | 6.4 ms | | NVIDIA Jetson Nano | 4×A57, 1.48GHz | 11.4 ms | 8.4 ms | | NXP i.MX 95 | 6×A55, 1.8GHz | 13.0 ms | 8.9 ms | | NXP i.MX 8M Plus | 4×A53, 1.8GHz | 13.4 ms | 10.0 ms | | Rockchip RK3566 | 4×A55, 1.8GHz | 15.2 ms | 9.8 ms |
Demo video
Simple interface
class VCodecContour : public VCodec
{
public:
/// Get library version.
static std::string getVersion();
/// Encode (NV12 source) or decode (H264 source) a 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;
};
Simple example
#include <cstdint>
#include <cstring>
#include <exception>
#include <iostream>
#include "VCodecContour.h"
using namespace std;
using namespace rapidpixel;
int main()
{
cout << "VCodecContour v" << VCodecContour::getVersion() << endl;
// Video: 1280 x 720 pixels (even numbers), 300 frames,
// 30 frames per second. Channel: 19.2 kbps.
const int width{1280};
const int height{720};
const int framesNumber{300};
const int fps{30};
const float bitrateKbps{19.2f};
// The constructors of the codec and of the frames throw std::bad_alloc
// if memory is not available.
try
{
// The encoder needs the bitrate and the frame rate.
VCodecContour encoder;
VCodecContour decoder;
if (!encoder.setParam(VCodecParam::BITRATE_KBPS, bitrateKbps) ||
!encoder.setParam(VCodecParam::FPS, static_cast<float>(fps)))
return 1;
// Source frame (NV12) with gray chroma.
Frame frame(width, height, Fourcc::NV12);
Frame packet;
Frame picture;
memset(frame.data + width * height, 128, width * height / 2);
int bytes{0};
int pictures{0};
for (int n = 0; n < framesNumber; ++n)
{
// Synthetic video: gray stripes which move to the left
for (int y = 0; y < height; ++y)
{
for (int x = 0; x < width; ++x)
{
const bool square{x>3 * n && x<3 * n + 200 && y>260 && y<460};
const int stripe{(x + 2 * n) / 160 % 2};
frame.data[y * width + x] =
static_cast<uint8_t>(square ? 235 : 60 + stripe * 60);
}
}
// Transmitter: one packet per frame
if (!encoder.transcode(frame, packet))
return 1;
bytes += packet.size;
// Receiver
if (!decoder.transcode(packet, picture))
return 1;
if (picture.size > 0)
++pictures;
}
cout << "Average bitrate: " << bytes * 8 * fps / framesNumber <<
" bits per second" << endl;
return pictures > 0 ? 0 : 1;
}
catch (const exception& error)
{
cout << "Error: " << error.what() << endl;
return 1;
}
}

