Abu1998 commited on
Commit
ac6173c
·
verified ·
1 Parent(s): 468ca76

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -4
app.py CHANGED
@@ -1,12 +1,15 @@
1
  import gradio as gr
2
  import cv2
3
  import os
 
 
4
 
5
  def extract_frames(video_path):
6
  output_folder = "extracted_frames"
7
  os.makedirs(output_folder, exist_ok=True)
8
 
9
  cap = cv2.VideoCapture(video_path)
 
10
  frame_count = 0
11
  extracted_images = []
12
 
@@ -15,20 +18,26 @@ def extract_frames(video_path):
15
  if not success:
16
  break
17
 
18
- image_path = os.path.join(output_folder, f"frame_{frame_count}.jpg")
19
  cv2.imwrite(image_path, frame)
20
  extracted_images.append(image_path)
21
  frame_count += 1
22
 
23
  cap.release()
24
- return extracted_images
 
 
 
 
 
 
25
 
26
  gui = gr.Interface(
27
  fn=extract_frames,
28
  inputs=gr.Video(label="Upload Video"),
29
- outputs=gr.Gallery(label="Extracted Frames"),
30
  title="Video Frame Extractor",
31
- description="Upload a video to extract all frames sequentially."
32
  )
33
 
34
  gui.launch()
 
1
  import gradio as gr
2
  import cv2
3
  import os
4
+ import shutil
5
+ import zipfile
6
 
7
  def extract_frames(video_path):
8
  output_folder = "extracted_frames"
9
  os.makedirs(output_folder, exist_ok=True)
10
 
11
  cap = cv2.VideoCapture(video_path)
12
+ fps = cap.get(cv2.CAP_PROP_FPS)
13
  frame_count = 0
14
  extracted_images = []
15
 
 
18
  if not success:
19
  break
20
 
21
+ image_path = os.path.join(output_folder, f"frame_{int(frame_count/fps)}.jpg")
22
  cv2.imwrite(image_path, frame)
23
  extracted_images.append(image_path)
24
  frame_count += 1
25
 
26
  cap.release()
27
+
28
+ zip_filename = "extracted_frames.zip"
29
+ with zipfile.ZipFile(zip_filename, 'w') as zipf:
30
+ for img in extracted_images:
31
+ zipf.write(img, os.path.basename(img))
32
+
33
+ return zip_filename
34
 
35
  gui = gr.Interface(
36
  fn=extract_frames,
37
  inputs=gr.Video(label="Upload Video"),
38
+ outputs=gr.File(label="Download Extracted Frames as ZIP"),
39
  title="Video Frame Extractor",
40
+ description="Upload a video to extract all frames sequentially and download as a ZIP file."
41
  )
42
 
43
  gui.launch()