File size: 1,221 Bytes
995402f
f1bbd74
 
ac6173c
f1bbd74
468ca76
995402f
f1bbd74
 
995402f
ac6173c
995402f
fb5a6eb
995402f
468ca76
f1bbd74
468ca76
 
f1bbd74
1d99a94
fb5a6eb
 
 
 
468ca76
f1bbd74
995402f
ac6173c
 
 
 
 
 
 
995402f
 
 
468ca76
ac6173c
468ca76
fb5a6eb
995402f
f1bbd74
468ca76
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
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()