From 71bf1bd4fa99a61242f5f3b0282cb2098bdf4923 Mon Sep 17 00:00:00 2001 From: JPABotermans <45882689+JPABotermans@users.noreply.github.com> Date: Wed, 25 Sep 2024 22:58:05 +0200 Subject: [PATCH 1/4] Solved bug where input_image wasn't yet defined/ --- scripts/sampling/simple_video_sample.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/sampling/simple_video_sample.py b/scripts/sampling/simple_video_sample.py index 29a8b8581..cb01abc32 100644 --- a/scripts/sampling/simple_video_sample.py +++ b/scripts/sampling/simple_video_sample.py @@ -168,7 +168,10 @@ def sample( if h % 64 != 0 or w % 64 != 0: width, height = map(lambda x: x - x % 64, (w, h)) - input_image = input_image.resize((width, height)) + if image.mode == "RGBA": + input_image = input_image.resize((width, height)) + else: + input_image = image.resize((width, height)) print( f"WARNING: Your image is of size {h}x{w} which is not divisible by 64. We are resizing to {height}x{width}!" ) From c98aa7e587b7608fb2c5ff2297508b47d118edae Mon Sep 17 00:00:00 2001 From: JPABotermans <45882689+JPABotermans@users.noreply.github.com> Date: Thu, 26 Sep 2024 01:04:37 +0200 Subject: [PATCH 2/4] Changed from imagio to cv2 --- scripts/sampling/simple_video_sample.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/scripts/sampling/simple_video_sample.py b/scripts/sampling/simple_video_sample.py index cb01abc32..a61ff0a1d 100644 --- a/scripts/sampling/simple_video_sample.py +++ b/scripts/sampling/simple_video_sample.py @@ -168,10 +168,7 @@ def sample( if h % 64 != 0 or w % 64 != 0: width, height = map(lambda x: x - x % 64, (w, h)) - if image.mode == "RGBA": - input_image = input_image.resize((width, height)) - else: - input_image = image.resize((width, height)) + input_image = input_image.resize((width, height)) print( f"WARNING: Your image is of size {h}x{w} which is not divisible by 64. We are resizing to {height}x{width}!" ) @@ -273,8 +270,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, (width, height)) + + # Step 4: Write frames to the video + for frame in frames: + video_writer.write(frame) # Write each frame to the video + + # Step 5: Release the VideoWriter + video_writer.release() + def get_unique_embedder_keys_from_conditioner(conditioner): From 32557639ba51171d87501524967fc7aa012dccf2 Mon Sep 17 00:00:00 2001 From: JPABotermans <45882689+JPABotermans@users.noreply.github.com> Date: Thu, 26 Sep 2024 01:08:44 +0200 Subject: [PATCH 3/4] Also solved input_image bug --- scripts/sampling/simple_video_sample.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/sampling/simple_video_sample.py b/scripts/sampling/simple_video_sample.py index a61ff0a1d..01ebc544f 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 w, h = image.size if h % 64 != 0 or w % 64 != 0: From f1d10a7225ca2ff39d5bde3bc33bfb71ab170bc0 Mon Sep 17 00:00:00 2001 From: JPABotermans <45882689+JPABotermans@users.noreply.github.com> Date: Thu, 26 Sep 2024 01:59:24 +0200 Subject: [PATCH 4/4] copied file to make input_image a PIL.Image.Image instance --- scripts/sampling/simple_video_sample.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/sampling/simple_video_sample.py b/scripts/sampling/simple_video_sample.py index 01ebc544f..8d0a690af 100644 --- a/scripts/sampling/simple_video_sample.py +++ b/scripts/sampling/simple_video_sample.py @@ -165,7 +165,7 @@ def sample( if image.mode == "RGBA": input_image = image.convert("RGB") else: - input_image = image + input_image = image.copy() w, h = image.size if h % 64 != 0 or w % 64 != 0: @@ -277,11 +277,11 @@ def denoiser(input, sigma, c): 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, (width, height)) + 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) # Write each frame to the video + video_writer.write(frame[..., ::-1]) # Write each frame to the video and convert to BGR # Step 5: Release the VideoWriter video_writer.release()