All Products
Search
Document Center

ApsaraVideo Live:StartLiveMPUTask

Last Updated:Dec 05, 2024

Creates a mixed-stream relay task.

Operation description

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, the 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. End
  • 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 Limitation

The QPS limit for this interface per user is 500 calls/second. Exceeding this limit will result in API throttling, which may impact your service. Please use it reasonably. For more information, refer to QPS Limitation.

Debugging

You can run this interface directly in OpenAPI Explorer, saving you the trouble of calculating signatures. After running successfully, OpenAPI Explorer can automatically generate SDK code samples.

Authorization information

The following table shows the authorization information corresponding to the API. The authorization information can be used in the Action policy element to grant a RAM user or RAM role the permissions to call this API operation. Description:

  • Operation: the value that you can use in the Action element to specify the operation on a resource.
  • Access level: the access level of each operation. The levels are read, write, and list.
  • Resource type: the type of the resource on which you can authorize the RAM user or the RAM role to perform the operation. Take note of the following items:
    • The required resource types are displayed in bold characters.
    • If the permissions cannot be granted at the resource level, All Resources is used in the Resource type column of the operation.
  • Condition Key: the condition key that is defined by the cloud service.
  • Associated operation: other operations that the RAM user or the RAM role must have permissions to perform to complete the operation. To complete the operation, the RAM user or the RAM role must have the permissions to perform the associated operations.
OperationAccess levelResource typeCondition keyAssociated operation
live:StartLiveMPUTaskcreate
*All Resources
*
    none
none

Request parameters

ParameterTypeRequiredDescriptionExample
AppIdstringYes

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 (-).

yourAppId
ChannelIdstringYes

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 (-).

yourChannelId
TaskIdstringYes

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.

yourTaskId
MixModestringYes

The stream mixing mode. Valid values:

  • 0: the single-stream relay mode. In this mode, the service only relays the original single stream, but does not transcode mixed streams. You do not need to set parameters for mixed-stream transcoding.
  • 1 (default): the mixed-stream relay mode.
0
StreamURLstringNo

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
  • If the ingest URL is under a domain name for which hotlink protection is enabled, you must include an access token in the URL.
  • You cannot use the same ingest URL in different tasks.
  • You cannot use the same ingest URL within 10 seconds after a task is stopped.
rtmp://example.com/live/stream
MultiStreamURLarray<object>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.
objectNo
URLstringNo

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.

rtmp://example.com/live/stream****
RegionstringNo

The region in which the streams are mixed. Valid values:

  • CN-Shanghai
  • AP-Singapore (default)
  • EMAA-Saudi
CN-Shanghai
SingleSubParamsobjectNo

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.

SourceTypestringNo

The type of the video source. This parameter is valid only when you set StreamType to 2. Valid values:

  • camera (default)
  • shareScreen
camera
StreamTypestringNo

The type of the stream that you want to relay. Valid values:

  • 0 (default): original stream
  • 1: only the audio track
  • 2: only the video track
0
UserIdstringYes

The user ID. In the single-stream relay mode, you can relay only one stream in a request.

yourSubUserId
TranscodeParamsobjectNo

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.

BackgroundobjectNo

The global background image.

RenderModestringNo

The display mode of the global background image.

  • 0: scales the background image proportionally to fit the view, with black bars displayed.
  • 1 (default): crops the background image to fit the view.
1
URLstringNo

The URL of the global background image. The URL can be up to 2,048 characters in length.

yourImageUrl
EncodeParamsobjectNo

The encoding parameters for the output stream.

AudioOnlystringNo

Specifies whether the output stream is an audio-only stream. Valid values:

  • true: The output stream is an audio-only stream. If you set this parameter to true, you need to configure only audio-related parameters under EncodeParams.
  • false (default): The output stream is not an audio-only stream. If you set this parameter to false, you need to configure all parameters under EncodeParams, except the VideoCodec and EnhancedParam parameters.
