新网创想网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
今天就跟大家聊聊有关利用python如何将m3u8视频合成文MP4文件,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
创新互联是一家企业级云计算解决方案提供商,超15年IDC数据中心运营经验。主营GPU显卡服务器,站群服务器,四川主机托管,海外高防服务器,大带宽服务器,动态拨号VPS,海外云手机,海外云服务器,海外服务器租用托管等。代码如下所示:
import os import requests import datetime from Crypto.Cipher import AES def decode_key_file(key_file_name): with open(key_file_name,"r") as f: data=f.read() return data def decode_m_file(m_file_name): with open(m_file_name,"r") as f: data=f.read() return data.split("\n")[6::2] def decode_video(filename): data_list=[[],[],[]] file_list=os.listdir(filename) for one_file_name in file_list: if "m3u8" in one_file_name: data_list[0].append(filename+"/"+one_file_name) elif "key" in one_file_name: data_list[1].append(filename + "/" + one_file_name) else: data_list[2].append(filename + "/" + one_file_name) key=decode_key_file(data_list[1][0]) name_list=decode_m_file(data_list[0][0]) for one_name in name_list: for path_name in data_list[2]: if one_name in path_name: with open(path_name,"rb") as f: data_name=f.read() if len(key): # AES 解密 cryptor = AES.new(key, AES.MODE_CBC, key) with open(key + ".mp4", 'ab') as f: f.write(cryptor.decrypt(data_name)) if __name__ == '__main__': decode_video("./data")