Repository: wandb/wandb
Issue category: Bug Report

Issue:
[Bug]: "wandb.Video requires moviepy when passing raw data" Error due to new moviepy version
### Describe the bug

The moviepy package was updated to 2.x and removed the `moviepy.editor` namespace (see [here](https://zulko.github.io/moviepy/getting_started/updating_to_v2.html)), breaking the `Video.encode` method. 
Fixing by either migrating to moviepy 2.x or pinning the earlier version.

Version info:
NixOS 24.05
Python 3.11.10
wandb 0.18.7
moviepy 2.1.1


Hints:

Patch:
diff --git a/wandb/sdk/data_types/video.py b/wandb/sdk/data_types/video.py
index 54e338ef2a5..41310640d6f 100644
--- a/wandb/sdk/data_types/video.py
+++ b/wandb/sdk/data_types/video.py
@@ -138,10 +138,21 @@ def __init__(
             self.encode(fps=fps)
 
     def encode(self, fps: int = 4) -> None:
-        mpy = util.get_module(
-            "moviepy.editor",
-            required='wandb.Video requires moviepy when passing raw data.  Install with "pip install wandb[media]"',
-        )
+        # Try to import ImageSequenceClip from the appropriate MoviePy module
+        mpy = None
+        try:
+            # Attempt to load moviepy.editor for MoviePy < 2.0
+            mpy = util.get_module(
+                "moviepy.editor",
+                required='wandb.Video requires moviepy when passing raw data. Install with "pip install wandb[media]"',
+            )
+        except wandb.Error:
+            # Fallback to moviepy for MoviePy >= 2.0
+            mpy = util.get_module(
+                "moviepy",
+                required='wandb.Video requires moviepy when passing raw data. Install with "pip install wandb[media]"',
+            )
+
         tensor = self._prepare_video(self.data)
         _, self._height, self._width, self._channels = tensor.shape  # type: ignore
 


Test patch: