File size: 325 Bytes
11554c5
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
import tempfile
import torch
from torch import Tensor
from torchvision.io import write_video

def export_to_video(tensor: Tensor, fps: int = 10) -> str:
    path = tempfile.NamedTemporaryFile(suffix=".mp4").name
    write_video(path, (tensor.permute(0, 2, 3, 1) * 255).clamp(0, 255).to(torch.uint8), fps=fps)
    return path