- Notifications
You must be signed in to change notification settings - Fork19
Pili Streaming Cloud Server-Side Library For Go, Version 2
License
NotificationsYou must be signed in to change notification settings
pili-engineering/pili-sdk-go.v2
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
URL
- RTMP推流地址: RTMPPublishURL(domain, hub, streamKey, mac, expireAfterSeconds)
- RTMP直播地址: RTMPPlayURL(domain, hub, streamKey)
- HLS直播地址: HLSPlayURL(domain, hub, streamKey)
- HDL直播地址: HDLPlayURL(domain, hub, streamKey)
- 直播封面地址: SnapshotPlayURL(domain, hub, streamKey)
Hub
- 创建流: hub.Create(streamKey)
- 获得流: hub.Stream(streamKey)
- 列出流: hub.List(prefix, limit, marker)
- 列出正在直播的流: hub.ListLive(prefix, limit, marker)
- 批量查询直播信息: hub.BatchLiveStatus(streams)
Stream
- 流信息: stream.Info()
- 禁用流: stream.DisableTill(till)
- 启用流: stream.Enable()
- 查询直播状态: stream.LiveStatus()
- 保存直播回放: stream.Saveas(options)
- 保存直播截图: stream.Snapshot(options)
- 更改流的实时转码规格: stream.UpdateConverts(profiles)
- 查询直播历史: stream.HistoryActivity(start, end)
before next step, install git.
// install latest version$ go get github.com/pili-engineering/pili-sdk-go.v2/pilipackage mainimport (// ..."github.com/pili-engineering/pili-sdk-go.v2/pili")var (AccessKey="<QINIU ACCESS KEY>"// 替换成自己 Qiniu 账号的 AccessKey.SecretKey="<QINIU SECRET KEY>"// 替换成自己 Qiniu 账号的 SecretKey.HubName="<PILI HUB NAME>"// Hub 必须事先存在.)funcmain() {// ...mac:=&pili.MAC{AccessKey, []byte(SecretKey)}client:=pili.New(mac,nil)// ...}
url:=pili.RTMPPublishURL("publish-rtmp.test.com","PiliSDKTest","streamkey",mac,60)fmt.Println(url)/*rtmp://publish-rtmp.test.com/PiliSDKTest/streamkey?e=1463023142&token=7O7hf7Ld1RrC_fpZdFvU8aCgOPuhw2K4eapYOdII:-5IVlpFNNGJHwv-2qKwVIakC0ME=*/
url:=pili.RTMPPlayURL("live-rtmp.test.com","PiliSDKTest","streamkey")fmt.Println(url)/*rtmp://live-rtmp.test.com/PiliSDKTest/streamkey*/
url:=pili.HLSPlayURL("live-hls.test.com","PiliSDKTest","streamkey")fmt.Println(url)/*http://live-hls.test.com/PiliSDKTest/streamkey.m3u8*/
url:=pili.HDLPlayURL("live-hdl.test.com","PiliSDKTest","streamkey")fmt.Println(url)/*http://live-hdl.test.com/PiliSDKTest/streamkey.flv*/
url:=pili.SnapshotPlayURL("live-snapshot.test.com","PiliSDKTest","streamkey")fmt.Println(url)/*http://live-snapshot.test.com/PiliSDKTest/streamkey.jpg*/
funcmain() {mac:=&pili.MAC{AccessKey, []byte(SecretKey)}client:=pili.New(mac,nil)hub:=client.Hub("PiliSDKTest")// ...}
stream,err:=hub.Create(key)iferr!=nil {return}info,err:=stream.Info()iferr!=nil {return}fmt.Println(info)/*{hub:PiliSDKTest,key:streamkey,disabled:false}*/
stream:=hub.Stream(key)info,err:=stream.Info()iferr!=nil {return}fmt.Println(info)/*{hub:PiliSDKTest,key:streamkey,disabled:false}*/
keys,marker,err:=hub.List(prefix,10,"")iferr!=nil {return}fmt.Printf("keys=%v marker=%v\n",keys,marker)/*keys=[streamkey] marker=*/
keys,marker,err:=hub.ListLive(prefix,10,"")iferr!=nil {return}fmt.Printf("keys=%v marker=%v\n",keys,marker)/*keys=[streamkey] marker=*/
items,err:=hub.BatchLiveStatus(streams)iferr!=nil {return}fmt.Println(items)/*[{streamKey1 {1487766696 172.21.2.14:63422 1042240 {46 24 0}}} {streamKey2 {1487768638 172.21.2.14:63793 1201352 {51 22 0}}}]*/
stream:=hub.Stream(key)info,err:=stream.Info()iferr!=nil {return}fmt.Println(info)/*{hub:PiliSDKTest,key:streamkey,disabled:false}*/
stream:=hub.Stream(key)info,err:=stream.Info()iferr!=nil {return}fmt.Println("before disable:",info)err=stream.DisableTill(time.Now().Add(time.Minute).Unix())iferr!=nil {return}info,err=stream.Info()iferr!=nil {return}fmt.Println("after call disable:",info)time.Sleep(time.Minute)info,err=stream.Info()iferr!=nil {return}fmt.Println("after time.Minute:",info)/*before disable: {hub:PiliSDKTest,key:sdkexample1487765261435788231A,disabled:false}after call disable: {hub:PiliSDKTest,key:sdkexample1487765261435788231A,disabled:true}after time.Minute: {hub:PiliSDKTest,key:sdkexample1487765261435788231A,disabled:false}*/
stream:=hub.Stream(key)info,err:=stream.Info()iferr!=nil {return}fmt.Println("before enable:",info)err=stream.Enable()iferr!=nil {return}info,err=stream.Info()iferr!=nil {return}fmt.Println("after enable:",info)/*before enable: {hub:PiliSDKTest,key:streamkey,disabled:true}after enable: {hub:PiliSDKTest,key:streamkey,disabled:false}*/
stream:=hub.Stream(key)status,err:=stream.LiveStatus()iferr!=nil {return}fmt.Printf("%+v\n",status)/*&{StartAt:1463382400 ClientIP:172.21.1.214:52897 BPS:128854 FPS:{Audio:38 Video:23 Data:0}}*/
stream:=hub.Stream(key)records,err:=stream.HistoryActivity(0,0)iferr!=nil {return}fmt.Println(records)/*[{1463382401 1463382441}]*/
stream:=hub.Stream(key)opts:=&pili.SaveasOptions{Format:"mp4",}fname,persistentID,err:=stream.Saveas(opts)iferr!=nil {return}fmt.Println(fname,persistentID)/*recordings/z1.PiliSDKTest.streamkey/1463156847_1463157463.mp4 z1.58ae57dc254f0e4d3f00000e*/
stream:=hub.Stream(key)info,err:=stream.Info()iferr!=nil {return}fmt.Println("before UpdateConverts:",info)err=stream.UpdateConverts([]string{"480p","720p"})iferr!=nil {return}info,err=stream.Info()iferr!=nil {return}fmt.Println("after UpdateConverts:",info)/*before UpdateConverts: {hub:PiliSDKTest,key:sdkexample1487834862156173949A,disabled:false,converts:[]}after UpdateConverts: {hub:PiliSDKTest,key:sdkexample1487834862156173949A,disabled:false,converts:[480p 720p]}*/
stream:=hub.Stream(key)opts:=&pili.SnapshotOptions{Format:"jpg",}fname,err:=stream.Snapshot(opts)iferr!=nil {return}fmt.Println(fname)/*streamkey-2741961933532577110.jpg*/
About
Pili Streaming Cloud Server-Side Library For Go, Version 2
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
No releases published
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.