Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid writing to disk with ImageSequenceClip #261

Closed
diakonovm opened this issue Feb 9, 2016 · 2 comments
Closed

Avoid writing to disk with ImageSequenceClip #261

diakonovm opened this issue Feb 9, 2016 · 2 comments

Comments

@diakonovm
Copy link

I am generating a significant number of images and writing them to disk. I then pass an array of the filenames to ImageSequenceClip. A major bottleneck is writing the images down to disk; is there a way to keep the images in memory then pass that to ImageSequenceClip, subsequently avoiding the time necessary to write/read to disk?

filenames = []
for i in range(0, FRAMES):
    filename = "tmp/frame_%s.png" % (i)
    filenames.append(filename)
    center_x = IMG_WIDTH / 2
    center_y = IMG_HEIGHT - ((IMG_HEIGHT - i * HEIGHT_INC) / 2) 
    width = IMG_WIDTH - i * WIDTH_INC
    height = IMG_HEIGHT - i * HEIGHT_INC
    img = vfx.crop(img_w_usr_img, x_center=center_x, y_center=center_y, width=width, height=height)
    img = img.resize( (VID_WIDTH, VID_HEIGHT) )
    img.save_frame(filename)
    print "Proccessed: %s" % (filename)

seq = ImageSequenceClip(filenames, fps=FPS)
@diakonovm
Copy link
Author

I ended up using get_frame() to get the numpy array of the image and it works much faster now.

@Zulko
Copy link
Owner

Zulko commented Feb 11, 2016

The snippet you provide doesn't allow me to give the best answer. There are many ways to do this in MoviePy, e.g. using VideoClip or ImageSequenceClip:

def make_frame(t):
    return some_numpy_array #  corresponding to the frame to display at time t

clip = VideoClip(make_frame, duration).set_fps(20)
clip.write(videofilename)

or

frames = []
for i in range(50):
    frames.append(some_frame) # some_frame is a numpy array of an image

clip = ImageSequenceClip(frames, fps=20)
clip.write(videofilename)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants