Video-To-Image / app.py
Abu1998's picture
Create app.py
f1bbd74 verified
raw
history blame
954 Bytes
import cv2
import os
import glob
def extract_frames_from_videos(input_folder, output_folder):
os.makedirs(output_folder, exist_ok=True)
video_files = glob.glob(os.path.join(input_folder, "*.mp4")) # Modify if using other formats
image_count = 0 # To maintain sequential numbering across videos
for video_file in video_files:
cap = cv2.VideoCapture(video_file)
success, frame = cap.read()
while success:
image_path = os.path.join(output_folder, f"{image_count}.jpg")
cv2.imwrite(image_path, frame)
image_count += 1
success, frame = cap.read()
cap.release()
print(f"Extraction complete. {image_count} images saved in {output_folder}")
# Example usage
input_folder = "videos" # Change this to the path where your videos are stored
output_folder = "output_images"
extract_frames_from_videos(input_folder, output_folder)