xxxxx.livepush.myqcloud.com
, where xxxxx represents a number called bizid..liveplay.myqcloud.com
). The CNAME domain name cannot be accessed directly. You need to complete the CNAME configuration with your domain name service provider. After the configuration takes effect, you can enjoy the CSS service. For detailed instructions, please refer to CNAME Configuration.xxxxx.livepush.myqcloud.com
to your CSS console by default. This domain name serves as a default push domain name agreed upon between CSS service and TRTC service.TRTCCloud
to publish the audio/video streams of local users to live streaming CDNs (known in TRTC as "relay to CDN").
The TRTC server will send the audio/video data directly to the CDN server. Because the data is not transcoded, the cost is relatively low.
However, if there are multiple users publishing audio/video streams in a room, there will be a CDN stream for each user. Multiple players are needed to play the streams, and they may not play in sync.TRTCPublishTarget
object and set mode
in the object to TRTCPublishBigStreamToCdn
or TRTCPublishSubStreamToCdn
. The former is used to publish the user’s primary stream (usually the camera), and the latter is used to publish the user’s substream (usually the screen).cdnUrlList
in the TRTCPublishTarget
object to one or multiple CDN addresses (which usually starts with rtmp://
). If you publish to the Tencent Cloud CDN, set isInternalLine
to true
; otherwise, set it to false
.TRTCStreamEncoderParam
and TRTCStreamMixingConfig
empty.startPublishMediaStream
. If the taskId
parameter returned by the onStartPublishMediaStream
callback is not empty, the local API call is successful.stopPublishMediaStream
, passing in the taskId
returned by onStartPublishMediaStream
.TRTCCloudDef.TRTCPublishTarget target = new TRTCCloudDef.TRTCPublishTarget();target.mode = TRTC_PublishBigStream_ToCdn;TRTCCloudDef.TRTCPublishCdnUrl cdnUrl= new TRTCCloudDef.TRTCPublishCdnUrl();cdnUrl.rtmpUrl = "rtmp://tencent/live/bestnews";cdnUrl.isInternalLine = true;target.cdnUrlList.add(cdnUrl);mTRTCCloud.startPublishMediaStream(target, null, null);
TRTCPublishTarget* target = [[TRTCPublishTarget alloc] init];target.mode = TRTCPublishBigStreamToCdn;TRTCPublishCdnUrl* cdnUrl = [[TRTCPublishCdnUrl alloc] init];cdnUrl.rtmpUrl = @"rtmp://tencent/live/bestnews";cdnUrl.isInternalLine = YES;NSMutableArray* cdnUrlList = [NSMutableArray new];[cdnUrlList addObject:cdnUrl];target.cdnUrlList = cdnUrlList;[_trtcCloud startPublishMediaStream:target encoderParam:nil mixingConfig:nil];
TRTCPublishTarget target;target.mode = TRTCPublishMode::TRTCPublishBigStreamToCdn;TRTCPublishCdnUrl* cdn_url_list = new TRTCPublishCdnUrl[1];cdn_url_list[0].rtmpUrl = "rtmp://tencent/live/bestnews";cdn_url_list[0].isInternalLine = true;target.cdnUrlList = cdn_url_list;target.cdnUrlListSize = 1;trtc->startPublishMediaStream(&target, nullptr, nullptr);delete[] cdn_url_list;
TRTCPublishTarget target = TRTCPublishTarget();target.mode = TRTCPublishMode.TRTCPublishBigStreamToCdn;TRTCPublishCdnUrl cdnUrlEntity = new TRTCPublishCdnUrl();cdnUrlEntity.rtmpUrl = "rtmp://tencent/live/bestnews";cdnUrlEntity.isInternalLine = true;target.cdnUrlList.add(cdnUrlEntity);trtcCloud.startPublishMediaStream(target: target);
TRTCStreamEncoderParam
and TRTCStreamMixingConfig
parameters of the API allow you to determine the details of stream mixing and transcoding.TRTCStreamMixingConfig
) and transcoding parameters (TRTCStreamEncoderParam
) you specify. Afterward, they will be published to CDNs. In this mode, additional transcoding fees are charged.TRTCPublishTarget
object and set mode
in the object to TRTCPublishMixStreamToCdn
.cdnUrlList
in the TRTCPublishTarget
object to one or multiple CDN addresses (which usually start with rtmp://
). If you publish to the Tencent Cloud CDN, set isInternalLine
to true
; otherwise, set it to false
.TRTCStreamEncoderParam
):AudioQuality
value you pass in when calling startLocalAudio
.videoEncodedWidth | videoEncodedHeight | videoEncodedFPS | videoEncodedGOP | videoEncodedKbps |
640 | 360 | 15 | 3 | 800 Kbps |
960 | 540 | 15 | 3 | 1200 Kbps |
1280 | 720 | 15 | 3 | 1500 Kbps |
1920 | 1080 | 15 | 3 | 2500 Kbps |
TRTCAudioQuality | audioEncodedSampleRate | audioEncodedChannelNum | audioEncodedKbps | audioEncodedCodecType |
TRTCAudioQualitySpeech | 48000 | 1 | 50 | 0 |
TRTCAudioQualityDefault | 48000 | 1 | 50 | 0 |
TRTCAudioQualityMusic | 48000 | 2 | 60 | 2 |
Example 1: Mix four users’ streams and use an image as the background.layout1
specifies the position (upper half of the canvas) and dimensions (640 x 480) of the camera video of userjerry
.Because no user IDs are specified forlayout2
,layout3
, andlayout4
, TRTC will display the videos of the other three users in the windows based on its own rule.Example 2: Mix the camera video and screen of one user plus the camera videos of three other users.layout1
specifies the position (left) and dimensions (1280 x 720) of userjerry
’s screen. The rendering mode used is aspect fit (Fit
), and the background color is black.layout2
specifies the position (top right) and dimensions (300 x 200) of userjerry
’s camera video. The rendering mode used is aspect fill (Fill
).Because no user IDs are specified forlayout3
,layout4
, andlayout5
, TRTC will display the videos of the other three users in the windows based on its own rule.
updatePublishMediaStream
, passing in the taskId
returned in step 6 as well as the new TRTCStreamMixingConfig
parameters. We recommend you do not change TRTCStreamEncoderParam
during relay because doing so will affect the stability of CDN playback.stopPublishMediaStream
, passing in the taskId
returned by onStartPublishMediaStream
.TRTCCloudDef.TRTCPublishTarget target = new TRTCCloudDef.TRTCPublishTarget();target.mode = TRTC_PublishMixedStream_ToCdn;TRTCCloudDef.TRTCPublishCdnUrl cdnUrl= new TRTCCloudDef.TRTCPublishCdnUrl();cdnUrl.rtmpUrl = "rtmp://tencent/live/bestnews";cdnUrl.isInternalLine = true;target.cdnUrlList.add(cdnUrl);TRTCCloudDef.TRTCStreamEncoderParam encoderParam= new TRTCCloudDef.TRTCStreamEncoderParam();encoderParam.videoEncodedWidth = 1280;encoderParam.videoEncodedHeight = 720;encoderParam.videoEncodedFPS = 15;encoderParam.videoEncodedGOP = 3;encoderParam.videoEncodedKbps = 1000;encoderParam.audioEncodedSampleRate = 48000;encoderParam.audioEncodedChannelNum = 1;encoderParam.audioEncodedKbps = 50;encoderParam.audioEncodedCodecType = 0;TRTCCloudDef.TRTCStreamMixingConfig mixingConfig =new TRTCCloudDef.TRTCStreamMixingConfig();TRTCCloudDef.TRTCVideoLayout layout1 = new TRTCCloudDef.TRTCVideoLayout();layout1.zOrder = 0;layout1.x = 0;layout1.y = 0;layout1.width = 720;layout1.height = 1280;layout1.fixedVideoStreamType = TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_SUB;layout1.fixedVideoUser.intRoomId = 1234;layout1.fixedVideoUser.userId = "mike";TRTCCloudDef.TRTCVideoLayout layout2 = new TRTCCloudDef.TRTCVideoLayout();layout2.zOrder = 0;layout2.x = 1300;layout2.y = 0;layout2.width = 300;layout2.height = 200;layout2.fixedVideoStreamType = TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_BIG;layout2.fixedVideoUser.intRoomId = 1234;layout2.fixedVideoUser.userId = "mike";TRTCCloudDef.TRTCVideoLayout layout3 = new TRTCCloudDef.TRTCVideoLayout();layout3.zOrder = 0;layout3.x = 1300;layout3.y = 220;layout3.width = 300;layout3.height = 200;layout3.fixedVideoStreamType = TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_SUB;layout3.fixedVideoUser = null;mixingConfig.videoLayoutList.add(layout1);mixingConfig.videoLayoutList.add(layout2);mixingConfig.videoLayoutList.add(layout3);mixingConfig.audioMixUserList = null;mTRTCCloud.startPublishMediaStream(target, encoderParam, mixingConfig);
TRTCPublishTarget* target = [[TRTCPublishTarget alloc] init];target.mode = TRTCPublishMixStreamToCdn;TRTCPublishCdnUrl* cdnUrl = [[TRTCPublishCdnUrl alloc] init];cdnUrl.rtmpUrl = @"rtmp://tencent/live/bestnews";cdnUrl.isInternalLine = YES;NSMutableArray* cdnUrlList = [NSMutableArray new];[cdnUrlList addObject:cdnUrl];target.cdnUrlList = cdnUrlList;TRTCStreamEncoderParam* encoderParam = [[TRTCStreamEncoderParam alloc] init];encoderParam.videoEncodedWidth = 1280;encoderParam.videoEncodedHeight = 720;encoderParam.videoEncodedFPS = 15;encoderParam.videoEncodedGOP = 3;encoderParam.videoEncodedKbps = 1000;encoderParam.audioEncodedSampleRate = 48000;encoderParam.audioEncodedChannelNum = 1;encoderParam.audioEncodedKbps = 50;encoderParam.audioEncodedCodecType = 0;TRTCStreamMixingConfig* config = [[TRTCStreamMixingConfig alloc] init];NSMutableArray* videoLayoutList = [NSMutableArray new];TRTCVideoLayout* layout1 = [[TRTCVideoLayout alloc] init];layout1.zOrder = 0;layout1.rect = CGRectMake(0, 0, 720, 1280);layout1.fixedVideoStreamType = TRTCVideoStreamTypeSub;layout1.fixedVideoUser.intRoomId = 1234;layout1.fixedVideoUser.userId = @"mike";TRTCVideoLayout* layout2 = [[TRTCVideoLayout alloc] init];layout2.zOrder = 0;layout2.rect = CGRectMake(1300, 0, 300, 200);layout2.fixedVideoStreamType = TRTCVideoStreamTypeBig;layout2.fixedVideoUser.intRoomId = 1234;layout2.fixedVideoUser.userId = @"mike";TRTCVideoLayout* layout3 = [[TRTCVideoLayout alloc] init];layout3.zOrder = 0;layout3.rect = CGRectMake(1300, 220, 300, 200);layout3.fixedVideoStreamType = TRTCVideoStreamTypeSub;layout3.fixedVideoUser = nil;[videoLayoutList addObject:layout1];[videoLayoutList addObject:layout2];[videoLayoutList addObject:layout3];config.videoLayoutList = videoLayoutList;config.audioMixUserList = nil;[_trtcCloud startPublishMediaStream:target encoderParam:encoderParam mixingConfig:config];
TRTCPublishTarget target;target.mode = TRTCPublishMode::TRTCPublishMixStreamToCdn;TRTCPublishCdnUrl* cdn_url = new TRTCPublishCdnUrl[1];cdn_url[0].rtmpUrl = "rtmp://tencent/live/bestnews";cdn_url[0].isInternalLine = true;target.cdnUrlList = cdn_url;target.cdnUrlListSize = 1;TRTCStreamEncoderParam encoder_param;encoder_param.videoEncodedWidth = 1280;encoder_param.videoEncodedHeight = 720;encoder_param.videoEncodedFPS = 15;encoder_param.videoEncodedGOP = 3;encoder_param.videoEncodedKbps = 1000;encoder_param.audioEncodedSampleRate = 48000;encoder_param.audioEncodedChannelNum = 1;encoder_param.audioEncodedKbps = 50;encoder_param.audioEncodedCodecType = 0;TRTCStreamMixingConfig config;TRTCVideoLayout* video_layout_list = new TRTCVideoLayout[3];TRTCUser* fixedVideoUser0 = new TRTCUser();fixedVideoUser0->intRoomId = 1234;fixedVideoUser0->userId = "mike";video_layout_list[0].zOrder = 0;video_layout_list[0].rect.left = 0;video_layout_list[0].rect.top = 0;video_layout_list[0].rect.right = 720;video_layout_list[0].rect.bottom = 1280;video_layout_list[0].fixedVideoStreamType =TRTCVideoStreamType::TRTCVideoStreamTypeSub;video_layout_list[0].fixedVideoUser = fixedVideoUser0;TRTCUser* fixedVideoUser1 = new TRTCUser();fixedVideoUser1->intRoomId = 1234;fixedVideoUser1->userId = "mike";video_layout_list[1].zOrder = 0;video_layout_list[1].rect.left = 1300;video_layout_list[1].rect.top = 0;video_layout_list[1].rect.right = 300;video_layout_list[1].rect.bottom = 200;video_layout_list[1].fixedVideoStreamType =TRTCVideoStreamType::TRTCVideoStreamTypeBig;video_layout_list[1].fixedVideoUser = fixedVideoUser1;video_layout_list[2].zOrder = 0;video_layout_list[2].rect.left = 1300;video_layout_list[2].rect.top = 220;video_layout_list[2].rect.right = 300;video_layout_list[2].rect.bottom = 200;video_layout_list[2].fixedVideoStreamType =TRTCVideoStreamType::TRTCVideoStreamTypeSub;video_layout_list[2].fixedVideoUser = nullptr;config.videoLayoutList = video_layout_list;config.videoLayoutListSize = 3;config.audioMixUserList = nullptr;trtc->startPublishMediaStream(&target, &encoder_param, &config);delete fixedVideoUser0;delete fixedVideoUser1;delete[] video_layout_list;
TRTCPublishTarget target = TRTCPublishTarget();target.mode = TRTCPublishMode.TRTCPublishMixStreamToCdn;TRTCPublishCdnUrl cdnUrlEntity = new TRTCPublishCdnUrl();cdnUrlEntity.rtmpUrl = "rtmp://tencent/live/bestnews";cdnUrlEntity.isInternalLine = true;target.cdnUrlList.add(cdnUrlEntity);TRTCStreamMixingConfig config = TRTCStreamMixingConfig();TRTCUser selfUser = TRTCUser();selfUser.userId = localUserId;selfUser.intRoomId = localRoomId;TRTCVideoLayout selfVideoLayout = TRTCVideoLayout();selfVideoLayout.fixedVideoStreamType = TRTCVideoStreamType.TRTCVideoStreamTypeBig;selfVideoLayout.rect = Rect(originX: 0, originY: 0, sizeWidth: 1080, sizeHeight: 1920);selfVideoLayout.zOrder = 0;selfVideoLayout.fixedVideoUser = selfUser;selfVideoLayout.fillMode = TRTCVideoFillMode.TRTCVideoFillMode_Fit;config.videoLayoutList.add(selfVideoLayout);TRTCUser remoteUser = TRTCUser();remoteUser.userId = remoteUserId;remoteUser.intRoomId = remoteRoomId;TRTCVideoLayout remoteVideoLayout = TRTCVideoLayout();remoteVideoLayout.fixedVideoStreamType = TRTCVideoStreamType.TRTCVideoStreamTypeBig;remoteVideoLayout.rect = Rect(originX: 100, originY: 50, sizeWidth: 216, sizeHeight: 384);remoteVideoLayout.zOrder = 1;remoteVideoLayout.fixedVideoUser = remoteUser;remoteVideoLayout.fillMode = TRTCVideoFillMode.TRTCVideoFillMode_Fit;config.videoLayoutList.add(remoteVideoLayout);TRTCStreamEncoderParam param = TRTCStreamEncoderParam();param.videoEncodedWidth = 1080;param.videoEncodedHeight = 1920;param.videoEncodedKbps = 5000;param.videoEncodedFPS = 30;param.videoEncodedGOP = 3;param.audioEncodedSampleRate = 48000;param.audioEncodedChannelNum = 2;param.audioEncodedKbps = 128;param.audioEncodedCodecType = 2;trtcCloud.startPublishMediaStream(target: target, config: config, params: param);
onCdnStreamStateChanged
callback event to get the latest status of a relay to CDN task. updatePublishMediaStream
, passing in the taskid
of the current task. Note that, in order to ensure the stability of the publishing process, you cannot switch from publishing a single stream to mixing and publishing only audios or only videos. By default, both audio and video data are published when you publish a single stream. If you switch to publishing mixed streams, you must also publish both audios and videos.TRTCStreamEncodeParam
and leave audioMixUserList
of TRTCStreamMixingConfig
empty.watermarkList
of TRTCStreamMixingConfig
to set watermarks.fixedVideoStreamType
of TRTCVideoLayout
to TRTCVideoStreamTypeSub
.startPublishMediaStream
to mix streams left the room.stopPublishMediaStream
to stop mixing the streams.
Was this page helpful?