前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >腾讯云实时音视频服务端混流参数详解和4种排版方式

腾讯云实时音视频服务端混流参数详解和4种排版方式

原创
作者头像
singleli
发布2022-11-28 00:14:58
1.4K0
发布2022-11-28 00:14:58
举报
文章被收录于专栏:腾讯云终端专家服务

一、服务端四种混流模板 1、悬浮模板(LayoutParams.Template = 0):

第一个进入房间的用户的视频画面会铺满整个屏幕,其他用户的视频画面从左下角依次水平排列,显示为小画面。 最多4行,每行最多4个,小画面悬浮于大画面之上。 最多支持1个大画面和15个小画面。 如果用户只发送音频,仍然会占用画面位置。

代码如下:

代码语言:javascript
复制
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.trtc.v20190722.TrtcClient;
import com.tencentcloudapi.trtc.v20190722.models.*;;
public class StartMCUMixTranscode
{
    public static void main(String [] args) {
        try{
            Credential cred = new Credential("SecretId", "SecretKey");
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("trtc.tencentcloudapi.com");
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);
            TrtcClient client = new TrtcClient(cred, "ap-guangzhou", clientProfile);
            StartMCUMixTranscodeRequest req = new StartMCUMixTranscodeRequest();
            req.setSdkAppId(1400505488L);
            req.setRoomId(661L);
            OutputParams outputParams1 = new OutputParams();
            outputParams1.setStreamId("crk661");
            outputParams1.setPureAudioStream(0L);
            outputParams1.setRecordId("crk");
            outputParams1.setRecordAudioOnly(0L);
            req.setOutputParams(outputParams1);
            EncodeParams encodeParams1 = new EncodeParams();
            encodeParams1.setVideoWidth(720L);
            encodeParams1.setVideoHeight(1280L);
            encodeParams1.setVideoBitrate(1500L);
            encodeParams1.setVideoFramerate(20L);
            encodeParams1.setVideoGop(3L);
            encodeParams1.setBackgroundColor(3394560L);
            encodeParams1.setAudioSampleRate(48000L);
            encodeParams1.setAudioBitrate(64L);
            encodeParams1.setAudioChannels(2L);
            encodeParams1.setAudioCodec(0L);
            req.setEncodeParams(encodeParams1);
            LayoutParams layoutParams1 = new LayoutParams();
            layoutParams1.setTemplate(0L);
            layoutParams1.setMainVideoUserId("666");
            layoutParams1.setMainVideoStreamType(0L);
            SmallVideoLayoutParams smallVideoLayoutParams1 = new SmallVideoLayoutParams();
            smallVideoLayoutParams1.setUserId("555");
            smallVideoLayoutParams1.setStreamType(0L);
            smallVideoLayoutParams1.setImageWidth(350L);
            smallVideoLayoutParams1.setImageHeight(350L);
            smallVideoLayoutParams1.setLocationX(370L);
            smallVideoLayoutParams1.setLocationY(930L);
            layoutParams1.setSmallVideoLayoutParams(smallVideoLayoutParams1);
            layoutParams1.setMainVideoRightAlign(0L);
            String[] mixVideoUids1 = {"111", "222", "333", "444"};
            layoutParams1.setMixVideoUids(mixVideoUids1);
            req.setLayoutParams(layoutParams1);
            PublishCdnParams publishCdnParams1 = new PublishCdnParams();
            publishCdnParams1.setBizId(9926L);
            String[] publishCdnUrls1 = {"http://cctv.com"};
            publishCdnParams1.setPublishCdnUrls(publishCdnUrls1);
            req.setPublishCdnParams(publishCdnParams1);
            StartMCUMixTranscodeResponse resp = client.StartMCUMixTranscode(req);
            System.out.println(StartMCUMixTranscodeResponse.toJsonString(resp));
        } catch (TencentCloudSDKException e) {
                System.out.println(e.toString());
        }
    }
}

2、九宫格模板(LayoutParams.Template = 1):

所有用户的视频画面大小一致,平分整个屏幕,人数越多,每个画面的尺寸越小。 最多支持16个画面,如果用户只发送音频,仍然会占用画面位置。

代码如下:

