安装ffmpeg命令工具:
1.下载ffmpeg工具 【官网】
2.如果需要下载 7-zip解压该文件【官网】
3.解压后重名解压文件夹为ffmpeg
4.复制ffmpeg文件夹到 "C:\Program Files"
5.添加系统环境变量 “C:\Program Files\ffmpeg\bin”
6.可以通过 ffmpeg 查看
7. 对于需要合并的ts 参考如下代码ffmpeg -f concat -i mylist.txt -c copy output.mp4
下载ts合并
import requests
import time
import threading
import queue
import randomdef write_ts(start_num, end_num):for i in range(start_num,end_num):a = random.randint(1,4)print(a)time.sleep(a)url = 'https://cagnagb/aaax%s.ts' % iresponse = requests.get(url, headers=headers)with open("./ts_files/%s.ts" % i, "wb") as f:f.write(response.content)print('%s 的 %s 完成' % (threading.current_thread().name,i))def create_thread(total_num,thread_num):count_num = thread_num - 1int_num = int(total_num/count_num)mod_num = total_num%count_numevery_num = (total_num - mod_num)/count_numfor x in range(count_num):start_num = every_num*xend_num = every_num*(x + 1)num2 = x + 1threading.Thread(target=write_ts,args=(int(start_num), int(end_num)), name='t%s' % int(num2)).start()threading.Thread(target=write_ts,args=(int(every_num * count_num),int(every_num * count_num + mod_num)), name='t%s'%int(thread_num)).start()def write_mylist(num,path1):arr1 = ["file '%s.ts'" % x for x in range(num)]write_txt = r"D:\pycharm\szd_file\ts_movies\mylist.txt"with open(write_txt, "w") as file:file.write('\n'.join(arr1))print('mylist.txt写入完成,请执行命令 【ffmpeg -f concat -i mylist.txt -c copy output.mp4】')if __name__ == '__main__':headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.81 Safari/537.36'}total_num = 2308thread_num = 60threading.Lock()create_thread(total_num, thread_num)write_mylist_path = r"D:\pagcd\mylist.txt"write_mylist(total_num,write_mylist_path)