Watermark

Update time: 2025/06/11 16:45:39

For the purposes of information security, copyright notice, anti-counterfeiting and publicity, you can add watermarks to the video canvas, such as text watermarks like corporate name and slogan, timestamp watermarks like recording time, and image watermarks like logos.

In education scenarios, this function can be used to set various types of watermarks (such as copyright owner logo) for teaching courseware; in financial scenarios, in order to ensure the salesperson's operation standardization, service quality, and information archiving, it is necessary to record the full process of business and apply appropriate watermarks for the purpose of anti-counterfeiting or recording.

The NERTC SDK supports the following three settings of watermarks on canvas:

  • Text watermark: A piece of text information is used as a watermark, where setting of font type and size is supported.
  • Dynamic timestamp watermark: The current timestamp is used as the watermark, and the display format is "2021-03-18 14:30:35".
  • Static image watermark: An image is used as a watermark.

Considerations

  • The watermark-related methods apply to the local or remote video canvas, and do not affect the video streaming. Once the canvas is removed, any watermark on it will also be removed automatically.
  • Before setting a watermark, you need to set the canvas through the canvas-related methods, such as setupLocalVideoCanvas, setupLocalSubStreamVideoCanvas, setupRemoteVideoCanvas, and setupRemoteSubStreamVideoCanvas.
  • When setting text, time stamp and image watermarks at the same time, the layers of canvas will be overwritten in the order of image, text and timestamp in the case of any overlap in the positions of different types of watermarks.

Add, modify or delete watermarks

After setting the video canvas, you can add a watermark to the video canvas by taking the following steps:

  • Call setLocalCanvasWatermarkConfigs to set the local video canvas watermark.
    • Adding watermarks to the main stream or SubStream canvas is supported.
    • Calling setLocalCanvasWatermarkConfigs again means to update the watermark.
    • Setting config to "null" means to clear the watermark.
  • Call setRemoteCanvasWatermarkConfigs to set the remote video canvas watermark of the specified user, where adding a watermark to the main stream or SubStream canvas is supported.
    • Adding watermarks to the main stream or SubStream canvas is supported.
    • Calling setRemoteCanvasWatermarkConfigs again means to update the watermark.
    • Setting config to "null" means to clear the watermark.

Set watermarks

When adding a canvas watermark, you can set the type and content of the watermark through the config field.

Text watermark

The enumeration value textWatermarks means to set a text watermark. When adding a text watermark, you need to set the following parameters:

  • A maximum of 10 text watermarks can be added.
  • There is no limit to the string length of the text watermark. The final presentation depends on the font size and the size of the watermark box, and areas beyond the watermark box will not be displayed.
  • The automatic line wrapping is supported for text watermarks. If the text length exceeds the width of the watermark box, the text will be automatically wrapped.
  • Setting the watermark box through offsetX and other parameters for text watermarks is supported. For details, please refer to Setting watermark position.
Parameter Description
content Specify the content of text watermark.
fontSize Font size. The default value is 10, which is equivalent to 10 x 15 points on a 144 dpi device.
fontColor Font color. The default is 0xFFFFFFFF, or white.

Timestamp watermark

The enumeration value timestampWatermark means to set a timestamp watermark.

  • A maximum of 1 timestamp watermark can be added.
  • The time of the timestamp watermark is the same as the current time, and changes in real time. The display format is “2021-03-18 14:30:35".
  • Setting the watermark box through offsetX and other parameters for timestamp watermarks is supported. For details, please refer to Setting watermark position.

When adding a timestamp watermark, you need to set the following parameters:

Parameter Description
fontSize Font size. The default value is 10, which is equivalent to 10 x 15 points on a 144 dpi device.
fontColor Font color. The default is 0xFFFFFFFF, or white.

Image watermark

The enumeration value imageWatermarks means to set an image watermark.

  • A maximum of 4 image watermarks can be added.
  • When setting multiple image watermarks, you can pass multiple image watermark arrays.

When adding an image watermark, you need to set the following parameters:

Parameter Description
images Image used as the watermark.
imageWidth Width of the watermark image. Its unit is pixel, and its default value is 0, which means that the original width of the image is applied.
imageHeight Height of the watermark image. Its unit is pixel, and its default value is 0, which means that the original height of the image is applied.
offsetX Horizontal distance between the upper left corner of the image and that of the video canvas. Its unit is pixel, and its default value is 0.
offsetY Vertical distance between the upper left corner of the image and that of the video canvas. Its unit is pixel, and its default value is 0.
fps Frame rate for playing. The default frame rate is 0 frame/sec, which means no automatic switching of images.
loop Whether to enable the loop or not. The loop is enabled by default. Once it is set to false, the watermark array will disappear after playing.

