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.
Common templates include 10, 30, 40, 310, 390, 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 | Template 30 |
---|---|
![]() |
![]() |
Template 40 | Template 310 |
![]() |
![]() |
Template 390 | Template 410 |
![]() |
![]() |
Template 510 | Template 610 |
![]() |
![]() |
For more information, please see CreateCommonMixStream.
This example shows you how to use a preset stream mix template to mix streams.
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>
{
"Response": {
"RequestId": "e8fa8015-0892-40d5-95c4-12a4bc06ed31"
}
}
This example shows you how to use a preset stream mix template to mix streams.
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>
{
"Response": {
"RequestId": "9d8d5837-2273-4936-8661-781aeab9bc9c"
}
}
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.
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>
{
"Response": {
"RequestId": "8c443359-ba07-4b81-add8-a6ff54f9bf54"
}
}
For more information, please see CancelCommonMixStream.
This example shows you how to cancel a stream mix by session ID.
https://live.tencentcloudapi.com/?Action=CancelCommonMixStream
&MixStreamSessionId=test_room
{
"Response": {
"RequestId": "3c140219-cfe9-470e-b241-907877d6fb03"
}
}
Note:
- 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.
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 |
|
-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 |
|
-11 | Layer error |
|
-20 | The input parameter does not match the API |
|
-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 |
|
-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` |
|
-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 |
|
-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. | - |
Note:For more FAQs about stream mix, please see On-cloud Stream Mix.
Was this page helpful?