I got this error

#67
by gammie12 - opened

ValueError Traceback (most recent call last)
in <cell line: 18>()
16
17 # convent to video
---> 18 video_path = export_to_video(video_frames)

/usr/local/lib/python3.10/dist-packages/diffusers/utils/export_utils.py in export_to_video(video_frames, output_video_path, fps)
133
134 fourcc = cv2.VideoWriter_fourcc(*"mp4v")
--> 135 h, w, c = video_frames[0].shape
136 video_writer = cv2.VideoWriter(output_video_path, fourcc, fps=fps, frameSize=(w, h))
137 for i in range(len(video_frames)):

ValueError: too many values to unpack (expected 3)

I have the same error. It probably has to do with the version of the torch or diffusers package...

There are inconsistencies with what diffusers expects. export_to_video is legacy and you will have to write your own exporter.

This worked for me:

import imageio # pip install imageio[ffmpeg]
import numpy as np
from PIL import Image

def convert_and_save_images_as_video(image_array, fps, output_file='generated.mp4'):
    writer = imageio.get_writer(output_file, fps=fps, codec='libx264')

    for img in image_array:
        # Convert the image from the 0-1 range to 0-255 range and cast to uint8
        img = (img * 255).astype(np.uint8)
        
        # Ensure the image has 3 channels (RGB)
        if len(img.shape) == 2:  # If grayscale, convert to RGB
            img = np.stack([img]*3, axis=-1)
        elif img.shape[-1] == 1:  # If single channel, convert to RGB
            img = np.repeat(img, 3, axis=-1)
        elif img.shape[-1] != 3:  # If not 3 channels, convert using PIL
            img = Image.fromarray(img).convert("RGB")
            img = np.array(img)

        # Append the image to the video
        writer.append_data(img)

    # Close the writer to save the video
    writer.close()

Sign up or log in to comment