在python中连接.m3u8中存在的文件

在python中连接.m3u8中存在的文件,python,concatenation,m3u8,Python,Concatenation,M3u8,我试图用python连接.m3u8播放列表中的.ts文件 有什么办法吗???如果是,请说明如何进行 提前感谢这应该行得通,我只在这个简短的脚本中添加了两条注释,因为我想这几乎是不言自明的 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_fi

我试图用python连接.m3u8播放列表中的.ts文件

有什么办法吗???如果是,请说明如何进行


提前感谢

这应该行得通,我只在这个简短的脚本中添加了两条注释,因为我想这几乎是不言自明的

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)

你到底想连接什么。ts文件是mpeg-2流,而.m3u8是文本文件?我想连接.ts文件,它们是视频文件。如果有任何帮助,将不胜感激。嘿,感谢您的回复…我正在使用的m3u8文件作为链接联机…这与此解决方案不起作用….:/well….我能够解决此问题…但您能否告诉我…..合并的.ts将保存在何处?它将保存到启动脚本的目录中。但是您可以自由指定路径,只需注意在windows上使用原始字符串,这样就不必逃避反斜杠。e、 g.打开(r'C:\path\to\merged.ts,'wb')。顺便说一句,如果这个答案对你有帮助的话,请你投赞成票。我不能投赞成票…没有足够的声誉…谢谢你的回答:)我认为这是不够的。从命令行连接文件不起作用。我认为您必须提取视频和音频流并重新封装它们