-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFrame_Extraction.py
53 lines (34 loc) · 1.13 KB
/
Frame_Extraction.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
import os
import cv2
# In[ ]:
def extract_frames(video_path, output_folder):
if not os.path.exists(output_folder):
os.makedirs(output_folder)
video = cv2.VideoCapture(video_path)
total_frames = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
frame_count = 0
while True:
ret, frame = video.read()
if not ret:
break
frame_path = os.path.join(output_folder, f"frame_{frame_count}.jpg")
cv2.imwrite(frame_path, frame)
frame_count += 1
progress_percent = (frame_count / total_frames) * 100
print(f"Extracting frames: {progress_percent:.2f}%")
video.release()
print("Frames extraction complete.")
video_path = "/path to your desired video"
extract_frames(video_path, output_folder)
# In[ ]:
def delete_images(folder):
for filename in os.listdir(folder):
file_path = os.path.join(folder, filename)
if os.path.isfile(file_path):
os.remove(file_path)
print("Deletion complete")
image_folder = "/path to folder containing the video frames"
delete_images(image_folder)