#
Video processing blocks
#
Table of Contents
Color effects Deinterlace Fish eye Flip/Rotate Gamma Gaussian blur Image overlay Mirror Perspective Pinch Resize Rotate Video sample grabber Sphere Square Stretch Text overlay Tunnel Twirl Video balance Video mixer Water ripple
#
Color effects
The block performs basic video frame color processing: fake heat camera toning, sepia toning, invert and slightly shade to blue, cross processing toning, and yellow foreground/blue background color filter.
#
Block info
Name: ColorEffectsBlock.
#
The sample pipeline
graph LR; UniversalSourceBlock-->ColorEffectsBlock; ColorEffectsBlock-->VideoRendererBlock;
#
Sample code
var pipeline = new MediaBlocksPipeline();
var filename = "test.mp4";
var fileSource = new UniversalSourceBlock(await UniversalSourceSettings.CreateAsync(new Uri(filename)));
// Sepia
var colorEffects = new ColorEffectsBlock(ColorEffectsPreset.Sepia);
pipeline.Connect(fileSource.VideoOutput, colorEffects.Input);
var videoRenderer = new VideoRendererBlock(pipeline, VideoView1);
pipeline.Connect(colorEffects.Output, videoRenderer.Input);
await pipeline.StartAsync();
#
Platforms
Windows, macOS, Linux, iOS, Android.
#
Deinterlace
The block deinterlaces interlaced video frames into progressive video frames. Several methods of processing are available. Use the DeinterlaceSettings class to configure the block.
#
Block info
Name: DeinterlaceBlock.
#
The sample pipeline
graph LR; UniversalSourceBlock-->DeinterlaceBlock; DeinterlaceBlock-->VideoRendererBlock;
#
Sample code
var pipeline = new MediaBlocksPipeline();
var filename = "test.mp4";
var fileSource = new UniversalSourceBlock(await UniversalSourceSettings.CreateAsync(new Uri(filename)));
var deinterlace = new DeinterlaceBlock(new DeinterlaceSettings());
pipeline.Connect(fileSource.VideoOutput, deinterlace.Input);
var videoRenderer = new VideoRendererBlock(pipeline, VideoView1);
pipeline.Connect(deinterlace.Output, videoRenderer.Input);
await pipeline.StartAsync();
#
Platforms
Windows, macOS, Linux, iOS, Android.
#
Fish eye
The fisheye block simulates a fisheye lens by zooming on the center of the image and compressing the edges.
#
Block info
Name: FishEyeBlock.
#
The sample pipeline
graph LR; UniversalSourceBlock-->FishEyeBlock; FishEyeBlock-->VideoRendererBlock;
#
Sample code
var pipeline = new MediaBlocksPipeline();
var filename = "test.mp4";
var fileSource = new UniversalSourceBlock(await UniversalSourceSettings.CreateAsync(new Uri(filename)));
var fishEye = new FishEyeBlock();
pipeline.Connect(fileSource.VideoOutput, fishEye.Input);
var videoRenderer = new VideoRendererBlock(pipeline, VideoView1);
pipeline.Connect(fishEye.Output, videoRenderer.Input);
await pipeline.StartAsync();
#
Platforms
Windows, macOS, Linux, iOS, Android.
#
Flip/Rotate
The block flips and rotates the video stream. Use the VideoFlipRotateMethod enumeration to configure.
#
Block info
Name: FlipRotateBlock.
#
The sample pipeline
graph LR; UniversalSourceBlock-->FlipRotateBlock; FlipRotateBlock-->VideoRendererBlock;
#
Sample code
var pipeline = new MediaBlocksPipeline();
var filename = "test.mp4";
var fileSource = new UniversalSourceBlock(await UniversalSourceSettings.CreateAsync(new Uri(filename)));
// 90 degree rotation
var flipRotate = new FlipRotateBlock(VideoFlipRotateMethod.Method90R);
pipeline.Connect(fileSource.VideoOutput, flipRotate.Input);
var videoRenderer = new VideoRendererBlock(pipeline, VideoView1);
pipeline.Connect(flipRotate.Output, videoRenderer.Input);
await pipeline.StartAsync();
#
Platforms
Windows, macOS, Linux, iOS, Android.
#
Gamma
The block performs gamma correction on a video stream.
#
Block info
Name: GammaBlock.
#
The sample pipeline
graph LR; UniversalSourceBlock-->GammaBlock; GammaBlock-->VideoRendererBlock;
#
Sample code
var pipeline = new MediaBlocksPipeline();
var filename = "test.mp4";
var fileSource = new UniversalSourceBlock(await UniversalSourceSettings.CreateAsync(new Uri(filename)));
var gamma = new GammaBlock(2.0);
pipeline.Connect(fileSource.VideoOutput, gamma.Input);
var videoRenderer = new VideoRendererBlock(pipeline, VideoView1);
pipeline.Connect(gamma.Output, videoRenderer.Input);
await pipeline.StartAsync();
#
Platforms
Windows, macOS, Linux, iOS, Android.
#
Gaussian blur
The block blurs the video stream using the Gaussian function.
#
Block info
Name: GaussianBlurBlock.
#
The sample pipeline
graph LR; UniversalSourceBlock-->GaussianBlurBlock; GaussianBlurBlock-->VideoRendererBlock;
#
Sample code
var pipeline = new MediaBlocksPipeline();
var filename = "test.mp4";
var fileSource = new UniversalSourceBlock(await UniversalSourceSettings.CreateAsync(new Uri(filename)));
var gaussianBlur = new GaussianBlurBlock();
pipeline.Connect(fileSource.VideoOutput, gaussianBlur.Input);
var videoRenderer = new VideoRendererBlock(pipeline, VideoView1);
pipeline.Connect(gaussianBlur.Output, videoRenderer.Input);
await pipeline.StartAsync();
#
Platforms
Windows, macOS, Linux, iOS, Android.
#
Image overlay
The block overlays an image loaded from a file onto a video stream.
You can set an image position and optional alpha value. 32-bit images with alpha-channel are supported.
#
Block info
Name: ImageOverlayBlock.
#
The sample pipeline
graph LR; UniversalSourceBlock-->ImageOverlayBlock; ImageOverlayBlock-->VideoRendererBlock;
#
Sample code
var pipeline = new MediaBlocksPipeline();
var filename = "test.mp4";
var fileSource = new UniversalSourceBlock(await UniversalSourceSettings.CreateAsync(new Uri(filename)));
var imageOverlay = new ImageOverlayBlock(@"logo.png");
pipeline.Connect(fileSource.VideoOutput, imageOverlay.Input);
var videoRenderer = new VideoRendererBlock(pipeline, VideoView1);
pipeline.Connect(imageOverlay.Output, videoRenderer.Input);
await pipeline.StartAsync();
#
Platforms
Windows, macOS, Linux, iOS, Android.
#
Mirror
The mirror block splits the image into two halves and reflects one over the other.
#
Block info
Name: MirrorBlock.
#
The sample pipeline
graph LR; UniversalSourceBlock-->MirrorBlock; MirrorBlock-->VideoRendererBlock;
#
Sample code
var pipeline = new MediaBlocksPipeline();
var filename = "test.mp4";
var fileSource = new UniversalSourceBlock(await UniversalSourceSettings.CreateAsync(new Uri(filename)));
var mirrorBlock = new MirrorBlock(MirrorMode.Top);
pipeline.Connect(fileSource.VideoOutput, mirrorBlock.Input);
var videoRenderer = new VideoRendererBlock(pipeline, VideoView1);
pipeline.Connect(mirrorBlock.Output, videoRenderer.Input);
await pipeline.StartAsync();
#
Platforms
Windows, macOS, Linux, iOS, Android.
#
Perspective
The perspective block applies a 2D perspective transform.
#
Block info
Name: PerspectiveBlock.
#
The sample pipeline
graph LR; UniversalSourceBlock-->PerspectiveBlock; PerspectiveBlock-->VideoRendererBlock;
#
Sample code
var pipeline = new MediaBlocksPipeline();
var filename = "test.mp4";
var fileSource = new UniversalSourceBlock(await UniversalSourceSettings.CreateAsync(new Uri(filename)));
var persBlock = new PerspectiveBlock(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
pipeline.Connect(fileSource.VideoOutput, persBlock.Input);
var videoRenderer = new VideoRendererBlock(pipeline, VideoView1);
pipeline.Connect(persBlock.Output, videoRenderer.Input);
await pipeline.StartAsync();
#
Platforms
Windows, macOS, Linux, iOS, Android.
#
Pinch
The block performs the pinch geometric transform of the image.
#
Block info
Name: PinchBlock.
#
The sample pipeline
graph LR; UniversalSourceBlock-->PinchBlock; PinchBlock-->VideoRendererBlock;
#
Sample code
var pipeline = new MediaBlocksPipeline();
var filename = "test.mp4";
var fileSource = new UniversalSourceBlock(await UniversalSourceSettings.CreateAsync(new Uri(filename)));
var pinchBlock = new PinchBlock();
pipeline.Connect(fileSource.VideoOutput, pinchBlock.Input);
var videoRenderer = new VideoRendererBlock(pipeline, VideoView1);
pipeline.Connect(pinchBlock.Output, videoRenderer.Input);
await pipeline.StartAsync();
#
Platforms
Windows, macOS, Linux, iOS, Android.
#
Rotate
The block rotates the image by a specified angle.
#
Block info
Name: RotateBlock.
#
The sample pipeline
graph LR; UniversalSourceBlock-->RotateBlock; RotateBlock-->VideoRendererBlock;
#
Sample code
var pipeline = new MediaBlocksPipeline();
var filename = "test.mp4";
var fileSource = new UniversalSourceBlock(await UniversalSourceSettings.CreateAsync(new Uri(filename)));
var rotateBlock = new RotateBlock(0.7);
pipeline.Connect(fileSource.VideoOutput, rotateBlock.Input);
var videoRenderer = new VideoRendererBlock(pipeline, VideoView1);
pipeline.Connect(rotateBlock.Output, videoRenderer.Input);
await pipeline.StartAsync();
#
Platforms
Windows, macOS, Linux, iOS, Android.
#
Resize
The block resizes the video stream. You can configure the resize method, the letterbox flag, and many other options.
Use the ResizeVideoEffect
class to configure.
#
Block info
Name: VideoResizeBlock.
#
The sample pipeline
graph LR; UniversalSourceBlock-->VideoResizeBlock; VideoResizeBlock-->VideoRendererBlock;
#
Sample code
var pipeline = new MediaBlocksPipeline();
var filename = "test.mp4";
var fileSource = new UniversalSourceBlock(await UniversalSourceSettings.CreateAsync(new Uri(filename)));
var videoResize = new VideoResizeBlock(new ResizeVideoEffect(1280, 720) { Letterbox = false });
pipeline.Connect(fileSource.VideoOutput, videoResize.Input);
var videoRenderer = new VideoRendererBlock(pipeline, VideoView1);
pipeline.Connect(videoResize.Output, videoRenderer.Input);
await pipeline.StartAsync();
#
Platforms
Windows, macOS, Linux, iOS, Android.
#
Video sample grabber
The video sample grabber calls an event for each video frame. You can save or process the received video frame.
#
Block info
Name: VideoSampleGrabberBlock.
#
The sample pipeline
graph LR; UniversalSourceBlock-->VideoSampleGrabberBlock; VideoSampleGrabberBlock-->VideoRendererBlock;
#
Sample code
var pipeline = new MediaBlocksPipeline();
var filename = "test.mp4";
var fileSource = new UniversalSourceBlock(await UniversalSourceSettings.CreateAsync(new Uri(filename)));
var videoSG = new VideoSampleGrabberBlock();
videoSG.OnVideoFrameBuffer += VideoSG_OnVideoFrameBuffer;
pipeline.Connect(fileSource.VideoOutput, videoSG.Input);
var videoRenderer = new VideoRendererBlock(pipeline, VideoView1);
pipeline.Connect(videoSG.Output, videoRenderer.Input);
await pipeline.StartAsync();
private void VideoSG_OnVideoFrameBuffer(object sender, VideoFrameBufferEventArgs e)
{
// save or process the video frame
}
#
Platforms
Windows, macOS, Linux, iOS, Android.
#
Sphere
The sphere block applies a sphere geometric transform to the video.
#
Block info
Name: SphereBlock.
#
The sample pipeline
graph LR; UniversalSourceBlock-->SphereBlock; SphereBlock-->VideoRendererBlock;
#
Sample code
var pipeline = new MediaBlocksPipeline();
var filename = "test.mp4";
var fileSource = new UniversalSourceBlock(await UniversalSourceSettings.CreateAsync(new Uri(filename)));
var sphereBlock = new SphereBlock();
pipeline.Connect(fileSource.VideoOutput, sphereBlock.Input);
var videoRenderer = new VideoRendererBlock(pipeline, VideoView1);
pipeline.Connect(sphereBlock.Output, videoRenderer.Input);
await pipeline.StartAsync();
#
Platforms
Windows, macOS, Linux, iOS, Android.
#
Square
The square block distorts the center part of the video into a square.
#
Block info
Name: SquareBlock.
#
The sample pipeline
graph LR; UniversalSourceBlock-->SquareBlock; SquareBlock-->VideoRendererBlock;
#
Sample code
var pipeline = new MediaBlocksPipeline();
var filename = "test.mp4";
var fileSource = new UniversalSourceBlock(await UniversalSourceSettings.CreateAsync(new Uri(filename)));
var squareBlock = new SquareBlock(new SquareVideoEffect());
pipeline.Connect(fileSource.VideoOutput, squareBlock.Input);
var videoRenderer = new VideoRendererBlock(pipeline, VideoView1);
pipeline.Connect(squareBlock.Output, videoRenderer.Input);
await pipeline.StartAsync();
#
Platforms
Windows, macOS, Linux, iOS, Android.
#
Stretch
The stretch block stretches the video in the circle around the center point.
#
Block info
Name: StretchBlock.
#
The sample pipeline
graph LR; UniversalSourceBlock-->StretchBlock; StretchBlock-->VideoRendererBlock;
#
Sample code
var pipeline = new MediaBlocksPipeline();
var filename = "test.mp4";
var fileSource = new UniversalSourceBlock(await UniversalSourceSettings.CreateAsync(new Uri(filename)));
var stretchBlock = new StretchBlock();
pipeline.Connect(fileSource.VideoOutput, stretchBlock.Input);
var videoRenderer = new VideoRendererBlock(pipeline, VideoView1);
pipeline.Connect(stretchBlock.Output, videoRenderer.Input);
await pipeline.StartAsync();
#
Platforms
Windows, macOS, Linux, iOS, Android.
#
Text overlay
The block adds the text overlay on top of the video stream.
#
Block info
Name: TextOverlayBlock.
#
The sample pipeline
graph LR; UniversalSourceBlock-->TextOverlayBlock; TextOverlayBlock-->VideoRendererBlock;
#
Sample code
var pipeline = new MediaBlocksPipeline();
var filename = "test.mp4";
var fileSource = new UniversalSourceBlock(await UniversalSourceSettings.CreateAsync(new Uri(filename)));
var textOverlay = new TextOverlayBlock(new TextOverlaySettings("Hello world!"));
pipeline.Connect(fileSource.VideoOutput, textOverlay.Input);
var videoRenderer = new VideoRendererBlock(pipeline, VideoView1);
pipeline.Connect(textOverlay.Output, videoRenderer.Input);
await pipeline.StartAsync();
#
Platforms
Windows, macOS, Linux, iOS, Android.
#
Tunnel
The block applies a light tunnel effect to a video stream.
#
Block info
Name: TunnelBlock.
#
The sample pipeline
graph LR; UniversalSourceBlock-->TunnelBlock; TunnelBlock-->VideoRendererBlock;
#
Sample code
var pipeline = new MediaBlocksPipeline();
var filename = "test.mp4";
var fileSource = new UniversalSourceBlock(await UniversalSourceSettings.CreateAsync(new Uri(filename)));
var tunnelBlock = new TunnelBlock();
pipeline.Connect(fileSource.VideoOutput, tunnelBlock.Input);
var videoRenderer = new VideoRendererBlock(pipeline, VideoView1);
pipeline.Connect(tunnelBlock.Output, videoRenderer.Input);
await pipeline.StartAsync();
#
Platforms
Windows, macOS, Linux, iOS, Android.
#
Twirl
The twirl block twists the video frame from the center out.
#
Block info
Name: TwirlBlock.
#
The sample pipeline
graph LR; UniversalSourceBlock-->TwirlBlock; TwirlBlock-->VideoRendererBlock;
#
Sample code
var pipeline = new MediaBlocksPipeline();
var filename = "test.mp4";
var fileSource = new UniversalSourceBlock(await UniversalSourceSettings.CreateAsync(new Uri(filename)));
var twirlBlock = new TwirlBlock();
pipeline.Connect(fileSource.VideoOutput, twirlBlock.Input);
var videoRenderer = new VideoRendererBlock(pipeline, VideoView1);
pipeline.Connect(twirlBlock.Output, videoRenderer.Input);
await pipeline.StartAsync();
#
Platforms
Windows, macOS, Linux, iOS, Android.
#
Video balance
The block processes the video stream and allows you to change brightness, contrast, hue, and saturation. Use the VideoBalanceVideoEffect class to configure the block settings.
#
Block info
Name: VideoBalanceBlock.
#
The sample pipeline
graph LR; UniversalSourceBlock-->VideoBalanceBlock; VideoBalanceBlock-->VideoRendererBlock;
#
Sample code
var pipeline = new MediaBlocksPipeline();
var filename = "test.mp4";
var fileSource = new UniversalSourceBlock(await UniversalSourceSettings.CreateAsync(new Uri(filename)));
var videoBalance = new VideoBalanceBlock(new VideoBalanceVideoEffect() { Brightness = 0.25 });
pipeline.Connect(fileSource.VideoOutput, videoBalance.Input);
var videoRenderer = new VideoRendererBlock(pipeline, VideoView1);
pipeline.Connect(videoBalance.Output, videoRenderer.Input);
await pipeline.StartAsync();
#
Platforms
Windows, macOS, Linux, iOS, Android.
#
Video mixer
The video mixer block has several inputs and one output. The block draws the inputs in the selected order at the selected positions. You can also set the desired level of transparency for each stream.
#
Block info
Name: VideoMixerBlock.
#
The sample pipeline
graph LR; UniversalSourceBlock#1-->VideoMixerBlock; UniversalSourceBlock#2-->VideoMixerBlock; VideoMixerBlock-->VideoRendererBlock;
#
Sample code
var pipeline = new MediaBlocksPipeline();
var filename1 = "test.mp4";
var fileSource1 = new UniversalSourceBlock(await UniversalSourceSettings.CreateAsync(new Uri(filename1)));
var filename2 = "test2.mp4";
var fileSource2 = new UniversalSourceBlock(await UniversalSourceSettings.CreateAsync(new Uri(filename2)));
var mixerSettings = new VideoMixerSettings();
mixerSettings.AddStream(new VideoMixerStream(new Rect(0, 0, 1280, 720), 0));
mixerSettings.AddStream(new VideoMixerStream(new Rect(100, 100, 420, 340), 1));
var videoMixer = new VideoMixerBlock(mixerSettings);
pipeline.Connect(fileSource1.VideoOutput, videoMixer.Inputs[0]);
pipeline.Connect(fileSource2.VideoOutput, videoMixer.Inputs[1]);
var videoRenderer = new VideoRendererBlock(pipeline, VideoView1);
pipeline.Connect(videoMixer.Output, videoRenderer.Input);
await pipeline.StartAsync();
#
Platforms
Windows, macOS, Linux, iOS, Android.
#
Water ripple
The water ripple block creates a water ripple effect on the video stream.
Use the WaterRippleVideoEffect
class to configure.
#
Block info
Name: WaterRippleBlock.
#
The sample pipeline
graph LR; UniversalSourceBlock-->WaterRippleBlock; WaterRippleBlock-->VideoRendererBlock;
#
Sample code
var pipeline = new MediaBlocksPipeline();
var filename = "test.mp4";
var fileSource = new UniversalSourceBlock(await UniversalSourceSettings.CreateAsync(new Uri(filename)));
var wrBlock = new WaterRippleBlock(new WaterRippleVideoEffect());
pipeline.Connect(fileSource.VideoOutput, wrBlock.Input);
var videoRenderer = new VideoRendererBlock(pipeline, VideoView1);
pipeline.Connect(wrBlock.Output, videoRenderer.Input);
await pipeline.StartAsync();
#
Platforms
Windows, macOS, Linux, iOS, Android.