python生成阿里云云直播推流播流地址

申请一个阿里云账号,进入控制台,添加云直播工能,就可以获得相关数据,

直接上代码,阿里云接口文档https://cloud.tencent.com/document/product/267/7977

key = 
streamId = "cc84ab712d"
str_time = '2018-09-12 23:59:59' 过期时间
bizId = 31482   直播码
#以上参数,都是腾讯云直播开通后,官方提供的

# 防盗链的key
def get_txSecret(key, livecode, str_time):
    struck_time = time.strptime(str_time, "%Y-%m-%d %H:%M:%S")
    unix_time = int(time.mktime(struck_time))
    txTime = hex(unix_time)[2:].upper()
    print(txTime)
    tx = hashlib.md5()
    tx.update((key + livecode + txTime).encode(encoding='utf-8'))

    return tx.hexdigest(), txTime

# 生成推流地址
def getPushUrl(self,bizId, streamId, key=None, str_time=None):
    self.livecode = str(bizId) + '_' + streamId
    if key and time:
        txSecret, txTime = Utils.get_txSecret(key, self.livecode, str_time)
        return 'rtmp://{}.livepush.myqcloud.com/live/{}?bizid={}&txSecret={}&txTime={}'.format(bizId, self.livecode,bizId,txSecret, txTime)
    else:
        return 'rtmp://{}.livepush.myqcloud.com/live/{}?bizid={}'.format(bizId, self.livecode, bizId)

# 生成播放地址
def getPlayUrl(self,bizId, streamId):
    # livecode = str(bizId) + '_' + streamId
    PlayUrls = [
        'rtmp://{}.liveplay.myqcloud.com/live/{}'.format(bizId, self.livecode),
        'http://{}.liveplay.myqcloud.com/live/{}.flv'.format(bizId, self.livecode),
        'http://{}.liveplay.myqcloud.com/live/{}.m3u8'.format(bizId, self.livecode)
    ]
    return PlayUrls

猜你喜欢

转载自www.cnblogs.com/zzy-9318/p/9832987.html