Skip to content

Commit 702a802

Browse files
author
金山云SDK
authored
Merge pull request KscSDK#50 from lj200987/master
直播转码选流
2 parents b7d1abd + a9284cc commit 702a802

File tree

6 files changed

+322
-13
lines changed

6 files changed

+322
-13
lines changed

examples/ket.py

Lines changed: 144 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,67 @@
11
#!/usr/bin/python
22
# -*- coding: UTF-8 -*-
33
from kscore.ket import getKetClient
4+
import time
45
import json
56

67
if __name__ == "__main__":
78
client = getKetClient("ket", "cn-beijing-6",use_ssl=False)
89

910
uniqname = 'mytest'
10-
presetname = 'testpreset00'
11+
presetname = 'testpreset'
1112
appname = 'live'
1213
description = 'just a demo'
13-
presetType = 'avop'
14+
presettype = 4
1415
streamid = 'myteststreamid'
16+
taskid = 'd41d8cd98f00b204e9800998ecf8427e'
1517
outpull = 1
1618
srcurl = "rtmp://qa-ws.test-rtmplive.ks-cdn.com/live/20160819"
1719

20+
# 删除模板
21+
#res = client.DelPreset(App=appname, UniqName=uniqname, Preset=presetname)
22+
#print json.dumps(res)
23+
1824
# 创建模板
1925
param = {
2026
"UniqName": uniqname,
2127
"Preset": presetname,
28+
"PresetType": presettype,
2229
"Description": description,
2330
"App": appname,
2431
"Output": [
2532
{
26-
"format":
33+
"Idx": 0,
34+
"Overlay":[
35+
{
36+
"inputIdx": 0,
37+
}
38+
],
39+
"Amix":[
40+
{
41+
"inputIdx": 0,
42+
}
43+
]
44+
},
45+
{
46+
"Idx": 1,
47+
"Overlay":
48+
{
49+
"inputIdx": 0,
50+
},
51+
"Amix":
52+
{
53+
"inputIdx": 0,
54+
}
55+
},
56+
{
57+
"Idx": 2,
58+
"Video":
59+
{
60+
"codec": "copy",
61+
},
62+
"Audio":
2763
{
28-
"output_format": 257,
29-
"abr": 70000,
30-
"vbr": 700000,
31-
"fr": 23
64+
"codec": "copy",
3265
}
3366
}
3467
]
@@ -48,10 +81,6 @@
4881
res = client.GetPresetList(App=appname, UniqName=uniqname)
4982
print json.dumps(res)
5083

51-
# 删除模板
52-
res = client.DelPreset(App=appname, UniqName=uniqname, Preset=presetname)
53-
print json.dumps(res)
54-
5584
# 启动外网拉流
5685
param1 = {
5786
"UniqName": uniqname,
@@ -79,3 +108,107 @@
79108
# 获取用户已占用配额
80109
res = client.GetQuotaUsed(UniqName=uniqname)
81110
print json.dumps(res)
111+
112+
# 发起轮播任务
113+
param3 = {
114+
"UniqName": uniqname,
115+
"App": appname,
116+
"StreamID": streamid,
117+
"Preset": presetname,
118+
"PubDomain": "test.uplive.ksyun.com",
119+
"DurationHour":168,
120+
"SrcInfo": [
121+
{
122+
"Path": "http://wangshuai9.ks3-cn-beijing.ksyun.com/ksyun.flv",
123+
"Index": 0
124+
}
125+
]
126+
}
127+
res = client.StartLoop(param3)
128+
print json.dumps(res)
129+
130+
# 更新轮播时长
131+
param5 = {
132+
"UniqName": uniqname,
133+
"App": appname,
134+
"StreamID": streamid,
135+
"DurationHour":100,
136+
}
137+
res = client.UpdateLoop(param5)
138+
print json.dumps(res)
139+
140+
# 查询轮播列表
141+
res = client.GetLoopList(App=appname, UniqName=uniqname, StreamID=streamid)
142+
print json.dumps(res)
143+
144+
# 停止轮播任务
145+
param4 = {
146+
"UniqName": uniqname,
147+
"App": appname,
148+
"StreamID": streamid,
149+
}
150+
res = client.StopLoop(param4)
151+
print json.dumps(res)
152+
153+
#查询直播转码时长统计数据接口调用示例 : GetLiveTransDuration
154+
#参数
155+
# StartUnixTime:查询起始时间戳秒数
156+
# EndUnixTime:查询截止时间戳秒数
157+
# Granularity:统计时间粒度
158+
# ResultType:返回结果类型
159+
start = "2017-06-16 00:00:00"
160+
end = "2017-06-20 00:00:00"
161+
t0 = time.strptime(start, "%Y-%m-%d %H:%M:%S")
162+
t1 = time.strptime(end, "%Y-%m-%d %H:%M:%S")
163+
startunixtime = int(time.mktime(t0))
164+
endunixtime = int(time.mktime(t1))
165+
granularity = 5
166+
resulttype = 1
167+
res = client.GetLiveTransDuration(startunixtime, endunixtime, uniqname, granularity, resulttype)
168+
print json.dumps(res)
169+
170+
# 创建选流任务
171+
param4 = {
172+
"UniqName": uniqname,
173+
"App": appname,
174+
"Preset": presetname,
175+
"SrcInfo": [
176+
{
177+
"Url": "rtmp://host/app/outernetStreamForSwitch",
178+
"Idx": 0
179+
},
180+
{
181+
"Streamid": "streamForSwitch",
182+
"Idx": 1
183+
}
184+
],
185+
"DstInfo": [
186+
{
187+
"Streamid":"stream0ForMonitor",
188+
"Idx": 0
189+
},
190+
{
191+
"Streamid": "stream1ForSwitch",
192+
"Idx": 1
193+
},
194+
{
195+
"Streamid": "stream2ForSwitch",
196+
"Idx": 2
197+
}
198+
]
199+
}
200+
res = client.CreateDirectorTask(param4)
201+
print json.dumps(res)
202+
203+
#更新选流任务
204+
param4["TaskID"] = taskid
205+
res = client.UpdateDirectorTask(param4)
206+
print json.dumps(res)
207+
208+
#查询选流任务
209+
res = client.QueryDirectorTask(App=appname, UniqName=uniqname, TaskID=taskid)
210+
print json.dumps(res)
211+
212+
#删除选流任务
213+
res = client.DelDirectorTask(App=appname, UniqName=uniqname, TaskID=taskid)
214+
print json.dumps(res)

examples/kvs.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- encoding:utf-8 -*-
22
from kscore.kvs import getKvsClient
33
import json
4+
import time
45

56
#没有配置kscore.cfg调用方式
67
#ks_access_key_id='xxxxxxxxxxxxxxxxxxxx'
@@ -66,6 +67,23 @@
6667
res = client.DelPreset(Preset=presetname)
6768
print json.dumps(res)
6869

70+
#修改任务队列接口调用示例 : UpdatePipeline
71+
# 该接口需要输入json格式数据
72+
pipeinfo = {
73+
"PipelineName": "usual",
74+
"Description": "test pipeline",
75+
"State": "Active",
76+
"RegularStart": "01:00:00",
77+
"RegularDuration":7200
78+
}
79+
res = client.UpdatePipeline(pipeinfo)
80+
print json.dumps(res)
81+
82+
#查询任务队列接口调用示例 : QueryPipeline
83+
# PipelineName:队列名称
84+
res = client.QueryPipeline(PipelineName="usual")
85+
print json.dumps(res)
86+
6987

7088
#创建任务接口调用示例 : CreateTask
7189
#具体参数请参考官方文档
@@ -124,3 +142,28 @@
124142
# Limit:单次请求的记录数,默认为100,最大值为100
125143
res = client.GetTaskMetaInfo(StartDate=20170100,EndDate=20170112,Marker=0,Limit=50)
126144
print json.dumps(res)
145+
146+
#查询转码时长统计数据接口调用示例 : GetMediaTransDuration
147+
#查询转码API调用次数统计数据接口调用示例 : GetInterfaceNumber
148+
#查询转码截图统计数据接口调用示例 : GetScreenshotNumber
149+
#参数
150+
# StartUnixTime:查询起始时间戳秒数
151+
# EndUnixTime:查询截止时间戳秒数
152+
# Granularity:统计时间粒度
153+
# ResultType:返回结果类型
154+
start = "2017-06-16 00:00:00"
155+
end = "2017-06-20 00:00:00"
156+
t0 = time.strptime(start, "%Y-%m-%d %H:%M:%S")
157+
t1 = time.strptime(end, "%Y-%m-%d %H:%M:%S")
158+
StartUnixTime = int(time.mktime(t0))
159+
EndUnixTime = int(time.mktime(t1))
160+
Granularity = 5
161+
ResultType = 1
162+
res = client.GetMediaTransDuration(StartUnixTime, EndUnixTime, Granularity, ResultType)
163+
print json.dumps(res)
164+
165+
res = client.GetInterfaceNumber(StartUnixTime, EndUnixTime, Granularity, ResultType)
166+
print json.dumps(res)
167+
168+
res = client.GetScreenshotNumber(StartUnixTime, EndUnixTime, Granularity, ResultType)
169+
print json.dumps(res)

kscore/data/ket/2017-01-01/service-2.yaml

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,52 @@ operations:
7070
input:
7171
shape: UniqNameInstance
7272

73-
shapes:
73+
StartLoop:
74+
name: StartLoop
75+
http:
76+
method: POST
77+
78+
StopLoop:
79+
name: StopLoop
80+
http:
81+
method: POST
82+
83+
UpdateLoop:
84+
name: UpdateLoop
85+
http:
86+
method: POST
87+
88+
GetLoopList:
89+
name: GetLoopList
90+
http:
91+
method: GET
92+
93+
GetLiveTransDuration:
94+
name: GetLiveTransDuration
95+
http:
96+
method: GET
97+
98+
CreateDirectorTask:
99+
name: CreateDirectorTask
100+
http:
101+
method: POST
102+
103+
UpdateDirectorTask:
104+
name: UpdateDirectorTask
105+
http:
106+
method: POST
107+
108+
DelDirectorTask:
109+
name: DelDirectorTask
110+
http:
111+
method: GET
112+
113+
QueryDirectorTask:
114+
name: QueryDirectorTask
115+
http:
116+
method: GET
117+
118+
shapes:
74119
App:
75120
type: string
76121
UniqName:

kscore/data/kvs/2017-01-01/service-2.yaml

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,31 @@ operations:
8888
requestUri: /
8989
input:
9090
shape: GetTaskByTaskIDInstance
91+
92+
UpdatePipeline:
93+
name: UpdatePipeline
94+
http:
95+
method: POST
96+
97+
QueryPipeline:
98+
name: QueryPipeline
99+
http:
100+
method: GET
101+
102+
GetInterfaceNumber:
103+
name: GetInterfaceNumber
104+
http:
105+
method: GET
106+
107+
GetMediaTransDuration:
108+
name: GetMediaTransDuration
109+
http:
110+
method: GET
111+
112+
GetScreenshotNumber:
113+
name: GetScreenshotNumber
114+
http:
115+
method: GET
91116

92117
shapes:
93118
Preset:
@@ -108,6 +133,16 @@ shapes:
108133
type: integer
109134
Limit:
110135
type: integer
136+
PipelineName:
137+
type: string
138+
StartUnixTime:
139+
type: integer
140+
EndUnixTime:
141+
type: integer
142+
Granularity:
143+
type: integer
144+
ResultType:
145+
type: integer
111146
PresetInstance:
112147
type: structure
113148
members:
@@ -152,4 +187,15 @@ shapes:
152187
Limit:
153188
shape: Limit
154189

155-
190+
StatisticsInstance:
191+
type: structure
192+
members:
193+
StartUnixTime:
194+
shape: StartUnixTime
195+
EndUnixTime:
196+
shape: EndUnixTime
197+
Granularity:
198+
shape: Granularity
199+
ResultType:
200+
shape: ResultType
201+

0 commit comments

Comments
 (0)