Saving video using moviepy from an array of images and fps value results in much too fast fps on playback

Viewed 558

I'm trying to read a video as an image array using moviepy so that I can edit the data and save it back to a video file, but I'm running into an issue when saving a video file from an array of images data.

Here is my code:

from moviepy.editor import *


# read video
path = "path/to/video.mp4"
clip = VideoFileClip(path)

# get video as an array of images:
nframes = clip.reader.nframes
frames = []
for i in range(nframes):
   frames.append(clip.get_frame(i))
fps = clip.fps

# save video
save_path = "save/path/video.mp4"
clip = ImageSequenceClip(frames, fps=fps)
clip.write_videofile(save_path, fps=fps)

This produces a video file at the save path containing all the video frames, but it plays ridiculously fast, like the fps is much higher than the actual fps. Calling for the fps value with print(fps) returns 30.

What is going wrong here? Thank you in advance you all your kind help!

1 Answers

Answer

The method clip.get_frame(i) returns a frame at the i'th second, not the i'th frame. I assume you're only getting 3.33% (1second/30fps) of your frames, resulting in 30x speed.

Related