diff --git a/README.md b/README.md index e89c5b4..c1c1320 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,19 @@ -# images-to-video-file -Developing a tool that can take images and turn them into a video file +# Image to Video Converter +Convert a sequence of images to a video usiing Python and OpenCV + +## Requirements +- Python: Version 3.x or above. +- OpenCV-Python library: This library will provide the tools needed to read images and generate video. + +## Setup & Installation: +1. Make sure you have Python 3 installed. +2. Install the `opencv-python` library using pip + +## How to Use +1. Prepare Your Images: Place all your images in a single folder. The script assumes that the images are named sequentially (e.g., frame001.png, frame002.png, ...). Ensure they are in the order you want them to appear in the video. +2. Run the script. Navigate to the directory containing the script and run: +```python images_to_video.py``` +By default, this will generate a video named output_video.avi with a frame rate of 30 FPS. If you want to customize the input folder, output video name, or frame rate, modify the parameters in the images_to_video function call within the script. + +## Contributing +Feel free to fork this project and make your own changes. Pull requests are welcome! \ No newline at end of file diff --git a/images_to_video.py b/images_to_video.py new file mode 100644 index 0000000..a29c537 --- /dev/null +++ b/images_to_video.py @@ -0,0 +1,40 @@ +import cv2 +import os + +def images_to_video(image_folder, output_video_file, fps=30): + """ + Convert a set of images in a folder to a video. + + Parameters: + - image_folder: path to the folder containing the images + - output_video_file: path to the output video file (e.g., 'output.avi') + - fps: frames per second for the output video + """ + + # Get all files from the folder + images = [img for img in os.listdir(image_folder) if img.endswith(".png")] + + # Sort the images by name + images.sort() + + # Determine the width and height from the first image + frame = cv2.imread(os.path.join(image_folder, images[0])) + h, w, layers = frame.shape + size = (w,h) + + # Create a video writer object + out = cv2.VideoWriter(output_video_file, cv2.VideoWriter_fourcc(*'DIVX'), fps, size) + + # Write each image to the video writer + for image in images: + img_path = os.path.join(image_folder, image) + img = cv2.imread(img_path) + out.write(img) + + # Release the video writer object + out.release() + +# Example usage: +# images_to_video('path_to_image_folder', 'output_video.avi', fps=30) + +images_to_video('images', 'outout_video.avi', fps=30) \ No newline at end of file