Video-To-Image / app.py
Abu1998's picture
Update app.py
1d99a94 verified
raw
history blame
1.22 kB
import gradio as gr
import cv2
import os
import zipfile
def extract_frames(video_path):
output_folder = "extracted_frames"
os.makedirs(output_folder, exist_ok=True)
cap = cv2.VideoCapture(video_path)
fps = cap.get(cv2.CAP_PROP_FPS)
extracted_images = []
frame_count = 0
while True:
success, frame = cap.read()
if not success:
break
if frame_count % int(fps / 24) == 0: # Extract 60 frames per second
image_path = os.path.join(output_folder, f"frame_{frame_count}.jpg")
cv2.imwrite(image_path, frame)
extracted_images.append(image_path)
frame_count += 1
cap.release()
zip_filename = "extracted_frames.zip"
with zipfile.ZipFile(zip_filename, 'w') as zipf:
for img in extracted_images:
zipf.write(img, os.path.basename(img))
return zip_filename
gui = gr.Interface(
fn=extract_frames,
inputs=gr.Video(label="Upload Video"),
outputs=gr.File(label="Download Extracted Frames as ZIP"),
title="Video Frame Extractor",
description="Upload a video to extract frames at 60 FPS and download as a ZIP file."
)
gui.launch()