MCPcopy Create free account
hub / github.com/thygate/stable-diffusion-webui-depthmap-script / frames_to_video

Function frames_to_video

src/video_mode.py:71–100  ·  view source on GitHub ↗
(fps, frames, path, name, colorvids_bitrate=None)

Source from the content-addressed store, hash-verified

69
70
71def frames_to_video(fps, frames, path, name, colorvids_bitrate=None):
72 if frames[0].mode == 'I;16': # depthmap video
73 import imageio_ffmpeg
74 writer = imageio_ffmpeg.write_frames(
75 os.path.join(path, f"{name}.avi"), frames[0].size, 'gray16le', 'gray16le', fps, codec='ffv1',
76 macro_block_size=1)
77 try:
78 writer.send(None)
79 for frame in frames:
80 writer.send(np.array(frame))
81 finally:
82 writer.close()
83 else:
84 arrs = [np.asarray(frame) for frame in frames]
85 from moviepy.video.io.ImageSequenceClip import ImageSequenceClip
86 clip = ImageSequenceClip(arrs, fps=fps)
87 done = False
88 priority = [('avi', 'png'), ('avi', 'rawvideo'), ('mp4', 'libx264'), ('webm', 'libvpx')]
89 if colorvids_bitrate:
90 priority = reversed(priority)
91 for v_format, codec in priority:
92 try:
93 br = f'{colorvids_bitrate}k' if codec not in ['png', 'rawvideo'] else None
94 clip.write_videofile(os.path.join(path, f"{name}.{v_format}"), codec=codec, bitrate=br)
95 done = True
96 break
97 except:
98 traceback.print_exc()
99 if not done:
100 raise Exception('Saving the video failed!')
101
102
103def process_predicitons(predictions, smoothening='none'):

Callers 1

gen_videoFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected