如何取消萤石云视频加密并获取直播地址

小编最近在项目中使用到了海康威视的摄像头做直播,发现海康威视的摄像头可以直接接入到萤石云,进行直播,而且也可以进行回放十分的方便,但是获取直播后的地址发现播放不了,显示视频加密了,那么我们就得把视频解密,可以参考萤石云开发文档 https://open.ys7.com/doc/zh/book/index/user.html
下面就是小编用Python写了个解决办法:

deviceSerial = "xxxxx"
validateCode = "xxxxx"
token = "xxxxx"
datas = {"deviceSerial": deviceSerial, "validateCode": validateCode, "accessToken": token}
#发起请求,关闭加密
r = requests.post("https://open.ys7.com/api/lapp/device/encrypt/off", data=datas)
print(r.text)
#数据转换成json
codeJson = r.json()
#获取返回码
code = codeJson['code']
#如果返回码为'10002'(accessToken异常或过期),则重新获取accessToken,重新请求关闭视频加密,并且保存请求内容
if code == '10002':
    #根据appKey和appSecret获取accessToken
    datas = {'appKey': video.appkey,'appSecret': video.appsecret}
    r = requests.post("https://open.ys7.com/api/lapp/token/get", data=datas)
    keyJson = r.json()
    data = keyJson['data']
    #提取accessToken
    accessToken = data['accessToken']
    datas = {'deviceSerial': deviceSerial,'validateCode': validateCode}
    datas['accessToken'] = accessToken
    token = accessToken
    #重新请求关闭视频加密
    r = requests.post("https://open.ys7.com/api/lapp/device/encrypt/off", data=datas)
    #保存请求内容
    print(r.text)
# 获取直播地址
datas = {'accessToken': token, 'deviceSerial': deviceSerial, 'quality': 2, 'protocol': 4}
r = requests.post("https://open.ys7.com/api/lapp/v2/live/address/get", data=datas)
video.livetext = json.loads(r.text).get('data')
Last modification:December 14th, 2021 at 07:59 am
If you think my article is useful to you, please feel free to appreciate