DSatishchandra commited on
Commit
9c8f2d7
·
verified ·
1 Parent(s): fd230fa

Update gully_drs_core/video_utils.py

Browse files
Files changed (1) hide show
  1. gully_drs_core/video_utils.py +10 -8
gully_drs_core/video_utils.py CHANGED
@@ -3,14 +3,16 @@ import tempfile
3
  import shutil
4
 
5
  def save_temp_video(uploaded_file):
6
- temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.mp4')
7
- if hasattr(uploaded_file, 'name'):
8
- with open(temp_file.name, 'wb') as f:
9
- shutil.copyfileobj(uploaded_file, f)
10
- else:
11
- with open(temp_file.name, 'wb') as f:
12
- f.write(uploaded_file.read())
13
- return temp_file.name
 
 
14
 
15
  def get_video_properties(video_path):
16
  cap = cv2.VideoCapture(video_path)
 
3
  import shutil
4
 
5
  def save_temp_video(uploaded_file):
6
+ # uploaded_file is expected to be the file path, not a file object
7
+ file_path = uploaded_file.name if hasattr(uploaded_file, 'name') else uploaded_file
8
+
9
+ # Open the file in binary mode to read its contents
10
+ with open(file_path, 'rb') as f:
11
+ # Create a temporary file
12
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as temp_video:
13
+ # Write the contents of the uploaded file to the temporary file
14
+ temp_video.write(f.read())
15
+ return temp_video.name
16
 
17
  def get_video_properties(video_path):
18
  cap = cv2.VideoCapture(video_path)