Concatenate the files present in .m3u8 in python

梦想与她 提交于 2019-12-05 03:58:35

问题


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


回答1:


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)


来源:https://stackoverflow.com/questions/22377674/concatenate-the-files-present-in-m3u8-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!