Update app.py
Browse files
app.py
CHANGED
@@ -245,19 +245,19 @@ def save_video_to_mp4(video_tensor, fps=20):
|
|
245 |
if video_numpy.max() <= 1.0:
|
246 |
video_numpy = (video_numpy * 255).astype(np.uint8)
|
247 |
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
byte_buffer = io.BytesIO()
|
253 |
|
254 |
# Get video dimensions
|
255 |
height, width, channels = video_numpy[0].shape
|
256 |
fourcc = cv2.VideoWriter_fourcc(*'mp4v') # Codec for .mp4
|
257 |
|
258 |
# Create VideoWriter object
|
259 |
-
|
260 |
-
out = cv2.VideoWriter(byte_buffer, fourcc, fps, (width, height), isColor=True)
|
261 |
|
262 |
# Write the frames to the output file
|
263 |
for frame in video_numpy:
|
@@ -266,9 +266,9 @@ def save_video_to_mp4(video_tensor, fps=20):
|
|
266 |
out.write(frame_bgr)
|
267 |
|
268 |
out.release()
|
269 |
-
|
270 |
-
byte_buffer.seek(0)
|
271 |
-
return byte_buffer.read()
|
272 |
|
273 |
# Function to list available videos dynamically
|
274 |
def list_videos():
|
|
|
245 |
if video_numpy.max() <= 1.0:
|
246 |
video_numpy = (video_numpy * 255).astype(np.uint8)
|
247 |
|
248 |
+
# Create a temporary file to save the video
|
249 |
+
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4")
|
250 |
+
output_path = temp_file.name
|
251 |
+
## Create an in-memory byte buffer to store the video
|
252 |
+
#byte_buffer = io.BytesIO()
|
253 |
|
254 |
# Get video dimensions
|
255 |
height, width, channels = video_numpy[0].shape
|
256 |
fourcc = cv2.VideoWriter_fourcc(*'mp4v') # Codec for .mp4
|
257 |
|
258 |
# Create VideoWriter object
|
259 |
+
out = cv2.VideoWriter(output_path, fourcc, fps, (width, height))
|
260 |
+
#out = cv2.VideoWriter(byte_buffer, fourcc, fps, (width, height), isColor=True)
|
261 |
|
262 |
# Write the frames to the output file
|
263 |
for frame in video_numpy:
|
|
|
266 |
out.write(frame_bgr)
|
267 |
|
268 |
out.release()
|
269 |
+
## Return the byte buffer's content (the video as bytes)
|
270 |
+
#byte_buffer.seek(0)
|
271 |
+
return output_path #byte_buffer.read()
|
272 |
|
273 |
# Function to list available videos dynamically
|
274 |
def list_videos():
|