EasyCVS作为EasyCVR衍生出来的平台,其功能并不比EasyCVR逊色,在经过我们不断测试之后,EasyCVS也被使用在了多个不同的项目中。
EasyCVS部分项目中出现了接入某云平台的H264设备能够正常的直播和录像回看,而H265设备的录像功能和直播功能均无法正常使用的问题。起初是因为客户云平台的录像配置将录像设置为mp4格式,而目前的web播放器都无法支持H265格式的MP4播放,因此录像无法播放。
随后我们将格式改成hls,仍然无法播放,这是因为客户后台设置了播放权限,因此阿里云后台会在原本的播放地址上加入一个鉴权的auth_key,而官方并没有提供接口来获取这个key。从而导致CVS后台获取到的并不是完整的播放地址。
EasyCVS后台地址:https://vgm-video-play.vitasoy-chn.com/Vitasoy-Video/stream104.m3u8
实际播放地址:https://vgm-video-play.vitasoy-chn.com/Vitasoy-Video/stream104.m3u8?auth_key=1627356318-0-0-587ed891911a07498771faaa5ea74da8
解决该问题可以有三种方法:
方法1:将接入阿里的视频源都同一修改为H264编码;
方法2:设置阿里后台的直播地址和录像为公共读模式;
方法3:后台根据API返回数据,自行计算auth_key;
auth_key计算Go语言代码示例:
func md5sum(src string) string {
h := md5.New()
h.Write([]byte(src))
return hex.EncodeToString(h.Sum(nil))
}
func a_auth(uri, key string, exp int64) string {
p, err := regexp.Compile("^(rtmp://)?([^/?]+)(/[^?]*)?(\\?.*)?$")
if err != nil {
fmt.Println(err)
return ""
}
m := p.FindStringSubmatch(uri)
var scheme, host, path, args string
if len(m) == 5 {
scheme, host, path, args = m[1], m[2], m[3], m[4]
} else {
scheme, host, path, args = "rtmp://", "", "/", ""
}
rand := "0" // "0" by default, other value is ok
uid := "0" // "0" by default, other value is ok
sstring := fmt.Sprintf("%s-%d-%s-%s-%s", path, exp, rand, uid, key)
hashvalue := md5sum(sstring)
auth_key := fmt.Sprintf("%d-%s-%s-%s", exp, rand, uid, hashvalue)
if len(args) != 0 {
return fmt.Sprintf("%s%s%s%s&auth_key=%s", scheme, host, path, args, auth_key)
} else {
return fmt.Sprintf("%s%s%s%s?auth_key=%s", scheme, host, path, args, auth_key)
}
}
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。