codelion commited on
Commit
64fe434
·
verified ·
1 Parent(s): c407d5f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -131,10 +131,18 @@ def main():
131
 
132
  source_path = None
133
  uploaded_file = None
134
- if source_type == "Video File":
135
- uploaded_file = st.file_uploader("Choose a video file", type=['mp4', 'avi', 'mov'])
136
- if uploaded_file:
137
- source_path = BytesIO(uploaded_file.getvalue())
 
 
 
 
 
 
 
 
138
  elif source_type == "RTSP Stream":
139
  source_path = st.text_input("Enter RTSP URL", placeholder="rtsp://your-camera-url")
140
 
 
131
 
132
  source_path = None
133
  uploaded_file = None
134
+ if source_type == "Video File" and source_path:
135
+ # Create a temporary file with a specific extension
136
+ temp_dir = tempfile.gettempdir()
137
+ temp_path = os.path.join(temp_dir, 'temp_video.mp4')
138
+ with open(temp_path, 'wb') as f:
139
+ f.write(source_path.getvalue())
140
+
141
+ cap = cv2.VideoCapture(temp_path)
142
+ if not cap.isOpened():
143
+ st.error("Error: Could not open video file. Please ensure it's a supported format (MP4 with H.264 encoding recommended)")
144
+ return None
145
+ return cap
146
  elif source_type == "RTSP Stream":
147
  source_path = st.text_input("Enter RTSP URL", placeholder="rtsp://your-camera-url")
148