You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
556 B
24 lines
556 B
import cv2
|
|
import os
|
|
|
|
# 创建输出文件夹
|
|
output_folder = "frames"
|
|
os.makedirs(output_folder, exist_ok=True)
|
|
|
|
# 打开视频文件
|
|
video = cv2.VideoCapture("./Movie/vid_0.mov")
|
|
frame_count = 0
|
|
|
|
while video.isOpened():
|
|
ret, frame = video.read()
|
|
if not ret:
|
|
break
|
|
|
|
# 保存帧为 PNG 图片
|
|
frame_path = os.path.join(output_folder, f"frame_{frame_count:04d}.png")
|
|
cv2.imwrite(frame_path, frame)
|
|
frame_count += 1
|
|
|
|
# 释放资源
|
|
video.release()
|
|
print(f"Saved {frame_count} frames to {output_folder}") |