Update app.py
Browse files
app.py
CHANGED
|
@@ -734,22 +734,38 @@ elif input_method == "Upload Video":
|
|
| 734 |
|
| 735 |
status_text.text("Creating processed video...")
|
| 736 |
|
| 737 |
-
# Create
|
| 738 |
-
|
|
|
|
| 739 |
|
| 740 |
-
#
|
| 741 |
-
|
| 742 |
-
|
| 743 |
-
|
| 744 |
-
|
| 745 |
-
|
| 746 |
-
|
|
|
|
| 747 |
|
| 748 |
-
#
|
| 749 |
-
|
|
|
|
| 750 |
|
| 751 |
-
#
|
| 752 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 753 |
|
| 754 |
# Analysis complete, display results
|
| 755 |
st.success(f"Video analysis complete. {len(processed_frames)} frames processed, {len(crash_frames)} crashes detected.")
|
|
|
|
| 734 |
|
| 735 |
status_text.text("Creating processed video...")
|
| 736 |
|
| 737 |
+
# Create a temporary file for the processed video
|
| 738 |
+
# Using a unique filename in the temporary directory
|
| 739 |
+
temp_output_path = os.path.join(tempfile.gettempdir(), f"processed_video_{int(time.time())}.mp4")
|
| 740 |
|
| 741 |
+
# Create video writer
|
| 742 |
+
fourcc = cv2.VideoWriter_fourcc(*'mp4v') # Use mp4v codec which is widely compatible
|
| 743 |
+
out = cv2.VideoWriter(
|
| 744 |
+
temp_output_path,
|
| 745 |
+
fourcc,
|
| 746 |
+
fps,
|
| 747 |
+
(frame_width, frame_height)
|
| 748 |
+
)
|
| 749 |
|
| 750 |
+
# Write frames to video
|
| 751 |
+
for frame_data in processed_frames:
|
| 752 |
+
out.write(frame_data["frame"])
|
| 753 |
|
| 754 |
+
# Release the writer
|
| 755 |
+
out.release()
|
| 756 |
+
|
| 757 |
+
# Read the file into memory
|
| 758 |
+
with open(temp_output_path, 'rb') as f:
|
| 759 |
+
video_bytes = f.read()
|
| 760 |
+
|
| 761 |
+
# Display video from bytes
|
| 762 |
+
st.video(video_bytes)
|
| 763 |
+
|
| 764 |
+
# Clean up the temporary output file
|
| 765 |
+
try:
|
| 766 |
+
os.remove(temp_output_path)
|
| 767 |
+
except:
|
| 768 |
+
pass
|
| 769 |
|
| 770 |
# Analysis complete, display results
|
| 771 |
st.success(f"Video analysis complete. {len(processed_frames)} frames processed, {len(crash_frames)} crashes detected.")
|