Zulko / moviepy

Video editing with Python
https://zulko.github.io/moviepy/
MIT License
12.09k stars 1.51k forks source link

Cannot resize clip #2069

Closed Alexciao closed 7 months ago

Alexciao commented 7 months ago
  File "D:\Coding\Python\Videofarm\video\editor.py", line 19, in background_clip
    cropped = cut.resize(height=1920)
  File "D:\Coding\Python\Videofarm\venv\lib\site-packages\moviepy\video\fx\resize.py", line 152, in resize
    newclip = clip.fl_image(fl)
  File "D:\Coding\Python\Videofarm\venv\lib\site-packages\moviepy\video\VideoClip.py", line 490, in fl_image
    return self.fl(lambda gf, t: image_func(gf(t)), apply_to)
  File "D:\Coding\Python\Videofarm\venv\lib\site-packages\moviepy\Clip.py", line 136, in fl
    newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))
  File "<decorator-gen-61>", line 2, in set_make_frame
  File "D:\Coding\Python\Videofarm\venv\lib\site-packages\moviepy\decorators.py", line 14, in outplace
    f(newclip, *a, **k)
  File "D:\Coding\Python\Videofarm\venv\lib\site-packages\moviepy\video\VideoClip.py", line 644, in set_make_frame
    self.size = self.get_frame(0).shape[:2][::-1]
  File "<decorator-gen-11>", line 2, in get_frame
  File "D:\Coding\Python\Videofarm\venv\lib\site-packages\moviepy\decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "D:\Coding\Python\Videofarm\venv\lib\site-packages\moviepy\Clip.py", line 93, in get_frame
    return self.make_frame(t)
  File "D:\Coding\Python\Videofarm\venv\lib\site-packages\moviepy\Clip.py", line 136, in <lambda>
    newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))
  File "D:\Coding\Python\Videofarm\venv\lib\site-packages\moviepy\video\VideoClip.py", line 490, in <lambda>
    return self.fl(lambda gf, t: image_func(gf(t)), apply_to)
  File "D:\Coding\Python\Videofarm\venv\lib\site-packages\moviepy\video\fx\resize.py", line 150, in <lambda>
    fl = lambda pic: resizer(pic.astype('uint8'), newsize)
  File "D:\Coding\Python\Videofarm\venv\lib\site-packages\moviepy\video\fx\resize.py", line 37, in resizer
    resized_pil = pilim.resize(newsize[::-1], Image.ANTIALIAS)
AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS'

Process finished with exit code 1

Expected Behavior

The clip resizes as normal.

Actual Behavior

This crashes because of an AttributeError.

Steps to Reproduce the Problem

Here's my code. It crashes when I try to resize the clip.

def background_clip_a(video_file, audio_file, duration):
    video = mp.VideoFileClip(video_file)
    audio = mp.AudioFileClip(audio_file)

    # Cut out the intro
    no_intro = video.subclip(45, video.duration)

    # Get a random piece of the clip that is the desired duration
    start_time = randint(0, int(no_intro.duration))
    cut = no_intro.subclip(start_time, start_time + duration)

    # Crop the clip to be vertical
    cropped = cut.resize(height=1920) # <--- Here is the crash.
    cropped = cropped.crop(x1=1166.6, y1=0, x2=2246.6, y2=1920)

    # Add the audio
    audio = audio.subclip(0, cropped.duration)
    audio = audio.volumex(0.15)
    video = cropped.set_audio(audio)

    output_filename = "tmp/background.mp4"
    video.write_videofile(output_filename, codec="libx264", audio_codec="aac")

    return output_filename

Specifications

Alexciao commented 7 months ago

I also tried with Py 3.11 and Py 3.12 but same thing

shaiunterslak commented 7 months ago

Also had this issue

Alexciao commented 7 months ago

@shaiunterslak I found a fix. In your requirements.txt file just add pillow==9.5.0 or install pillow version 9.5.0 with Pip. The latest version, 10.0.0, removed some constants.

Alexciao commented 7 months ago

This issue is fixed