MLVBLiveRoom
用来帮助开发者快速实现连麦需求,为了更好的满足开发者针对连麦功能的需求,腾讯云新增了基于 RTC 协议的连麦方案,同时提供了更加简单灵活的 V2 接口。对比项 | RTMP 方案 | RTC 方案 |
协议 | RTMP 基于 TCP 协议 | RTC 基于 UDP 协议(更适合流媒体传输) |
QoS | 弱网抗性能力弱 | 50%丢包率可正常视频观看,70%丢包率可正常语音连麦 |
支持区域 | 仅支持中国内地(大陆)地区 | 全球覆盖 |
使用产品 | 需开通移动直播、云直播服务 | 需开通移动直播、云直播、实时音视频服务 |
价格 | 0.0028美元/分钟 | 阶梯价格,详情请参见 RTC 连麦方案怎么计算费用 |
V2TXLivePusher
(推流)、 V2TXLivePlayer
(拉流),用来帮助客户实现更加灵活、更低延时、更多人数的直播互动场景。开播端可以利用 V2 提供的 RTC 推流能力,默认情况下,观众端观看则可使用 CDN 方式进行拉流。 CDN 观看费用较低。如果观众端有连麦需求,连麦观众上麦后,可以从 CDN 切换到 RTC 进行观看,这样延时更低,互动效果更好。RTC 连麦需要另外开通服务。
下面是 MLVB-API-Example Demo 的演示效果。主播端(手机 A) | 连麦观众(手机 B) | 普通观众(手机 C) |
![]() | ![]() | ![]() |
主播端(手机 A) | 连麦观众(手机 B) | 普通观众(手机 C) |
![]() | ![]() | ![]() |
trtc://
协议推流,播放流也从 CDN 切到超低延迟的 trtc://
协议。V2TXLivePusher pusher = new V2TXLivePusherImpl(this, V2TXLiveMode.TXLiveMode_RTC);pushURLA= "trtc://cloud.tencent.com/push/streamid?sdkappid=1400188888&userId=A&usersig=xxx";pusher.startPush(pushURLA);
V2TXLivePusher *pusher = [[V2TXLivePusher alloc] initWithLiveMode:V2TXLiveMode_RTC];NSString *pushURLA = @"trtc://cloud.tencent.com/push/streamid?sdkappid=1400188888&userId=A&usersig=xxx";[pusher startPush:pushURLA];
V2TXLivePlayer player = new V2TXLivePlayerImpl(mContext);/*** 这里使用 CDN 拉流,支持 FLV、HLS、WebRTC 协议,任选一种协议。FLV、HLS 等标准协议价格更合理,WebRTC 快直播能够提供更低延迟的互动体验。* playURLA= "http://3891.liveplay.myqcloud.com/live/streamidA.flv";* playURLA= "http://3891.liveplay.myqcloud.com/live/streamidA.hls";* playURLA= "webrtc://3891.liveplay.myqcloud.com/live/streamidA"*/player.startPlay(playURLA);
V2TXLivePlayer * player = [[V2TXLivePlayer alloc] init];/*** 这里使用 CDN 拉流,支持 FLV、HLS、WebRTC 协议,任选一种协议。FLV、HLS 等标准协议价格更合理,WebRTC 快直播能够提供更低延迟的互动体验。* NSString *playURLA= @"http://3891.liveplay.myqcloud.com/live/streamidA.flv";* NSString *playURLA= @"http://3891.liveplay.myqcloud.com/live/streamidA.hls";* NSString *playURLA= @"webrtc://3891.liveplay.myqcloud.com/live/streamidA"*/[player setRenderView:view];[player startPlay:playURLA];
V2TXLivePusher
发起推流(后续会称呼为连麦观众 B)。V2TXLivePusher pusher = new V2TXLivePusherImpl(this,V2TXLiveMode.TXLiveMode_RTC);pushURLB= "trtc://cloud.tencent.com/push/streamid?sdkappid=1400188888&userId=B&usersig=xxx";pusher.startPush(pushURLB);
V2TXLivePusher *pusher = [[V2TXLivePusher alloc] initWithLiveMode:V2TXLiveMode_RTC];NSString *pushURLB = @"trtc://cloud.tencent.com/push/streamid?sdkappid=1400188888&userId=B&usersig=xxx";[pusher startPush:pushURLB];
V2TXLivePlayer
使用 RTC 协议拉取放连麦观众 B 的流。V2TXLivePlayer player = new V2TXLivePlayerImpl(mContext);playURLB= "trtc://cloud.tencent.com/play/streamid?sdkappid=1400188888&userId=B&usersig=xxx&appscene=live";player.startPlay(playURLB);
V2TXLivePlayer * player = [[V2TXLivePlayer alloc] init];NSString* playURLB = @"trtc://cloud.tencent.com/play/streamid?sdkappid=1400188888&userId=B&usersig=xxx&appscene=live";[player setRenderView:view];[player startPlay:playURLB];
V2TXLivePlayer
切换至 RTC 协议,开始播放主播 A 的流。V2TXLivePlayer player = new V2TXLivePlayerImpl(mContext);playURLA= "trtc://cloud.tencent.com/play/streamid?sdkappid=1400188888&userId=A&usersig=xxx&appscene=live";player.startPlay(playURLA);
V2TXLivePlayer * player = [[V2TXLivePlayer alloc] init];NSString* playURLA = @"trtc://cloud.tencent.com/play/streamid?sdkappid=1400188888&userId=A&usersig=xxx&appscene=live";[player setRenderView:view];[player startPlay:playURLA];
音频采样率 audioSampleRate
、音频码率 audioBitrate
和 声道数 audioChannels
等。
如果您的业务场景中也包含视频,需同时设置视频相关的参数,例如 视频宽度 videoWidth
、视频高度 videoHeight
、视频码率 videoBitrate
、视频帧率 videoFramerate
等。V2TXLiveDef.V2TXLiveTranscodingConfig config = new V2TXLiveDef.V2TXLiveTranscodingConfig();// 设置分辨率为 720 × 1280, 码率为 1500kbps,帧率为 20FPSconfig.videoWidth = 720;config.videoHeight = 1280;config.videoBitrate = 1500;config.videoFramerate = 20;config.videoGOP = 2;config.audioSampleRate = 48000;config.audioBitrate = 64;config.audioChannels = 2;config.mixStreams = new ArrayList<>();// 主播摄像头的画面位置V2TXLiveDef.V2TXLiveMixStream local = new V2TXLiveDef.V2TXLiveMixStream();local.userId = "localUserId";local.streamId = null; // 本地画面不用填写 streamID,远程需要local.x = 0;local.y = 0;local.width = videoWidth;local.height = videoHeight;local.zOrder = 0; // zOrder 为 0 代表主播画面位于最底层config.mixStreams.add(local);// 连麦者的画面位置V2TXLiveDef.V2TXLiveMixStream remoteA = new V2TXLiveDef.V2TXLiveMixStream();remoteA.userId = "remoteUserIdA";remoteA.streamId = "remoteStreamIdA"; // 本地画面不用填写 streamID,远程需要remoteA.x = 400; //仅供参考remoteA.y = 800; //仅供参考remoteA.width = 180; //仅供参考remoteA.height = 240; //仅供参考remoteA.zOrder = 1;config.mixStreams.add(remoteA);// 连麦者的画面位置V2TXLiveDef.V2TXLiveMixStream remoteB = new V2TXLiveDef.V2TXLiveMixStream();remoteB.userId = "remoteUserIdB";remoteB.streamId = "remoteStreamIdB"; // 本地画面不用填写 streamID,远程需要remoteB.x = 400; //仅供参考remoteB.y = 800; //仅供参考remoteB.width = 180; //仅供参考remoteB.height = 240; //仅供参考remoteB.zOrder = 1;config.mixStreams.add(remoteB);// 发起云端混流pusher.setMixTranscodingConfig(config);
V2TXLiveTranscodingConfig *config = [[V2TXLiveTranscodingConfig alloc] init];// 设置分辨率为 720 × 1280, 码率为 1500kbps,帧率为 20FPSconfig.videoWidth = 720;config.videoHeight = 1280;config.videoBitrate = 1500;config.videoFramerate = 20;config.videoGOP = 2;config.audioSampleRate = 48000;config.audioBitrate = 64;config.audioChannels = 2;// 主播摄像头的画面位置V2TXLiveMixStream *local = [[V2TXLiveMixStream alloc] init];local.userId = @"localUserId";local.streamId = nil; // 本地画面不用填写 streamID,远程需要local.x = 0;local.y = 0;local.width = videoWidth;local.height = videoHeight;local.zOrder = 0; // zOrder 为 0 代表主播画面位于最底层// 连麦者的画面位置V2TXLiveMixStream *remoteA = [[V2TXLiveMixStream alloc] init];remoteA.userId = @"remoteUserIdA";remoteA.streamId = @"remoteStreamIdA"; // 本地画面不用填写 streamID,远程需要remoteA.x = 400; //仅供参考remoteA.y = 800; //仅供参考remoteA.width = 180; //仅供参考remoteA.height = 240; //仅供参考remoteA.zOrder = 1;// 连麦者的画面位置V2TXLiveMixStream *remoteB = [[V2TXLiveMixStream alloc] init];remoteB.userId = @"remoteUserIdB";remoteB.streamId = @"remoteStreamIdB"; // 本地画面不用填写 streamID,远程需要remoteB.x = 400; //仅供参考remoteB.y = 800; //仅供参考remoteB.width = 180; //仅供参考remoteB.height = 240; //仅供参考remoteB.zOrder = 1;//设置混流 streamsconfig.mixStreams = @[local,remoteA,remoteB];// 发起云端混流pusher.setMixTranscodingConfig(config);
V2TXLivePusher&V2TXLivePlayer
接口时,同一台设备不支持使用相同 streamid 同时推流和拉流,而 TXLivePusher&TXLivePlayer
可以支持?V2TXLivePusher&V2TXLivePlayer
是 腾讯云 TRTC 协议实现,其基于 UDP 的超低延时的私有协议暂时还不支持同一台设备,使用相同的 streamid,一边推超低延时流,一边拉超低延时的流,同时考虑到用户的使用场景,所以暂时并未支持,后续会酌情考虑此问题的优化。//UserSig 计算公式,其中 secretkey 为计算 usersig 用的加密密钥usersig = hmacsha256(secretkey, (userid + sdkappid + currtime + expire +base64(userid + sdkappid + currtime + expire)))
-5
,代表什么意思?
本页内容是否解决了您的问题?