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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM