Spaces:
Paused
Paused
Update web-demos/hugging_face/app.py
Browse files
web-demos/hugging_face/app.py
CHANGED
@@ -326,7 +326,8 @@ def inpaint_video(video_state, resize_ratio_number, dilate_radius_number, raft_i
|
|
326 |
neighbor_length=neighbor_length_number,
|
327 |
ref_stride=ref_stride_number) # numpy array, T, H, W, 3
|
328 |
|
329 |
-
|
|
|
330 |
|
331 |
return video_output, operation_log, operation_log
|
332 |
print("Inpainting resolution:", inpainted_frames[0].shape)
|
@@ -344,6 +345,7 @@ def generate_video_from_frames(frames, output_path, fps=30):
|
|
344 |
"""
|
345 |
# Приведение fps к обычному float (из np.float64, если нужно)
|
346 |
import numpy as np
|
|
|
347 |
import torch
|
348 |
import torchvision
|
349 |
import os
|
@@ -358,14 +360,19 @@ def generate_video_from_frames(frames, output_path, fps=30):
|
|
358 |
assert all(f.shape == frames[0].shape for f in frames), "All frames must have the same shape"
|
359 |
|
360 |
# Convert to tensor (T, H, W, C)
|
361 |
-
frames = torch.from_numpy(np.asarray(frames))
|
362 |
|
363 |
# Ensure output directory exists
|
364 |
if not os.path.exists(os.path.dirname(output_path)):
|
365 |
os.makedirs(os.path.dirname(output_path))
|
366 |
|
367 |
# Write the video
|
368 |
-
torchvision.io.write_video(output_path, frames, fps=fps, video_codec="libx264")
|
|
|
|
|
|
|
|
|
|
|
369 |
return output_path
|
370 |
|
371 |
def restart():
|
|
|
326 |
neighbor_length=neighbor_length_number,
|
327 |
ref_stride=ref_stride_number) # numpy array, T, H, W, 3
|
328 |
|
329 |
+
output_path = "./result/inpaint/{}".format(video_state["video_name"])
|
330 |
+
video_output = generate_video_from_frames(inpainted_frames, output_path=output_path, fps=fps, bitrate="30M") # import video_input to name the output video
|
331 |
|
332 |
return video_output, operation_log, operation_log
|
333 |
print("Inpainting resolution:", inpainted_frames[0].shape)
|
|
|
345 |
"""
|
346 |
# Приведение fps к обычному float (из np.float64, если нужно)
|
347 |
import numpy as np
|
348 |
+
import imageio
|
349 |
import torch
|
350 |
import torchvision
|
351 |
import os
|
|
|
360 |
assert all(f.shape == frames[0].shape for f in frames), "All frames must have the same shape"
|
361 |
|
362 |
# Convert to tensor (T, H, W, C)
|
363 |
+
#frames = torch.from_numpy(np.asarray(frames))
|
364 |
|
365 |
# Ensure output directory exists
|
366 |
if not os.path.exists(os.path.dirname(output_path)):
|
367 |
os.makedirs(os.path.dirname(output_path))
|
368 |
|
369 |
# Write the video
|
370 |
+
#torchvision.io.write_video(output_path, frames, fps=fps, video_codec="libx264")
|
371 |
+
#return output_path
|
372 |
+
writer = imageio.get_writer(output_path, fps=fps, codec='libx264', bitrate=bitrate)
|
373 |
+
for frame in frames:
|
374 |
+
writer.append_data(frame.astype(np.uint8))
|
375 |
+
writer.close()
|
376 |
return output_path
|
377 |
|
378 |
def restart():
|