codelion commited on
Commit
46d55ac
·
verified ·
1 Parent(s): 14dd08e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -9
app.py CHANGED
@@ -9,6 +9,8 @@ import time
9
  from io import BytesIO
10
  import threading
11
  import queue
 
 
12
  from datetime import datetime
13
 
14
  # Set page config to wide mode
@@ -63,9 +65,14 @@ def load_processor():
63
  def get_video_source(source_type, source_path=None):
64
  if source_type == "Webcam":
65
  return cv2.VideoCapture(0)
66
- elif source_type == "Video File":
67
- return cv2.VideoCapture(source_path)
68
- elif source_type == "RTSP Stream":
 
 
 
 
 
69
  return cv2.VideoCapture(source_path)
70
  return None
71
 
@@ -122,16 +129,15 @@ def main():
122
  # Video source selection
123
  source_type = st.selectbox(
124
  "Select Video Source",
125
- ["Video File"]
126
  )
127
 
128
  source_path = None
 
129
  if source_type == "Video File":
130
- source_file = st.file_uploader("Choose a video file", type=['mp4', 'avi', 'mov'])
131
- if source_file:
132
- # Save the uploaded file temporarily
133
- temp_file = BytesIO(source_file.read())
134
- source_path = temp_file
135
  elif source_type == "RTSP Stream":
136
  source_path = st.text_input("Enter RTSP URL", placeholder="rtsp://your-camera-url")
137
 
 
9
  from io import BytesIO
10
  import threading
11
  import queue
12
+ import os
13
+ import tempfile
14
  from datetime import datetime
15
 
16
  # Set page config to wide mode
 
65
  def get_video_source(source_type, source_path=None):
66
  if source_type == "Webcam":
67
  return cv2.VideoCapture(0)
68
+ elif source_type == "Video File" and source_path:
69
+ # Create a temporary file
70
+ temp_dir = tempfile.gettempdir()
71
+ temp_path = os.path.join(temp_dir, 'temp_video.mp4')
72
+ with open(temp_path, 'wb') as f:
73
+ f.write(source_path.getvalue())
74
+ return cv2.VideoCapture(temp_path)
75
+ elif source_type == "RTSP Stream" and source_path:
76
  return cv2.VideoCapture(source_path)
77
  return None
78
 
 
129
  # Video source selection
130
  source_type = st.selectbox(
131
  "Select Video Source",
132
+ ["Webcam", "Video File", "RTSP Stream"]
133
  )
134
 
135
  source_path = None
136
+ uploaded_file = None
137
  if source_type == "Video File":
138
+ uploaded_file = st.file_uploader("Choose a video file", type=['mp4', 'avi', 'mov'])
139
+ if uploaded_file:
140
+ source_path = BytesIO(uploaded_file.getvalue())
 
 
141
  elif source_type == "RTSP Stream":
142
  source_path = st.text_input("Enter RTSP URL", placeholder="rtsp://your-camera-url")
143