Spaces:
Running
on
Zero
Running
on
Zero
Use tempfile
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import colorsys
|
| 2 |
import gc
|
|
|
|
| 3 |
from collections.abc import Iterator
|
| 4 |
|
| 5 |
import cv2
|
|
@@ -1116,14 +1117,14 @@ with gr.Blocks(title="SAM3", theme=Soft(primary_hue="blue", secondary_hue="rose"
|
|
| 1116 |
frames_np.append(np.array(img)[:, :, ::-1])
|
| 1117 |
if (idx + 1) % 60 == 0:
|
| 1118 |
gc.collect()
|
| 1119 |
-
out_path = "/tmp/sam3_playback.mp4"
|
| 1120 |
try:
|
| 1121 |
-
|
| 1122 |
-
|
| 1123 |
-
|
| 1124 |
-
|
| 1125 |
-
|
| 1126 |
-
|
|
|
|
| 1127 |
except Exception as e:
|
| 1128 |
print(f"Failed to render video with cv2: {e}")
|
| 1129 |
raise gr.Error(f"Failed to render video: {e}")
|
|
|
|
| 1 |
import colorsys
|
| 2 |
import gc
|
| 3 |
+
import tempfile
|
| 4 |
from collections.abc import Iterator
|
| 5 |
|
| 6 |
import cv2
|
|
|
|
| 1117 |
frames_np.append(np.array(img)[:, :, ::-1])
|
| 1118 |
if (idx + 1) % 60 == 0:
|
| 1119 |
gc.collect()
|
|
|
|
| 1120 |
try:
|
| 1121 |
+
with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as out_path:
|
| 1122 |
+
fourcc = cv2.VideoWriter_fourcc(*"mp4v")
|
| 1123 |
+
writer = cv2.VideoWriter(out_path.name, fourcc, fps, (w, h))
|
| 1124 |
+
for fr_bgr in frames_np:
|
| 1125 |
+
writer.write(fr_bgr)
|
| 1126 |
+
writer.release()
|
| 1127 |
+
return out_path.name
|
| 1128 |
except Exception as e:
|
| 1129 |
print(f"Failed to render video with cv2: {e}")
|
| 1130 |
raise gr.Error(f"Failed to render video: {e}")
|