转载请表明出处 https://blog.csdn.net/Amor_Leo/article/details/117956858 谢谢
简介
官网文档
Amazon Interactive Video Service (IVS) 是一项托管的实时视频流服务,可让您:
创建频道并在几分钟内开始流式传输。
构建引人入胜的交互式体验以及超低延迟的实时视频。
将视频大规模分发到一系列设备和平台。
轻松集成到网站和应用程序中。
Amazon IVS 让您可以专注于构建自己的交互式应用程序和受众体验。使用 Amazon IVS,您无需管理基础设施或开发和配置视频工作流程的组件,即可安全、可靠且经济高效。
Amazon IVS 支持 RTMPS 流。RTMPS 是 RTMP(实时消息传递协议)的安全版本,在 TLS 上运行。RTMP 是通过网络传输视频的行业标准。
java整合 创建频道Channel
pom
<properties>
<aws-s3.version>1.12.5</aws-s3.version>
<aws-ivs.version>1.12.5</aws-ivs.version>
<aws-core.version>1.12.5</aws-core.version>
</properties>
<!-- 如果需要录制 则加S3依赖 Set Up to Auto-Record to Amazon S3 (Optional)->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>${aws-s3.version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-ivs</artifactId>
<version>${aws-ivs.version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-core</artifactId>
<version>${aws-core.version}</version>
</dependency>
yml
aws:
ivs:
accessKey: xxxx
secretKey: xxxx
ivs连接配置
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.ivs.AmazonIVS;
import com.amazonaws.services.ivs.AmazonIVSAsyncClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author LHL
* @since 2021/6/15
*/
@Configuration
@Slf4j
public class AmazonIvsConfig {
/**
* 账号key
*/
@Value("${aws.ivs.accessKey}")
private String accessKey;
/**
* 私钥
*/
@Value("${aws.ivs.secretKey}")
private String secretKey;
/**
* 初始化生成AmazonIVS 客户端配置
*/
@Bean(name = "amazonIVS")
public AmazonIVS getAmazonIVS() {
BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
// US_EAST_1 根据你aws区域改变
return AmazonIVSAsyncClient.builder().withRegion(Regions.US_EAST_1.getName())
.withCredentials(new AWSCredentialsProvider() {
@Override
public AWSCredentials getCredentials() {
return credentials;
}
@Override
public void refresh() {
}
}).build();
}
}
创建/删除频道
@Resource
private AmazonIVS amazonIVS;
// 创建频道Channel
private CreateChannelResult createChannel(CreateChannelRequest channelRequest) {
return amazonIVS.createChannel(channelRequest);
}
//删除频道Channel
private DeleteChannelResult deleteChannel(DeleteChannelRequest channelRequest) {
return amazonIVS.deleteChannel(channelRequest);
}
public void test() {
// 创建频道
CreateChannelRequest channelRequest = new CreateChannelRequest();
// 频道名称
channelRequest.setName("channel-live");
// 通道延迟模式 ,确定允许的分辨率和比特率。如果超出允许的分辨率或比特率,则流可能会立即断开连接。
// STANDARD:原始输入会产生多种品质,以自动为观看者提供有关其设备和网络状况的最佳体验。垂直分辨率最高可以达到1080,比特率最高可以达到8.5 Mbps;
// BASIC:Amazon IVS将原始输入传递给查看者。观看者的视频质量选择仅限于原始输入。垂直分辨率最高可以达到480,比特率最高可以达到1.5 Mbps。
channelRequest.setType("STANDARD");
// 通道延迟模式 NORMAL | LOW
channelRequest.setLatencyMode("LOW");
CreateChannelResult result = createChannel(channelRequest);
// 推流 例如 rtmps://a1b2c3d4e5f6.global-contribute.live-video.net/app/
StringBuilder pushUrl = new StringBuilder("rtmps://");
pushUrl.append(result.getChannel().getIngestEndpoint());
pushUrl.append("/app/");
// 拉流 观看直播
String pullUrl = result.getChannel().getPlaybackUrl();
log.info("aws IVS pushUrl: {}, pullUrl: {}", pushUrl.toString(), pullUrl);
// 秘钥
String streamKey = result.getStreamKey().getValue();
pushUrl.append(result.getStreamKey().getValue());
log.info("aws IVS streamKey: {}", streamKey);
// 删除频道
String arn = result.getChannel().getArn();
log.info("aws IVS delete Channel arg: arn: {}", arn);
DeleteChannelRequest channelRequest2 = new DeleteChannelRequest();
channelRequest2.setArn(arn);
DeleteChannelResult channelResult = deleteChannel(channelRequest2);
// status 204 成功
log.info("delete channel result: {}", channelResult.getSdkHttpMetadata().getHttpStatusCode());
}