代码语言:javascript
复制
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.trtc.v20190722.TrtcClient;
import com.tencentcloudapi.trtc.v20190722.models.*;;
public class StartMCUMixTranscode
{
    public static void main(String [] args) {
        try{
            Credential cred = new Credential("SecretId", "SecretKey");
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("trtc.tencentcloudapi.com");
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);
            TrtcClient client = new TrtcClient(cred, "ap-guangzhou", clientProfile);
            StartMCUMixTranscodeRequest req = new StartMCUMixTranscodeRequest();
            req.setSdkAppId(1400505488L);
            req.setRoomId(661L);
            OutputParams outputParams1 = new OutputParams();
            outputParams1.setStreamId("crk661");
            outputParams1.setPureAudioStream(0L);
            outputParams1.setRecordId("crk");
            outputParams1.setRecordAudioOnly(0L);
            req.setOutputParams(outputParams1);
            EncodeParams encodeParams1 = new EncodeParams();
            encodeParams1.setVideoWidth(720L);
            encodeParams1.setVideoHeight(1280L);
            encodeParams1.setVideoBitrate(1500L);
            encodeParams1.setVideoFramerate(20L);
            encodeParams1.setVideoGop(3L);
            encodeParams1.setBackgroundColor(3394560L);
            encodeParams1.setAudioSampleRate(48000L);
            encodeParams1.setAudioBitrate(64L);
            encodeParams1.setAudioChannels(2L);
            encodeParams1.setAudioCodec(0L);
            req.setEncodeParams(encodeParams1);
            LayoutParams layoutParams1 = new LayoutParams();
            layoutParams1.setTemplate(1L);
            layoutParams1.setMainVideoUserId("666");
            layoutParams1.setMainVideoStreamType(0L);
            SmallVideoLayoutParams smallVideoLayoutParams1 = new SmallVideoLayoutParams();
            smallVideoLayoutParams1.setUserId("555");
            smallVideoLayoutParams1.setStreamType(0L);
            smallVideoLayoutParams1.setImageWidth(350L);
            smallVideoLayoutParams1.setImageHeight(350L);
            smallVideoLayoutParams1.setLocationX(370L);
            smallVideoLayoutParams1.setLocationY(930L);
            layoutParams1.setSmallVideoLayoutParams(smallVideoLayoutParams1);
            layoutParams1.setMainVideoRightAlign(0L);
            String[] mixVideoUids1 = {"111", "222", "333", "444"};
            layoutParams1.setMixVideoUids(mixVideoUids1);
            layoutParams1.setPureAudioHoldPlaceMode(0L);
            req.setLayoutParams(layoutParams1);
            PublishCdnParams publishCdnParams1 = new PublishCdnParams();
            publishCdnParams1.setBizId(9926L);
            String[] publishCdnUrls1 = {"http://cctv.com"};
            publishCdnParams1.setPublishCdnUrls(publishCdnUrls1);
            req.setPublishCdnParams(publishCdnParams1);
            StartMCUMixTranscodeResponse resp = client.StartMCUMixTranscode(req);
            System.out.println(StartMCUMixTranscodeResponse.toJsonString(resp));
        } catch (TencentCloudSDKException e) {
                System.out.println(e.toString());
        }
    }
}

3、屏幕分享模板(LayoutParams.Template = 2)

适合视频会议和在线教育场景的布局。 屏幕分享(或者主讲的摄像头)始终占据屏幕左侧的大画面位置,其他用户依次垂直排列于右侧。 需要通过 LayoutParams.MainVideoUserId 和 LayoutParams.MainVideoStreamType 这两个参数来指定左侧主画面的内容。 最多两列,每列最多8个小画面。最多支持1个大画面和15个小画面。 如果用户只发送音频,仍然会占用画面位置。

代码如下:

