欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

m3u8 文件后缀 jpg、png 等处理方法与视频合并

最编程 2024-06-10 08:53:35
...
# 解析伪装成png的ts def resolve_ts(src_path, dst_path): ''' 如果m3u8返回的ts文件地址为 https://p1.eckwai.com/ufile/adsocial/7ead0935-dd4f-4d2f-b17d-dd9902f8cc77.png 则需要下面处理后 才能进行合并 原因在于 使用Hexeditor打开后,发现文件头被描述为了PNG 在这种情况下,只需要将其中PNG文件头部分全部使用FF填充,即可处理该问题 :return: ''' if not os.path.exists(dst_path): os.mkdir(dst_path) file_list = sorted(os.listdir(src_path), key=lambda x: int(x.split('.')[0])) for i in file_list: origin_ts = os.path.join(src_path, i) resolved_ts = os.path.join(dst_path, i) try: infile = open(origin_ts, "rb") # 打开文件 outfile = open(resolved_ts, "wb") # 内容输出 data = infile.read() outfile.write(data) outfile.seek(0x00) outfile.write(b'\xff\xff\xff\xff') outfile.flush() infile.close() # 文件关闭 outfile.close() except: pass """ else: # 删除目录 shutil.rmtree(src_path) # 将副本重命名为正式文件 os.rename(dst_path, dst_path.rstrip('2')) """ print('resolve ' + origin_ts + ' success')

推荐阅读