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