jschwab21 commited on
Commit
96c84ad
·
verified ·
1 Parent(s): 8a53d3b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -2
app.py CHANGED
@@ -1,4 +1,7 @@
1
  import gradio as gr
 
 
 
2
 
3
  def save_and_display_video(video_file):
4
  if video_file is None:
@@ -10,17 +13,37 @@ def save_and_display_video(video_file):
10
  file_path = 'uploaded_video.mp4' # Assuming .mp4 for simplicity
11
  with open(file_path, 'wb') as f:
12
  f.write(video_file)
13
- return file_path, "Video uploaded and displayed successfully."
 
 
 
 
 
 
14
  else:
15
  return None, "Uploaded file is empty."
16
  except Exception as e:
17
  return None, f"An error occurred: {str(e)}"
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  with gr.Blocks() as demo:
20
  with gr.Column():
21
  video_file = gr.File(label="Upload Video File", type="binary", file_types=["video"], interactive=True)
22
  output_video = gr.Video()
23
- output_message = gr.Textbox(label="Output Message")
24
  submit_button = gr.Button("Display Video")
25
  submit_button.click(
26
  fn=save_and_display_video,
 
1
  import gradio as gr
2
+ import os
3
+ from scenedetect import VideoManager, SceneManager
4
+ from scenedetect.detectors import ContentDetector
5
 
6
  def save_and_display_video(video_file):
7
  if video_file is None:
 
13
  file_path = 'uploaded_video.mp4' # Assuming .mp4 for simplicity
14
  with open(file_path, 'wb') as f:
15
  f.write(video_file)
16
+
17
+ scenes = find_scenes(file_path)
18
+ scene_info = ', '.join([f"Start: {start.get_seconds()}, End: {end.get_seconds()}" for start, end in scenes])
19
+ if scenes:
20
+ return file_path, f"Video uploaded and displayed successfully. Scenes detected: {scene_info}"
21
+ else:
22
+ return file_path, "Video uploaded but no scenes were detected."
23
  else:
24
  return None, "Uploaded file is empty."
25
  except Exception as e:
26
  return None, f"An error occurred: {str(e)}"
27
 
28
+ def find_scenes(video_path):
29
+ video_manager = VideoManager([video_path])
30
+ scene_manager = SceneManager()
31
+ scene_manager.add_detector(ContentDetector(threshold=30))
32
+ video_manager.set_downscale_factor()
33
+
34
+ video_manager.start()
35
+ scene_manager.detect_scenes(frame_source=video_manager)
36
+
37
+ scene_list = scene_manager.get_scene_list(base_timecode=video_manager.get_base_timecode())
38
+ video_manager.release()
39
+
40
+ return scene_list
41
+
42
  with gr.Blocks() as demo:
43
  with gr.Column():
44
  video_file = gr.File(label="Upload Video File", type="binary", file_types=["video"], interactive=True)
45
  output_video = gr.Video()
46
+ output_message = gr.Textbox(label="Output Message", lines=4)
47
  submit_button = gr.Button("Display Video")
48
  submit_button.click(
49
  fn=save_and_display_video,