felix.wf commited on
Commit
1448eef
·
1 Parent(s): 04d1a7a

save uploaded video into a temp file

Browse files
Files changed (1) hide show
  1. app.py +7 -1
app.py CHANGED
@@ -5,6 +5,7 @@ from PIL import Image
5
  import pandas as pd
6
  import numpy as np
7
  import cv2
 
8
 
9
 
10
 
@@ -121,8 +122,13 @@ if file_name is not None:
121
  st.pyplot(pie_fig) # Display the pie chart
122
 
123
  elif file_name.type.startswith('video'):
 
 
 
 
 
124
  # Process video
125
- video = cv2.VideoCapture(file_name)
126
  frame_count = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
127
  frame_rate = int(video.get(cv2.CAP_PROP_FPS))
128
  frame_interval = frame_rate # Process one frame per second
 
5
  import pandas as pd
6
  import numpy as np
7
  import cv2
8
+ import tempfile
9
 
10
 
11
 
 
122
  st.pyplot(pie_fig) # Display the pie chart
123
 
124
  elif file_name.type.startswith('video'):
125
+ # Save the uploaded video to a temporary file
126
+ with tempfile.NamedTemporaryFile(delete=False) as temp_video_file:
127
+ temp_video_file.write(file_name.read())
128
+ temp_video_path = temp_video_file.name
129
+
130
  # Process video
131
+ video = cv2.VideoCapture(temp_video_path)
132
  frame_count = int(video.get(cv2.CAP_PROP_FRAME_COUNT))
133
  frame_rate = int(video.get(cv2.CAP_PROP_FPS))
134
  frame_interval = frame_rate # Process one frame per second