out = None
pbar = tqdm(total=total_frames, desc="转换进度", unit="帧") # total 未知时可省略
while cap.isOpened():
flag, frame = cap.read()
if not flag:
break
# ... 生成 out_image (numpy BGR) ...
if out is None:
fourcc = cv2.VideoWriter_fourcc(*"mp4v")
out = cv2.VideoWriter(opt.output, fourcc, fps,
(out_image.shape[1], out_image.shape[0]))
out.write(out_image)
pbar.update(1)
pbar.close()
cap.release()
if out is not None:
out.release()