项目作者: BPing

项目描述 :
aliyun live SDK for golang
高级语言: Go
项目地址: git://github.com/BPing/aliyun-live-go-sdk.git
创建时间: 2016-06-21T09:13:27Z
项目社区:https://github.com/BPing/aliyun-live-go-sdk

开源协议:Apache License 2.0

下载


aliyun-live-go-sdk

Build Status Coverage Status Go Report Card

  1. 阿里云直播 golang SDK

阿里云视频直播接口文档

快速开始

  1. package main
  2. import (
  3. "github.com/BPing/aliyun-live-go-sdk/aliyun"
  4. "github.com/BPing/aliyun-live-go-sdk/device/live"
  5. "github.com/BPing/aliyun-live-go-sdk/util"
  6. "time"
  7. "fmt"
  8. )
  9. const (
  10. AccessKeyId = "<Yours' Id>"
  11. AccessKeySecret = "<...>"
  12. )
  13. func main() {
  14. cert := aliyun.NewCredentials(AccessKeyId, AccessKeySecret)
  15. live := live.NewLive(cert, "<Yours' CDN>", "app-name",nil).SetDebug(true)
  16. resp := make(map[string]interface{})
  17. live.StreamsPublishList(time.Now().Add(-time.Hour * 12), time.Now(), &resp)
  18. fmt.Println(resp)
  19. }

构建安装

go get:

  1. go get github.com/BPing/aliyun-live-go-sdk

文档

Example

直播(Live)

  1. v0.5,v0.5-)
  2. 方法名以"WithApp"结尾代表可以更改请求中 "应用名字(AppName)"
  3. 否则按默认的(初始化时设置的AppName)。
  4. 如果为空,代表忽略参数AppName
  5. v0.6+
  6. 移除以"WithApp"为后缀方法。
  1. cert := client.NewCredentials(AccessKeyId, AccessKeySecret)
  2. liveM := live.NewLive(cert, DomainName, AppName, nil).SetDebug(true)
  • 获取流列表

    1. resp := make(map[string]interface{})
    2. liveM.StreamsPublishList(time.Now().Add(-time.Hour * 12), time.Now(), &resp)
    3. fmt.Println(resp)
    4. // @appname 应用名 为空时,忽略此参数
    5. resp := make(map[string]interface{})
    6. liveM.StreamsPublishListWithApp(AppName,time.Now().Add(-time.Hour * 12), time.Now(), &resp)
    7. fmt.Println(resp)
  • 获取黑名单

    1. resp = make(map[string]interface{})
    2. err = liveM.StreamsBlockList(&resp)
    3. fmt.Println(err, resp)
  • 获取流的在线人数

    1. resp1 := live.OnlineInfoResponse{}
    2. err := liveM.StreamOnlineUserNum("video-name", &resp1)
    3. fmt.Println(err, resp1)
    4. // @appname 应用名 为空时,忽略此参数 (v0.5,v0.5-)
    5. resp1 := live.OnlineInfoResponse{}
    6. err := liveM.StreamOnlineUserNumWithApp(AppName,"video-name", &resp1)
    7. fmt.Println(err, resp1)
  • 获取控制历史

    1. resp = make(map[string]interface{})
    2. err = liveM.StreamsControlHistory(time.Now().Add(-time.Hour * 12), time.Now(), &resp)
    3. // (v0.5,v0.5-)
    4. //err = liveM.StreamsControlHistoryWithApp(AppName,time.Now().Add(-time.Hour * 12), time.Now(), &resp)
    5. fmt.Println(err, resp)
  • 禁止

    1. resp = make(map[string]interface{})
    2. err = liveM.ForbidLiveStreamWithPublisher("video-name", nil, &resp)
    3. fmt.Println(err, resp)
  • 恢复

    1. resp = make(map[string]interface{})
    2. err = liveM.ResumeLiveStreamWithPublisher("video-name", &resp)
    3. fmt.Println(err, resp)

录制(请看文档)

