Update app.py
Browse files
app.py
CHANGED
|
@@ -66,12 +66,17 @@ 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
elif source_type == "RTSP Stream" and source_path:
|
| 76 |
return cv2.VideoCapture(source_path)
|
| 77 |
return None
|
|
@@ -131,18 +136,10 @@ def main():
|
|
| 131 |
|
| 132 |
source_path = None
|
| 133 |
uploaded_file = None
|
| 134 |
-
if source_type == "Video File"
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 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 |
|
|
|
|
| 66 |
if source_type == "Webcam":
|
| 67 |
return cv2.VideoCapture(0)
|
| 68 |
elif source_type == "Video File" and source_path:
|
| 69 |
+
# Create a temporary file with a specific extension
|
| 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 |
+
|
| 75 |
+
cap = cv2.VideoCapture(temp_path)
|
| 76 |
+
if not cap.isOpened():
|
| 77 |
+
st.error("Error: Could not open video file. Please ensure it's a supported format (MP4 with H.264 encoding recommended)")
|
| 78 |
+
return None
|
| 79 |
+
return cap
|
| 80 |
elif source_type == "RTSP Stream" and source_path:
|
| 81 |
return cv2.VideoCapture(source_path)
|
| 82 |
return None
|
|
|
|
| 136 |
|
| 137 |
source_path = None
|
| 138 |
uploaded_file = None
|
| 139 |
+
if source_type == "Video File":
|
| 140 |
+
uploaded_file = st.file_uploader("Choose a video file", type=['mp4', 'avi', 'mov'])
|
| 141 |
+
if uploaded_file:
|
| 142 |
+
source_path = BytesIO(uploaded_file.getvalue())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
elif source_type == "RTSP Stream":
|
| 144 |
source_path = st.text_input("Enter RTSP URL", placeholder="rtsp://your-camera-url")
|
| 145 |
|