Watermark Processing
This feature is supported starting from SDK version 5.2.5.
RC supports adding watermarks to video streams during live streaming. There are two approaches to watermark control. This document focuses on Approach 1:
- Approach 1: Use the
setWatermark
method provided by the client SDK to add image watermarks. The video stream published by the client will include the watermark, so all viewers subscribing to the stream (either individual or mixed) will see the watermarked video. - Approach 2: Use the server API
/rtc/mcu/config
endpoint to add timestamp, text, or image watermarks on the server side. This approach supports adding watermarks to individual or mixed video streams, but only viewers subscribing to the mixed stream will see the watermark. For server-side implementation details, refer to the server documentation Live Stream Mixing.
Approach 1 is suitable for allowing app users to add personalized watermarks. Approach 2 is better for adding uniform watermarks across the app.
Watermarks added via the client and server are independent. If both are used, viewers subscribing to the mixed stream may see overlapping watermarks.
Set Watermark
The RCRTCEngine
provides a built-in method for setting watermarks. Call setWatermark(String imagePath, Point<double> position, double zoom)
to add watermarks to video streams captured by the camera, custom files, or screen sharing. Watermark settings are independent for each video stream.
Method
/**
* Set watermark
*
* @param logoIcon Watermark image. Pass `null` to remove the watermark.
* @param rect Watermark size and position
* @return Whether the watermark setup was successful
*/
Future<int> setWatermark(String imagePath, Point<double> position, double zoom);
Parameter | Type | Required | Description |
---|---|---|---|
imagePath | String | Yes | Local path of the watermark image |
position | Point<double> | Yes | Watermark position. Note: Values range from 0 to 1. The SDK calculates the actual pixel position based on video resolution. |
zoom | double | Yes | Watermark scaling ratio. Note: Values range from 0 < zoom ≤ 1. The SDK calculates the actual size based on video resolution. |
position
is normalized, with the top-left corner as the origin (0~1).x
andy
represent the watermark coordinates.zoom
: Watermark scaling ratio (0 < zoom ≤ 1). For example, a watermark image width of 480 × 0.2 = 96, with height scaled proportionally based on the original aspect ratio.
Example: If the video resolution is 480 (width) × 640 (height), withposition
set to (0.1, 0.1) andzoom
to 0.2, the watermark's top-left coordinates will be (480 × 0.1, 640 × 0.1) = (48, 64). The watermark width will be 480 × 0.2 = 96, and the height will be auto-calculated by the SDK.
Remove Watermark
Call the removeWatermark
method of the RCRTCEngine
object to remove client-side watermarks.
Method
// Remove client-side watermark
Future<int> removeWatermark();
Example Code
// Add watermark
engine.onWatermarkSet = (int code, String? message) {
if (code == 0) {
// Watermark set successfully
}
};
engine.setWatermark('imagePath', Point(0.1, 0.1), 0.2);
// Remove watermark
engine.onWatermarkRemoved = (int code, String? message) {
if (code == 0) {
// Watermark removed successfully
}
};
engine.removeWatermark();
Notes
-
Avoid using excessively large watermark images. Recommended dimensions: ≤200px in width/height to prevent issues with Android native layer Bitmap conversion.
-
Do not repeatedly call the add/remove watermark APIs in a loop.
-
On Android, watermark functionality requires enabling external storage read/write permissions in
AndroidManifest.xml
. For Android 6.0+, dynamic permission requests are needed:<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />