Creates a mixed-stream relay task.
Usage notes
By default, you can create up to 200 single-stream relay tasks and up to 40 mixed-stream relay tasks for an application. To increase the quota, submit a ticket.
Lifecycle of a stream relay task
Start- Call the StartLiveMPUTask operation to create a task.
- If no user joins the channel, an error indicating that the channel does not exist is returned.
- Stream relay is not performed if no stream is ingested. In this case, no relayed stream is available for playback.
- If the task is in the mixed-stream relay mode, make sure that at least one user is ingesting a stream, which can be relayed for playback. A black screen is displayed in the pane of a user who is not ingesting a stream.
- We recommend that you record the task status, task mode, and task parameters on your business server.
- Task status: started or stopped.
- Task mode: single-stream relay or mixed-stream relay.
- Task parameters: the latest input parameters. For example, after your call of the UpdateLiveMPUTask operation is successful, record the task parameters, which are the latest.
- In co-streaming or battle scenarios, the task is in the mixed-stream relay mode. If the streamer leaves the channel due to exceptions and re-joins the channel, you can directly call the StartLiveMPUTask operation on your business server to start stream relay based on the recorded task parameters.
- If the task has not been automatically cleared by the system, the task is directly started.
- If the task has not been automatically cleared by the system, a message indicating that the task already exists is returned.
- After the streamer leaves the channel, you need to call the StopLiveMPUTask operation to stop the task.
- If all users specified in the task have left the channel, but you do not call the StopLiveMPUTask operation, the system stops the task in 2 minutes.
QPS limit
You can call this operation up to 500 times per second per account. Requests that exceed this limit are dropped and you will experience service interruptions. We recommend that you take note of this limit when you call this operation. For more information, see QPS limits.
Debugging
Request parameters
Parameter |
Type |
Required |
Example |
Description |
Action | String | Yes | StartLiveMPUTask | The operation that you want to perform. Set the value to StartLiveMPUTask. |
AppId | String | Yes | yourAppId | The application ID. You can specify only one application ID. The ID can be up to 64 characters in length and can contain letters, digits, underscores (_), and hyphens (-). |
ChannelId | String | Yes | yourChannelId | The channel ID. You can specify only one channel ID. The ID can be up to 64 characters in length and can contain letters, digits, underscores (_), and hyphens (-). |
TaskId | String | Yes | yourTaskId | The task ID. You can specify only one task ID. The ID can be up to 55 characters in length and can contain letters, digits, underscores (_), and hyphens (-). The ID must be unique. |
MixMode | String | Yes | 0 | The stream mixing mode. Valid values:
|
StreamURL | String | No | rtmp://example.com/live/stream | The ingest URL. You can specify only one ingest URL in the Real-Time Messaging Protocol (RTMP) format. The URL can be up to 2,048 characters in length. For information about the generation rules of ingest URLs, see Ingest and streaming URLs. Note
|
MultiStreamURL | Array | No | The multiple ingest URLs to relay. This parameter allows you to specify multiple ingest URLs. Note The StreamURL and MultiStreamURL parameters are mutually exclusive. You must specify one of the two parameters. |
|
URL | String | No | rtmp://example.com/live/stream**** | The ingest URL. Only the RTMP format is supported. The URL can be up to 2,048 characters in length. For information about the generation rules of ingest URLs, see Ingest and streaming URLs. |
Region | String | No | CN-Shanghai | The region in which the streams are mixed. Valid values:
|
SingleSubParams | Object | No | The single-stream relay parameters. These parameters are required if you set MixMode to 0. Leave these parameters empty in the mixed-stream relay mode. |
|
SourceType | String | No | camera | The type of the video source. This parameter is valid only when you set StreamType to 2. Valid values:
|
StreamType | String | No | 0 | The type of the stream that you want to relay. Valid values:
|
UserId | String | Yes | yourSubUserId | The user ID. In the single-stream relay mode, you can relay only one stream in a request. |
TranscodeParams | Object | No | The mixed-stream relay parameters. These parameters are required if you set MixMode to 1. Leave these parameters empty in the single-stream relay mode. |
|
Background | Object | No | The global background image. |
|
RenderMode | String | No | 1 | The display mode of the global background image. Valid values:
|
URL | String | No | yourImageUrl | The URL of the global background image. The URL can be up to 2,048 characters in length. |
EncodeParams | Object | No | The encoding parameters for the output stream. |
|
AudioOnly | String | No | false | Specifies whether the output stream is an audio-only stream. Valid values:
|
AudioBitrate | String | No | 128 | The bitrate of the audio. Valid values: [8,500]. Unit: Kbit/s. |
AudioChannels | String | No | 2 | The number of sound channels. Valid values: 1 and 2. |
AudioSampleRate | String | No | 44100 | The audio sampling rate. Valid values: 8000, 16000, 32000, 44100, and 48000. Unit: Hz. |
VideoCodec | String | No | H.264 | The video codec. Valid values:
|
VideoBitrate | String | No | 3500 | The bitrate of the video. Valid values: [1,10000]. Unit: Kbit/s. |
VideoFramerate | String | No | 25 | The frame rate of the video. Valid values: [1,60]. Unit: frames per second (FPS). |
VideoGop | String | No | 20 | The group of pictures (GOP) size of the video. Valid values: [1,60]. |
VideoHeight | String | No | 1000 | The height of the video. Valid values: [0,1920]. Unit: pixels. |
VideoWidth | String | No | 1920 | The width of the video. Valid values: [0,1920]. Unit: pixels. |
EnhancedParam | String | No | {"profile": "high", "preset": "veryfast"} | The parameter used for encoding enhancement, which is a JSON string. The parameter includes the optional profile and preset fields.
Note A value of superfast for the preset field is suitable for real-time communication scenarios. We recommend that you not set the field if you are not a professional encoding engineer. |
Layout | Object | No | The video layout information. Note If video transcoding is required, you must specify the video layout information, including the x-coordinate and y-coordinate, the width and height, and the layer. For audio-only transcoding, leave the video layout information empty. |
|
UserPanes | Array | No | The information about the panes. |
|
UserInfo | Object | No | The information about the user whose stream is played in the pane. If you leave this parameter empty, the system automatically sets this parameter based on the order in which streamers join the channel. Note
|
|
SourceType | String | No | camera | The type of the video source. This parameter is valid only when you set StreamType to 2. Valid values:
|
ChannelId | String | No | yourChannelId | The ID of the channel where the user is. If the user is in the same channel, you can leave this parameter empty. We recommend that you specify this parameter when you perform stream mixing across channels. |
UserId | String | No | yourSubUserId | The user ID. |
Height | String | No | 0.2632 | The height of the pane. The value is normalized. |
Width | String | No | 0.3564 | The width of the pane. The value is normalized. |
X | String | No | 0.2456 | The x-coordinate of the pane. The value is normalized. |
Y | String | No | 0.3789 | The y-coordinate of the pane. The value is normalized. |
ZOrder | String | No | 0 | The layer in which the pane resides. A value of 0 indicates the bottom layer. Each increment of the value by 1 indicates the next upper layer. |
BackgroundImageUrl | String | No | yourImageUrl | The URL of the background image of the pane. The URL can be up to 2,048 characters in length. This image is displayed if the user turns off the camera or is not present in the channel. |
RenderMode | String | No | 1 | The display mode of the pane. Valid values:
|
UserInfos | Array | No | The information about the user whose stream is subscribed to. If you leave this parameter empty, streams from all users are mixed. |
|
SourceType | String | No | camera | The type of the video source that is subscribed to. This parameter is valid only when you set StreamType to 2. Valid values:
|
StreamType | String | No | 0 | The type of the relayed stream that is subscribed to. Valid values:
|
ChannelId | String | No | yourChannelId | The ID of the channel where the subscribed user is. If the user is in the same channel, you can leave this parameter empty. We recommend that you specify this parameter when you perform stream mixing across channels. |
UserId | String | Yes | yourSubUserId | The ID of the subscribed user. |
SeiParams | Object | No | The supplemental enhancement information (SEI) parameters. |
|
LayoutVolume | Object | No | The layout and volume SEI. If you leave this parameter empty, the default layout and volume SEI is used. |
|
FollowIdr | String | No | 0 | Specifies whether to include the SEI in an Instantaneous Decoder Refresh (IDR) frame. Valid values:
|
Interval | String | No | 1000 | The interval at which the SEI is sent. Valid values: [1000,5000]. Unit: milliseconds. |
PassThrough | Object | No | Specifies whether to pass through the SEI. |
|
FollowIdr | String | No | 0 | Specifies whether to include the SEI in an IDR frame. Valid values:
|
Interval | String | No | 1000 | The interval at which the SEI is sent. Valid values: [1000,5000]. Unit: milliseconds. |
PayloadContent | String | No | yourPayloadContent | The payload content of the SEI. |
PayloadContentKey | String | No | yourPayloadContentKey | The key of the payload content of the SEI. If you do not specify this parameter, the default value udd is used. |
PayloadType | String | No | 100 | The custom payload_type of the SEI. Valid values: 100 to 254. If you do not specify this parameter, the default value 5 is used. |
Layout and volume SEI
Parameter |
Description |
canvas |
The information about the canvas. The following fields are included:
|
stream |
The information about the video stream. The following fields are included:
|
ts |
The operating system timestamp when the SEI is generated. Unit: milliseconds. |
ver |
The version of the SEI. For example, the current version is 1.0.0.20220915. |
udd |
The custom scenario-based event that is sent by using the PassThrough parameter. The content of the event is specified by the PayloadContent parameter. |
If a single streamer is streaming, the SEI message that viewers receive contains information about only one participant. If co-streaming or a battle occurs, the SEI message that viewers receive contains information about multiple participants.
For example, when the streamer whose user ID is 111 is streaming, an SEI frame in the following format is sent to the viewer side:
{"canvas":{"w":1920,"h":1080,"bgnd":0},"stream":[{"uid":"111","paneid":-1,"zorder":0,"x":0,"y":0,"w":0,"h":0,"type":0,"status":1,"muted":0,"vol":0,"vad":0}],"ver":"1.0.0.20220915","ts":1697696105170}
When the streamer whose user ID is 111 is co-streaming with a co-streamer whose user ID is 222, an SEI frame in the following format is sent to the viewer side:
{"canvas":{"w":1920,"h":1080,"bgnd":0},"stream":[{"uid":"111","paneid":0,"zorder":1,"x":0,"y":0.25,"w":0.5,"h":0.5,"type":0,"status":1,"muted":0,"vol":1,"vad":119},{"uid":"222","paneid":1,"zorder":1,"x":0.5018382,"y":0.25,"w":0.5,"h":0.5,"type":0,"status":1,"muted":0,"vol":60,"vad":123}],"ver":"1.0.0.20220915","ts":1697696106230}
Viewers can determine whether a streaming layout changes based on the number of stream arrays. If only one stream array exists, a single streamer is streaming. If more than one stream array exists, co-streaming or a battle occurs. The layout information of the participants can indicate the position of each participant in the mixed stream.
SEI pass-through
- To configure custom SEI, call the StartLiveMPUTask operation to start a mixed-stream relay task and specify the PayloadContent parameter under the PassThrough parameter, or call the UpdateLiveMPUTask operation to update a mixed-stream relay task and specify the PayloadContent parameter under the PassThrough parameter.
- Custom SEI can be sent periodically. You can use the Interval parameter under the PassThrough parameter to specify the interval in milliseconds.
- Custom SEI can also be sent with keyframes by specifying the FollowIdr parameter under the PassThrough parameter.
- You can configure settings to periodically send the custom SEI and send the custom SEI with keyframes at the same time. For example, you can set the Interval parameter to 1000 and the FollowIdr parameter to 1 to send the custom SEI every 1,000 milliseconds and include the custom SEI in keyframes.
- If you do not specify the Interval parameter and the FollowIdr parameter, the custom SEI is sent only once when you call the operation.
For example, the streamer whose user ID is 111 ingests a stream and calls the UpdateLiveMPUTask operation to specify periodic SEI. In the operation, the Interval parameter is set to 1000, the FollowIdr parameter is set to 0, and the PayloadContent parameter is set to "hello world". In this case, the custom SEI is sent every 1,000 milliseconds. The SEI frame received on the viewer side is in the following format:
{"canvas":{"w":1920,"h":1080,"bgnd":0},"stream":[{"uid":"111","paneid":-1,"zorder":0,"x":0,"y":0,"w":0,"h":0,"type":0,"status":1,"muted":0,"vol":0,"vad":0}],"ver":"1.0.0.20220915","ts":1697696109876,"udd":"hello world"}
Mixed-stream relay across channels
If you want to mix streams from multiple streamers across multiple channels and relay the mixed stream to ApsaraVideo Live, you must specify the user ID and channel ID of the streamer who initiates the cross-channel call and the user IDs of other streamers as input parameters to create a mixed-stream relay task. Example:
In a battle scenario, Streamer A in Channel A initiates a cross-channel battle with Streamer B in Channel B by using the client interface and relays the mixed stream to viewers in Channel A. In this example, the following parameters are specified:
- ChannelID: channelA
- UserId under UserInfos: userA and userB
Response parameters
Parameter |
Type |
Example |
Description |
RequestId | String | 0F72851F-5DC1-1979-9B2C-450040316C3E | The request ID. |
Examples
Sample requests
http(s)://live.aliyuncs.com/?Action=StartLiveMPUTask
&AppId=yourAppId
&ChannelId=yourChannelId
&TaskId=yourTaskId
&MixMode=0
&StreamURL=rtmp://example.com/live/stream
&MultiStreamURL=[{"URL":"rtmp://example.com/live/stream****"}]
&Region=CN-Shanghai
&SingleSubParams={"SourceType":"camera","StreamType":"0","UserId":"yourSubUserId"}
&TranscodeParams={"Background":{"RenderMode":"1","URL":"yourImageUrl"},"EncodeParams":{"AudioOnly":"false","AudioBitrate":"128","AudioChannels":"2","AudioSampleRate":"44100","VideoCodec":"H.264","VideoBitrate":"3500","VideoFramerate":"25","VideoGop":"20","VideoHeight":"1000","VideoWidth":"1920","EnhancedParam":"{\"profile\": \"high\", \"preset\": \"veryfast\"}"},"Layout":{"UserPanes":[{"UserInfo":{"SourceType":"camera","ChannelId":"yourChannelId","UserId":"yourSubUserId"},"Height":"0.2632","Width":"0.3564","X":"0.2456","Y":"0.3789","ZOrder":"0","BackgroundImageUrl":"yourImageUrl","RenderMode":"1"}]},"UserInfos":[{"SourceType":"camera","StreamType":"0","ChannelId":"yourChannelId","UserId":"yourSubUserId"}]}
&SeiParams={"LayoutVolume":{"FollowIdr":"0","Interval":"1000"},"PassThrough":{"FollowIdr":"0","Interval":"1000","PayloadContent":"yourPayloadContent","PayloadContentKey":"yourPayloadContentKey"},"PayloadType":"100"}
&<Common request parameters>
Sample success responses
XML
format
HTTP/1.1 200 OK
Content-Type:application/xml
<StartLiveMPUTaskResponse>
<RequestId>0F72851F-5DC1-1979-9B2C-450040316C3E</RequestId>
</StartLiveMPUTaskResponse>
JSON
format
HTTP/1.1 200 OK
Content-Type:application/json
{
"RequestId" : "0F72851F-5DC1-1979-9B2C-450040316C3E"
}
Error codes
For a list of error codes, see Service error codes.