Numpy Deprecation Warning During Reshape
Expected Behavior
Reading a frame from a video (e.g. via VideoFileClip.get_frame()) should not emit any warnings on a supported, up-to-date numpy version.
Actual Behavior
Every raw-frame decode emits a DeprecationWarning on numpy >= 2.5:
moviepy/video/io/ffmpeg_reader.py:228: DeprecationWarning: Setting the shape on a NumPy array has been deprecated in NumPy 2.5.
As an alternative, you can create a new view using np.reshape (with copy=False if needed).
result.shape = (h, w, len(s) // (w * h)) # reshape((h, w, len(s)//(w*h)))The cause is FFMPEG_VideoReader.read_frame() in moviepy/video/io/ffmpeg_reader.py, which assigns directly to ndarray.shape instead of using np.reshape/.reshape():
result.shape = (h, w, len(s) // (w * h)) # reshape((h, w, len(s)//(w*h)))numpy 2.5 deprecated in-place shape assignment on arrays; a future numpy release is expected to turn this into a hard error. Since this line runs on every frame decode, it's the single most-triggered warning across the whole test suite (it showed up in every test that reads real video frames).
Suggested fix — replace the in-place assignment with a reshape call:
result = result.reshape((h, w, len(s) // (w * h)))Steps and code to Reproduce the Problem
This is self-contained — it generates its own tiny video, so no external media is needed:
import warnings
warnings.simplefilter("always")
from moviepy import ColorClip, VideoFileClip
clip = ColorClip((64, 64), color=(255, 0, 0), duration=1)
clip.write_videofile("repro.mp4", fps=24, logger=None)
reader_clip = VideoFileClip("repro.mp4")
frame = reader_clip.get_frame(0) # <-- DeprecationWarning fires here
print("frame shape:", frame.shape)Output:
C:\...\moviepy\video\io\ffmpeg_reader.py:228: DeprecationWarning: Setting the shape on a NumPy array has been deprecated in NumPy 2.5.
As an alternative, you can create a new view using np.reshape (with copy=False if needed).
result.shape = (h, w, len(s) // (w * h)) # reshape((h, w, len(s)//(w*h)))
frame shape: (64, 64, 3)Used medias
None — the reproduction script above generates its own test video via ColorClip.write_videofile().
Specifications
- Python Version: 3.14.5
- MoviePy Version: 2.2.0
- Platform Name: Windows
- Platform Version: Windows 11, build 10.0.26200 (numpy 2.5.1)
Source: Zulko/moviepy