代码语言:javascript
复制
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.trtc.v20190722.TrtcClient;
import com.tencentcloudapi.trtc.v20190722.models.*;;
public class StartMCUMixTranscode
{
    public static void main(String [] args) {
        try{
            Credential cred = new Credential("SecretId", "SecretKey");
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("trtc.tencentcloudapi.com");
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);
            TrtcClient client = new TrtcClient(cred, "ap-guangzhou", clientProfile);
            StartMCUMixTranscodeRequest req = new StartMCUMixTranscodeRequest();
            req.setSdkAppId(1400505488L);
            req.setRoomId(661L);
            OutputParams outputParams1 = new OutputParams();
            outputParams1.setStreamId("crk661");
            outputParams1.setPureAudioStream(0L);
            outputParams1.setRecordId("crk");
            outputParams1.setRecordAudioOnly(0L);
            req.setOutputParams(outputParams1);
            EncodeParams encodeParams1 = new EncodeParams();
            encodeParams1.setVideoWidth(720L);
            encodeParams1.setVideoHeight(1280L);
            encodeParams1.setVideoBitrate(1500L);
            encodeParams1.setVideoFramerate(20L);
            encodeParams1.setVideoGop(3L);
            encodeParams1.setBackgroundColor(3394560L);
            encodeParams1.setAudioSampleRate(48000L);
            encodeParams1.setAudioBitrate(64L);
            encodeParams1.setAudioChannels(2L);
            encodeParams1.setAudioCodec(0L);
            req.setEncodeParams(encodeParams1);
            LayoutParams layoutParams1 = new LayoutParams();
            layoutParams1.setTemplate(2L);
            layoutParams1.setMainVideoUserId("666");
            layoutParams1.setMainVideoStreamType(0L);
            SmallVideoLayoutParams smallVideoLayoutParams1 = new SmallVideoLayoutParams();
            smallVideoLayoutParams1.setUserId("555");
            smallVideoLayoutParams1.setStreamType(0L);
            smallVideoLayoutParams1.setImageWidth(350L);
            smallVideoLayoutParams1.setImageHeight(350L);
            smallVideoLayoutParams1.setLocationX(370L);
            smallVideoLayoutParams1.setLocationY(930L);
            layoutParams1.setSmallVideoLayoutParams(smallVideoLayoutParams1);
            layoutParams1.setMainVideoRightAlign(0L);
            String[] mixVideoUids1 = {"111", "222", "333", "444"};
            layoutParams1.setMixVideoUids(mixVideoUids1);
            layoutParams1.setPureAudioHoldPlaceMode(0L);
            req.setLayoutParams(layoutParams1);
            PublishCdnParams publishCdnParams1 = new PublishCdnParams();
            publishCdnParams1.setBizId(9926L);
            String[] publishCdnUrls1 = {"http://cctv.com"};
            publishCdnParams1.setPublishCdnUrls(publishCdnUrls1);
            req.setPublishCdnParams(publishCdnParams1);
            StartMCUMixTranscodeResponse resp = client.StartMCUMixTranscode(req);
            System.out.println(StartMCUMixTranscodeResponse.toJsonString(resp));
        } catch (TencentCloudSDKException e) {
                System.out.println(e.toString());
        }
    }
}

4、画中画模板(LayoutParams.Template = 3):

该模板以“一大一小,一前一后”的模式混合房间中的两路画面,即将房间中一路画面铺满整个屏幕,再将一路画面作为小画面悬浮在大画面之上,小画面的位置可以通过参数指定。 您可以通过 LayoutParams 中的 MainVideoUserId 和 MainVideoStreamType 参数指定大画面这一路的用户 ID 和流类型。 您可以通过 LayoutParams 中的 SmallVideoLayoutParams 参数指定小画面这一路的用户 ID、流类型和布局位置等信息。 场景示例1:在线教育场景中,混合老师端摄像头(通常作为小画面)和老师端屏幕(通常作为大画面)两路画面,并混合课堂中学生的声音。 场景示例2:1v1 视频通话场景中,混合远端用户画面(通常作为大画面)和本地用户画面(通常作为小画面)。

代码如下:

