Issue while playing a video created in Python

84 views Asked by At

I am creating a video out of all these images but for some reason, it is blank while playing. I don't know what the probable reason is since it doesn't show any error.

from PIL import Image
import os
import imageio

folder_path = r'\Distances'
output_movie_path = os.path.join(folder_path, 'output_movie.mp4')
output_image_size = (8272, 4144)

# Create a list of image filepaths
image_filepaths = [os.path.join(folder_path, f'Histogram_Sublist_{i}.jpg') for i in range(1, 126)]

# Resize and save each image
for image_filepath in image_filepaths:
    img = Image.open(image_filepath)
    
    # Resize maintaining aspect ratio
    img_resized = img.resize(output_image_size)
    
    # Save the image in RGB mode
    img_resized = img_resized.convert("RGB")
    img_resized.save(image_filepath)

# Create the movie
with imageio.get_writer(output_movie_path, fps=5) as writer:
    for image_filepath in image_filepaths:
        image = imageio.v2.imread(image_filepath)
        writer.append_data(image)

print(f'Movie saved at: {output_movie_path}')
1

There are 1 answers

5
Tino D On

You did not close the writer, add the following at the end of your code

writer.close()