tencent cloud

Feedback

Last updated: 2024-09-02 17:21:28
    This document mainly explains how to add a watermark to a video stream.

    Implementation Steps

    Enable the camera

    trtcCloud.startLocalPreview(isFrontCamera, viewId);

    Watermarking

    Assuming we need to add a local image bg_main_title.png as a watermark on the Main Screen (TRTC_VIDEO_STREAM_TYPE_BIG):
    trtcCloud.setWatermark("images/bg_main_title.png", TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_BIG, 0.3, 0.4, 0.4);
    The position of the watermark is specified by the rect parameter, which is a tuple parameter in the format (x,y,width,height)
    x: Coordinates of the watermark, value range is a float between 0 and 1.
    y: Coordinates of the watermark, value range is a float between 0 and 1.
    width: Width of the watermark, value range is a float between 0 and 1.
    height: No need to set, the SDK will automatically calculate a suitable height based on the aspect ratio of the watermark image.
    
    Example of parameter setting:
    If the current video encoding resolution is 540 × 960, and the rect parameter is set to (0.1, 0.1, 0.2, 0.0),
    then the top-left coordinate point of the watermark will be (540 × 0.1, 960 × 0.1) which is (54, 96). The watermark's width will be 540 × 0.2 = 108px. The height of the watermark will be automatically calculated by the SDK based on the aspect ratio of the watermark image.
    Note:
    The watermark image must use a transparent background PNG format.
    The watermark added through the setWatermark interface is not visible in the local preview. To view the watermark effect, you need to get the user stream with the set watermark from the remote end.

    Pulling the video stream with a watermark

    Pull the user video stream with a watermark on another device.
    trtcCloud.startRemoteView("denny", TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_BIG, viewId);

    Cancel the watermark

    By passing a null value, you can cancel the watermark in your published video stream.
    trtcCloud.setWatermark("", TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_BIG, 0.3, 0.4, 0.4);
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support