萤石官方文档链接
萤石官方文档中描述了获取直播信息的若干种方法,本方法是用python写的,需要appKey和appSecret才能获取。代码如下:
import cv2
import sys
import requests
import json
class YingShiLiveUrl:
def __init__(self,appKey,appSecret,mode):
self.appKey=appKey
self.appSecret=appSecret
self.accessToken=''
self.mode=mode
def get_accessToken(self):
appKey=self.appKey
appSecret=self.appSecret
url = "https://open.ys7.com/api/lapp/token/get"
data = {
"POST" : "/api/lapp/token/get HTTP/1.1",
"Host":"open.ys7.com",
"Content-Type": "application/x-www-form-urlencoded",
"appKey":appKey,
"appSecret":appSecret
}
res = requests.post(url=url,data=data)
resJson=json.loads(res.text)
accessToken=resJson['data']['accessToken']
self.accessToken=accessToken
def get_VIDEO_URL(self):
accessToken=self.accessToken
url='https://open.ys7.com/api/lapp/live/video/list'
data = {
"POST" : "/api/lapp/token/get HTTP/1.1",
"Host":"open.ys7.com",
"Content-Type": "application/x-www-form-urlencoded",
"accessToken":accessToken
}
res = requests.post(url=url,data=data)
resJson=json.loads(res.text)
urls=[]
for i in range(len(resJson['data'])):
url=resJson['data'][i][mode]
urls.append(url)
return urls
def get_camera(VIDEO_URL):
cap = cv2.VideoCapture(VIDEO_URL)
if (cap.isOpened() == False):
print('!!! Unable to open URL')
sys.exit(-1)
fps = cap.get(cv2.CAP_PROP_FPS)
wait_ms = int(1000/fps)
print('FPS:', fps)
while(True):
# read one frame
ret, frame = cap.read()
cv2.imshow("fitcurve_.jpg",frame)
if cv2.waitKey(wait_ms) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
if __name__ == "__main__":
appKey="9mqitppidgce4y8n54ranvyqc9fjtsrl"
appSecret="096e76501644989b63ba0016ec5776"
mode='hdAddress' #高清模式
YingShi=YingShiLiveUrl(appKey,appSecret,mode)
YingShi.get_accessToken()
urls=YingShi.get_VIDEO_URL()
print(urls)
for url in urls:
get_camera(url)