uncleh00ru

VideoConfigSVI_v04

Apr 20th, 2026 (edited)
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.98 KB | Source Code | 0 0
  1. # custom_nodes/video_config_svi_v04.py
  2. import re
  3.  
  4. try:
  5.     from server import PromptServer
  6. except Exception:
  7.     PromptServer = None
  8.  
  9. class VideoConfigSVI:
  10.     @classmethod
  11.     def INPUT_TYPES(cls):
  12.         return {
  13.             "required": {
  14.                 "preset": ([
  15.                     "Custom",
  16.  
  17.                     "─ 9:16 ─",
  18.                     "352x640",
  19.                     "544x960",
  20.                     "720x1280",
  21.                     "864x1536",
  22.                     "1008x1792",
  23.                     "1088x1920",
  24.  
  25.                     "─ 2:3 ─",
  26.                     "512x768",
  27.                     "640x960",
  28.                     "768x1152",
  29.                     "896x1344",
  30.                     "1024x1536",
  31.                     "1152x1728",
  32.                     "1280x1920",
  33.  
  34.                     "─ 3:4 ─",
  35.                     "480x640",
  36.                     "720x960",
  37.                     "768x1024",
  38.                     "864x1152",
  39.                     "960x1280",
  40.                     "1152x1536",
  41.                     "1344x1792",
  42.                     "1440x1920",
  43.  
  44.                     "─ 1:1 ─",
  45.                     "640x640",
  46.                     "1024x1024",
  47.                     "1920x1920",
  48.                 ], {"default": "720x1280"}),
  49.                 "invert": ("BOOLEAN", {"default": False}),
  50.                 "custom_width":  ("INT", {"default": 0, "min": 0, "max": 8192, "step": 8}),
  51.                 "custom_height": ("INT", {"default": 0, "min": 0, "max": 8192, "step": 8}),
  52.                 "fps":     ("INT",   {"default": 16, "min": 1, "max": 240, "step": 1}),
  53.                 "total_steps": ("INT", {"default": 6, "min": 0, "max": 100, "step": 1}),
  54.                 "shift": ("INT", {"default": 5, "min": 0, "max": 100, "step": 1}),
  55.                 "prefix": ("STRING", {"default": ""}),
  56.             },
  57.         }
  58.  
  59.     RETURN_TYPES = (
  60.         "INT",    # width
  61.         "INT",    # height
  62.         "FLOAT",  # fps
  63.         "INT",    # total_steps
  64.         "FLOAT",    # shift
  65.         "STRING", # label
  66.     )
  67.  
  68.     RETURN_NAMES = (
  69.         "width",
  70.         "height",
  71.         "fps",
  72.         "total_steps",
  73.         "shift",
  74.         "prefix",
  75.     )
  76.  
  77.     FUNCTION = "select"
  78.     CATEGORY = "utils/video"
  79.  
  80.     def select(
  81.         self,
  82.         preset,
  83.         invert,
  84.         custom_width,
  85.         custom_height,
  86.         fps,
  87.         total_steps,
  88.         shift,
  89.         prefix,
  90.     ):
  91.         # ---- guard for category labels ----
  92.         if preset.startswith("─"):
  93.             raise ValueError("Please select a resolution, not a category label.")
  94.  
  95.         # ---- resolution ----
  96.         if preset == "Custom":
  97.             w = custom_width
  98.             h = custom_height
  99.             if w <= 0 or h <= 0:
  100.                 raise ValueError("Custom resolution must be greater than 0.")
  101.         else:
  102.             m = re.match(r"^(\d+)x(\d+)$", preset)
  103.             if not m:
  104.                 raise ValueError(f"Invalid preset format: {preset}")
  105.             w, h = int(m.group(1)), int(m.group(2))
  106.  
  107.         # Swap width/height if needed
  108.         if invert:
  109.             w, h = h, w
  110.  
  111.         return (
  112.             w,
  113.             h,
  114.             float(fps),
  115.             int(total_steps),
  116.             float(shift),
  117.             prefix,
  118.         )
  119.  
  120. class VideoFramesConfig:
  121.     @classmethod
  122.     def INPUT_TYPES(cls):
  123.         return {
  124.             "required": {
  125.                 "fps": ("FLOAT",),
  126.                 "seconds": ("FLOAT", {
  127.                     "default": 5.0,
  128.                     "min": 0.5,
  129.                     "max": 100.0,
  130.                     "step": 0.5
  131.                 }),
  132.                 "width": ("INT",),
  133.                 "height": ("INT",),
  134.             },
  135.             "hidden": {
  136.                 "unique_id": "UNIQUE_ID",
  137.             },
  138.         }
  139.  
  140.     RETURN_TYPES = ("INT",)
  141.     RETURN_NAMES = ("frames",)
  142.  
  143.     FUNCTION = "calculate"
  144.  
  145.     CATEGORY = "utils/video"
  146.  
  147.     def calculate(self, fps, seconds, width, height, unique_id=None):
  148.  
  149.         # ---- adjust frame_count (4n + 1) ----
  150.         frames = int(round(fps * seconds))
  151.         frames = round((frames - 1) / 4) * 4 + 1
  152.         frames = max(1, frames)
  153.  
  154.         # ---- calculate megapixel ----
  155.         megapixels = (width * height * frames) / 1_000_000.0
  156.  
  157.         if unique_id and PromptServer and hasattr(PromptServer, "instance"):
  158.             try:
  159.                 PromptServer.instance.send_progress_text(
  160.                     f"<tr><td>Output: </td>"
  161.                     f"<td><b>{width}x{height}x{frames}f</b> | <b style='color:#FFA500;'>{megapixels:.2f}</b><b> MP</b></td></tr>",
  162.                     unique_id
  163.                 )
  164.             except Exception:
  165.                 pass
  166.  
  167.         return (frames,)
  168.  
  169.  
  170. NODE_CLASS_MAPPINGS = {
  171.     "VideoConfigSVI": VideoConfigSVI,
  172.     "VideoFramesConfig": VideoFramesConfig
  173. }
  174.  
  175. NODE_DISPLAY_NAME_MAPPINGS = {
  176.     "VideoConfigSVI": "Video Config (SVI)",
  177.     "VideoFramesConfig": "Video Frames Config"
  178. }
Advertisement
Add Comment
Please, Sign In to add comment