Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Features

  • 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)

Contents

Installation

before next step, install git.

// install latest version$ go get github.com/pili-engineering/pili-sdk-go.v2/pili

Usage

Configuration

package 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

Generate RTMP publish URL

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=*/

Generate RTMP play URL

url:=pili.RTMPPlayURL("live-rtmp.test.com","PiliSDKTest","streamkey")fmt.Println(url)/*rtmp://live-rtmp.test.com/PiliSDKTest/streamkey*/

Generate HLS play URL

url:=pili.HLSPlayURL("live-hls.test.com","PiliSDKTest","streamkey")fmt.Println(url)/*http://live-hls.test.com/PiliSDKTest/streamkey.m3u8*/

Generate HDL play URL

url:=pili.HDLPlayURL("live-hdl.test.com","PiliSDKTest","streamkey")fmt.Println(url)/*http://live-hdl.test.com/PiliSDKTest/streamkey.flv*/

Generate Snapshot play URL

url:=pili.SnapshotPlayURL("live-snapshot.test.com","PiliSDKTest","streamkey")fmt.Println(url)/*http://live-snapshot.test.com/PiliSDKTest/streamkey.jpg*/

Hub

Instantiate a Pili Hub object

funcmain() {mac:=&pili.MAC{AccessKey, []byte(SecretKey)}client:=pili.New(mac,nil)hub:=client.Hub("PiliSDKTest")// ...}

Create a new Stream

stream,err:=hub.Create(key)iferr!=nil {return}info,err:=stream.Info()iferr!=nil {return}fmt.Println(info)/*{hub:PiliSDKTest,key:streamkey,disabled:false}*/

Get a Stream

stream:=hub.Stream(key)info,err:=stream.Info()iferr!=nil {return}fmt.Println(info)/*{hub:PiliSDKTest,key:streamkey,disabled:false}*/

List Streams

keys,marker,err:=hub.List(prefix,10,"")iferr!=nil {return}fmt.Printf("keys=%v marker=%v\n",keys,marker)/*keys=[streamkey] marker=*/

List live Streams

keys,marker,err:=hub.ListLive(prefix,10,"")iferr!=nil {return}fmt.Printf("keys=%v marker=%v\n",keys,marker)/*keys=[streamkey] marker=*/

Batch query live status

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

Get Stream info

stream:=hub.Stream(key)info,err:=stream.Info()iferr!=nil {return}fmt.Println(info)/*{hub:PiliSDKTest,key:streamkey,disabled:false}*/

Disable a Stream

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}*/

Enable a Stream

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}*/

Get Stream live status

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}}*/

Get Stream history activity

stream:=hub.Stream(key)records,err:=stream.HistoryActivity(0,0)iferr!=nil {return}fmt.Println(records)/*[{1463382401 1463382441}]*/

Save Stream live playback

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*/

Update Stream converts

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]}*/

Save Stream snapshot

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

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors3

  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp