2.2.17. Video Outputs

Incoming and outgoing video feeds can optionally output video to a local window, as an RTP stream over UDP, to an inter pipe for other feeds to access or to a V4L2 loopback device (virtual camera).

This is specified during construction of the video feed type, by passing a VideoOutputFeedComponent object.

For example, to display an outgoing Media Server video feed in a local window:

    PxMedia::VideoOutputFeedAuto localOut;
    auto                         outgoingFeed =
        PxMedia::MediaServerOutgoingVideoFeed::create(mediaSession, props, input, localOut);

To display an outgoing Media Server video feed via RTP/UDP:

    PxMedia::VideoOutputFeedUdp udpOutput;
    udpOutput.host("localhost");
    udpOutput.port(5006);
    PxMedia::X264EncoderFeedComponent encoder;
    encoder.bitrate(5000_kbps);
    udpOutput.encoder(encoder);
    auto outgoingFeed =
        PxMedia::MediaServerOutgoingVideoFeed::create(mediaSession, props, inputVideo, udpOutput);

To output a local video feed to a V4L2 loopback device (Linux only):

    PxMedia::VideoOutputFeedV4Linux2 v4l2Output;
    v4l2Output.device("/dev/video2");

    PxMedia::UtilityVideoLocalFeed::FeedProperties utilProps{"v4l2-output"};
    auto                                           result =
        PxMedia::UtilityVideoLocalFeed::create(context, utilProps, inputVideo, v4l2Output);

Note

V4L2 loopback output requires the v4l2loopback kernel module to be loaded. The specified device (e.g., /dev/video2) must exist and be a valid V4L2 loopback device. Add loopback devices with specific settings using modprobe, for example:

sudo modprobe v4l2loopback exclusive_caps=1,1,1,1 max_buffers=2 devices=4

To disable local output of an outgoing Media Server video feed:

    PxMedia::VideoOutputComponentNull nullOutput;
    auto                              outgoingFeed =
        PxMedia::MediaServerOutgoingVideoFeed::create(mediaSession, props, inputVideo, nullOutput);

Note that the output encoder properties can be set using encoderProperties(). For a list of available encoder properties, see X264EncoderFeedComponent.

To use a hardware encoder like VAAPI (Intel/AMD GPUs) instead of the default X264 software encoder, use encoder():

    // Create a VAAPI hardware encoder for Intel/AMD GPUs
    PxMedia::H264VaapiEncoderComponent vaapiEncoder;
    vaapiEncoder.bitrate(5000_kbps);

    PxMedia::VideoOutputFeedUdp udpOutput;
    udpOutput.host("localhost");
    udpOutput.port(5006);
    udpOutput.encoder(vaapiEncoder);
    auto outgoingFeed =
        PxMedia::MediaServerOutgoingVideoFeed::create(mediaSession, props, inputVideo, udpOutput);

For a list of available VAAPI encoder properties, see H264VaapiEncoderComponent.

To display an incoming Peer video feed in a local window:

    PxMedia::VideoOutputFeedAuto localOut;
    auto                         remotePeerFeed =
        PxMedia::PeerRemoteVideoFeed::create(peerSession, feedProperties, localOut);

To display an incoming Peer video feed via RTP/UDP:

    PxMedia::VideoOutputFeedUdp udpOutput;
    udpOutput.host("localhost");
    udpOutput.port(5006);
    PxMedia::X264EncoderFeedComponent encoder;
    encoder.bitrate(5000_kbps);
    udpOutput.encoder(encoder);
    auto remotePeerFeed =
        PxMedia::PeerRemoteVideoFeed::create(peerSession, feedProperties, udpOutput);

To allow another feed to read an outgoing Media Server video feed via an inter pipe:

    PxMedia::VideoOutputFeedInter outputVideo;
    auto                          outgoingFeed =
        PxMedia::MediaServerOutgoingVideoFeed::create(mediaSession, props, input, outputVideo);

When using VideoOutputFeedInter, all calls to makeInput() must be made before the output is passed to a feed create() call. Inputs obtained after the feed has been created will not be connected to the pipeline.

Each VideoInputFeedInter obtained from makeInput() can only be used in a single feed. Likewise, each VideoOutputFeedInter can only be used in a single feed. Violating either constraint is detected and surfaces as a PipelineElementBadProps error when the affected feed is created.