合并视频报错,合并出会出现声画不同步,或画面卡顿现象
个人解决办法:
排查发现,copy命令最大支持301个.ts文件合并, 超出会报错
故压缩列表,将数量比较大的.ts数据, 以N(N<=301)个为一组合并添加到新的列表 ,再使用
s = '+'.join(新的.ts列表)
print(os.system(f'copy /b {s} movie.mp4')) 进行合并,如下图,仅供思路参考
def zip_ts_lst(lst, files):
"""
:param lst: 需要压缩的.ts文件列表
:param files: 当前路径下存放压缩后的.ts文件夹名称
:return:
"""
# copy命令最大支持301个.ts文件合并, 超出会报错!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# # 压缩列表,将数量比较大的.ts数据, 以N个为一组合并添加到新的列表
zip_lst = []
# lst最大索引位
max_index = len(lst) - 1
star, end = 0, 301
while True:
# 压缩后的.ts文件命名
zip_temp_ts = f'zip_temp_{end}.ts'
# 如果结束索引位大于最大索引为
if end > max_index:
last_step = max_index - end
end += last_step
new_lst = lst[star: end]
new_lst = ' + '.join(new_lst)
new_lst = new_lst.replace('/', r'\\')
os.system(fr'copy /b {new_lst} {files}\\{zip_temp_ts}')
zip_lst.append(fr'{files}\\{zip_temp_ts}')
break
new_lst = lst[star: end]
new_lst = ' + '.join(new_lst)
new_lst = new_lst.replace('/', r'\\')
os.system(fr'copy /b {new_lst} {files}\\{zip_temp_ts}')
zip_lst.append(fr'{files}\\{zip_temp_ts}')
star = end
end += 301
return zip_lst
def merge_ts():
# mac : cat 1.ts 2.ts > xxx.mp4 使用空格隔开
# window : copy /b 1.ts+2.ts+3.ts xxx.mp4
lst = []
with open('second_视频爬取.txt', mode='r', encoding='utf-8') as f:
for line in f:
if line.startswith('#'):
continue
line = line.strip()
line = line.split('/hls/')[-1]
lst.append(fr'video1/temp_{line}')
zip_lst = zip_ts_lst(lst, 'video3')
s = ' + '.join(zip_lst)
s = s.replace('/', r'\\')
os.system('chcp 65001')
os.system(fr'copy /b {s} movie.mp4')
这种方法有点呆,但是解决目前的问题,够用了。一时之间,没有特别好的办法,望大神赐教