Transcoding video

KlvInjector provides video transcoding functionality.

Working with RAW video buffers.

KlvInjector supports receiving MPEG-TS streams with H.264 or H.265 payloads, as well as RTP streams carrying H.264, H.265, or AV1 video. It provides a built-in transcoding option that converts the video to H.264 while multiplexing STANAG 4609 metadata into the output stream.

Configuration Options

Users can configure key transcoding parameters, including: - Video profile
- Resolution
- Bitrate
- Frame rate

RTP Stream Format

When receiving RTP streams, users must specify the payload format by appending it to the stream URL.

rtp://127.0.0.1:1234/format=av1

The format must be one of the following: - m2t (mpegts over rtp)
- h264
- h265
- av1

More on video encoder

Configuring Video transcoding:

This code snippet demonstrates how to configure video transcoding from rtp stream with av1 codec.

Let's create a VS project, add the references and make sure all the required dependencies are copied to the target directory.

Next, we create an instance of the KlvInjector, initialize it and add events:

CKlvInjector m_KlvInjector = new CKlvInjector();

// Setup events
m_KlvInjector.PlayerEvent += new NotifyPlayerEvent(OnPlayerEvent);
m_KlvInjector.ErrorEvent += new NotifyError(OnErrorEvent);

There are some additional parameters that may be configured:

// Setup video / audio rendering
// Set to true if you want to decode and show the video
m_KlvInjector.RenderVideo = true; 

// Set Window handle to render video to. If set to 0, a default window will be created internally.
m_KlvInjector.Hwnd = 0;

// Configure KlvInsertion mode - SYNC or ASYNC
m_klvProps = new KlvDataPropsWr(ProcessingModeWr.INSERT_KLV_SYNC);

Next, we'll configure the output. In this demo we'll have both network and file targets, so the resulted STANAG stream will be simultaneously recorded to file and sent to the network.

// Network stream target
m_KlvInjector.NetTarget.Url = m_targetUrl;
m_KlvInjector.NetTarget.Use = true;

// File target
m_KlvInjector.FileTarget.Dir = Path.GetDirectoryName(m_targetFile);
m_KlvInjector.FileTarget.Name = Path.GetFileName(m_targetFile);
m_KlvInjector.FileTarget.SegmentationType = FileSegmentationType.SegmentationType_None;
m_KlvInjector.FileTarget.Use = true;

There are some additional parameters that can be configured but for the sake of simplicity we'll first go with defaults.

As we need to transcode video, lets set the related parameters:

    var encodingParams = new EncoderConfigParamsWr2();
    encodingParams.Profile = m_EncodingProfile;
    encodingParams.BitRate = 1024 * m_EncodingBitrate;
    //    encodingParams.Width = (int)m_FrameWidth;    // Keep original, if not set or -1
    //    encodingParams.Height = (int)m_FrameHeight;  // Keep original, if not set or -1

    m_KlvInjector.TranscodeIncomingVideo(new VideoEncodePropsWr()
    {
        IsEnabled = true,
        EncodingParams = encodingParams
    });

Now, we just need to init and start the Injector. The url provided to the Init function describes rtp stream with av1 coded.

// Initialize injector
m_KlvInjector.Init("rtp://127.0.0.1:1234/format=av1");
// Start Processing
m_KlvInjector.Start();