截图(2017-01-18)

  • 添加截图配置

    1. oss := live.OssInfo{
    2. OssBucket: OssBucket,
    3. OssEndpoint: OssEndpoint,
    4. OssObject: OssObject,
    5. OssObjectPrefix: OssObjectPrefix,
    6. }
    7. config:=live.SnapshotConfig{
    8. OssInfo:oss,
    9. TimeInterval : 5,
    10. OverwriteOssObject : "{AppName}/{StreamName}.jpg",
    11. }
    12. resp := make(map[string]interface{})
    13. err:=liveM.AddLiveAppSnapshotConfig(config,&resp)
    14. fmt.Println(err, resp)
  • 更新截图配置

    1. config.SequenceOssObject="{AppName}/{StreamName}.jpg"
    2. resp = make(map[string]interface{})
    3. err=liveM.UpdateLiveAppSnapshotConfig(config,&resp)
    4. fmt.Println(err, resp)
  • 查询域名截图配置

    1. param:=live.LiveSnapshotParam{
    2. PageNum:1,
    3. PageSize:10,
    4. Order:"asc",
    5. }
    6. resp = make(map[string]interface{})
    7. err=liveM.LiveSnapshotConfig(param,&resp)
    8. fmt.Println(err, resp)
  • 查询截图信息

    1. resp = make(map[string]interface{})
    2. err=liveM.LiveStreamSnapshotInfo("test-video-name1",time.Now().Add(-time.Hour*24*20), time.Now(),10,&resp)
    3. fmt.Println(err, resp)
  • 删除截图配置

    1. resp = make(map[string]interface{})
    2. err=liveM.DeleteLiveAppSnapshotConfig(&resp)
    3. fmt.Println(err, resp)

转码(2017-01-19)

  • 添加转码配置

    1. resp := make(map[string]interface{})
    2. err:=liveM.AddLiveStreamTranscode("a","no","no",&resp)
    3. fmt.Println(err, resp)
  • 查询转码配置信息

    1. resp = make(map[string]interface{})
    2. err=liveM.LiveStreamTranscodeInfo(&resp)
    3. fmt.Println(err, resp))
  • 删除转码配置

    1. resp = make(map[string]interface{})
    2. err=liveM.DeleteLiveStreamTranscode("a",&resp)
    3. fmt.Println(err, resp)

混流(2017-01-19)

  • 开始混流操作

    1. err=liveM.StartMixStreamsService(...)
  • 结束混流操作

    1. err=liveM.StopMixStreamsService(...)

    拉流(2017-10-12)

  • 添加拉流信息

    1. err=liveM.AddLivePullStreamInfoConfig(...)
  • 删除拉流信息

    1. err=liveM.DeleteLivePullStreamInfoConfig(...)
  • 查询域名下拉流配置信息

    1. err=liveM.DescribeLivePullStreamConfig(...)

