from moviepy.editor import VideoFileClip import cv2 # load the video clip clip = VideoFileClip("video.mp4") # iterate through the frames for frame in clip.iter_frames(): # display each frame on screen cv2.imshow('frame', frame) cv2.waitKey(25) # release the video stream and close the window clip.reader.close() cv2.destroyAllWindows()
from moviepy.editor import VideoFileClip import os # load the video clip clip = VideoFileClip("video.mp4") # create a directory to store the frames if not os.path.exists("frames"): os.makedirs("frames") # iterate through the frames for i, frame in enumerate(clip.iter_frames()): # save each frame as an image file filename = os.path.join("frames", f"frame_{i}.jpg") cv2.imwrite(filename, frame) # release the video stream clip.reader.close()In this example, we load a video clip and create a directory to store each frame as an image file. We then iterate through each frame using the `iter_frames` method and save each frame as an image file using the OpenCV library. Package Library: moviepy.editor