将视频分解为帧序列
# -*- coding: utf-8 -*-
# @Time : 2022/6/23 15:54
# @Author : lc
# @File : video_to_frame.py
# @Software: PyCharm
# @Function: Break video to sequence of frames
import cv2
def video_to_frame(video_path, save_dir):
videoCapture = cv2.VideoCapture()
videoCapture.open(video_path)
fps = videoCapture.get(cv2.CAP_PROP_FPS)
frames = videoCapture.get(cv2.CAP_PROP_FRAME_COUNT)
print("fps=", int(fps), "frames=", int(frames))
for i in range(int(frames)):
ret, frame = videoCapture.read()
cv2.imwrite(save_dir + str(i).zfill(5) + ".jpg", frame)
return
if __name__ == '__main__':
video_path = r"./video/0163.mp4"
save_dir = r"./com/"
video_to_frame(video_path, save_dir)
print("Completed !")