Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # custom_nodes/video_config_svi_v04.py
- import re
- try:
- from server import PromptServer
- except Exception:
- PromptServer = None
- class VideoConfigSVI:
- @classmethod
- def INPUT_TYPES(cls):
- return {
- "required": {
- "preset": ([
- "Custom",
- "─ 9:16 ─",
- "352x640",
- "544x960",
- "720x1280",
- "864x1536",
- "1008x1792",
- "1088x1920",
- "─ 2:3 ─",
- "512x768",
- "640x960",
- "768x1152",
- "896x1344",
- "1024x1536",
- "1152x1728",
- "1280x1920",
- "─ 3:4 ─",
- "480x640",
- "720x960",
- "768x1024",
- "864x1152",
- "960x1280",
- "1152x1536",
- "1344x1792",
- "1440x1920",
- "─ 1:1 ─",
- "640x640",
- "1024x1024",
- "1920x1920",
- ], {"default": "720x1280"}),
- "invert": ("BOOLEAN", {"default": False}),
- "custom_width": ("INT", {"default": 0, "min": 0, "max": 8192, "step": 8}),
- "custom_height": ("INT", {"default": 0, "min": 0, "max": 8192, "step": 8}),
- "fps": ("INT", {"default": 16, "min": 1, "max": 240, "step": 1}),
- "total_steps": ("INT", {"default": 6, "min": 0, "max": 100, "step": 1}),
- "shift": ("INT", {"default": 5, "min": 0, "max": 100, "step": 1}),
- "prefix": ("STRING", {"default": ""}),
- },
- }
- RETURN_TYPES = (
- "INT", # width
- "INT", # height
- "FLOAT", # fps
- "INT", # total_steps
- "FLOAT", # shift
- "STRING", # label
- )
- RETURN_NAMES = (
- "width",
- "height",
- "fps",
- "total_steps",
- "shift",
- "prefix",
- )
- FUNCTION = "select"
- CATEGORY = "utils/video"
- def select(
- self,
- preset,
- invert,
- custom_width,
- custom_height,
- fps,
- total_steps,
- shift,
- prefix,
- ):
- # ---- guard for category labels ----
- if preset.startswith("─"):
- raise ValueError("Please select a resolution, not a category label.")
- # ---- resolution ----
- if preset == "Custom":
- w = custom_width
- h = custom_height
- if w <= 0 or h <= 0:
- raise ValueError("Custom resolution must be greater than 0.")
- else:
- m = re.match(r"^(\d+)x(\d+)$", preset)
- if not m:
- raise ValueError(f"Invalid preset format: {preset}")
- w, h = int(m.group(1)), int(m.group(2))
- # Swap width/height if needed
- if invert:
- w, h = h, w
- return (
- w,
- h,
- float(fps),
- int(total_steps),
- float(shift),
- prefix,
- )
- class VideoFramesConfig:
- @classmethod
- def INPUT_TYPES(cls):
- return {
- "required": {
- "fps": ("FLOAT",),
- "seconds": ("FLOAT", {
- "default": 5.0,
- "min": 0.5,
- "max": 100.0,
- "step": 0.5
- }),
- "width": ("INT",),
- "height": ("INT",),
- },
- "hidden": {
- "unique_id": "UNIQUE_ID",
- },
- }
- RETURN_TYPES = ("INT",)
- RETURN_NAMES = ("frames",)
- FUNCTION = "calculate"
- CATEGORY = "utils/video"
- def calculate(self, fps, seconds, width, height, unique_id=None):
- # ---- adjust frame_count (4n + 1) ----
- frames = int(round(fps * seconds))
- frames = round((frames - 1) / 4) * 4 + 1
- frames = max(1, frames)
- # ---- calculate megapixel ----
- megapixels = (width * height * frames) / 1_000_000.0
- if unique_id and PromptServer and hasattr(PromptServer, "instance"):
- try:
- PromptServer.instance.send_progress_text(
- f"<tr><td>Output: </td>"
- f"<td><b>{width}x{height}x{frames}f</b> | <b style='color:#FFA500;'>{megapixels:.2f}</b><b> MP</b></td></tr>",
- unique_id
- )
- except Exception:
- pass
- return (frames,)
- NODE_CLASS_MAPPINGS = {
- "VideoConfigSVI": VideoConfigSVI,
- "VideoFramesConfig": VideoFramesConfig
- }
- NODE_DISPLAY_NAME_MAPPINGS = {
- "VideoConfigSVI": "Video Config (SVI)",
- "VideoFramesConfig": "Video Frames Config"
- }
Advertisement
Add Comment
Please, Sign In to add comment