开发指南

本文介绍了使用导播API服务的操作步骤及说明。

特别说明

  • 请您区分导播服务与云导播台,导播服务仅提供API服务,您需要自行开发完成前端页面与交互部分,本文适用于导播服务。

  • 云导播台用户请忽略该文档,视频直播控制台提供了导播台产品,可直接使用前端页面进行导播操作。具体操作请参见云导播快速入门

阅读对象

  • 具备Java或者PHP开发能力,具体请参见Java SDK使用说明

  • 了解导播产品的基本功能

  • 了解视频直播的基本功能

前提条件

导播操作步骤

  1. 配置导播台

    步骤说明

    导播台实例创建完成后,根据使用需求完成导播台名称、域名、转码、录制、延播、备播素材等配置。

    接口说明

    名称

    描述

    SetCasterConfig

    设置导播台配置信息

    domainName

    将客户提供的域名绑定至导播台实例

    casterTemplate

    配置导播台输出分辨率

    liveTemplate

    配置导播台直播转码参数

    recordConfig

    配置导播台直播录制参数

    示例代码

    AddCasterVideoResourceRequest addCasterVideoResourceRequest = new AddCasterVideoResourceRequest();
    addCasterVideoResourceRequest.setCasterId("LIVEPRODUCER_POST-cn-0pp123h****");
    addCasterVideoResourceRequest.setResourceName("LIVEPRODUCER_POST-cn-0pp123h****");
    addCasterVideoResourceRequest.setLocationId("RV01" ); // RV01~RV06为视频源在预监窗口的位置ID,不可重复,布局通过该ID引用视频源
    addCasterVideoResourceRequest.setLiveStreamUrl( null); // 采用点播素材时不输入
    addCasterVideoResourceRequest.setMaterialId("LIVEPRODUCER_POST-cn-0pp123h****");
    addCasterVideoResourceRequest.setRepeatNum( -1); // 视频播放完毕后循环播放
    AddCasterVideoResourceResponse response = client.getAcsResponse(addCasterVideoResourceRequest);
    
    // 修改视频源(AddCasterVideo)
    ModifyCasterVideoResourceRequest modifyCasterVideoResourceRequest = new ModifyCasterVideoResourceRequest();
    modifyCasterVideoResourceRequest.setCasterId("LIVEPRODUCER_POST-cn-0pp123h****");
    modifyCasterVideoResourceRequest.setResourceId("LIVEPRODUCER_POST-cn-0pp123h****");
    modifyCasterVideoResourceRequest.setLiveStreamUrl(“rtmp://192.168.1.1“);
    modifyCasterVideoResourceRequest.setResourceName("LIVEPRODUCER_POST-cn-0pp123h****");
    ModifyCasterVideoResourceResponse response = client.getAcsResponse(modifyCasterVideoResourceRequest);
    
    // 查询视频源列表(DescribeCasterVideo)
    DescribeCasterVideoResourcesRequest describeCasterVideoResourcesRequest = new DescribeCasterVideoResourcesRequest();
    describeCasterVideoResourcesRequest.setCasterId("LIVEPRODUCER_POST-cn-0pp123h****");
    DescribeCasterVideoResourcesResponse response = client.getAcsResponse(describeCasterVideoResourcesRequest);
    
    // 删除视频源列表(DescribeCasterVideo)
    DeleteCasterVideoResourceRequest deleteCasterVideoResourceRequest = new DeleteCasterVideoResourceRequest();
    deleteCasterVideoResourceRequest.setCasterId("LIVEPRODUCER_POST-cn-0pp123h****");
    deleteCasterVideoResourceRequest.setResourceId("LIVEPRODUCER_POST-cn-0pp123h****");
    DeleteCasterVideoResourceResponse response = client.getAcsResponse(deleteCasterVideoResourceRequest);
  2. 编辑视频源

    步骤说明

    配置用于输出的视频源信息,目前支持直播流及点播素材两种类型。

    接口说明

    名称

    描述

    AddCasterVideo

    新增视频源

    ModifyCasterVideoResource

    修改视频源

    DescribeCasterVideoResources

    查询视频源列表

    DeleteCasterVideoResource

    删除视频源

    liveStreamUrl

    视频源类型为直播流时需提供直播流地址

    materialId

    视频源类型为点播素材时需提供点播素材ID,以及循环播放次数(repeatNum)

    locationId

    配置视频源名称及视频源位置,作为布局画面的引用编号

    示例代码

     // 新增视频源(AddCasterVideo)
    AddCasterVideoResourceRequest addCasterVideoResourceRequest = new AddCasterVideoResourceRequest();
    addCasterVideoResourceRequest.setCasterId("LIVEPRODUCER_POST-cn-0pp123h****");
    addCasterVideoResourceRequest.setResourceName("LIVEPRODUCER_POST-cn-0pp123h****");
    addCasterVideoResourceRequest.setLocationId("RV01" ); // RV01~RV06为视频源在预监窗口的位置ID,不可重复,布局通过该ID引用视频源
    addCasterVideoResourceRequest.setLiveStreamUrl( null); // 采用点播素材时不输入
    addCasterVideoResourceRequest.setMaterialId("LIVEPRODUCER_POST-cn-0pp123h****");
    addCasterVideoResourceRequest.setRepeatNum( -1); // 视频播放完毕后循环播放
    AddCasterVideoResourceResponse response = client.getAcsResponse(addCasterVideoResourceRequest);
    
    // 修改视频源(AddCasterVideo)
    ModifyCasterVideoResourceRequest modifyCasterVideoResourceRequest = new ModifyCasterVideoResourceRequest();
    modifyCasterVideoResourceRequest.setCasterId("LIVEPRODUCER_POST-cn-0pp123h****");
    modifyCasterVideoResourceRequest.setResourceId("LIVEPRODUCER_POST-cn-0pp123h****");
    modifyCasterVideoResourceRequest.setLiveStreamUrl(“rtmp://192.168.1.1“);
    modifyCasterVideoResourceRequest.setResourceName("LIVEPRODUCER_POST-cn-0pp123h****");
    ModifyCasterVideoResourceResponse response = client.getAcsResponse(modifyCasterVideoResourceRequest);
    
    // 查询视频源列表(DescribeCasterVideo)
    DescribeCasterVideoResourcesRequest describeCasterVideoResourcesRequest = new DescribeCasterVideoResourcesRequest();
    describeCasterVideoResourcesRequest.setCasterId("LIVEPRODUCER_POST-cn-0pp123h****");
    DescribeCasterVideoResourcesResponse response = client.getAcsResponse(describeCasterVideoResourcesRequest);
    
    // 删除视频源列表(DescribeCasterVideo)
    DeleteCasterVideoResourceRequest deleteCasterVideoResourceRequest = new DeleteCasterVideoResourceRequest();
    deleteCasterVideoResourceRequest.setCasterId("LIVEPRODUCER_POST-cn-0pp123h****");
    deleteCasterVideoResourceRequest.setResourceId("LIVEPRODUCER_POST-cn-0pp123h****");
    DeleteCasterVideoResourceResponse response = client.getAcsResponse(deleteCasterVideoResourceRequest);                        
  3. 编辑组件

    步骤说明

    配置用于输出的组件信息,目前支持文字及图片两种类型。

    接口说明

    名称

    描述

    AddCasterComponent

    新增组件

    ModifyCasterComponent

    修改组件

    DescribeCasterComponents

    查询组件列表

    DeleteCasterComponent

    删除组件

    说明

    配置组件内容:

    • 文字组件需提供文字内容、字体比例、颜色等。

    • 图片组件需提供图片素材ID。

    示例代码

    // 新增组件(AddCasterComponent)
    JSONObject componentLayer = new JSONObject();
    componentLayer.put("HeightNormalized", 0.2);
    componentLayer.put("WidthNormalized", 0.2);
    JSONArray positionNormalized = new JSONArray();
    positionNormalized.add("0.3");
    positionNormalized.add("0.3");
    componentLayer.put("PositionNormalized", positionNormalized);
    componentLayer.put("PositionRefer", "topLeft");
    JSONObject textLayerContent = new JSONObject(); // 组件TextLayerContent
    textLayerContent.put("Text", text);
    textLayerContent.put("Color", 0xff0000);
    textLayerContent.put("FontName", "KaiTi");
    textLayerContent.put("SizeNormalized", 0.3F);
    textLayerContent.put("BorderWidthNormalized", 0.3F);
    textLayerContent.put("BorderColor", 0xff0000);
    AddCasterComponentRequest addCasterComponntRequest = new AddCasterComponentRequest(); // 设置组件元素属性
    addCasterComponntRequest.setCasterId(casterId);
    addCasterComponntRequest.setLocationId(locationId);
    addCasterComponntRequest.setComponentName(componentName);
    addCasterComponntRequest.setComponentType("text");
    addCasterComponntRequest.setEffect(effect);
    addCasterComponntRequest.setComponentLayer(componentLayer.toJSONString());
    addCasterComponntRequest.setTextLayerContent(textLayerContent.toJSONString());
    AddCasterComponentResponse response = client.getAcsResponse(addCasterComponntRequest);
    
    // 修改组件(ModifyCasterComponent)
    JSONObject componentLayer = new JSONObject();
    componentLayer.put("HeightNormalized", 0.6);
    componentLayer.put("WidthNormalized", 0.6);
    JSONArray positionNormalized = new JSONArray();
    positionNormalized.add("0.3");
    positionNormalized.add("0.3");
    componentLayer.put("PositionNormalized", positionNormalized);
    componentLayer.put("PositionRefer", "topLeft");
    JSONObject textLayerContent = new JSONObject();// 组件TextLayerContent
    textLayerContent.put("Text", text);
    textLayerContent.put("Color", 0xff0000);
    textLayerContent.put("FontName", "KaiTi");
    textLayerContent.put("SizeNormalized", 0.3F);
    textLayerContent.put("BorderWidthNormalized", 0.3F);
    textLayerContent.put("BorderColor", 0xff0000);
    ModifyCasterComponentRequest modifyCasterComponentRequest = new ModifyCasterComponentRequest(); // 设置组件元素属性
    modifyCasterComponentRequest.setCasterId("LIVEPRODUCER_POST-cn-0pp123h****");
    modifyCasterComponentRequest.setComponentId("LIVEPRODUCER_POST-cn-0pp123h****");
    modifyCasterComponentRequest.setComponentName("LIVEPRODUCER_POST-cn-0pp123h****");
    modifyCasterComponentRequest.setComponentType("text"); // 文本类型
    modifyCasterComponentRequest.setEffect("none"); // 无特效
    modifyCasterComponentRequest.setComponentLayer(componentLayer.toJSONString());
    modifyCasterComponentRequest.setTextLayerContent(textLayerContent.toJSONString());
    ModifyCasterComponentResponse response = client.getAcsResponse(modifyCasterComponentRequest);
    
    // 查询组件列表(DescribeCasterComponents)
    DescribeCasterComponentsRequest describeCasterComponentsRequest= new DescribeCasterComponentsRequest();
    describeCasterComponentsRequest.setCasterId("LIVEPRODUCER_POST-cn-0pp123h****");
    DescribeCasterComponentsResponse response = iAcsClient.getAcsResponse(describeCasterComponentsRequest);
    
    // 删除组件列表(DescribeCasterComponent)
    DeleteCasterComponentRequest deleteCasterComponentRequest = new DeleteCasterComponentRequest();
    deleteCasterComponentRequest.setCasterId("LIVEPRODUCER_POST-cn-0pp123h****");
    deleteCasterComponentRequest.setComponentId("LIVEPRODUCER_POST-cn-0pp123h****");
    DeleteCasterComponentResponse response = client.getAcsResponse(deleteCasterComponentRequest);                        
  4. 编辑布局

    步骤说明

    配置用于导播输出的画面布局,用户可自定义画面及位置,目前支持最多四个画面。

    接口说明

    名称

    描述

    AddCasterLayout

    新增布局

    ModifyCasterLayout

    修改布局

    DescribeCasterLayouts

    查询布局列表

    DeleteCasterLayout

    删除视频源

    videoLayer

    配置布局样式信息列表

    audioLayer

    配置音频信息列表

    blendList

    配置视频源位置列表

    mixList

    音频位置列表

    示例代码

    JSONObject componentLayer = new JSONObject();
    componentLayer.put("HeightNormalized", 0.6);
    componentLayer.put("WidthNormalized", 0.6);
    JSONArray positionNormalized = new JSONArray();
    positionNormalized.add("0.3");
    positionNormalized.add("0.3");
    componentLayer.put("PositionNormalized", positionNormalized);
    componentLayer.put("PositionRefer", "topLeft");
    JSONObject imageLayerContent = new JSONObject(); // 组件ImageLayerContent
    imageLayerContent.put("MaterialId", "materailId");
    AddCasterComponentRequest addCasterComponntRequest = new AddCasterComponentRequest(); // 设置组件元素属性
    addCasterComponntRequest.setCasterId("LIVEPRODUCER_POST-cn-0pp123h****");
    addCasterComponntRequest.setLocationId("RC01"); // 与组件关联的LocationId
    addCasterComponntRequest.setComponentName("LIVEPRODUCER_POST-cn-0pp123h****");
    addCasterComponntRequest.setComponentType("image"); // 图片类型
    addCasterComponntRequest.setEffect("none"); // 无特效
    addCasterComponntRequest.setComponentLayer(componentLayer.toJSONString());
    addCasterComponntRequest.setImageLayerContent(imageLayerContent.toJSONString());
    AddCasterComponentResponse response = client.getAcsResponse(addCasterComponntRequest);
    
    // 修改布局(ModifyCasterLayout)
    ModifyCasterLayoutRequest modifyCasterLayoutRequest = new ModifyCasterLayoutRequest();
    modifyCasterLayoutRequest.setCasterId("LIVEPRODUCER_POST-cn-0pp123h****");
    modifyCasterLayoutRequest.setLayoutId("LIVEPRODUCER_POST-cn-0pp123h****");
    List videoLayersList = new ArrayList(); // 视频layer
    ModifyCasterLayoutRequest.VideoLayer videoLayer1 = new ModifyCasterLayoutRequest.VideoLayer();
    videoLayer1.setHeightNormalized(0.5F);
    videoLayer1.setWidthNormalized(0.5F);
    videoLayer1.setPositionRefer("topLeft");
    videoLayer1.setPositionNormalizeds(Arrays.asList(new Float[]{0F, 0F}));
    videoLayersList.add(videoLayer1);
    ModifyCasterLayoutRequest.VideoLayer videoLayer2 = new ModifyCasterLayoutRequest.VideoLayer();
    videoLayer2.setHeightNormalized(0.5F);
    videoLayer2.setWidthNormalized(0.5F);
    videoLayer2.setPositionRefer("topLeft");
    videoLayer2.setPositionNormalizeds(Arrays.asList(new Float[]{0.5F, 0F}));
    videoLayersList.add(videoLayer2);
    ModifyCasterLayoutRequest.VideoLayer videoLayer3 = new ModifyCasterLayoutRequest.VideoLayer();
    videoLayer3.setHeightNormalized(0.5F);
    videoLayer3.setWidthNormalized(0.5F);
    videoLayer3.setPositionRefer("topLeft");
    videoLayer3.setPositionNormalizeds(Arrays.asList(new Float[]{0.2F, 0.5F}));
    videoLayersList.add(videoLayer3);
    modifyCasterLayoutRequest.setVideoLayers(videoLayersList);
    List audioLayerList = new ArrayList();
    ModifyCasterLayoutRequest.AudioLayer audioLayer1 = new ModifyCasterLayoutRequest.AudioLayer(); // 音频layer
    audioLayer1.setVolumeRate(1F);
    audioLayer1.setValidChannel("all");
    audioLayerList.add(audioLayer1);
    ModifyCasterLayoutRequest.AudioLayer audioLayer2 = new ModifyCasterLayoutRequest.AudioLayer();
    audioLayer2.setVolumeRate(1F);
    audioLayer2.setValidChannel("all");
    audioLayerList.add(audioLayer2);
    ModifyCasterLayoutRequest.AudioLayer audioLayer3 = new ModifyCasterLayoutRequest.AudioLayer();
    audioLayer3.setVolumeRate(1F);
    audioLayer3.setValidChannel("all");
    audioLayerList.add(audioLayer3);
    modifyCasterLayoutRequest.setAudioLayers(audioLayerList);
    modifyCasterLayoutRequest.setBlendLists(Arrays.asList(new String[]{"RV01", "RV02", "RV03"}));
    modifyCasterLayoutRequest.setMixLists(Arrays.asList(new String[]{"RV01", "RV02", "RV03"}));
    ModifyCasterLayoutResponse response = client.getAcsResponse(modifyCasterLayoutRequest);
    
    // 查询布局列表(DescribeCasterLayout)
    DescribeCasterLayoutsRequest request = new DescribeCasterLayoutsRequest();
    request.setCasterId("LIVEPRODUCER_POST-cn-0pp123h****");
    DescribeCasterLayoutsResponse response = client.getAcsResponse(request);
    
    // 删除布局(DescribeCasterLayout)
    DeleteCasterLayoutRequest deleteCasterLayoutRequest = new DeleteCasterLayoutRequest();
    deleteCasterLayoutRequest.setCasterId("LIVEPRODUCER_POST-cn-0pp123h****");
    deleteCasterLayoutRequest.setLayoutId("LIVEPRODUCER_POST-cn-0pp123h****");
    DeleteCasterLayoutResponse response = client.getAcsResponse(deleteCasterLayoutRequest);                        
  5. 启动导播台

    示例代码

    导播台创建并配置完毕后,即可启动导播台,启动底层音视频处理任务。

    前提条件

    完成导播台配置,包括域名、导播台输出分辨率等。

    接口说明

    名称

    描述

    StartCaster

    启动导播台

    CasterID

    指定需要启动的导播台实例ID

    说明

    接口启动成功后返回PVW及PGM场景信息列表,包括场景ID及流信息等,后续操作指定场景时指定场景ID即可。

    示例代码

    StartCasterRequest request = new StartCasterRequest();
    request.setCasterId("test");
    StartCasterResponse response = client.getAcsResponse(request);
    System.out.println(new Gson().toJson(response));
  6. 更新场景

    步骤说明

    导播台启动成功后,可将已配置好的布局(组件)生效至指定场景。

    前提条件

    • 完成指定布局(组件)的编辑

    • 指定场景存在并启动

    接口说明

    名称

    描述

    UpdateCasterSceneConfig

    更新场景配置

    DeleteCasterSceneConfig

    删除场景配置

    CasterID

    指定导播台实例ID

    SceneID

    指定场景ID

    示例代码

    // 更新场景配置(UpdateCasterSceneConfig)
    UpdateCasterSceneConfigRequest updateCasterSceneConfigRequest = new UpdateCasterSceneConfigRequest();
    updateCasterSceneConfigRequest.setCasterId("LIVEPRODUCER_POST-cn-0pp123h****");
    updateCasterSceneConfigRequest.setSceneId("LIVEPRODUCER_POST-cn-0pp123h****");
    updateCasterSceneConfigRequest.setComponentIds(componentList);
    UpdateCasterSceneConfigResponse response = client.getAcsResponse(updateCasterSceneConfigRequest);
    
    // 删除场景配置(DeleteCasterSceneConfig)
    DeleteCasterSceneConfigRequest deleteCasterSceneConfigRequest = new DeleteCasterSceneConfigRequest();
    deleteCasterSceneConfigRequest.setCasterId("LIVEPRODUCER_POST-cn-0pp123h****");
    deleteCasterSceneConfigRequest.setType("Component") // 清除场景中的组件配置
    DeleteCasterSceneConfigResponse response = client.getAcsResponse(deleteCasterSceneConfigRequest);                       
  7. 预监(PVW)切换到节目(PGM)

    步骤说明

    导播台启动成功后,可将PVW的布局配置信息设置到PGM场景。

    前提条件

    • PVW场景存在并启动

    • PGM场景存在并启动

    接口说明

    名称

    描述

    CopyCasterSceneConfig

    更新场景配置

    CasterID

    指定导播台实例ID

    FromSceneID

    指定PVW场景ID

    ToSceneID

    指定PGM场景ID

    示例代码

    // 场景切换(CopyCasterSceneConfig)
    CopyCasterSceneConfigRequest copyCasterSceneConfigRequest = new CopyCasterSceneConfigRequest();
    copyCasterSceneConfigRequest.setCasterId("LIVEPRODUCER_POST-cn-0pp123h****");
    copyCasterSceneConfigRequest.setFromSceneId("LIVEPRODUCER_POST-cn-0pp123h****");
    copyCasterSceneConfigRequest.setToSceneId("LIVEPRODUCER_POST-cn-0pp123h****");
    CopyCasterSceneConfigResponse response = client.getAcsResponse(copyCasterSceneConfigRequest);                 
  8. 预监开启、关闭

    步骤说明

    导播台启动成功后,可通过预监开启、关闭服务控制PVW场景,关闭PVW场景后布局及视频源变动可直接生效至PGM场景。

    前提条件

    PVW场景存在。

    接口说明

    名称

    描述

    StartCasterScene

    预监开启

    StopCasterScene

    预监关闭

    CasterID

    指定导播台实例ID

    SceneID

    指定PVW场景ID

    示例代码

     // 预监开启(StartCasterScene)
    StartCasterSceneRequest startCasterSceneRequest = new StartCasterSceneRequest();
    startCasterSceneRequest.setCasterId("LIVEPRODUCER_POST-cn-0pp123h****");
    startCasterSceneRequest.setSceneId("LIVEPRODUCER_POST-cn-0pp123h****");
    StartCasterSceneResponse response = client.getAcsResponse(startCasterSceneRequest);
    
    // 预监关闭(StopCasterScene)
    StopCasterSceneRequest stopCasterSceneRequest = new StopCasterSceneRequest();
    stopCasterSceneRequest.setCasterId("LIVEPRODUCER_POST-cn-0pp123h****");
    stopCasterSceneRequest.setSceneId("LIVEPRODUCER_POST-cn-0pp123h****");
    StopCasterSceneResponse response = client.getAcsResponse(stopCasterSceneRequest);                        
  9. 备播切换、切回

    步骤说明

    导播台启动成功后,可通过备播切换服务将PGM场景切换至备播画面,若需要切回直播场景可通过回切直播服务完成。

    前提条件

    • 导播台实例已启动

    • 完成备播素材ID配置

    接口说明

    名称

    描述

    EffectCasterUrgent

    备播紧急生效

    SetCasterSceneConfig

    切回直播

    CasterID

    指定导播台实例ID

    SceneID

    指定PGM场景实例ID

    示例代码

     // 切换备播(StartCasterScene)
    EffectCasterUrgentRequest effectCasterUrgentRequest = new EffectCasterUrgentRequest();
    effectCasterUrgentRequest.setCasterId("LIVEPRODUCER_POST-cn-0pp123h****");
    effectCasterUrgentRequest.setSceneId("LIVEPRODUCER_POST-cn-0pp123h****");
    EffectCasterUrgentResponse response = client.getAcsResponse(effectCasterUrgentRequest);
    
    // 切回直播(SetCasterSceneConfig)
    SetCasterSceneConfigRequest setCasterSceneConfigRequest = new SetCasterSceneConfigRequest();
    setCasterSceneConfigRequest.setCasterId("LIVEPRODUCER_POST-cn-0pp123h****");
    setCasterSceneConfigRequest.setSceneId("LIVEPRODUCER_POST-cn-0pp123h****");
    setCasterSceneConfigRequest.setLayoutId(null); // 若需要退出备播播放传null,若需要转到指定布局输入layoutId即可
    SetCasterSceneConfigResponse response = client.getAcsResponse(setCasterSceneConfigRequest);       
  10. 停止导播台

    步骤说明

    导播台启动成功后,可通过停止导播台服务停止指定导播台及底层音视频任务。

    前提条件

    导播台实例已启动。

    接口说明

    名称

    描述

    StopCaster

    停止导播台

    CasterID

    指定导播台实例ID

    示例代码

    // 停止导播台(StopCaster)
    StopCasterRequest request = new StopCasterRequest();
    request.setCasterId("LIVEPRODUCER_POST-cn-0pp123h****");
    StopCasterResponse response = client.getAcsResponse(request);