github:https://github.com/BPing/aliyun-live-go-sdkhtml
阿里云直播 golang SDK
阿里云视频直播接口文档git
package main import ( "github.com/BPing/aliyun-live-go-sdk/aliyun" "github.com/BPing/aliyun-live-go-sdk/device/live" "github.com/BPing/aliyun-live-go-sdk/util" "time" "fmt" ) const ( AccessKeyId = "<Yours' Id>" AccessKeySecret = "<...>" ) func main() { cert := aliyun.NewCredentials(AccessKeyId, AccessKeySecret) live := live.NewLive(cert, "<Yours' CDN>", "app-name",nil).SetDebug(true) resp := make(map[string]interface{}) live.StreamsPublishList(time.Now().Add(-time.Hour * 12), time.Now(), &resp) fmt.Println(resp) }
go get:github
go get github.com/BPing/aliyun-live-go-sdk
方法名以"WithApp"结尾表明能够更改请求中 "应用名字(AppName)", 不然按默认的(初始化时设置的AppName)。 若是为空,表明忽略参数AppName
cert := client.NewCredentials(AccessKeyId, AccessKeySecret) liveM := live.NewLive(cert, DomainName, AppName, nil).SetDebug(true)
resp := make(map[string]interface{}) liveM.StreamsPublishList(time.Now().Add(-time.Hour * 12), time.Now(), &resp) fmt.Println(resp) // @appname 应用名 为空时,忽略此参数 resp := make(map[string]interface{}) liveM.StreamsPublishListWithApp(AppName,time.Now().Add(-time.Hour * 12), time.Now(), &resp) fmt.Println(resp)
resp = make(map[string]interface{}) err = liveM.StreamsBlockList(&resp) fmt.Println(err, resp)
resp1 := live.OnlineInfoResponse{} err := liveM.StreamOnlineUserNum("video-name", &resp1) fmt.Println(err, resp1) // @appname 应用名 为空时,忽略此参数 resp1 := live.OnlineInfoResponse{} err := liveM.StreamOnlineUserNumWithApp(AppName,"video-name", &resp1) fmt.Println(err, resp1)
resp = make(map[string]interface{}) err = liveM.StreamsControlHistory(time.Now().Add(-time.Hour * 12), time.Now(), &resp) //err = liveM.StreamsControlHistoryWithApp(AppName,time.Now().Add(-time.Hour * 12), time.Now(), &resp) fmt.Println(err, resp)
resp = make(map[string]interface{}) err = liveM.ForbidLiveStreamWithPublisher("video-name", nil, &resp) fmt.Println(err, resp)
resp = make(map[string]interface{}) err = liveM.ResumeLiveStreamWithPublisher("video-name", &resp) fmt.Println(err, resp)
oss := live.OssInfo{ OssBucket: OssBucket, OssEndpoint: OssEndpoint, OssObject: OssObject, OssObjectPrefix: OssObjectPrefix, } config:=live.SnapshotConfig{ OssInfo:oss, TimeInterval : 5, OverwriteOssObject : "{AppName}/{StreamName}.jpg", } resp := make(map[string]interface{}) err:=liveM.AddLiveAppSnapshotConfig(config,&resp) fmt.Println(err, resp)
config.SequenceOssObject="{AppName}/{StreamName}.jpg" resp = make(map[string]interface{}) err=liveM.UpdateLiveAppSnapshotConfig(config,&resp) fmt.Println(err, resp)
param:=live.LiveSnapshotParam{ PageNum:1, PageSize:10, Order:"asc", } resp = make(map[string]interface{}) err=liveM.LiveSnapshotConfig(param,&resp) fmt.Println(err, resp)
resp = make(map[string]interface{}) err=liveM.LiveStreamSnapshotInfo("test-video-name1",time.Now().Add(-time.Hour*24*20), time.Now(),10,&resp) fmt.Println(err, resp)
resp = make(map[string]interface{}) err=liveM.DeleteLiveAppSnapshotConfig(&resp) fmt.Println(err, resp)
resp := make(map[string]interface{}) err:=liveM.AddLiveStreamTranscode("a","no","no",&resp) fmt.Println(err, resp)
resp = make(map[string]interface{}) err=liveM.LiveStreamTranscodeInfo(&resp) fmt.Println(err, resp))
resp = make(map[string]interface{}) err=liveM.DeleteLiveStreamTranscode("a",&resp) fmt.Println(err, resp)
err=liveM.StartMixStreamsService(...)
err=liveM.StopMixStreamsService(...)
err=liveM.AddLivePullStreamInfoConfig(...)
err=liveM.DeleteLivePullStreamInfoConfig(...)
err=liveM.DescribeLivePullStreamConfig(...)
err=liveM.AddLiveMixConfig(...)
err=liveM.DescribeLiveMixConfig(...)
err=liveM.DeleteLiveMixConfig(...)
err=liveM.StartMultipleStreamMixService(...)
err=liveM.StopMultipleStreamMixService(...)
err=liveM.AddMultipleStreamMixService(...)
err=liveM.RemoveMultipleStreamMixService(...)
err=liveM.AddLiveMixNotifyConfig(...)
err=liveM.DescribeLiveMixNotifyConfig(...)
err=liveM.DeleteLiveMixNotifyConfig(...)
err=liveM.UpdateLiveMixNotifyConfig(...)
err=liveM.SetStreamsNotifyUrlConfig(...)
err=liveM.DeleteLiveStreamsNotifyUrlConfig(...)
err=liveM.StreamsNotifyUrlConfig(...)
//若是 streamCert 为空的话,则表明不开启直播流鉴权 cert := client.NewCredentials(AccessKeyId, AccessKeySecret) streamCert := live.NewStreamCredentials(PrivateKey, live.DefaultStreamTimeout) liveM := live.NewLive(cert, DomainName, AppName, streamCert) // GetStream 获取直播流 // @describe 每一次都生成新的流实例,不检查流名的惟一性,而且同一个名字会生成不一样的实例的, // 因此,使用时候,请自行确保流名的惟一性 stream := liveM.GetStream("video-name")
// RTMP 推流地址 // 若是开启了直播流鉴权,签名失效后,会从新生成新的有效的推流地址 stream.RtmpPublishUrl()
url:=stream.RtmpLiveUrls()
url:=stream.HlsLiveUrls()
url:=stream.HttpFlvLiveUrls()
num:=stream.OnlineUserNum()
isOnline:=stream.Online()
isBlocked:=stream.Blocked()
// type FrameRateAndBitRateInfos struct { // FrameRateAndBitRateInfo []FrameRateAndBitRateInfo //} // //// 各直播流的帧率/码率信息 //type FrameRateAndBitRateInfo struct { // StreamUrl string // 直播流的URL // VideoFrameRate int // 直播流的视频帧率 // AudioFrameRate int // 直播流的音频帧率 // BitRate int // 直播流的码率 //} frameRateAndBitRateInfo,err:=stream.FrameRateAndBitRateData()
// 查询截图信息 // type StreamSnapshotInfoResponse struct { // client.Response // LiveStreamSnapshotInfoList struct { // StreamSnapshotInfo []StreamSnapshotInfo `json:"StreamSnapshotInfo" xml:"StreamSnapshotInfo"` // } `json:"LiveStreamSnapshotInfoList" xml:"LiveStreamSnapshotInfoList"` //截图内容列表,没有则返回空数组 // NextStartTime string // // } streamSnapshotInfo,err:=stream.SnapshotInfo(time.Now().Add(-time.Hour * 12), time.Now(), 10)
采用 Apache License, Version 2.0许可证受权原则。golang