python合成m3u8文件,串联python中.m3u8中存在的文件

I am trying to concatenate .ts files present in a .m3u8 playlist in python,

Is there any way of doing it ??? If yes please do explain how

Thanks in advance

解决方案

This should work, I only added two comments to this short script cause I guess it's pretty much self-explanatory.

import shutil

# Parse playlist for filenames with ending .ts and put them into the list ts_filenames

with open('playlist.m3u8', 'r') as playlist:

ts_filenames = [line.rstrip() for line in playlist

if line.rstrip().endswith('.ts')]

# open one ts_file from the list after another and append them to merged.ts

with open('merged.ts', 'wb') as merged:

for ts_file in ts_filenames:

with open(ts_file, 'rb') as mergefile:

shutil.copyfileobj(mergefile, merged)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值