代码语言:javascript
复制
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.trtc.v20190722.TrtcClient;
import com.tencentcloudapi.trtc.v20190722.models.*;;
public class StartMCUMixTranscode
{
    public static void main(String [] args) {
        try{
            Credential cred = new Credential("SecretId", "SecretKey");
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("trtc.tencentcloudapi.com");
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);
            TrtcClient client = new TrtcClient(cred, "ap-guangzhou", clientProfile);
            StartMCUMixTranscodeRequest req = new StartMCUMixTranscodeRequest();
            req.setSdkAppId(1400505488L);
            req.setRoomId(661L);
            OutputParams outputParams1 = new OutputParams();
            outputParams1.setStreamId("crk661");
            outputParams1.setPureAudioStream(0L);
            outputParams1.setRecordId("crk");
            outputParams1.setRecordAudioOnly(0L);
            req.setOutputParams(outputParams1);
            EncodeParams encodeParams1 = new EncodeParams();
            encodeParams1.setVideoWidth(720L);
            encodeParams1.setVideoHeight(1280L);
            encodeParams1.setVideoBitrate(1500L);
            encodeParams1.setVideoFramerate(20L);
            encodeParams1.setVideoGop(3L);
            encodeParams1.setBackgroundColor(3394560L);
            encodeParams1.setAudioSampleRate(48000L);
            encodeParams1.setAudioBitrate(64L);
            encodeParams1.setAudioChannels(2L);
            encodeParams1.setAudioCodec(0L);
            req.setEncodeParams(encodeParams1);
            LayoutParams layoutParams1 = new LayoutParams();
            layoutParams1.setTemplate(3L);
            layoutParams1.setMainVideoUserId("666");
            layoutParams1.setMainVideoStreamType(0L);
            SmallVideoLayoutParams smallVideoLayoutParams1 = new SmallVideoLayoutParams();
            smallVideoLayoutParams1.setUserId("555");
            smallVideoLayoutParams1.setStreamType(0L);
            smallVideoLayoutParams1.setImageWidth(350L);
            smallVideoLayoutParams1.setImageHeight(350L);
            smallVideoLayoutParams1.setLocationX(370L);
            smallVideoLayoutParams1.setLocationY(930L);
            layoutParams1.setSmallVideoLayoutParams(smallVideoLayoutParams1);
            layoutParams1.setMainVideoRightAlign(0L);
            String[] mixVideoUids1 = {"111", "222", "333", "444"};
            layoutParams1.setMixVideoUids(mixVideoUids1);
            layoutParams1.setPureAudioHoldPlaceMode(0L);
            req.setLayoutParams(layoutParams1);
            PublishCdnParams publishCdnParams1 = new PublishCdnParams();
            publishCdnParams1.setBizId(9926L);
            String[] publishCdnUrls1 = {"http://cctv.com"};
            publishCdnParams1.setPublishCdnUrls(publishCdnUrls1);
            req.setPublishCdnParams(publishCdnParams1);
            StartMCUMixTranscodeResponse resp = client.StartMCUMixTranscode(req);
            System.out.println(StartMCUMixTranscodeResponse.toJsonString(resp));
        } catch (TencentCloudSDKException e) {
                System.out.println(e.toString());
        }
    }
}

5、自定义模板(LayoutParams.Template = 4):

适用于需要自定义排布各路画面位置的场景,您可以通过 LayoutParams 中的 PresetLayoutConfig 参数(这是一个数组),预先设置各路画面的位置。 您可以不指定 PresetLayoutConfig 参数中的 UserId 参数,排版引擎会根据进房的先后顺序,将进房的用户依次分配到 PresetLayoutConfig 数组中指定的各个位置上。 如果 PresetLayoutConfig 数组中的某一个被指定了 UserId 参数,则排版引擎会预先给指定的用户预留好他/她在画面中的位置。 如果用户只上行音频,不上行视频,该用户依然会占用画面位置。 当 PresetLayoutConfig 数组中预设的位置被用完后,排版引擎将不再混合其它用户的画面和声音。

注意: 云端混流服务最多支持同时混合16路音视频流,如果用户只有音频也会被算作一路。

代码如下:

