【python小工具】seq文件提取jpg图片

it2024-11-03  4

import os def seq2jpg(seq_root): """逐级遍历,将所有seq转换成jpg""" def _seq2jpg(seq_path): """转换单个seq文件""" with open(seq_path, 'rb') as f: seq = f.read() # 图片bytes头 header = b"\xFF\xD8\xFF\xE0\x00\x10\x4A\x46\x49\x46" img_ls = seq.split(header)[1:] # 去掉第1个 # 保存在当前路径,新建同名文件夹 save_dir = seq_path[:-4] if not os.path.exists(save_dir): os.mkdir(save_dir) for n, img in enumerate(img_ls): img_path = os.path.join(save_dir, '%d.jpg' % n) with open(img_path, 'wb') as f: f.write(header + img) # 遍历seq_root下所有目录和文件 for parent, _, filenames in os.walk(seq_root): for filename in filenames: # seq格式 if filename[-4:] == '.seq': seq_path = os.path.join(parent, filename) _seq2jpg(seq_path)
最新回复(0)