在 IVS 服务器端合成中启用屏幕共享 - Amazon IVS

在 IVS 服务器端合成中启用屏幕共享

要使用固定的屏幕共享布局,请执行以下步骤。

创建 EncoderConfiguration 资源

下面的命令创建 EncoderConfiguration 资源,用于配置服务器端合成参数(视频比特率、帧速率和分辨率)。

aws ivs-realtime create-encoder-configuration --name "test-ssc-with-screen-share" --video={bitrate=2000000,framerate=30,height=720,width=1280}

使用 screen-share 属性创建舞台参与者令牌。由于我们将指定 screen-share 作为 featured 槽位的名称,因此我们需要创建一个 screen-share 属性设置为 true 的舞台令牌:

aws ivs-realtime create-participant-token --stage-arn "arn:aws:ivs:us-east-1:123456789012:stage/u9OiE29bT7Xp" --attributes screen-share=true

响应如下:

{ "participantToken": { "attributes": { "screen-share": "true" }, "expirationTime": "2023-08-04T05:26:11+00:00", "participantId": "E813MFklPWLF", "token": "eyJhbGciOiJLTVMiLCJ0eXAiOiJKV1QifQ.eyJleHAiOjE2OTExMjY3NzEsImlhdCI6MTY5MTA4MzU3MSwianRpIjoiRTgxM01Ga2xQV0xGIiwicmVzb3VyY2UiOiJhcm46YXdzOml2czp1cy1lYXN0LTE6OTI3ODEwOTY3Mjk5OnN0YWdlL3U5T2lFMjliVDdYcCIsInRvcGljIjoidTlPaUUyOWJUN1hwIiwiZXZlbnRzX3VybCI6IndzczovL3VzLWVhc3QtMS5ldmVudHMubGl2ZS12aWRlby5uZXQiLCJ3aGlwX3VybCI6Imh0dHBzOi8vYjJlYTVjMmZmMzU1Lmdsb2JhbC53aGlwLmxpdmUtdmlkZW8ubmV0IiwiYXR0cmlidXRlcyI6eyJzY3JlZW4tc2hhcmUiOiJ0cnVlIn0sImNhcGFiaWxpdGllcyI6eyJhbGxvd19wdWJsaXNoIjp0cnVlLCJhbGxvd19zdWJzY3JpYmUiOnRydWV9LCJ2ZXJzaW9uIjoiMC4zIn0.MGUCMFvMzv35O4yVzM9tIWZl7n3mmFQhleqsRSBx_G2qT2YUDlWSNg6H1vL7sAWQMeydSAIxAIvdfqt3Fh1MLiyelc9NnTjI5hL3YPKqDX6J3NDH1fksh8_5y1jztoPDy4yVA5OmtA" } }

开始合成

要使用屏幕共享功能开始合成,我们使用以下命令:

aws ivs-realtime start-composition --stage-arn "arn:aws:ivs:us-east-1:927810967299:stage/8faHz1SQp0ik" --destinations '[{"channel": {"channelArn": "arn:aws:ivs:us-east-1:927810967299:channel/DOlMW4dfMR8r", "encoderConfigurationArn": "arn:aws:ivs:us-east-1:927810967299:encoder-configuration/DEkQHWPVaOwO"}}]' --layout '{"grid":{"featuredParticipantAttribute":"screen-share"}}'

响应如下:

{ "composition" : { "arn" : "arn:aws:ivs:us-east-1:927810967299:composition/B19tQcXRgtoz", "destinations" : [ { "configuration" : { "channel" : { "channelArn" : "arn:aws:ivs:us-east-1:927810967299:channel/DOlMW4dfMR8r", "encoderConfigurationArn" : "arn:aws:ivs:us-east-1:927810967299:encoder-configuration/DEkQHWPVaOwO" }, "name" : "" }, "id" : "SGmgBXTULuXv", "state" : "STARTING" } ], "layout" : { "grid" : { "featuredParticipantAttribute" : "screen-share", "gridGap": 2, "omitStoppedVideo": false, "videoAspectRatio": "VIDEO" } }, "stageArn" : "arn:aws:ivs:us-east-1:927810967299:stage/8faHz1SQp0ik", "startTime" : "2023-09-27T21:32:38Z", "state" : "STARTING", "tags" : { } } }

当舞台参与者 E813MFklPWLF 加入舞台时,该参与者的视频将显示在精选槽位中,所有其他舞台发布者将在呈现在该槽位下方:

使用屏幕共享功能开始合成。

停止合成

要随时停止合成,请调用 StopComposition 端点:

aws ivs-realtime stop-composition --arn arn:aws:ivs:us-east-1:927810967299:composition/B19tQcXRgtoz