1.3.8. Feed Stages
Overview
So far, feeds have a rather fixed structure, taking some kind of input (e.g. from a camera) and outputting it to some target, which could be a local output (e.g. a window) or to a remote recipient.
Feed “stages” allow additional processing to be applied to the feed - e.g. a video feed could be rotated and/or cropped before continuing its journey to the target. Importantly, the application can decide the order in which these stages are applied, allowing a chain of processing and feed modification to occur for any given feed.
Creating a feed stage
A feed stage is a special type of feed component that take a media type (e.g. video) and outputs the same media type. Depending on the stage’s purpose, it may modify the media in some way, but it could also be used to inspect the media and perform other processing or actions (e.g. analysing the feed media for some purpose).
In the following example, we create a stage that will:
Rotate the video feed by 90 degrees, then
Crop the video feed top and bottom by 128 pixels
using namespace Proximie;
// Create a rotate/crop stage
PxMedia::VideoStageRotateCrop rotateCrop;
rotateCrop
.order(PxMedia::VideoStageRotateCrop::Order::RotateFlipThenCrop)
.rotateFlip(PxMedia::VideoStageRotateCrop::RotateFlip::Clockwise90)
.cropRectangle().top(128).bottom(128);
All feed stages are derived from VideoFeedStageComponent
.
For more details and a list of available stage subclasses, see the API documentation for
VideoFeedStageComponent
itself.
Applying stages to a feed component
As mentioned above, certain feed components allow stages to be added to them. For example, most video sources allow stages to be applied for post-processing the source video.
Here we create an input feed as normal:
PxMedia::VideoInputFeedV4Linux2 video;
video.deviceProperties().device("/dev/video0");
video.videoCapabilities().frameRate(30);
Then, we can set the sequence of video stages:
video.videoStages().sequence({rotateCrop});
In this case, we just set a single stage, but note that the video stages
sequence()
method takes a
vector of stages, allowing multiple stages to be applied in the given order.
Once the stages are added to the feed component, the application can use that component
to create a feed as normal.
The stages defined using sequence()
are inserted into the resulting feed’s pipeline.
auto created = PxMedia::MediaServerOutgoingVideoFeed::create(session, props, video, output);
if (created) {
// ...
See the process of creating feeds described in the section Managing feeds for more details.