Generate multiple frames (e.g., 10 frames for the video)
num_frames = 10
frames = []
for i in range(num_frames):
prompt = f"A serene landscape with mountains and a river, frame {i+1}" # Adjust this prompt as needed
print(f"Generating frame {i+1}...")
# Generate an image from the prompt
image = generator(prompt)
image_path = os.path.join(frame_folder, f"frame_{i+1}.png")
# Save the generated image
image[0]['image'].save(image_path)
# Add the frame to the video
img = cv2.imread(image_path)
img = cv2.resize(img, (frame_width, frame_height)) # Resize the image to match video resolution
out.write(img) # Write the frame to the video file
Release the video writer and clean up
out.release()
cv2.destroyAllWindows()
Optionally, remove the generated frames after creating the video
for frame in frames:
os.remove(frame)
print("Video generation complete! Check the 'output_video.mp4' file.")