Skip to content

Commit

Permalink
update README, push first version of script
Browse files Browse the repository at this point in the history
  • Loading branch information
kashfifahim committed Oct 23, 2023
1 parent 8e32ba8 commit 0b4d0a7
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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!
40 changes: 40 additions & 0 deletions images_to_video.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 0b4d0a7

Please sign in to comment.