code: def save_video_as_grid_and_mp4(
      video_batch: torch.Tensor, save_path: str, T: int, fps: int = 5
  ):
      os.makedirs(save_path, exist_ok=True)
      base_count = len(glob(os.path.join(save_path, "*.mp4")))
  
      video_batch = rearrange(
          video_batch, "(b t) c h w -> b t c h w", t=T
      )
      video_batch = embed_watermark(video_batch)
      for vid in video_batch:
          save_image(
              vid,
              fp=os.path.join(save_path, f"{base_count:06d}.png"),
              nrow=4,
          )
  
          video_path = os.path.join(save_path, f"{base_count:06d}.mp4")
  
          writer = cv2.VideoWriter(
              video_path,
              cv2.VideoWriter_fourcc(*"MP4V"),
              fps,
              (vid.shape[-1], vid.shape[-2]),
          )
  
          vid = (
              (rearrange(vid, "t c h w -> t h w c") * 255)
              .cpu()
              .numpy()
              .astype(np.uint8)
          )
          for frame in vid:
              frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
              writer.write(frame)
  
          writer.release()
  
          video_path_h264 = video_path[:-4] + "_h264.mp4"
          os.system(
              f"ffmpeg -i {video_path} -c:v libx264 {video_path_h264}"
          )
  
          with open(video_path_h264, "rb") as f:
              video_bytes = f.read()
          st.video(video_bytes)
  
          base_count += 1
  
imports: import copy
  import math
  import os
  from glob import glob
  from typing import Dict, List, Optional, Tuple, Union
  import cv2
  import numpy
  import streamlit
  import torch
  import torch.nn
  import torchvision.transforms
  from einops import rearrange, repeat
  from imwatermark import WatermarkEncoder
  from omegaconf import ListConfig, OmegaConf
  from PIL import Image
  from safetensors.torch import load_file
  from torch import autocast
  from torchvision import transforms
  from torchvision.utils import make_grid, save_image
  from scripts.demo.discretization import Img2ImgDiscretizationWrapper, Txt2NoisyDiscretizationWrapper
  from scripts.util.detection.nsfw_and_watermark_dectection import DeepFloydDataFiltering
  from sgm.inference.helpers import embed_watermark
  from sgm.modules.diffusionmodules.guiders import LinearPredictionGuider, VanillaCFG
  from sgm.modules.diffusionmodules.sampling import DPMPP2MSampler, DPMPP2SAncestralSampler, EulerAncestralSampler, EulerEDMSampler, HeunEDMSampler, LinearMultistepSampler
  from sgm.util import append_dims, default, instantiate_from_config
label_desc: Use image node_id 24 for calling a global function with example usage: save_video_as_grid_and_mp4(video_batch, save_path, T, fps) without return types