Lonely Guy
Lonely Guy

Reputation: 11

How to extract all the frames from a video?

Hey so I wanted to know how I can extract all frames from a vide using MoviePy Currently I am doing it in open-cv which is really really slow. My current code :-

vidObj = cv2.VideoCapture("./video.mp4")
count = 0
flag = 1
while flag:
    flag, image = vidObj.read()
    try:
        cv2.imwrite(f"./images/frame{count}.jpg", image)
    except:
        break
    count += 1

Can someone tell me how to achieve the same in MoviePy please?

Upvotes: 1

Views: 2276

Answers (1)

Jan Ochwat
Jan Ochwat

Reputation: 82

You can use the write_images_sequence() method.

%05d represents a 5 digit frame index.

from moviepy.editor import VideoFileClip

video = VideoFileClip('video.mp4')
video.write_images_sequence('frame%05d.png', logger='bar')

Upvotes: 2

Related Questions