Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -27,26 +27,19 @@ def process_video(video_path: str):
|
|
| 27 |
T, H, W = video_tensor.shape
|
| 28 |
|
| 29 |
temp_path = tempfile.mktemp(suffix=".mp4")
|
| 30 |
-
|
| 31 |
-
# Normalize video to [0,1]
|
| 32 |
video_tensor = np.clip(video_tensor, 0, 1)
|
|
|
|
| 33 |
|
| 34 |
writer = imageio.get_writer(
|
| 35 |
temp_path, fps=30, codec="libx264", ffmpeg_params=["-pix_fmt", "yuv420p"]
|
| 36 |
)
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
# writer.append_data(colored)
|
| 43 |
-
# writer.close()
|
| 44 |
-
with iio.imopen(temp_path, "w", plugin="ffmpeg", fps=30, codec="libx264", pixelformat="yuv420p") as vid:
|
| 45 |
-
for t in range(T):
|
| 46 |
-
frame = video_tensor[t]
|
| 47 |
-
colored = (cmap(frame)[..., :3] * 255).astype(np.uint8)
|
| 48 |
-
vid.append_data(colored)
|
| 49 |
|
|
|
|
| 50 |
return video_path, temp_path
|
| 51 |
|
| 52 |
# Unified processing
|
|
|
|
| 27 |
T, H, W = video_tensor.shape
|
| 28 |
|
| 29 |
temp_path = tempfile.mktemp(suffix=".mp4")
|
|
|
|
|
|
|
| 30 |
video_tensor = np.clip(video_tensor, 0, 1)
|
| 31 |
+
cmap = cm.get_cmap("inferno")
|
| 32 |
|
| 33 |
writer = imageio.get_writer(
|
| 34 |
temp_path, fps=30, codec="libx264", ffmpeg_params=["-pix_fmt", "yuv420p"]
|
| 35 |
)
|
| 36 |
|
| 37 |
+
for t in range(T):
|
| 38 |
+
frame = video_tensor[t]
|
| 39 |
+
colored = (cmap(frame)[..., :3] * 255).astype(np.uint8)
|
| 40 |
+
writer.append_data(colored)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
+
writer.close()
|
| 43 |
return video_path, temp_path
|
| 44 |
|
| 45 |
# Unified processing
|