python合并大量ts文件成mp4格式(ps:上限是450,亲测)
1 import os 2 #exec_str = r'copy /b ts/c9645620628078.ts+ts/c9645620628079.ts ts/1.ts' 3 #os.system(exec_str) 4 f = open('index.m3u8', 'r', encoding='utf-8') 5 text_list = f.readlines() 6 files = [] 7 for i in text_list: 8 if i.find('#EX')==-1: 9 files.append(i) 10 11 f.close() 12 13 14 tmp = [] 15 for file in files[0:450]: 16 tmp.append(file.replace("\n","")) 17 # 合并ts文件 18 os.chdir("ts/") 19 shell_str = '+'.join(tmp) 20 #print(shell_str) 21 shell_str = 'copy /b '+ shell_str + ' 5.mp4' 22 23 os.system(shell_str) 24 print(shell_str)
耐得住寂寞,才能登得顶
Gitee码云:https://gitee.com/lyc96/projects