false
AudioBitratestringNo

The bitrate of the audio. Valid values: [8,500]. Unit: Kbit/s.

128
AudioChannelsstringNo

The number of sound channels. Valid values: 1 and 2.

2
AudioSampleRatestringNo

The audio sampling rate. Valid values: 8000, 16000, 32000, 44100, and 48000. Unit: Hz.

44100
VideoCodecstringNo

The video codec. Valid values:

  • H.264 (default)
  • H.265
H.264
VideoBitratestringNo

The bitrate of the video. Valid values: [1,10000]. Unit: Kbit/s.

3500
VideoFrameratestringNo

The frame rate of the video. Valid values: [1,60]. Unit: frames per second (FPS).

25
VideoGopstringNo

The group of pictures (GOP) size of the video. Valid values: [1,60].

20
VideoHeightstringNo

The height of the video. Valid values: [0,1920]. Unit: pixels.

1000
VideoWidthstringNo

The width of the video. Valid values: [0,1920]. Unit: pixels.

1920
EnhancedParamstringNo

The parameter used for encoding enhancement, which is a JSON string. The parameter includes the optional profile and preset fields.

  • profile: the encoding level. If the video codec is H.264, the valid values of this field are baseline, main, and high. If the video codec is H.265, the valid value of this field is main.
  • preset: adjusts the trade-off between encoding speed and video quality. The valid values of this field are ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, and placebo. Each value specifies a level of trade-off between encoding speed and video quality. For example, the ultrafast preset has the fastest encoding speed but the lowest video quality, while the placebo preset sacrifices the encoding speed for the best video quality.
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.
{"profile": "high", "preset": "veryfast"}
LayoutobjectNo

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.
UserPanesarray<object>No

The information about the panes.

objectNo

The information about the pane.

UserInfoobjectNo

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
  • If you specify the information about a user by using this parameter, the information about the user must also be specified by using the TranscodeParams.UserInfos parameter.

  • This parameter is valid only when you set StreamType to 0 or 2.

SourceTypestringNo

The type of the video source. This parameter is valid only when you set StreamType to 2. Valid values:

  • camera (default)
  • shareScreen
camera
ChannelIdstringNo

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.

yourChannelId
UserIdstringNo

The user ID.

yourSubUserId
HeightstringNo

The height of the pane. The value is normalized.

0.2632
WidthstringNo

The width of the pane. The value is normalized.

0.3564
XstringNo

The x-coordinate of the pane. The value is normalized.

0.2456
YstringNo

The y-coordinate of the pane. The value is normalized.

0.3789
ZOrderstringNo

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.

0
BackgroundImageUrlstringNo

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.

yourImageUrl
RenderModestringNo

The display mode of the pane. Valid values:

  • 0: scales the video proportionally to fit the view, with black bars displayed.
  • 1 (default): crops the video to fit the view.
1
UserInfosarray<object>No

The information about the users whose streams are subscribed to. If you leave this parameter empty, streams from all users are mixed.

objectNo

The information about the user.

SourceTypestringNo

The type of the video source that is subscribed to. This parameter is valid only when you set StreamType to 2. Valid values:

  • camera (default)
  • shareScreen
camera
StreamTypestringNo

The type of the relayed stream that is subscribed to. Valid values:

  • 0 (default): original stream
  • 1: only the audio track
  • 2: only the video track
0
ChannelIdstringNo

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.

yourChannelId
UserIdstringYes

The ID of the subscribed user.

yourSubUserId
SeiParamsobjectNo

The supplemental enhancement information (SEI) parameters.

LayoutVolumeobjectNo

The layout and volume SEI. If you leave this parameter empty, the default layout and volume SEI is used.

FollowIdrstringNo

Specifies whether to include the SEI in an Instantaneous Decoder Refresh (IDR) frame. Valid values:

  • 0: does not include the SEI.
  • 1: includes the SEI.
