23、合并多个ts文件
<pre><code>copy /b "000000.ts"+"000001.ts"+"000002.ts"+"000003.ts"+"000004.ts" new.mp4
</code></pre>
<p>可以复制到 .bat文件内 ,双击 把当前目录下这几个文件合并为一个</p>
<p>可以用python脚本</p>
<pre><code>import os
import time
def merge(t,cmd):
time.sleep(t)
res=os.popen(cmd)
print(res.read())
url = '\"000000.ts\"'
for i in range(1, 5):
url_1 = '\"%06d.ts\"' % i
url = url + '+' + url_1
print(url)
print("copy /b " + url+ " new.mp4")
merge(5,"copy /b " + url+ " new.mp4")</code></pre>
<pre><code>"000000.ts"+"000001.ts"+"000002.ts"+"000003.ts"+"000004.ts"
copy /b "000000.ts"+"000001.ts"+"000002.ts"+"000003.ts"+"000004.ts" new.mp4
000000.ts
000001.ts
000002.ts
000003.ts
000004.ts
1 file(s) copied.
</code></pre>
<p>建议写到python文件内,然后在命令行运行</p>
<pre><code>E:\work\mp4>python merge.py</code></pre>
<pre><code>import os
import time
def merge(t,cmd):
time.sleep(t)
res=os.popen(cmd)
print(res.read())
url = '\"000000.ts\"'
for i in range(1, 416):
url_1 = '\"%06d.ts\"' % i
url = url + '+' + url_1
print(url)
print("copy /b " + url+ " new.mp4")
merge(5,"copy /b " + url+ " new.mp4")</code></pre>
<h2>多线程下载</h2>
<pre><code># https://www.88ys.cc/vod-play-id-58547-src-1-num-1.html 电影地址
import requests
import os
import time
from multiprocessing import Pool
def run(i):
url = 'http://vedio.leiphone.com/4AZBKpkM7ytiEV7zrT_3N6ovM64=/loWdooQlyH_CDgR759d0B92XWCRt/%06d.ts' % i
print("开始下载:"+url)
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.92 Safari/537.36"}
r = requests.get(url, headers = headers)
# print(r.content)
abc = './mp4{}'.format(url[-10:])
print(abc)
with open('./mp4{}'.format(url[-10:]),'wb') as f:
f.write(r.content)
def merge(t,cmd):
time.sleep(t)
res=os.popen(cmd)
print(res.read())
def teurl():
for i in range(0,20):
url = '/%06d.ts' % i
print(url)
if __name__ == '__main__':
# teurl()
# 创建进程池,执行10个任务
# pool = Pool(10)
# for i in range(5,416):
# pool.apply_async(run, (i,)) #执行任务
# pool.close()
# pool.join()
# #调用合并
# # 把 MP4 文件夹下所有ts文件合并为 new.MP4
url = '\"E:\\work\\000000.ts\"'
for i in range(1, 416):
url_1 = '\"E:\\work\\%06d.ts\"' % i
url = url + '+' + url_1
print(url)
print("copy /b " + url+ " new.mp4")
merge(5,"copy /b " + url+ " new.mp4")
print('ok!处理完成')
</code></pre>