Skip to content

Commit 5240a0b

Browse files
Frames to vedio convertor added
1 parent 11eff76 commit 5240a0b

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import os
2+
import cv2
3+
4+
def convert_frames_to_video(img_folder_path, fps):
5+
images = [os.path.join(img_folder_path, img) for img in os.listdir(img_folder_path)]
6+
7+
frame = cv2.imread(images[0])
8+
height, width, layers = frame.shape
9+
10+
video_name = input("Enter the video name(just the filename): ").strip()
11+
if not video_name.endswith(".avi"):
12+
video_name += ".avi"
13+
14+
video = cv2.VideoWriter(video_name, 0, fps, (width, height))
15+
16+
for image in images:
17+
video.write(cv2.imread(image))
18+
19+
cv2.destroyAllWindows()
20+
video.release()
21+
22+
if _name_ == "_main_":
23+
img_folder_path = input("Enter the folder path containing images: ").strip()
24+
fps = int(input("Enter the fps needed: "))
25+
convert_frames_to_video(img_folder_path, fps)

Frames to Vedio converter/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Convert Frames to Video
2+
3+
This python script will convert all the frames from a folder into a video. This is accomplished using OpenCV, a highly optimized library for computer vision applications. Specifically, we use the VideoWriter function to combine images(in a particular fps) and obtain a video.
4+
5+
## Setting up:
6+
7+
- Create a virtual environment and activate it
8+
9+
- Install the requirements
10+
11+
```sh
12+
$ pip install opencv-python
13+
```
14+
15+
## Running the script:
16+
17+
```sh
18+
$ python frames_to_video_converter.py [image_folder_path] #without the brackets
19+
```
20+
21+
The script will ask you for the needed 'fps' and a video name.
22+
23+
## Note:
24+
25+
The images in the folder should be numbered in the order in which they appear in the video.
26+
27+
![Pendulum frames images](https://i.imgur.com/MArsSBS.jpg)
28+
29+
After running the script, the video will be created in the directory where the script is running.
30+
31+
![frames_video](https://i.imgur.com/nk1aAw5.gif)

0 commit comments

Comments
 (0)