diff --git a/scripts/sampling/simple_video_sample.py b/scripts/sampling/simple_video_sample.py index 29a8b8581..8d0a690af 100644 --- a/scripts/sampling/simple_video_sample.py +++ b/scripts/sampling/simple_video_sample.py @@ -164,6 +164,8 @@ def sample( with Image.open(input_img_path) as image: if image.mode == "RGBA": input_image = image.convert("RGB") + else: + input_image = image.copy() w, h = image.size if h % 64 != 0 or w % 64 != 0: @@ -270,8 +272,20 @@ def denoiser(input, sigma, c): .numpy() .astype(np.uint8) ) + frames = [frame for frame in vid] video_path = os.path.join(output_folder, f"{base_count:06d}.mp4") - imageio.mimwrite(video_path, vid) + fourcc = cv2.VideoWriter_fourcc(*'mp4v') # Specify the codec for MP4 + + # Step 3: Create a VideoWriter object + video_writer = cv2.VideoWriter(video_path, fourcc, fps_id, (w,h)) + + # Step 4: Write frames to the video + for frame in frames: + video_writer.write(frame[..., ::-1]) # Write each frame to the video and convert to BGR + + # Step 5: Release the VideoWriter + video_writer.release() + def get_unique_embedder_keys_from_conditioner(conditioner):