Text overlay
Products: Video Capture SDK .Net, Media Player SDK .Net, Video Edit SDK .Net
Engines: VideoCaptureCore, MediaPlayerCore, VideoEditCore
Introduction
This example demonstrates how to overlay text on a video stream. You can set the font, size, color, position of the text, and other properties.
Sample code
Most simple text overlay with custom position:
var effect = new VideoEffectTextLogo(true, "textoverlay");
// set position
effect.Left = 20;
effect.Top = 20;
// set Font (System.Drawing.Font)
effect.Font = new Font("Arial", 40);
// set text
effect.Text = "Hello, world!";
// set text color
effect.FontColor = Color.Yellow;
MediaPlayer1.Video_Effects_Add(effect);
Date/time and frame number modes
You can set custom modes to display the current date and time, current video time stamp, or frame number.
Use the Mode
property to set the mode:
// set mode and mask
effect.Mode = TextLogoMode.DateTime;
effect.DateTimeMask = "yyyy-MM-dd. hh:mm:ss";
You can use the TimeStampMask
and DateTimeMask
properties to set the mask for the time and date. Frame number mode does not require any additional settings.
Fade-in and fade-out
You can set the fade-in and fade-out effects for the text overlay.
// add the fade-in
effect.FadeIn = true;
effect.FadeInDuration = TimeSpan.FromMilliseconds(5000);
// add the fade-out
effect.FadeOut = true;
effect.FadeOutDuration = TimeSpan.FromMilliseconds(5000);
Rotate
You can rotate the text overlay by 90, 180, or 270 degrees.
// set rotation mode
effect.RotationMode = TextRotationMode.Rm90;
Flip
You can flip the text overlay horizontally, vertically, or both.
// set flip mode
effect.FlipMode = TextFlipMode.XAndY;
Visit our GitHub page to get more code samples.