Create a custom layout

更新时间:
复制 MD 格式

ApsaraVideo Live production studios support single-screen, Picture-in-Picture (PiP), quad-screen, and custom layouts for diverse streaming scenarios.

Custom layout steps

  1. Define the number of video windows, the referenced video sources and their location IDs, and the layer hierarchy.
  2. Define the coordinate system, coordinates, and width or height scaling ratio for each window.
  3. Define the number of audio mixes, the referenced audio sources and their location IDs, and the audio mixing order.
  4. Define the volume multiplier and input sound channel for each audio source.

Sample parameters for a custom PiP layout

Parameter values are defined in Add a production studio layout.

Name Example value Description
Action AddCasterLayout API operation name.
CasterId LIVEPRODUCER_POST-cn-v0h1557**** Production studio ID.
BlendList.1 RV01 Location ID of the bottom-layer video source.
BlendList.2 RV02 Location ID of the top-layer video source.
MixList.1 RV01 Location ID of the video source.
VideoLayer.1.HeightNormalized 1.0 Normalized height. Width scales proportionally.
VideoLayer.1.PositionNormalized.1 1.0 Normalized X coordinate.
VideoLayer.1.PositionNormalized.2 1.0 Normalized Y coordinate.
VideoLayer.1.PositionRefer topLeft Reference coordinate system. Origin: top-left corner of the playback window.
VideoLayer.2.HeightNormalized 0.3 Normalized height. Width scales proportionally.
VideoLayer.2.PositionNormalized.1 0.2 Normalized X coordinate.
VideoLayer.2.PositionNormalized.2 0.2 Normalized Y coordinate.
VideoLayer.2.PositionRefer topLeft Reference coordinate system. Origin: top-left corner of the playback window.
AudioLayer.1.ValidChannel leftChannel Uses the left sound channel as audio input.
AudioLayer.1.VolumeRate 1.0 Volume multiplier. 1.0 = original volume.
Note A.n refers to the nth parameter in list A. A.n.B refers to parameter B of the nth struct in list A.

Code sample

public AddCasterLayoutResponse addCasterLayoutSample() {
        /*Set BlendList*/
        ArrayList<String> blendList = new ArrayList<String>();
        blendList.add("RV01");
        blendList.add("RV02");
        /*Set VideoLayers*/
        ArrayList<VideoLayer> videoLayers = new ArrayList<VideoLayer>();
        VideoLayer videoLayerRv01 = new VideoLayer();
        ArrayList<Float> positionNormalizedRv01 = new ArrayList<Float>();
        positionNormalizedRv01.add(0f);
        positionNormalizedRv01.add(0f);
        videoLayerRv01.setHeightNormalized(1f);  // Set the normalized height ratio for the video.
        videoLayerRv01.setPositionNormalizeds(positionNormalizedRv01); // Set the normalized coordinates for the video.
        videoLayerRv01.setPositionRefer("topLeft"); // Set the reference coordinate system for the video origin.
        videoLayers.add(videoLayerRv01);
        VideoLayer videoLayerRv02 = new VideoLayer();
        ArrayList<Float> positionNormalizedRv02 = new ArrayList<Float>();
        positionNormalizedRv02.add(0.2f);
        positionNormalizedRv02.add(0.2f);
        videoLayerRv02.setHeightNormalized(0.3f);  // Set the normalized height ratio for the video.
        videoLayerRv02.setPositionNormalizeds(positionNormalizedRv02); // Set the normalized coordinates for the video.
        videoLayerRv02.setPositionRefer("topLeft"); // Set the reference coordinate system for the video origin.
        videoLayers.add(videoLayerRv02);
        /*Set MixList*/
        ArrayList<String> mixList = new ArrayList<String>();
        mixList.add("RV01");
        /*Set AudioLayers*/
        ArrayList<AudioLayer> audioLayers = new ArrayList<AudioLayer>();
        AudioLayer audioLayer = new AudioLayer();
        audioLayer.setVolumeRate(1f); // Set the audio volume multiplier.
        audioLayer.setValidChannel("leftChannel"); // Set the audio input channel.
        audioLayers.add(audioLayer);

        AddCasterLayoutRequest addCasterLayoutRequest = new AddCasterLayoutRequest();
        addCasterLayoutRequest.setCasterId("LIVEPRODUCER_POST-cn-v0h1557****"); // Set the production studio ID.
        addCasterLayoutRequest.setBlendLists(blendList); // Set BlendList.
        addCasterLayoutRequest.setMixLists(mixList);  // Set MixList.
        addCasterLayoutRequest.setVideoLayers(videoLayers); // Set VideoLayers.
        addCasterLayoutRequest.setAudioLayers(audioLayers); // Set AudioLayers.
        AddCasterLayoutResponse addCasterLayoutResponse = null;
        try {
            addCasterLayoutResponse = LiveClient.getClient().getAcsResponse(addCasterLayoutRequest);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return addCasterLayoutResponse;
    }