Watermark (Beta)
The Watermark extension works with Web SDK v4.24.0 or later to add image watermarks to video streams. The extension supports customizable watermark properties such as position, size, and transparency, and can be applied to both local and remote video tracks.
Understand the tech
The Watermark extension integrates into the Web SDK's video processing pipeline to overlay images onto video streams in real-time. When enabled, the extension processes each video frame by compositing the watermark image at the specified position with the configured transparency level.
Prerequisites
To use the Watermark extension, ensure that:
- You are using the latest version of Chrome (recommended), Edge, or Firefox desktop browser.
- You have implemented the SDK quickstart in your project using the Web SDK version 4.24.0 or later.
Implementation
Follow these steps to integrate the Watermark extension and add watermarks to your video streams.
Integrate the extension
Use npm to integrate the agora-extension-video-watermark package into your project.
-
Install the Watermark extension:
-
Import the watermark module in your
.jsfile:
Register the extension
Call AgoraRTC.registerExtensions and pass the created VideoWatermarkExtension instance to register the Watermark extension.
Agora recommends creating only one VideoWatermarkExtension instance.
Enable the extension
Follow these steps to enable the Watermark extension:
-
Call
createProcessorto create anIVWProcessorinstance: -
Call the SDK's
pipemethod and specify theprocessorDestinationproperty to inject the extension into the video processing pipeline:
Add watermarks
The Watermark extension supports two methods for creating watermark images:
-
Use an existing HTMLImageElement
If you already have an image element in the DOM (for example, from an
<img>tag), you can use it directly: -
Use an image URL (asynchronous)
You can also create a watermark from an image URL. This method loads the image asynchronously, so you must wait for the
.readyPromise to complete before use:Note- When loading images from URLs, the operation may fail due to Cross-Origin Resource Policy (CORP) restrictions. If image loading fails, the
readyPromise is rejected with an error. - To use the original image dimensions, set both
widthandheightto-1.
- When loading images from URLs, the operation may fail due to Cross-Origin Resource Policy (CORP) restrictions. If image loading fails, the
Enable the processor
After adding watermarks, call enable to activate the processor:
Manage watermarks
You can dynamically enable or disable the watermark as follows:
Release resources
When you no longer need the Watermark extension, properly release resources:
Complete sample code
The following example demonstrates complete usage of the Watermark extension:
Sample code
Reference
This section contains content that completes the information on this page, or points you to documentation that explains other aspects to this product.
API reference
This section provides the core API reference for the Watermark extension.
addVideoWatermark
Adds a watermark image to the video stream.
Parameters
watermark: AnAgoraWatermarkImageinstance.
Returns
The watermark ID for subsequent watermark management. Returns -1 if the operation fails.
clearVideoWatermarks
Removes all added video watermarks.
Returns
true: Successfully removed all watermarks.false: Failed to remove watermarks.
removeVideoWatermark
Removes a specific video watermark by ID.
Parameters
id: The ID of the watermark to remove.
Returns
true: Successfully removed the specified watermark.false: Failed to remove the watermark.
release
Releases the IVWProcessor resources.
AgoraWatermarkImage
Creates a watermark image instance.
Parameters
image: TheHTMLImageElementto use as the watermark. Ifnull, no image is used.url: The image URL to use as the watermark. Ifnullor an empty string, no image is used.x: The x-coordinate (in pixels) of the image on the video, relative to the top-left corner. Default is0.y: The y-coordinate (in pixels) of the image on the video, relative to the top-left corner. Default is0.width: The desired width (in pixels) of the watermark image. Default is-1, which uses the original width after the image loads.height: The desired height (in pixels) of the watermark image. Default is-1, which uses the original height after the image loads.alpha: The image opacity, from0.0(completely transparent) to1.0(completely opaque). Default is1.0.