windows 合并视频,os.system报错\合并出的视频卡顿出现声画不同步

合并视频报错,合并出会出现声画不同步,或画面卡顿现象 

个人解决办法:

排查发现,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')

这种方法有点呆,但是解决目前的问题,够用了。一时之间,没有特别好的办法,望大神赐教

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值