StartMCUMixTranscode
(for numeric room ID/string-type room ID) and StopMCUMixTranscode
(for numeric room ID/string-type room ID), which can also be used to enable and disable CDN relayed live streaming and on-cloud recording.LayoutParams.MainVideoUserId
and LayoutParams.MainVideoStreamType
to specify the image displayed as the big image on the left.MainVideoUserId
and MainVideoStreamType
in LayoutParams
to specify the user ID whose image is displayed as the big image and the stream type.SmallVideoLayoutParams
in LayoutParams
to specify the user ID whose image is displayed as the small image, the stream type, and the position of the image.PresetLayoutConfig
(an array) to preset the position of each image in stream mixing.UserId
in PresetLayoutConfig
, the layout engine will assign users to the positions specified by PresetLayoutConfig
in room entry sequence.UserId
in PresetLayoutConfig
, the layout engine will reserve the position for the specified user.PresetLayoutConfig
are occupied, the layout engine will stop mixing the video and audio of other users.Parameter | Description | Recommended Value |
AudioSampleRate | Audio sample rate | 48000 |
AudioBitrate | Audio bitrate (Kbps) | 64 |
AudioChannels | Number of sound channels | 2 |
VideoWidth | Video width, required for audio-video output | Custom |
VideoHeight | Video height, required for audio-video output | Custom |
VideoBitrate | Video bitrate, in Kbps, required for audio-video output | Custom |
VideoFramerate | Frame rate, required for audio-video output | 15 |
VideoGop | GOP, required for audio-video output | 3 |
BackgroundColor | Background color | Custom |
streamID
for the mixed stream (required)streamID
for the mixed stream in CSS CDN. You can play back this stream only if you have activated CSS and configured a playback domain name.OutputParams.PureAudioStream
parameter to 1
, and only audio data will be forwarded to CDNs after stream mixing.OutputParams.RecordId_start time_end time
, e.g. file001_2020-02-16-12-12-12_2020-02-16-13-13-13
.OutputParams.RecordAudioOnly
parameter to 1
, and mixed streams will be recorded as MP3 files.Parameter | Audio-only Mode (`PureAudio`) | Preset Layout Mode (`PresetLayout`) | Screen Sharing Mode (`ScreenSharing`) | Manual Mode (`Manual`) |
Call | Once | Once | Once | You need to call the stream mixing API whenever one of the following happens: A co-anchor joins. A co-anchor leaves. A co-anchor turns on/off the camera. A co-anchor turns on/off the mic. |
Mixed content | Audio only | You can specify the content to be mixed for each channel. | Students’ videos are not mixed. | You can specify the content to be mixed for each channel. |
audioSampleRate | 48000 is recommended. | 48000 is recommended. | 48000 is recommended. | 48000 is recommended. |
audioBitrate | 64 is recommended. | 64 is recommended. | 64 is recommended. | 64 is recommended. |
audioChannels | 2 is recommended. | 2 is recommended. | 2 is recommended. | 2 is recommended. |
videoWidth | - | Cannot be 0 | 0 is recommended. | Cannot be 0 |
videoHeight | - | Cannot be 0 | 0 is recommended. | Cannot be 0 |
videoBitrate | - | Cannot be 0 | 0 is recommended. | Cannot be 0 |
videoFramerate | - | 15 is recommended. | 15 is recommended. | 15 is recommended. |
videoGOP | - | 3 is recommended. | 3 is recommended. | 3 is recommended. |
mixUsers array | - | Use placeholders for the setting. | - | Use actual `userIds` for the setting. |
PureAudio
)AudioCall
) and audio chat rooms (VoiceChatRoom
). You can select this mode when calling the enterRoom API of the SDK.
In this mode, the SDK automatically mixes all the audio streams in a room into one stream.enterRoom()
function to enter a room, set the AppScene
parameter to TRTCAppSceneAudioCall
or TRTCAppSceneVoiceChatRoom
, which indicates that there will be only audio in the room.streamId
parameter in TRTCParams
for mixed streams.startLocalAudio()
to enable local audio capturing and uploading.setMixTranscodingConfig()
API to enable On-Cloud MixTranscoding. You need to set the mode
parameter in TRTCTranscodingConfig
to TRTCTranscodingConfigMode_Template_PureAudio, and specify audio quality-related parameters such as audioSampleRate
, audioBitrate
, and audioChannels
.setMixTranscodingConfig()
API once after entering a room and enabling local audio publishing.VideoCall
) and interactive live streaming (LIVE
). You can select this mode when calling the enterRoom API of the SDK.
In the preset layout mode, the SDK automatically mixes multiple audio and video streams in a room into one stream according to the preset layout rules.enterRoom()
function to enter a room, set the AppScene
parameter to TRTCAppSceneVideoCall
or TRTCAppSceneLIVE
, whichever fits your needs.streamId
parameter in TRTCParams
for mixed streams.startLocalPreview()
and startLocalAudio()
to enable local audio and video publishing.setMixTranscodingConfig()
API to enable On-Cloud MixTranscoding. You need to set the mode
parameter in TRTCTranscodingConfig
to TRTCTranscodingConfigMode_Template_PresetLayout, and specify audio quality-related parameters such as audioSampleRate
, audioBitrate
, and audioChannels
, as well as video quality-related parameters such as videoWidth
, videoHeight
, videoBitrate
, and videoFramerate
.mixUser
parameter. In the preset layout mode, you must set userId
to a placeholder, which could be $PLACE_HOLDER_REMOTE$, $PLACE_HOLDER_LOCAL_MAIN$, or $PLACE_HOLDER_LOCAL_SUB$. Their meanings are described below.Placeholder | Description | Multiple Allowed |
$PLACE_HOLDER_LOCAL_MAIN$ | Local camera image | No |
$PLACE_HOLDER_LOCAL_SUB$ | Local screen sharing image (image only) | No |
$PLACE_HOLDER_REMOTE$ | Remote co-anchor(s) | Yes |
TRTCTranscodingConfig *config = [[TRTCTranscodingConfig alloc] init];// Set the resolution to 720 x 1280 px, bitrate to 1500 Kbps, and frame rate to 20 FPSconfig.videoWidth = 720;config.videoHeight = 1280;config.videoBitrate = 1500;config.videoFramerate = 20;config.videoGOP = 2;config.audioSampleRate = 48000;config.audioBitrate = 64;config.audioChannels = 2;// Use the preset layout modeconfig.mode = TRTCTranscodingConfigMode_Template_PresetLayout;NSMutableArray *mixUsers = [NSMutableArray new];// Position of the camera image of the anchorTRTCMixUser* local = [TRTCMixUser new];local.userId = @"$PLACE_HOLDER_LOCAL_MAIN$";local.zOrder = 0; // When `zOrder` is set to `0`, it indicates that the anchor's image is displayed at the bottom.local.rect = CGRectMake(0, 0, videoWidth, videoHeight);local.roomID = nil; // Required for remote users but not for the local user[mixUsers addObject:local];// Image position of co-anchorTRTCMixUser* remote1 = [TRTCMixUser new];remote1.userId = @"$PLACE_HOLDER_REMOTE$";remote1.zOrder = 1;remote1.rect = CGRectMake(400, 800, 180, 240); // For reference onlyremote1.roomID = @"97392"; // Required for remote users but not for the local user[mixUsers addObject:remote1];// Image position of co-anchorTRTCMixUser* remote2 = [TRTCMixUser new];remote2.userId = @"$PLACE_HOLDER_REMOTE$";remote2.zOrder = 1;remote2.rect = CGRectMake(400, 500, 180, 240); // For reference onlyremote2.roomID = @"97392"; // Required for remote users but not for the local user[mixUsers addObject:remote2];config.mixUsers = mixUsers;// Enable On-Cloud MixTranscoding[_trtc setMixTranscodingConfig:config];
TRTCCloudDef.TRTCTranscodingConfig config = new TRTCCloudDef.TRTCTranscodingConfig();// Set the resolution to 720 x 1280 px, bitrate to 1500 Kbps, and frame rate to 20 FPSconfig.videoWidth = 720;config.videoHeight = 1280;config.videoBitrate = 1500;config.videoFramerate = 20;config.videoGOP = 2;config.audioSampleRate = 48000;config.audioBitrate = 64;config.audioChannels = 2;// Use the preset layout modeconfig.mode = TRTCCloudDef.TRTC_TranscodingConfigMode_Template_PresetLayout;config.mixUsers = new ArrayList<>();// Position of the camera image of the anchorTRTCCloudDef.TRTCMixUser local = new TRTCCloudDef.TRTCMixUser();local.userId = "$PLACE_HOLDER_LOCAL_MAIN$";local.zOrder = 0; // When `zOrder` is set to `0`, it indicates that the anchor's image is displayed at the bottomlocal.x = 0;local.y = 0;local.width = videoWidth;local.height = videoHeight;local.roomId = null; // Required for remote users but not for the local userconfig.mixUsers.add(local);// Image position of co-anchorTRTCCloudDef.TRTCMixUser remote1 = new TRTCCloudDef.TRTCMixUser();remote1.userId = "$PLACE_HOLDER_REMOTE$";remote1.zOrder = 1;remote1.x = 400; // For reference onlyremote1.y = 800; // For reference onlyremote1.width = 180; // For reference onlyremote1.height = 240; // For reference onlyremote1.roomId = 97392; // Required for remote users but not for the local userconfig.mixUsers.add(remote1);// Image position of co-anchorTRTCCloudDef.TRTCMixUser remote2 = new TRTCCloudDef.TRTCMixUser();remote2.userId = "$PLACE_HOLDER_REMOTE$";remote2.zOrder = 1;remote1.x = 400; // For reference onlyremote1.y = 500; // For reference onlyremote1.width = 180; // For reference onlyremote1.height = 240; // For reference onlyremote1.roomId = 97393; // Required for remote users but not for the local userconfig.mixUsers.add(remote2);// Enable On-Cloud MixTranscoding.trtc.setMixTranscodingConfig(config);
TRTCTranscodingConfig config;// Set the resolution to 720 x 1280 px, bitrate to 1500 Kbps, and frame rate to 20 FPSconfig.videoWidth = 1280;config.videoHeight = 720;config.videoBitrate = 1500;config.videoFramerate = 20;config.videoGOP = 2;config.audioSampleRate = 48000;config.audioBitrate = 64;config.audioChannels = 2;// Use the preset layout modeconfig.mode == TRTCTranscodingConfigMode_Template_PresetLayoutTRTCMixUser* mixUsersArray = new TRTCMixUser[3];mixUsersArray[0].userId = "$PLACE_HOLDER_LOCAL_MAIN$";mixUsersArray[0].zOrder = 0; // When `zOrder` is set to `0`, it indicates that the anchor's image is displayed at the bottom.mixUsersArray[0].rect.left = 0;mixUsersArray[0].rect.top = 0;mixUsersArray[0].rect.right = videoWidth;mixUsersArray[0].rect.bottom = videoHeight;mixUsersArray[0].roomId = nullptr; // Required for remote users but not for the local usermixUsersArray[1].userId = "$PLACE_HOLDER_REMOTE$";mixUsersArray[1].zOrder = 1;mixUsersArray[1].rect.left = 400; // For reference onlymixUsersArray[1].rect.top = 800; // For reference onlymixUsersArray[1].rect.right = 180; // For reference onlymixUsersArray[1].rect.bottom = 240; // For reference onlymixUsersArray[1].roomId = 97392; // Required for remote users but not for the local usermixUsersArray[2].userId = "$PLACE_HOLDER_REMOTE$";mixUsersArray[2].zOrder = 1;mixUsersArray[2].rect.left = 400; // For reference onlymixUsersArray[2].rect.top = 500; // For reference onlymixUsersArray[2].rect.right = 180; // For reference onlymixUsersArray[2].rect.bottom = 240; // For reference onlymixUsersArray[2].roomId = 97393; // Required for remote users but not for the local userconfig.mixUsersArray = mixUsersArray;// Enable On-Cloud MixTranscodingtrtc->setMixTranscodingConfig(&config);
TRTCTranscodingConfig config = new TRTCTranscodingConfig();// Set the resolution to 720 x 1280 px, bitrate to 1500 Kbps, and frame rate to 20 FPSconfig.videoWidth = 1280;config.videoHeight = 720;config.videoBitrate = 1500;config.videoFramerate = 20;config.videoGOP = 2;config.audioSampleRate = 48000;config.audioBitrate = 64;config.audioChannels = 2;config.mode = RTCTranscodingConfigMode.TRTCTranscodingConfigMode_Template_PresetLayout;TRTCMixUser[] mixUsersArray = new TRTCMixUser[3];// Position of the camera image of the anchorTRTCMixUser local = new TRTCMixUser();local.userId = "$PLACE_HOLDER_LOCAL_MAIN$";local.zOrder = 0; // When `zOrder` is set to `0`, it indicates that the anchor's image is displayed at the bottom.local.roomId = null; // Required for remote users but not for the local userRECT rtLocal = new RECT() {left = 0,top = 0,right = videoWidth,bottom = videoHeight};local.rect = rtLocal;mixUsersArray[0] = local;// Image position of co-anchorTRTCMixUser remote1 = new TRTCMixUser();remote1.userId = "$PLACE_HOLDER_REMOTE$";remote1.zOrder = 1;remote1.roomID = 97392; // Required for remote users but not for the local userRECT rtRemote1 = new RECT() { // For reference onlyleft = 420,top = 81,right = 240 + left,bottom = 240 + top};remote1.rect = rtRemote1;mixUsersArray[1] = remote1;// Image position of co-anchorTRTCMixUser remote2 = new TRTCMixUser();remote2.userId = "$PLACE_HOLDER_REMOTE$";remote2.zOrder = 1;remote2.roomId = 97393; // Required for remote users but not for the local userRECT rtRemote2 = new RECT() { // For reference onlyleft = 660,top = 400,right = 240 + left,bottom = 240 + top};rtRemote2.rect = rtRemote2;mixUsersArray[2] = remote2;// Enable On-Cloud MixTranscodingconfig.mixUsersArray = mixUsersArray;trtc.setMixTranscodingConfig(config);
TRTCCloud trtcCloud = await TRTCCloud.sharedInstance();trtcCloud.setMixTranscodingConfig(TRTCTranscodingConfig(appId: 1252463788, // For reference onlybizId: 3891, // For reference only// Set the resolution to 720 x 1280 px, bitrate to 1500 Kbps, and frame rate to 20 FPSvideoWidth: 720,videoHeight: 1280,videoBitrate: 1500,videoFramerate: 20,videoGOP: 2,audioSampleRate: 48000,audioBitrate: 64,audioChannels: 2,// Use the preset layout modemode: TRTCCloudDef.TRTC_TranscodingConfigMode_Template_PresetLayout,mixUsers: [// Position of the camera image of the anchorTRTCMixUser(userId: "$PLACE_HOLDER_LOCAL_MAIN$",roomId: null, // Required for remote users but not for the local userzOrder: 0, // When `zOrder` is set to `0`, it indicates that the anchor's image is displayed at the bottomx: 0, // For reference onlyy: 0,streamType: 0,width: 300,height: 400),TRTCMixUser(userId: '$PLACE_HOLDER_REMOTE$',roomId: '256', // Required for remote users but not for the local userzOrder: 1,x: 100, // For reference onlyy: 100,streamType: 0,width: 160,height: 200)],));
try {// Present layout modeconst config = {mode: 'preset-layout',videoWidth: 720,videoHeight: 1280,videoBitrate: 1500,videoFramerate: 20,videoGOP: 2,audioSampleRate: 48000,audioBitrate: 64,audioChannels: 2,// Preset the positions of the local camera stream and two remote streams.mixUsers: [{width: 720,height: 1280,locationX: 0,locationY: 0,pureAudio: false,userId: 'jack', // Placeholder for the local camera stream. Pass in the `userId` of the user whose camera stream is pushed.zOrder: 1},{width: 180,height: 240,locationX: 400,locationY: 800,pureAudio: false,userId: '$PLACE_HOLDER_REMOTE$', // Placeholder for a remote imagezOrder: 2},{width: 180,height: 240,locationX: 400,locationY: 500,pureAudio: false,userId: '$PLACE_HOLDER_REMOTE$', // Placeholder for a remote imagezOrder: 2}];}await client.startMixTranscode(config);} catch (error) {console.error('startMixTranscode failed ', error);}
setMixTranscodingConfig()
API once after entering a room and enabling local audio publishing.ScreenSharing
)AppScene
parameter to TRTCAppSceneLIVE
when calling the enterRoom API of the SDK.
In the screen sharing mode, the SDK prepares a canvas in the specified resolution. When the teacher is not sharing his or her screen, the SDK stretches the teacher’s camera image to fit the canvas. After the teacher enables screen sharing, the SDK does the same to the screen sharing image. This ensures consistency in the resolution of mixed streams and avoids incompatibility issues caused by inconsistencies in the resolution of recorded and played back videos (average players cannot play videos with changing resolution.)enterRoom()
function to enter a room, set the AppScene
parameter to TRTCAppSceneLIVE
.streamId
parameter in TRTCParams
for mixed streams.startLocalPreview()
and startLocalAudio()
to enable local audio and video publishing.setMixTranscodingConfig()
API to enable On-Cloud MixTranscoding. You need to set the mode
parameter in TRTCTranscodingConfig
to TRTCTranscodingConfigMode_Template_ScreenSharing, and specify audio quality-related parameters such as audioSampleRate
, audioBitrate
, and audioChannels
, as well as video quality-related parameters such as videoWidth
, videoHeight
, videoBitrate
, and videoFramerate
.videoWidth
and videoHeight
are set to 0
, the SDK will work out an appropriate resolution based on the aspect ratio of the user's screen.setMixTranscodingConfig()
API once after entering a room and enabling local audio publishing.setLocalVideoRenderCallback()
and setRemoteVideoRenderCallback()
to display the teacher’s camera image and students’ images on the shared screen.videoWidth
and videoHeight
in TRTCTranscodingConfig
to 0
. If the teacher's screen width is smaller than 1920 px, the SDK will use the actual resolution of the teacher's screen; otherwise it will select a resolution from 1920 x 1080 px (16:9), 1920 x 1200 px (16:10), and 1920 x 1440 px (4:3), depending on the aspect ratio of the teacher’s screen.Manual
)TRTCTranscodingConfig
and listen for the onUserVideoAvailable()
and onUserAudioAvailable()
callbacks in TRTCCloudDelegate
. The callbacks keep you up to date about the users who are sending audio and video in the room so that you can modify the mixUsers
parameter accordingly. Otherwise stream mixing will fail.enterRoom()
function to enter a room, set the AppScene
parameter based on your needs.streamId
parameter in TRTCParams
for mixed streams.startLocalAudio()
to enable local audio publishing. You may also call startLocalPreview()
to enable video publishing.setMixTranscodingConfig()
API to enable On-Cloud MixTranscoding. You need to set the mode
parameter in TRTCTranscodingConfig
to TRTCTranscodingConfigMode_Manual, and specify audio quality-related parameters such as audioSampleRate
, audioBitrate
, and audioChannels
. If your applications also involve the transfer of video data, you also need to set video quality-related parameters such as videoWidth
, videoHeight
, videoBitrate
, and videoFramerate
.onUserVideoAvailable()
and onUserAudioAvailable()
callbacks in TRTCCloudDelegate
and set the mixUsers parameter as needed.userId
in mixUser
to the actual user ID of each co-anchor and set the pureAudio
parameter in mixUser
based on whether a co-anchor has enabled video.In the manual mode, you need to listen for the mic on/off events of co-anchors in the room and call the setMixTranscodingConfig()
API multiple times depending on the number of co-anchors and whether they are sending audio and video.
setMixTranscodingConfig
, has left the room.nil
/null
to manually stop stream mixing.
Was this page helpful?