Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
388f445
1
Parent(s):
d27c119
update export video
Browse files
LHM/utils/ffmpeg_utils.py
CHANGED
@@ -36,7 +36,7 @@ def encodeffmpeg(inputs, frame_rate, output, format="png"):
|
|
36 |
os.system(cmd)
|
37 |
print("video done!")
|
38 |
|
39 |
-
def images_to_video(images, output_path, fps, gradio_codec: bool, verbose=False, bitrate="
|
40 |
os.makedirs(os.path.dirname(output_path), exist_ok=True)
|
41 |
frames = []
|
42 |
for i in range(images.shape[0]):
|
@@ -46,9 +46,13 @@ def images_to_video(images, output_path, fps, gradio_codec: bool, verbose=False,
|
|
46 |
f"Frame shape mismatch: {frame.shape} vs {images.shape}"
|
47 |
assert frame.min() >= 0 and frame.max() <= 255, \
|
48 |
f"Frame value out of range: {frame.min()} ~ {frame.max()}"
|
|
|
49 |
else:
|
50 |
frame = images[i]
|
51 |
-
|
|
|
|
|
|
|
52 |
|
53 |
frames = np.stack(frames)
|
54 |
iio.imwrite(output_path,frames,fps=fps,codec="libx264",pixelformat="yuv420p",bitrate=bitrate,macro_block_size=16)
|
|
|
36 |
os.system(cmd)
|
37 |
print("video done!")
|
38 |
|
39 |
+
def images_to_video(images, output_path, fps, gradio_codec: bool, verbose=False, bitrate="2M"):
|
40 |
os.makedirs(os.path.dirname(output_path), exist_ok=True)
|
41 |
frames = []
|
42 |
for i in range(images.shape[0]):
|
|
|
46 |
f"Frame shape mismatch: {frame.shape} vs {images.shape}"
|
47 |
assert frame.min() >= 0 and frame.max() <= 255, \
|
48 |
f"Frame value out of range: {frame.min()} ~ {frame.max()}"
|
49 |
+
|
50 |
else:
|
51 |
frame = images[i]
|
52 |
+
width, height = frame.shape[1], frame.shape[0]
|
53 |
+
# reshape to limit the export time
|
54 |
+
if width > 1200 or height > 1200 or images.shape[0] > 400:
|
55 |
+
frames.append(cv2.resize(frame, (width // 2, height // 2)))
|
56 |
|
57 |
frames = np.stack(frames)
|
58 |
iio.imwrite(output_path,frames,fps=fps,codec="libx264",pixelformat="yuv420p",bitrate=bitrate,macro_block_size=16)
|