Zulko / moviepy

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

AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS' #2098

Closed Rhythmicc closed 4 months ago

Rhythmicc commented 5 months ago

Expected Behavior

Actual Behavior

❯ qs v2gif 2325906-matrix-cores-web-02.mp4 --qs-debug
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /opt/homebrew/lib/python3.11/site-packages/QuickStart_Rhy/main.py:45 in main                     │
│                                                                                                  │
│   42 │   │   │   │   if help_flag:                                                               │
│   43 │   │   │   │   │   return command_help(func_name)                                          │
│   44 │   │   │   │   func_table = cmd_table[func_name]                                           │
│ ❱ 45 │   │   │   │   requirePackage(func_table["self"], func_table[func_name][0])()              │
│   46 │   │   except Exception as e:                                                              │
│   47 │   │   │   from . import qs_default_console                                                │
│   48                                                                                             │
│                                                                                                  │
│ /opt/homebrew/lib/python3.11/site-packages/QuickStart_Rhy/imageDeal.py:102 in v2gif              │
│                                                                                                  │
│    99 │   else:                                                                                  │
│   100 │   │   video_2_gif(video, sz, fps) if sz and fps else video_2_gif(                        │
│   101 │   │   │   video, sz                                                                      │
│ ❱ 102 │   │   ) if sz else video_2_gif(video, fps=fps) if fps else video_2_gif(video)            │
│   103                                                                                            │
│   104                                                                                            │
│   105 def remove_audio():                                                                        │
│                                                                                                  │
│ /opt/homebrew/lib/python3.11/site-packages/QuickStart_Rhy/ImageTools/VideoTools.py:34 in wrapper │
│                                                                                                  │
│    31 │   │   │   │   f'{"No a file" if user_lang != "zh" else "不是文件"}: {path}',             │
│    32 │   │   │   )                                                                              │
│    33 │   │   mpy = requirePackage("moviepy", "editor")                                          │
│ ❱  34 │   │   func(path, *args, **kwargs, mpy=mpy)                                               │
│    35 │                                                                                          │
│    36 │   return wrapper                                                                         │
│    37                                                                                            │
│                                                                                                  │
│ /opt/homebrew/lib/python3.11/site-packages/QuickStart_Rhy/ImageTools/VideoTools.py:54 in         │
│ video_2_gif                                                                                      │
│                                                                                                  │
│    51 │   """                                                                                    │
│    52 │   file_name = ".".join(os.path.basename(path).split(".")[:-1]) + ".gif"                  │
│    53 │   dir_name = os.path.abspath(os.path.dirname(path))                                      │
│ ❱  54 │   ct = mpy.VideoFileClip(path) if not size else mpy.VideoFileClip(path).resize(size)     │
│    55 │   ct.write_gif(os.path.join(dir_name, file_name), fps=fps)                               │
│    56                                                                                            │
│    57                                                                                            │
│                                                                                                  │
│ /opt/homebrew/lib/python3.11/site-packages/moviepy/video/fx/resize.py:152 in resize              │
│                                                                                                  │
│   149 │   else:                                                                                  │
│   150 │   │   fl = lambda pic: resizer(pic.astype('uint8'), newsize)                             │
│   151 │                                                                                          │
│ ❱ 152 │   newclip = clip.fl_image(fl)                                                            │
│   153 │                                                                                          │
│   154 │   if apply_to_mask and clip.mask is not None:                                            │
│   155 │   │   newclip.mask = resize(clip.mask, newsize, apply_to_mask=False)                     │
│                                                                                                  │
│ /opt/homebrew/lib/python3.11/site-packages/moviepy/video/VideoClip.py:490 in fl_image            │
│                                                                                                  │
│    487 │   │   `get_frame(t)` by another frame,  `image_func(get_frame(t))`                      │
│    488 │   │   """                                                                               │
│    489 │   │   apply_to = apply_to or []                                                         │
│ ❱  490 │   │   return self.fl(lambda gf, t: image_func(gf(t)), apply_to)                         │
│    491 │                                                                                         │
│    492 │   # --------------------------------------------------------------                      │
│    493 │   # C O M P O S I T I N G                                                               │
│                                                                                                  │
│ /opt/homebrew/lib/python3.11/site-packages/moviepy/Clip.py:136 in fl                             │
│                                                                                                  │
│   133 │   │   │   apply_to = []                                                                  │
│   134 │   │                                                                                      │
│   135 │   │   #mf = copy(self.make_frame)                                                        │
│ ❱ 136 │   │   newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))                    │
│   137 │   │                                                                                      │
│   138 │   │   if not keep_duration:                                                              │
│   139 │   │   │   newclip.duration = None                                                        │
│ in set_make_frame:2                                                                              │
│                                                                                                  │
│ /opt/homebrew/lib/python3.11/site-packages/moviepy/decorators.py:14 in outplace                  │
│                                                                                                  │
│    11 def outplace(f, clip, *a, **k):                                                            │
│    12 │   """ Applies f(clip.copy(), *a, **k) and returns clip.copy()"""                         │
│    13 │   newclip = clip.copy()                                                                  │
│ ❱  14 │   f(newclip, *a, **k)                                                                    │
│    15 │   return newclip                                                                         │
│    16                                                                                            │
│    17 @decorator.decorator                                                                       │
│                                                                                                  │
│ /opt/homebrew/lib/python3.11/site-packages/moviepy/video/VideoClip.py:644 in set_make_frame      │
│                                                                                                  │
│    641 │   │   attribute set to `mf`.                                                            │
│    642 │   │   """                                                                               │
│    643 │   │   self.make_frame = mf                                                              │
│ ❱  644 │   │   self.size = self.get_frame(0).shape[:2][::-1]                                     │
│    645 │                                                                                         │
│    646 │   @outplace                                                                             │
│    647 │   def set_audio(self, audioclip):                                                       │
│ in get_frame:2                                                                                   │
│                                                                                                  │
│ /opt/homebrew/lib/python3.11/site-packages/moviepy/decorators.py:89 in wrapper                   │
│                                                                                                  │
│    86 │   │   │   │    for (arg, name) in zip(a, names)]                                         │
│    87 │   │   new_kw = {k: fun(v) if k in varnames else v                                        │
│    88 │   │   │   │    for (k,v) in kw.items()}                                                  │
│ ❱  89 │   │   return f(*new_a, **new_kw)                                                         │
│    90 │   return decorator.decorator(wrapper)                                                    │
│    91                                                                                            │
│    92                                                                                            │
│                                                                                                  │
│ /opt/homebrew/lib/python3.11/site-packages/moviepy/Clip.py:93 in get_frame                       │
│                                                                                                  │
│    90 │   │   │   │   self.memoized_frame = frame                                                │
│    91 │   │   │   │   return frame                                                               │
│    92 │   │   else:                                                                              │
│ ❱  93 │   │   │   return self.make_frame(t)                                                      │
│    94 │                                                                                          │
│    95 │   def fl(self, fun, apply_to=None, keep_duration=True):                                  │
│    96 │   │   """ General processing of a clip.                                                  │
│                                                                                                  │
│ /opt/homebrew/lib/python3.11/site-packages/moviepy/Clip.py:136 in <lambda>                       │
│                                                                                                  │
│   133 │   │   │   apply_to = []                                                                  │
│   134 │   │                                                                                      │
│   135 │   │   #mf = copy(self.make_frame)                                                        │
│ ❱ 136 │   │   newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))                    │
│   137 │   │                                                                                      │
│   138 │   │   if not keep_duration:                                                              │
│   139 │   │   │   newclip.duration = None                                                        │
│                                                                                                  │
│ /opt/homebrew/lib/python3.11/site-packages/moviepy/video/VideoClip.py:490 in <lambda>            │
│                                                                                                  │
│    487 │   │   `get_frame(t)` by another frame,  `image_func(get_frame(t))`                      │
│    488 │   │   """                                                                               │
│    489 │   │   apply_to = apply_to or []                                                         │
│ ❱  490 │   │   return self.fl(lambda gf, t: image_func(gf(t)), apply_to)                         │
│    491 │                                                                                         │
│    492 │   # --------------------------------------------------------------                      │
│    493 │   # C O M P O S I T I N G                                                               │
│                                                                                                  │
│ /opt/homebrew/lib/python3.11/site-packages/moviepy/video/fx/resize.py:150 in <lambda>            │
│                                                                                                  │
│   147 │   │   fl = lambda pic: 1.0*resizer((255 * pic).astype('uint8'), newsize)/255.0           │
│   148 │                                                                                          │
│   149 │   else:                                                                                  │
│ ❱ 150 │   │   fl = lambda pic: resizer(pic.astype('uint8'), newsize)                             │
│   151 │                                                                                          │
│   152 │   newclip = clip.fl_image(fl)                                                            │
│   153                                                                                            │
│                                                                                                  │
│ /opt/homebrew/lib/python3.11/site-packages/moviepy/video/fx/resize.py:37 in resizer              │
│                                                                                                  │
│    34 │   │   │   │   newshape = (newsize[0],newsize[1])                                         │
│    35 │   │   │                                                                                  │
│    36 │   │   │   pilim = Image.fromarray(pic)                                                   │
│ ❱  37 │   │   │   resized_pil = pilim.resize(newsize[::-1], Image.ANTIALIAS)                     │
│    38 │   │   │   #arr = np.fromstring(resized_pil.tostring(), dtype='uint8')                    │
│    39 │   │   │   #arr.reshape(newshape)                                                         │
│    40 │   │   │   return np.array(resized_pil)                                                   │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS'

Steps to Reproduce the Problem

Specifications

Rhythmicc commented 5 months ago

I have noticed #2057, now it solved!

keikoro commented 4 months ago

Is this a duplicate of the other issue, can it be closed?

keikoro commented 4 months ago

Closing this as duplicate of #2072, which seems to be the only ticket referencing the library's actual release notes.