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 (can be generated in CSS console > Address Generator), 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
.// Publish the local user's stream to a live streaming CDN.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);
// Publish the local user's stream to a live streaming CDN.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];
// Publish the local user's stream to a live streaming CDN.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;
const options = {target: {publishMode: PublishMode.PublishMainStreamToCDN}}try {await trtc.startPlugin('CDNStreaming', options);} catch (error) {console.error('CDNStreaming start failed', error);}
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
):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 |
AudioQuality
value you pass in when calling startLocalAudio
.TRTCAudioQuality | audioEncodedSampleRate | audioEncodedChannelNum | audioEncodedKbps |
TRTCAudioQualitySpeech | 48000 | 1 | 50 |
TRTCAudioQualityDefault | 48000 | 1 | 50 |
TRTCAudioQualityMusic | 48000 | 2 | 60 |
layout1
specifies the position (upper half of the canvas) and dimensions (640 x 480) of the camera video of user jerry
.layout2
, layout3
, and layout4
, TRTC will display the videos of the other three users in the windows based on its own rule.
layout1
specifies the position (left) and dimensions (1280 x 720) of user jerry
'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 user jerry
's camera video. The rendering mode used is aspect fill (Fill
).layout3
, layout4
, and layout5
, 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
.// Specify the publishing mode as TRTC_PublishMixedStream_ToCdn.TRTCCloudDef.TRTCPublishTarget target = new TRTCCloudDef.TRTCPublishTarget();target.mode = TRTC_PublishMixedStream_ToCdn;// Specify the CDN address for publishing.TRTCCloudDef.TRTCPublishCdnUrl cdnUrl= new TRTCCloudDef.TRTCPublishCdnUrl();cdnUrl.rtmpUrl = "rtmp://tencent/live/bestnews";cdnUrl.isInternalLine = true;target.cdnUrlList.add(cdnUrl);
// Specify the publishing mode as TRTCPublishMixStreamToCdn.TRTCPublishTarget* target = [[TRTCPublishTarget alloc] init];target.mode = TRTCPublishMixStreamToCdn;// Specify the CDN address for publishing.TRTCPublishCdnUrl* cdnUrl = [[TRTCPublishCdnUrl alloc] init];cdnUrl.rtmpUrl = @"rtmp://tencent/live/bestnews";cdnUrl.isInternalLine = YES;NSMutableArray* cdnUrlList = [NSMutableArray new];[cdnUrlList addObject:cdnUrl];target.cdnUrlList = cdnUrlList;// Set the secondary encoding parameters for the mixed audio and video streams.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;// Set the layout parameters for the screen.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;// Initiate stream mixing.[_trtcCloud startPublishMediaStream:target encoderParam:encoderParam mixingConfig:config];
// Specify the publishing mode as TRTCPublishMixStreamToCdn.TRTCPublishTarget target;target.mode = TRTCPublishMode::TRTCPublishMixStreamToCdn;// Specify the CDN address for publishing.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;// Set the secondary encoding parameters for the mixed audio and video streams.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;// Set the layout parameters for the screen.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;// Initiate stream mixing.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);
true
, it will be a mixed-stream relay. If set to false
, it will be a relay to CDN.Field Name | Description | Required |
SdkAppId | TRTC's SdkAppId. | Yes |
RoomId | Main room ID. | Yes |
RoomIdType | Main room type. | Yes |
WithTranscoding | Whether to transcode. | Yes |
Field Name | Description | Required |
AgentParams.UserId | The UserId used by the relay service in a TRTC room. Do not use the same UserId as those used by normal users in the room. | Yes |
AgentParams.UserSig | The user signature for the relay service to enter a TRTC room. | Yes |
AgentParams.MaxIdleTime | Idle wait time. | No |
Field Name | Description | Required |
AudioParams.AudioEncode | Audio output encoding parameter for stream mixing. | No |
AudioParams.SubscribeAudioList | Audio user allowlist for stream mixing. | No |
Field Name | Description | Required |
VideoParams.VideoEncode | Video output encoding parameter for stream mixing. | No |
VideoParams.LayoutParams | Layout parameters for stream mixing. | No |
VideoParams.BackGroundColor | Canvas background color for stream mixing. | No |
VideoParams.BackgroundImageUrl | Canvas background image URL for stream mixing. | No |
VideoParams.WaterMarkList | Watermark parameter for stream mixing. | No |
Field Name | Description | Required |
SingleSubscribeParams.UserMediaStream.UserInfo | TRTC user parameters. | No |
SingleSubscribeParams.UserMediaStream.StreamType | Primary stream and substream types. | No |
Field Name | Description | Required |
PublishCdnParams.N.PublishCdnUrl | CDN relay URL. | Yes |
PublishCdnParams.N.IsTencentCdn | Whether it is a Tencent Cloud CDN. 0: non-Tencent Cloud CDN; 1: Tencent Cloud CDN. If this parameter is not specified, the default value is 1. Note: 1. To avoid unintended relay fees, it is recommended to explicitly specify this parameter. Relaying to a non-Tencent Cloud CDN will incur relay fees. For details, refer to the API documentation. 2. By default, the sites in the Chinese mainland only support relaying to a Tencent Cloud CDN. If you need to relay to a third-party CDN, contact Tencent Cloud technical support. | No |
Field Name | Description | Required |
FeedBackRoomParams.N.RoomId | RoomId of the room to which streams are pushed back. | Yes |
FeedBackRoomParams.N.RoomIdType | Type of the room to which streams are pushed back. 0: an integer room number; 1: a string room number. | No |
FeedBackRoomParams.N.UserId | UserId used by the room to which streams are pushed back. Note: This UserId cannot be the same as other UserIds already used in TRTC or relay services. It is recommended to include the room ID as part of the UserId. | Yes |
FeedBackRoomParams.N.UserSig | The user signature corresponding to the UserId of the room. For the specific calculation method, refer to the TRTC UserSig calculation scheme. | Yes |
Field Name | Description | Required |
McuSeiParams.LayoutVolume | The SEI for volume layout contains a fixed JSON structure. See the description below for details. | No |
McuSeiParams.PassThrough | Pass-through SEI. | No |
{"app_data": "test","canvas": {"w": 1280,"h": 720},"regions": [{"uid": "test1","zorder": 1,"volume": 60,"x": 0,"y": 0,"w": 640,"h": 360},{"uid": "test2","zorder": 1,"volume": 80,"x": 640,"y": 0,"w": 640,"h": 360}],"ver": "1.0","ts": 1648544726}
Field Name | Description |
SdkAppId | TRTC's SdkAppId. |
TaskId | The unique string ID of the relay task. |
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.TRTCParams
of the enterRoom
function.TRTCParams
of the enterRoom
function.Splicing | Applications created on or after January 9, 2020 | Applications created and used before January 9, 2020 |
Splicing Rules | streamId = urlencode(sdkAppId_roomId_userId_streamType) | streamId = bizid_MD5(roomId_userId_streamType) |
Calculation Example | If sdkAppId = 12345678, roomId = 12345, userId = userA, and the user is currently using a camera, then streamId = 12345678_12345_userA_main. | If bizid = 1234, roomId = 12345, userId = userA, and the user is currently using a camera, then streamId = 1234_MD5(12345_userA_main) = 1234_8D0261436C375BB0DEA901D86D7D70E8. |
Application
/ - [AppDelegate application:didFinishLaunchingWithOptions:]
):public class MApplication extends Application {@Overridepublic void onCreate() {super.onCreate();String licenceURL = ""; // Obtained license URLString licenceKey = ""; // Obtained license keyV2TXLivePremier.setLicence(this, licenceURL, licenceKey);V2TXLivePremier.setObserver(new V2TXLivePremierObserver() {@Overridepublic void onLicenceLoaded(int result, String reason) {Log.i(TAG, "onLicenceLoaded: result:" + result + ", reason:" + reason);}});}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {NSString * const licenceURL = @"<Obtained license URL>";NSString * const licenceKey = @"<Obtained license key>";// V2TXLivePremier is in the V2TXLivePremier.h header file.[V2TXLivePremier setLicence:licenceURL key:licenceKey];[V2TXLivePremier setObserver:self];NSLog(@"SDK Version = %@", [V2TXLivePremier getSDKVersionStr]);return YES;}#pragma mark - V2TXLivePremierObserver- (void)onLicenceLoaded:(int)result Reason:(NSString *)reason {NSLog(@"onLicenceLoaded: result:%d reason:%@", result, reason);}@end
http://PlaybackDomainName/AppName(default live)/StreamName(StreamID).flv
RTMP protocol playback address: rtmp://example.myhost.com/AppName_example/StreamName_exampleFLV protocol playback address: http://example.myhost.com/AppName_example/StreamName_example.flvHLS protocol playback address: http://example.myhost.com/AppName_example/StreamName_example.m3u8
Relayed Stream Type | V2TXLivePlayer Playback Mode | Average Latency | Actual Test Result |
Independent screen | Speed mode (recommended) | 2s - 3s | On the left in the figure below (orange) |
Mixed screen | Speed mode (recommended) | 4s - 5s | On the right in the figure below (blue) |
// Auto mode[_txLivePlayer setCacheParams:1 maxTime:5];// Speed mode[_txLivePlayer setCacheParams:1 maxTime:1];// Smooth mode[_txLivePlayer setCacheParams:5 maxTime:5];// Start playback after setting is completed.
startPublishMediaStream
) has exited the room.stopPublishMediaStream
.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
.
Was this page helpful?