def tensor_to_video(x):
    """[0-1] tensor to video"""
    x = (x * 2 - 1).detach().cpu()
    x = torch.clamp(x, -1, 1)
    x = (x + 1) / 2
    x = x.permute(1, 0, 2, 3).float().numpy() # c t h w -> t c h w
    x = (255 * x).astype(np.uint8)
    return x
[0-1] tensor to video
opensora/models/causalvideovae/utils/video_utils.py