diff --git a/src/diffusers/utils/loading_utils.py b/src/diffusers/utils/loading_utils.py index ba528c7f857c..9d729d31157c 100644 --- a/src/diffusers/utils/loading_utils.py +++ b/src/diffusers/utils/loading_utils.py @@ -143,6 +143,8 @@ def load_video( if convert_method is not None: pil_images = convert_method(pil_images) + else: + pil_images = [image.convert("RGB") for image in pil_images] if return_fps: if fps is None: diff --git a/tests/others/test_utils.py b/tests/others/test_utils.py index 0341623d8783..a9df31befdf1 100755 --- a/tests/others/test_utils.py +++ b/tests/others/test_utils.py @@ -17,11 +17,12 @@ import os import warnings +import PIL.Image import pytest import torch from diffusers import __version__ -from diffusers.utils import deprecate, torch_utils +from diffusers.utils import deprecate, load_video, torch_utils from diffusers.utils.torch_utils import TorchDeviceBackend, empty_device_cache, get_device from ..testing_utils import CaptureLogger, Expectations, str_to_bool @@ -372,6 +373,18 @@ def check(value, key): expectations.find_expectation(("xpu", None)) +class TestLoadVideo: + def test_gif_frames_are_rgb(self, tmp_path): + # Pillow decodes the first GIF frame as "P" and later frames as "RGB" + frames = [PIL.Image.new("RGB", (8, 8), color) for color in ("red", "green", "blue")] + path = str(tmp_path / "video.gif") + frames[0].save(path, save_all=True, append_images=frames[1:], duration=100) + + video = load_video(path) + + assert [frame.mode for frame in video] == ["RGB", "RGB", "RGB"] + + def parse_flag_from_env(key, default=False): try: value = os.environ[key]