音视频通话

本地直播推流

功能介绍

用于1个或多个主播实时连麦互动,然后图像和声音将在SDK本地进行混合,然后直接向CDN流媒体服务器推流,直播观众就可以获取RTMP或HLS流观看直播了。

1.创建混图器

  • 左右布局示例图

左右布局示例图

  • 接口调用:
//混图器参数配置
const mixerCfg = {
	dstResolution: {
		width: 1280,
		height: 720
	},
	frameRate: 15,
	bitRate: 1000000,
	defaultQP: 26,
	gop: 15,
}

const mixerContents = [{
	//自己的视频
	type: 0,
	top: 0,
	left: 0,
	width: 640,
	height: 720,
	userId: "myUserId",
	camId: -1,
}, {
	//对端成员的视频
	type: 0,
	top: 0,
	left: 640,
	width: 640,
	height: 720,
	userId: "remoteUserId",
	camId: -1
}]

// 创建混图器, 设置混图器编号为1
const sdkErr = RTCSDK.createLocMixer("1", mixerCfg, mixerContents);
if(sdkErr === 0){
    //创建成功
}

相关API请参考:

相关结构定义请参考:

2.添加直播推流

  • 接口调用:
//推流到A,B两个直播平台
const MixerOutPutCfgs = [];
MixerOutPutCfgs.push({
	type: 1,
	liveUrl: "rtmp://A/xxx"
});

MixerOutPutCfgs.push({
	type: 1,
	liveUrl: "rtmp://B/xxx"
});
const errCode = RTCSDK.addLocMixerOutput("1", MixerOutPutCfgs)


if (errCode === 0) {
    //启动成功
}

相关API请参考:

相关结构定义请参考:

3.直播推流回调处理

RTCSDK.on("locMixerOutputInfo", ({ mixerID, nameOrUrl, outputInfo }) => {
	if ( outputInfo.state === 3 ){
        //推流出错,errCode中有错误原因
    }
})

相关API请参考:

4. 更新直播内容

  • 画中画布局示例图

画中画布局示例图

  • 接口调用:
// 录制参数列表中,越靠后的元素会覆盖之前的元素
const mixerContents = [{
	//对端的视频
	type: 0,
	top: 0,
	left: 0,
	width: 1280,
	height: 720,
	userId: "remoteUserId",
	camId: -1,
}, {
	//自己的视频(小窗口)
	type: 0,
	top: 1280 - 256,
	left: 720 - 144,
	width: 256,
	height: 144,
	userId: "myUserId",
	camId: -1
}]

// 创建混图器, 设置混图器编号为1
const sdkErr = RTCSDK.updateLocMixerContent("1", mixerContents);
if (sdkErr == 0) {
    //更新配置成功
}

相关API请参考:

5.结束

//混图器编号
const mixerID = "1";

//销毁混图器, 输出自动结束
RTCSDK.destroyLocMixer(mixerID);

相关API请参考: