tencent cloud

Feedback

Stream Mix

Last updated: 2023-10-07 14:11:40
    CSS provides live stream mix feature, which can synchronously mix multiple streams of input sources into a new stream based on the configured stream mix layout for interactive live streaming. In addition, the stream mix feature has been connected to TencentCloud API 3.0. For more information, please see CreateCommonMixStream. This document uses examples to describe how to implement live stream mix in different scenarios.

    Notes

    Using stream mix will incur transcoding fees. For details, please see Live Transcoding (Watermarking, Stream Mixing).
    To use the mixing and cropping feature, the value of the cropping parameter cannot exceed the value of input stream parameter.

    Supported Features

    Up to 16 concurrent streams can be mixed.
    Up to 5 types of input sources (audio and video, pure audio, pure video, image, and canvas) can be mixed.
    Mixed streams can be output as a new stream.
    Cropping and watermarking are supported.
    Template configuration is supported.
    Recording based on stream mix is supported.
    Automatic stream mix is supported.
    Stream mix types and positions can be switched in real time.
    Stream mix can be started/canceled seamlessly.

    Common Layout Templates

    Common templates include 10, 30, 40, 310,410, 510, and 610. When using them, you do not need to enter the position and length/width parameters of the input stream, and the original image will be auto-scaled. You only need to pass in the template ID.
    Figures of common layout templates:
    Template 10 Preview Image
    Template 30 Preview Image
    
    
    
    
    
    
    Template 40 Preview Image
    Template 310 Preview Image
    
    
    
    
    
    
    Template 410 Preview Image
    Template 510 Preview Image
    
    
    
    
    
    
    Template 610 Preview Image
    
    
    

    Creating Stream Mix Session

    Parameters

    For more information, please see CreateCommonMixStream.

    Scenario 1. Applying for stream mix - using template 20

    This example shows you how to use a preset stream mix template to mix streams.

    Sample input code

    https://live.tencentcloudapi.com/?Action=CreateCommonMixStream
    &MixStreamSessionId=test_room
    &MixStreamTemplateId=20
    &OutputParams.OutputStreamName=test_stream1
    &InputStreamList.0.InputStreamName=test_stream1
    &InputStreamList.0.LayoutParams.ImageLayer=1
    &InputStreamList.1.InputStreamName=test_stream2
    &InputStreamList.1.LayoutParams.ImageLayer=2
    &<Common request parameters>

    Sample output code

    {
    "Response": {
    "RequestId": "e8fa8015-0892-40d5-95c4-12a4bc06ed31"
    }
    }

    Stream mix effect for mic connect

    
    img
    
    

    Scenario 2. Applying for stream mix - using template 390

    This example shows you how to use a preset stream mix template to mix streams.

    Sample input code

    https://live.tencentcloudapi.com/?Action=CreateCommonMixStream
    &MixStreamSessionId=test_room
    &MixStreamTemplateId=390
    &OutputParams.OutputStreamName=test_stream2
    &InputStreamList.0.InputStreamName=test_stream1
    &InputStreamList.0.LayoutParams.ImageLayer=1
    &InputStreamList.0.LayoutParams.InputType=3
    &InputStreamList.0.LayoutParams.ImageWidth=1920 (canvas width)
    &InputStreamList.0.LayoutParams.ImageHeight=1080 (canvas height)
    &InputStreamList.0.LayoutParams.Color=0x000000
    &InputStreamList.1.InputStreamName=test_stream2
    &InputStreamList.1.LayoutParams.ImageLayer=2
    &InputStreamList.2.InputStreamName=test_stream3
    &InputStreamList.2.LayoutParams.ImageLayer=3
    &<Common request parameters>

    Sample output code

    {
    "Response": {
    "RequestId": "9d8d5837-2273-4936-8661-781aeab9bc9c"
    }
    }

    Stream mix effect for host competition

    
    img
    
    

    Scenario 3. Custom stream mix

    Use the custom layout, where the position parameters LocationX and LocationY represent the absolute pixel distance between the top-left corner of the small image and that of the background image.
    
    

    Sample input code

    https://live.tencentcloudapi.com/?Action=CreateCommonMixStream
    &MixStreamSessionId=test_room
    &OutputParams.OutputStreamName=test_stream2
    &InputStreamList.0.InputStreamName=test_stream1
    &InputStreamList.0.LayoutParams.ImageLayer=1
    &InputStreamList.0.LayoutParams.InputType=3
    &InputStreamList.0.LayoutParams.ImageWidth = 1920
    &InputStreamList.0.LayoutParams.ImageHeight= 1080
    &InputStreamList.0.LayoutParams.Color=0x000000
    &InputStreamList.1.InputStreamName=test_stream2
    &InputStreamList.1.LayoutParams.ImageLayer=2
    &InputStreamList.1.LayoutParams.ImageWidth = 640
    &InputStreamList.1.LayoutParams.ImageHeight= 360
    &InputStreamList.1.LayoutParams.LocationX= 50
    &InputStreamList.1.LayoutParams.LocationY= 720
    &InputStreamList.2.InputStreamName=test_stream3
    &InputStreamList.2.LayoutParams.ImageLayer=3
    &InputStreamList.2.LayoutParams.ImageWidth = 640
    &InputStreamList.2.LayoutParams.ImageHeight= 360
    &InputStreamList.2.LayoutParams.LocationX= 740
    &InputStreamList.2.LayoutParams.LocationY= 720
    &<Common request parameters>

    Sample output code

    {
    "Response": {
    "RequestId": "8c443359-ba07-4b81-add8-a6ff54f9bf54"
    }
    }

    Custom stream mix effect

    
    
    

    Canceling Stream Mix

    Parameters

    For more information, please see CancelCommonMixStream.

    Examples

    This example shows you how to cancel a stream mix by session ID.

    Sample input code

    https://live.tencentcloudapi.com/?Action=CancelCommonMixStream
    &MixStreamSessionId=test_room

    Sample output code

    {
    "Response": {
    "RequestId": "3c140219-cfe9-470e-b241-907877d6fb03"
    }
    }
    Caution
    After applying for canceling stream mix, wait at least for 5s before canceling it.
    After canceling the stream mix, wait at least for half a minute before you can apply for stream mix using the same session ID.

    Error Codes

    For stream mix API 3.0, most common error codes have been transformed into the style of API 3.0 error code. However, some error codes remain unchanged, which will be provided in the format of err_code [ $code ],msg [ $message ] in Message and prompted as an InvalidParameter error. The causes of specific codes are as detailed below:
    Error Code
    Reason
    Troubleshooting
    -1
    An error occurred while parsing the input parameters
    
    Check whether the JSON format of the request body is correct.
    
    Check whether `InputStreamList` is empty.
    
    -2
    Incorrect input parameter
    Check whether the image parameter is too large.
    -3
    The number of streams is incorrect
    Check whether the number of input streams is within the range of [1,16].
    -4
    Incorrect stream parameter
    
    Check whether the length/width of the input/output stream are within the range of (0,3000).
    
    Check whether the number of input streams is within the range of (0,16].
    
    Check whether the input stream carries `LayoutParams`.
    
    Check whether `InputType` is supported (valid values: 0, 2, 3, 4, 5).
    
    Check whether the stream ID length is within the range of (1,80).
    
    -11
    Layer error
    
    Check whether the number of layers is the same as the number of input streams.
    
    Check whether the layer ID is duplicate.
    
    Check whether the layer ID is within the range of (0,16].
    
    -20
    The input parameter does not match the API
    
    Check whether the number of input streams matches the template ID.
    
    Check whether the color parameter is correct.
    
    -21
    The number of input streams for stream mix is incorrect
    Check whether there are at least two input streams.
    -28
    Failed to get the background length/width
    
    Check whether the canvas length and width are set when setting the canvas.
    
    Check whether the background stream exists (stream mix needs to start 5 seconds after push starts).
    
    -29
    Incorrect cropping parameter
    Check whether the cropping position is out of the stream length/width range.
    -33
    Incorrect watermark image ID
    Check whether the input image ID is set.
    -34
    Failed to get the URL of the watermark image
    Check whether the image has been successfully uploaded and whether the URL has been generated.
    -111
    The `OutputStreamName` parameter does not match `OutputStreamType`
    
    If `OutputStreamType` is set to `0`, `OutputStreamName` should be in `InputStreamList`.
    
    If `OutputStreamType` is set to `1`, `OutputStreamName` should not be in `InputStreamList`.
    
    -300
    The output stream ID has already been used
    Check whether the current output stream belongs to another stream mix task.
    -505
    Failed to find the input stream in `upload`
    Check whether stream mix is initiated 5 seconds after the push and whether the stream can be played back.
    -507
    Failed to query the stream length/width parameters
    
    Check whether the canvas length and width are set.
    
    Check whether the push succeeds. We recommend you start stream mix 5 seconds after push starts.
    
    -508
    Incorrect output stream ID
    Check whether different output stream IDs are used by the same `MixStreamSessionId`.
    -10031
    Failed to trigger stream mix
    We recommend you start stream mix 5 seconds after push starts.
    -30300-31001-31002
    The `sessionid` does not exist when stream mix is canceled
    Check whether the `MixStreamSessionId` exists.
    -31003
    The output stream ID does not match that in `session`
    Check the output stream ID entered when stream mix is canceled.
    -31004
    The output stream bitrate is invalid
    Check whether the output stream bitrate is within the range of [1,50000].
    Others
    For other errors, please contact customer service for assistance.
    -
    

    FAQs

    Note
    For more FAQs about stream mix, please see On-cloud Stream Mix.
    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