Python: Get Frames from the Video with OpenCV
作者:XD / 发表: 2022年4月20日 00:57 / 更新: 2022年4月20日 01:02 / 编程笔记 / 阅读量:1153
Python: Get Frames from the Video with OpenCV
import os
import cv2
video_path = "test.mp4"
video_name = os.path.basename(video_path)
cap = cv2.VideoCapture(video_path)
save_dir = os.path.join('./result', video_name)
success, frame = cap.read()
frame_index = 1
save_format = 'img{:06d}.jpg'
while success:
frame_path = os.path.join(save_dir, save_format.format(frame_index))
cv2.imwrite(frame_path, frame)
frame_index += 1
success, frame = cap.read()