简体   繁体   中英

MoviePy shows frames as tiles across video

I have this weird bug with moviePy. I'm creating a video using VideoClip where frames are defined using numpy arrays.

For the example, I'm using a single frame that looks like this (when printed with matplotlib)

plt.imshow(frame)
plt.show()

在此处输入图片说明

When I create a video using only this frame, it looks like this:

def get_frame(t):
    return frame

animation = VideoClip(get_frame, duration=3)
animation.ipython_display(fps=3, codec='mpeg4')

在此处输入图片说明

Why does moviepy repeat the frame instead of stretching it?

I've tried playing with the video size etc, but nothing changed.


Here's the whole code:

from moviepy.editor import VideoClip
import numpy as np

frame = np.zeros([400, 400])
frame[10:40,50:80] = 100

plt.imshow(frame)
plt.show()

def get_frame(t):
    return frame

animation = VideoClip(get_frame, duration=3)
animation.ipython_display(fps=3, codec='mpeg4')

I've found the problem: The numpy array should be 3D and what I had was 1D. Fixing this solved it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM