tencent cloud

Feedback

StartMCUMixTranscodeByStrRoomId

Last updated: 2021-10-27 16:01:47

1. API Description

Domain name for API request: trtc.tencentcloudapi.com.

This API is used to enable On-Cloud MixTranscoding and specify the position of each channel of image in stream mixing.

There may be multiple channels of audio/video streams in a TRTC room. You can call this API to request the Tencent Cloud server to mix multiple channels of video images and audio into one channel and specify the position of each image so as to produce only one channel of audio/video stream for recording and live streaming.

You can use this API to perform the following operations:

  • Set image and audio quality parameters of the mixed stream, including video resolution, bitrate, frame rate, and audio quality.
  • Set the layout, i.e., the position of each channel of image. You only need to set it once when enabling On-Cloud MixTranscoding, and the layout engine will automatically arrange images as configured.
  • Set the names of recording files for future playback.
  • Set the stream ID for CDN live streaming.

Currently, On-Cloud MixTranscoding supports the following layout templates:

  • Floating: the entire screen is covered by the video image of the first user who enters the room, and the images of other users are displayed as small images in horizontal rows in the bottom-left corner in room entry sequence. The screen can accommodate up to 4 rows of 4 small images, which float over the big image. Up to 1 big image and 15 small images can be displayed. A user sending audio only will still occupy an image spot.
  • Grid: the images of all users split the screen evenly. The more the users, the smaller the image dimensions. Up to 16 images can be displayed. A user sending audio only will still occupy an image spot.
  • Screen sharing: this template is designed for video conferencing and online classes. The shared screen (or camera image of the anchor) is always displayed as the big image, which occupies the left half of the screen, and the images of other users occupy the right half in up to 2 columns of a maximum of 8 small images each. Up to 1 big image and 15 small images can be displayed. If the aspect ratio of upstream images does not match that of output images, the big image on the left will be scaled and displayed in whole, while the small images on the right will be cropped.
  • Picture-in-picture: this template mixes the big and small images or big image of a user with the audio of other users. The small image floats over the big image. You can specify the user whose big and small images are displayed and the position of the small image.
  • Custom: you can use custom templates to specify the image positions of users in mixed streams or preset image positions. If users are assigned to preset positions, the layout engine will reserve the positions for the users; if not, users will occupy the positions in room entry sequence. Once all preset positions are occupied, TRTC will stop mixing the audio and images of other users. If the placeholding feature is enabled for a custom template (PlaceHolderMode in LayoutParams is set to 1), but a user for whom a place is reserved is not sending video data, the position will show the corresponding placeholder image (PlaceImageId).

Notes:

  1. As On-Cloud MixTranscoding is a paid feature, you will be charged for calling this API. For details, see Billing of On-Cloud MixTranscoding.
  2. You can call this API only if your application is created on or after January 9, 2020. Applications created before use the stream mixing service of CSS by default. If you want to switch to MCU On-Cloud MixTranscoding, please submit a ticket.
  3. You cannot use the server and client stream mixing APIs at the same time.

A maximum of 20 requests can be initiated per second for this API.

We recommend you to use API Explorer
Try it
API Explorer provides a range of capabilities, including online call, signature authentication, SDK code generation, and API quick search. It enables you to view the request, response, and auto-generated examples.

2. Input Parameters

The following request parameter list only provides API request parameters and some common parameters. For the complete common parameter list, see Common Request Parameters.

Parameter Name Required Type Description
Action Yes String Common parameter. The value used for this API: StartMCUMixTranscodeByStrRoomId.
Version Yes String Common parameter. The value used for this API: 2019-07-22.
Region Yes String Common parameter. For more information, please see the list of regions supported by the product. This API only supports: ap-beijing, ap-guangzhou
SdkAppId Yes Integer SDKAppId of TRTC
StrRoomId Yes String Room ID in string type
OutputParams Yes OutputParams On-Cloud MixTranscoding output parameters
EncodeParams Yes EncodeParams On-Cloud MixTranscoding output encoding parameters
LayoutParams Yes LayoutParams On-Cloud MixTranscoding output layout parameters
PublishCdnParams No PublishCdnParams Relayed push parameters of a non-Tencent Cloud CDN

3. Output Parameters

Parameter Name Type Description
RequestId String The unique request ID, which is returned for each request. RequestId is required for locating a problem.