0
IntervalstringNo

The interval at which the SEI is sent. Valid values: [1000,5000]. Unit: milliseconds.

1000
PassThroughobjectNo

Specifies whether to pass through the SEI.

FollowIdrstringNo

Specifies whether to include the SEI in an IDR frame. Valid values:

  • 0: does not include the SEI.
  • 1: includes the SEI.
0
IntervalstringNo

The interval at which the SEI is sent. Valid values: [1000,5000]. Unit: milliseconds.

1000
PayloadContentstringNo

The payload content of the SEI.

yourPayloadContent
PayloadContentKeystringNo

The key of the payload content of the SEI. If you do not specify this parameter, the default value udd is used.

yourPayloadContentKey
PayloadTypestringNo

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.

100

Layout and volume SEI

ParameterDescription
canvasThe information about the canvas. The following fields are included:- w: the width of the canvas. Unit: pixels.- h: the height of the canvas. Unit: pixels.- bgnd: the background color of the canvas, which is an RGB value in the format of a hexadecimal integer.
streamThe information about the video stream. The following fields are included:- uid: the user ID of the streamer.- paneid: the sequence number of the pane on the canvas. Valid values: [0,8].- zorder: the layer of the pane. Valid values: [0,99].- x: the x-coordinate of the pane on the canvas. The value is normalized.- y: the y-coordinate of the pane on the canvas. The value is normalized.- w: the width of the pane. The value is normalized.- h: the height of the pane. The value is normalized.- type: the source of the video stream in the pane. Valid values: 0 (camera) and 1 (screen sharing).- status: the status of the video stream in the pane. Valid values: 0 (not pulled) and 1 (pulled).- muted: the mute status of the streamer. Valid values: 0 (not muted) and 1 (muted). For example, when two streamers (Streamer A and Streamer B) have a battle, if Streamer A mutes Streamer B, the muted field displayed for Streamer B is 1.- vol: the volume of the streamer. Valid values: [0,255]. Unit: dB.- vad: detects human voice. Valid values: [0,150]. 150 indicates that human voice is detected and a value other than 150 indicates the period of time during which the volume of human voice decreases to 0.
tsThe operating system timestamp when the SEI is generated. Unit: milliseconds.
verThe version of the SEI. For example, the current version is 1.0.0.20220915.
uddThe custom scenario-based event that is sent by using the PassThrough parameter. The content of the event is specified by the PayloadContent parameter.

The following example shows a co-streaming scenario:

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

Note To create a cross-channel mixed-stream relay task, make sure that a cross-channel call has been initiated by using the SDK on the client side. If users in different channels are not making a call with each other, you cannot create a cross-channel mixed-stream relay task. For more information about how to initiate a cross-channel call, see Cross-channel subscription.

Response parameters

ParameterTypeDescriptionExample
object
RequestIdstring

The request ID.

0F72851F-5DC1-1979-9B2C-450040316C3E

Examples

Sample success responses

JSONformat

{
  "RequestId": "0F72851F-5DC1-1979-9B2C-450040316C3E"
}

Error codes

HTTP status codeError codeError message
400InvalidParam%s
400InvalidAppId%s
403OperationDeniedYour account has not enabled the Live service
403Forbidden%s
404MissingParam%s
500InternalErrorInternalError

For a list of error codes, visit the Service error codes.

Change history

Change timeSummary of changesOperation
2024-11-14The Error code has changed. The request parameters of the API has changedView Change Details
2024-10-30The Error code has changedView Change Details
2024-08-13The Error code has changedView Change Details
2024-08-06The Error code has changed. The request parameters of the API has changedView Change Details
2024-07-04The Error code has changedView Change Details
2024-06-12The Error code has changedView Change Details
2024-03-07The Error code has changedView Change Details
2024-03-01The Error code has changedView Change Details
2023-12-26The Error code has changedView Change Details