Set watermark position

When adding a watermark, you can set the position and area size of the watermark through offsetX, offsetY, wmWidth and wmHeight. Where:

  • offsetX and offsetY are used to set the horizontal and vertical positions of a watermark.
  • wmWidth and wmHeight are used to set the area size of the watermark box.

In the case of an image watermark, wmWidth and wmHeight are used to set the size of the image watermark.

The watermark frame is the outer border of the watermark, which is colorless and can be used to control the width and height of the watermark area. For example, you can control the size of the watermark box to enable automatic line wrap if there are too many words. If the watermark box exceeds the range of canvas, only the overlapping part of the watermark box and the canvas is displayed.

Parameter Description
offsetX Horizontal distance between the upper left corner of the watermark and that of the video canvas. Unit: pixel.
offsetY Vertical distance between the upper left corner of the watermark and that of the video canvas. Unit: pixel.
wmColor Color of the watermark background area. The default value is 0x88888888, which is grey. Setting the transparency level is supported.
wmWidth Width of the watermark box. Unit: pixel. The default value is 0, which means no watermark box.
wmHeight Height of the watermark box. Unit: pixel. The default value is 0, which means no watermark box.

Sample code

The following sample codes demonstrate how to set 3 watermarks, including 1 image watermark, 1 timestamp watermark, and 1 text watermark.

NERtcCanvasWatermarkConfig config = new NERtcCanvasWatermarkConfig();
//Timestamp watermark
config.timestampWatermark = new NERtcTimestampWatermarkConfig(); 
config.timestampWatermark.fontSize = 10;
config.timestampWatermark.fontColor = 0xFFFFFFFF;
config.timestampWatermark.offsetX = 0;
config.timestampWatermark.offsetY = 0;
config.timestampWatermark.wmColor = 0x88888888;
config.timestampWatermark.wmWidth = 0;
config.timestampWatermark.wmHeight = 0;

//Text watermark
int len = 4; //Two text watermarks
NERtcTextWatermarkConfig[] textWatermarkConfigs = new NERtcTextWatermarkConfig[len];
config.textWatermarks = textWatermarkConfigs;
for(int i =0; i< len; i++) {
    NERtcTextWatermarkConfig textConfig = new NERtcTextWatermarkConfig();
    textConfig.content = "Test : " + i;
    textConfig.fontSize = 10;
    textConfig.fontColor = 0xFFFFFFFF;
    textConfig.offsetX = 0;
    textConfig.offsetY = 0;
    textConfig.wmColor = 0x88888888;
    textConfig.wmWidth = 0;
    textConfig.wmHeight = 0;
    textWatermarkConfigs[i] = textConfig;
}

//Image watermark
len = 2; //Two image watermarks
NERtcImageWatermarkConfig[] imageWatermarkConfigs = new NERtcImageWatermarkConfig[len];
config.imageWatermarks = imageWatermarkConfigs;
for(int i =0; i< len; i++) {
    NERtcImageWatermarkConfig imageConfig = new NERtcImageWatermarkConfig();
    Bitmap[] bitmaps = new Bitmap[len];
    for(int j=0;j<len;j++) {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inPreferredConfig = Bitmap.Config.ARGB_8888;
        Bitmap tmp = BitmapFactory.decodeStream(getAssets().open(dir +"/" + waters[j]));
        bitmaps[j] = tmp;
    }
    imageConfig.images = bitmaps;    
    imageConfig.imageWidth = 0;
    imageConfig.imageHeight = 0;
    imageConfig.offsetX = 0;
    imageConfig.offsetY = 0;
    imageConfig.fps = 2;
    imageConfig.loop = true;
    imageWatermarkConfigs[i] = imageConfig;
}
NERtcVideoStreamType type = NERtcVideoStreamType.kNERtcVideoStreamTypeMain;
NERtcEx.getInstance().setLocalCanvasWatermarkConfigs(type,config);
Was this page helpful?
Yes
No
  • Considerations
  • Add, modify or delete watermarks
  • Set watermarks
  • Text watermark
  • Timestamp watermark
  • Image watermark
  • Set watermark position
  • Sample code