连麦((2017-10-12)

  • 添加连麦配置

    1. err=liveM.AddLiveMixConfig(...)
  • 查询连麦配置

    1. err=liveM.DescribeLiveMixConfig(...)
  • 删除连麦配置

    1. err=liveM.DeleteLiveMixConfig(...)
  • 开启多人连麦服务

    1. err=liveM.StartMultipleStreamMixService(...)
  • 停止多人连麦服务

    1. err=liveM.StopMultipleStreamMixService(...)
  • 往主流添加一路流

    1. err=liveM.AddMultipleStreamMixService(...)
  • 从主流移除一路流

    1. err=liveM.RemoveMultipleStreamMixService(...)
  • 添加连麦回调配置

    1. err=liveM.AddLiveMixNotifyConfig(...)
  • 查询连麦回调配置

    1. err=liveM.DescribeLiveMixNotifyConfig(...)
  • 删除连麦回调配置

    1. err=liveM.DeleteLiveMixNotifyConfig(...)
  • 更新连麦回调配置

    1. err=liveM.UpdateLiveMixNotifyConfig(...)

状态通知((2017-10-12)

  • 设置回调链接

    1. err=liveM.SetStreamsNotifyUrlConfig(...)
  • 删除推流回调配置

    1. err=liveM.DeleteLiveStreamsNotifyUrlConfig(...)
  • 查询推流回调配置

    1. err=liveM.StreamsNotifyUrlConfig(...)

直播转点播((2018-05-20)

  • 增加直播录制转点播配置

    1. err=liveM.AddLiveRecordVodConfig(...)
  • 删除直播录制转点播配置

    1. err=liveM.DeleteLiveRecordVodConfig(...)
  • 查询直转点配置列表

    1. err=liveM.DescribeLiveRecordVodConfigs(...)

资源监控((2018-05-20)

  • 查询直播域名的网络带宽监控数据

    1. err=liveM.DescribeLiveDomainBpsData(...)
  • 查询直播域名录制时长数据

    1. err=liveM.DescribeLiveDomainRecordData(...)
  • 查询直播域名截图张数数据

    1. err=liveM.DescribeLiveDomainSnapshotData(...)
  • 查询直播域名网络流量监控数据

    1. err=liveM.DescribeLiveDomainTrafficData(...)
  • 查询直播域名转码时长数据

    1. err=liveM.DescribeLiveDomainTranscodeData(...)
  • 查询直播流历史在线人数

    1. err=liveM.DescribeLiveStreamHistoryUserNum(...)

直播审核((2018-05-20)

  • 查询审核配置

    1. err=liveM.DescribeLiveSnapshotDetectPornConfig(...)
  • 添加审核配置

    1. err=liveM.AddLiveSnapshotDetectPornConfig(...)
  • 更新审核回调

    1. err=liveM.UpdateLiveSnapshotDetectPornConfig(...)
  • 删除审核回调

    1. err=liveM.DeleteLiveSnapshotDetectPornConfig(...)
  • 查询审核回调

    1. err=liveM.DescribeLiveDetectNotifyConfig(...)
  • 添加回调通知

    1. err=liveM.AddLiveDetectNotifyConfig(...)
  • 更新回调通知
    1. err=liveM.UpdateLiveDetectNotifyConfig(...)
  • 删除审核回调
    1. err=liveM.DeleteLiveDetectNotifyConfig(...)

流(Stream)

  1. //如果 streamCert 为空的话,则代表不开启直播流鉴权
  2. cert := client.NewCredentials(AccessKeyId, AccessKeySecret)
  3. streamCert := live.NewStreamCredentials(PrivateKey, live.DefaultStreamTimeout)
  4. liveM := live.NewLive(cert, DomainName, AppName, streamCert)
  5. // GetStream 获取直播流
  6. // @describe 每一次都生成新的流实例,不检查流名的唯一性,并且同一个名字会生成不同的实例的,
  7. // 所以,使用时候,请自行确保流名的唯一性
  8. stream := liveM.GetStream("video-name")
  • 获取RTMP推流地址

    1. // RTMP 推流地址
    2. // 如果开启了直播流鉴权,签名失效后,会重新生成新的有效的推流地址
    3. stream.RtmpPublishUrl()
  • RTMP 直播播放地址

    1. url:=stream.RtmpLiveUrls()
  • HLS 直播播放地址

    1. url:=stream.HlsLiveUrls()
  • FLV 直播播放地址

    1. url:=stream.HttpFlvLiveUrls()
  • 获取在线人数

    1. num:=stream.OnlineUserNum()
  • 是否在线

    1. isOnline:=stream.Online()
  • 是否被禁止

    1. isBlocked:=stream.Blocked()
  • 获取直播流的帧率和码率

    1. // type FrameRateAndBitRateInfos struct {
    2. // FrameRateAndBitRateInfo []FrameRateAndBitRateInfo
    3. //}
    4. //
    5. //// 各直播流的帧率/码率信息
    6. //type FrameRateAndBitRateInfo struct {
    7. // StreamUrl string // 直播流的URL
    8. // VideoFrameRate int // 直播流的视频帧率
    9. // AudioFrameRate int // 直播流的音频帧率
    10. // BitRate int // 直播流的码率
    11. //}
    12. frameRateAndBitRateInfo,err:=stream.FrameRateAndBitRateData()
  • 获取截图信息

    1. // 查询截图信息
    2. // type StreamSnapshotInfoResponse struct {
    3. // client.Response
    4. // LiveStreamSnapshotInfoList struct {
    5. // StreamSnapshotInfo []StreamSnapshotInfo `json:"StreamSnapshotInfo" xml:"StreamSnapshotInfo"`
    6. // } `json:"LiveStreamSnapshotInfoList" xml:"LiveStreamSnapshotInfoList"` //截图内容列表,没有则返回空数组
    7. // NextStartTime string //
    8. // }
    9. streamSnapshotInfo,err:=stream.SnapshotInfo(time.Now().Add(-time.Hour * 12), time.Now(), 10)

依赖

github.com/BPing/go-toolkit/http-client

贡献参与者

License

采用 Apache License, Version 2.0许可证授权原则。

参考文献

参考项目: https://github.com/denverdino/aliyungo