今天就跟大家聊聊有關(guān)利用python如何將m3u8視頻合成文MP4文件,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。
創(chuàng)新互聯(lián)是一家企業(yè)級云計算解決方案提供商,超15年IDC數(shù)據(jù)中心運營經(jīng)驗。主營GPU顯卡服務器,站群服務器,四川主機托管,海外高防服務器,大帶寬服務器,動態(tài)撥號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")