代码语言:javascript
复制
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.trtc.v20190722.TrtcClient;
import com.tencentcloudapi.trtc.v20190722.models.*;;
public class StartMCUMixTranscode
{
    public static void main(String [] args) {
        try{
            Credential cred = new Credential("SecretId", "SecretKey");
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("trtc.tencentcloudapi.com");
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);
            TrtcClient client = new TrtcClient(cred, "ap-guangzhou", clientProfile);
            StartMCUMixTranscodeRequest req = new StartMCUMixTranscodeRequest();
            req.setSdkAppId(1400505488L);
            req.setRoomId(661L);
            OutputParams outputParams1 = new OutputParams();
            outputParams1.setStreamId("crk661");
            outputParams1.setPureAudioStream(0L);
            outputParams1.setRecordId("crk");
            outputParams1.setRecordAudioOnly(0L);
            req.setOutputParams(outputParams1);
            EncodeParams encodeParams1 = new EncodeParams();
            encodeParams1.setVideoWidth(720L);
            encodeParams1.setVideoHeight(1280L);
            encodeParams1.setVideoBitrate(1500L);
            encodeParams1.setVideoFramerate(20L);
            encodeParams1.setVideoGop(3L);
            encodeParams1.setBackgroundColor(3394560L);
            encodeParams1.setAudioSampleRate(48000L);
            encodeParams1.setAudioBitrate(64L);
            encodeParams1.setAudioChannels(2L);
            encodeParams1.setAudioCodec(0L);
            req.setEncodeParams(encodeParams1);
            LayoutParams layoutParams1 = new LayoutParams();
            layoutParams1.setTemplate(3L);
            layoutParams1.setMainVideoUserId("666");
            layoutParams1.setMainVideoStreamType(0L);
            SmallVideoLayoutParams smallVideoLayoutParams1 = new SmallVideoLayoutParams();
            smallVideoLayoutParams1.setUserId("555");
            smallVideoLayoutParams1.setStreamType(0L);
            smallVideoLayoutParams1.setImageWidth(350L);
            smallVideoLayoutParams1.setImageHeight(350L);
            smallVideoLayoutParams1.setLocationX(370L);
            smallVideoLayoutParams1.setLocationY(930L);
            layoutParams1.setSmallVideoLayoutParams(smallVideoLayoutParams1);
            layoutParams1.setMainVideoRightAlign(0L);
            String[] mixVideoUids1 = {"111", "222", "333", "444"};
            layoutParams1.setMixVideoUids(mixVideoUids1);
            PresetLayoutConfig[] presetLayoutConfigs1 = new PresetLayoutConfig[2];
            PresetLayoutConfig presetLayoutConfig1 = new PresetLayoutConfig();
            presetLayoutConfig1.setUserId("224");
            presetLayoutConfig1.setStreamType(0L);
            presetLayoutConfig1.setImageWidth(350L);
            presetLayoutConfig1.setImageHeight(350L);
            presetLayoutConfig1.setLocationX(370L);
            presetLayoutConfig1.setLocationY(930L);
            presetLayoutConfig1.setZOrder(0L);
            presetLayoutConfig1.setRenderMode(0L);
            presetLayoutConfig1.setMixInputType(0L);
            presetLayoutConfigs1[0] = presetLayoutConfig1;
            PresetLayoutConfig presetLayoutConfig2 = new PresetLayoutConfig();
            presetLayoutConfig2.setUserId("225");
            presetLayoutConfig2.setStreamType(0L);
            presetLayoutConfig2.setImageWidth(350L);
            presetLayoutConfig2.setImageHeight(350L);
            presetLayoutConfig2.setLocationX(370L);
            presetLayoutConfig2.setLocationY(580L);
            presetLayoutConfig2.setZOrder(1L);
            presetLayoutConfig2.setRenderMode(0L);
            presetLayoutConfigs1[1] = presetLayoutConfig2;
            layoutParams1.setPresetLayoutConfig(presetLayoutConfigs1);
            layoutParams1.setPlaceHolderMode(0L);
            layoutParams1.setPureAudioHoldPlaceMode(0L);
            req.setLayoutParams(layoutParams1);
            PublishCdnParams publishCdnParams1 = new PublishCdnParams();
            publishCdnParams1.setBizId(9926L);
            String[] publishCdnUrls1 = {"http://cctv.com"};
            publishCdnParams1.setPublishCdnUrls(publishCdnUrls1);
            req.setPublishCdnParams(publishCdnParams1);
            StartMCUMixTranscodeResponse resp = client.StartMCUMixTranscode(req);
            System.out.println(StartMCUMixTranscodeResponse.toJsonString(resp));
        } catch (TencentCloudSDKException e) {
                System.out.println(e.toString());
        }
    }
}

二、混流参数详解:

1、首先先配置TRTC的SDKAppId和房间号RoomId

2、在调用REST API StartMCUMixTranscode时,先手要设置一下LayoutParams参数(混流输出布局参数)。

LayoutParams.Template的值分别是:0(悬浮模板)、1(九宫格模板)、2(屏幕分享模板)、3(画中画模板)、4(自定义模板)

3、混流编码参数混流编码参数:EncodeParams

4、混流输出控制参数:OutputParams

MCU混流的输出参数

5、第三方CDN转推参数:PublishCdnParams

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
内容分发网络 CDN
内容分发网络(Content Delivery Network,CDN)通过将站点内容发布至遍布全球的海量加速节点,使其用户可就近获取所需内容,避免因网络拥堵、跨运营商、跨地域、跨境等因素带来的网络不稳定、访问延迟高等问题,有效提升下载速度、降低响应时间,提供流畅的用户体验。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档