串联python中.m3u8中存在的文件 [英] Concatenate the files present in .m3u8 in python

查看:117
本文介绍了串联python中.m3u8中存在的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将python .m3u8播放列表中存在的.ts文件连接起来,

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

预先感谢

推荐答案

此应该可以使用,我只在这个简短的脚本中添加了两条注释,因为我想这几乎是不言自明的。

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)

这篇关于串联python中.m3u8中存在的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