MCPcopy
hub / github.com/MeiGen-AI/InfiniteTalk / cache_video

Function cache_video

wan/utils/multitalk_utils.py:203–235  ·  view source on GitHub ↗
(tensor,
                save_file=None,
                fps=30,
                suffix='.mp4',
                nrow=8,
                normalize=True,
                value_range=(-1, 1),
                retry=5)

Source from the content-addressed store, hash-verified

201 return name
202
203def cache_video(tensor,
204 save_file=None,
205 fps=30,
206 suffix='.mp4',
207 nrow=8,
208 normalize=True,
209 value_range=(-1, 1),
210 retry=5):
211
212 # cache file
213 cache_file = osp.join('/tmp', rand_name(
214 suffix=suffix)) if save_file is None else save_file
215
216 # save to cache
217 error = None
218 for _ in range(retry):
219
220 # preprocess
221 tensor = tensor.clamp(min(value_range), max(value_range))
222 tensor = torch.stack([
223 torchvision.utils.make_grid(
224 u, nrow=nrow, normalize=normalize, value_range=value_range)
225 for u in tensor.unbind(2)
226 ],
227 dim=1).permute(1, 2, 3, 0)
228 tensor = (tensor * 255).type(torch.uint8).cpu()
229
230 # write video
231 writer = imageio.get_writer(cache_file, fps=fps, codec='libx264', quality=10, ffmpeg_params=["-crf", "10"])
232 for frame in tensor.numpy():
233 writer.append_data(frame)
234 writer.close()
235 return cache_file
236
237def save_video_ffmpeg(gen_video_samples, save_path, vocal_audio_list, fps=25, quality=5, high_quality_save=False):
238

Callers 1

save_video_ffmpegFunction · 0.70

Calls 1

rand_nameFunction · 0.70

Tested by

no test coverage detected