4. Example

Example1 Enabling On-Cloud MixTranscoding

This example shows you how to enable On-Cloud MixTranscoding for a specified room (ID: Room_3560) and specify the screen sharing template for image layout.

The On-Cloud MixTranscoding parameters are as follows:

  • CDN live stream ID: 1400188366_3560_mix
  • Recording file name: 1400188366_3560_mix_file
  • Video parameters for CDN live stream: aspect ratio: 1280 x 720; bitrate: 1560 Kbps; frame rate: 15 FPS; GOP: 2 seconds
  • Audio parameters for CDN live stream: audio sample rate: 48 kHz; bitrate: 64 Kbps; sound channel: dual
  • Layout template: screen sharing. The screen sharing image of user main_pc occupies the left side of the screen as the big image.

Input Example

https://trtc.tencentcloudapi.com/?Action=StartMCUMixTranscodeByStrRoomId
&SdkAppId=1400188366
&StrRoomId=Room_3560
&OutputParams.StreamId=1400188366_3560_mix
&OutputParams.PureAudioStream=0
&OutputParams.RecordId=1400188366_3560_mix_file
&OutputParams.RecordAudioOnly=0
&EncodeParams.VideoWidth=1280
&EncodeParams.VideoHeight=720
&EncodeParams.VideoBitrate=1560
&EncodeParams.VideoFramerate=15
&EncodeParams.VideoGop=2
&EncodeParams.BackgroundColor=0
&EncodeParams.AudioSampleRate=48000
&EncodeParams.AudioBitrate=64
&EncodeParams.AudioChannels=2
&LayoutParams.Template=2
&LayoutParams.MainVideoUserId=main_pc
&LayoutParams.MainVideoStreamType=1
&<Common request parameters>

Output Example

{
  "Response": {
    "RequestId": "eac6b301-a322-493a-8e36-83b295459397"
  }
}

5. Developer Resources

SDK

TencentCloud API 3.0 integrates SDKs that support various programming languages to make it easier for you to call APIs.

Command Line Interface

6. Error Code

The following only lists the error codes related to the API business logic. For other error codes, see Common Error Codes.

Error Code Description
FailedOperation.RequestRejection The TencentCloud API On-Cloud MixTranscoding template conflicts with On-Cloud MixTranscoding settings in the SDK.
FailedOperation.RoomNotExist The room does not exist.
InternalError Internal error.
InvalidParameter.AudioEncodeParams Invalid audio codec parameter.
InvalidParameter.EncodeParams Invalid EncodeParams.
InvalidParameter.MainVideoStreamType Invalid stream type of the big image.
InvalidParameter.OutputParams Incorrect OutputParams parameter.
InvalidParameter.PresetLayoutConfig Incorrect parameters for custom layout.
InvalidParameter.PureAudioStream Incorrect parameters for audio-only stream pushing.
InvalidParameter.RecordAudioOnly Incorrect parameters for audio-only recording.
InvalidParameter.RecordId Incorrect RecordId parameter.
InvalidParameter.RoomId RoomId is incorrect.
InvalidParameter.SdkAppId SdkAppId is incorrect.
InvalidParameter.SmallVideoLayoutParams Invalid small image layout parameter.
InvalidParameter.SmallVideoStreamType Invalid StreamType under SmallVideoLayoutParams.
InvalidParameter.StreamId Incorrect StreamId parameter.
InvalidParameter.VideoResolution Invalid video resolution.
InvalidParameterValue.RoomId Invalid RoomId.
MissingParameter.AudioEncodeParams Audio output parameters are missing in EncodeParams.
MissingParameter.BizId BizId missing in relayed push parameters.
MissingParameter.EncodeParams Missing EncodeParams parameter.
MissingParameter.OutputParams Missing OutputParams parameter.
MissingParameter.PresetLayoutConfig Custom layout parameter missing.
MissingParameter.PublishCdnParams Relaying parameter missing.
MissingParameter.PublishCdnUrls Destination missing in relayed push parameters.
MissingParameter.StreamId The StreamId parameter is missing in OutputParams.
MissingParameter.VideoEncodeParams Video output parameters are missing in EncodeParams.
UnauthorizedOperation.SdkAppId No permission to manipulate SdkAppId.
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