aliyun-go-live-sdk

詳細信息請看

github:https://github.com/BPing/aliyun-live-go-sdkhtml

Build Status Coverage Status Go Report Card

阿里雲直播 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

文檔

Example

直播(Live)

方法名以"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)

錄製(請看文檔)

截圖(2017-01-18)

  • 添加截圖配置
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)

轉碼(2017-01-19)

  • 添加轉碼配置
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)

混流(2017-01-19)

  • 開始混流操做
err=liveM.StartMixStreamsService(...)
  • 結束混流操做
err=liveM.StopMixStreamsService(...)

拉流(2017-10-12)

  • 添加拉流信息
err=liveM.AddLivePullStreamInfoConfig(...)
  • 刪除拉流信息
err=liveM.DeleteLivePullStreamInfoConfig(...)
  • 查詢域名下拉流配置信息
err=liveM.DescribeLivePullStreamConfig(...)

連麥((2017-10-12)

  • 添加連麥配置
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(...)

狀態通知((2017-10-12)

  • 設置回調連接
err=liveM.SetStreamsNotifyUrlConfig(...)
  • 刪除推流回調配置
err=liveM.DeleteLiveStreamsNotifyUrlConfig(...)
  • 查詢推流回調配置
err=liveM.StreamsNotifyUrlConfig(...)

流(Stream)

//若是 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推流地址
// RTMP 推流地址
    // 若是開啓了直播流鑑權,簽名失效後,會從新生成新的有效的推流地址
    stream.RtmpPublishUrl()
  • RTMP 直播播放地址
url:=stream.RtmpLiveUrls()
  • HLS 直播播放地址
url:=stream.HlsLiveUrls()
  • FLV 直播播放地址
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)

License

採用 Apache License, Version 2.0許可證受權原則。golang

本站公眾號
   歡迎關注本站公眾號,獲取更多信息