Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/diffusers/utils/loading_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 14 additions & 1 deletion tests/others/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
Loading