feat(wan_ai_t2v): improve video generation and error handling

- Remove unused imports (os, tempfile)
- Add fallback VideoFromFile class for better compatibility
- Simplify video download and processing logic
- Add timeout parameter (120s) to video download request
- Improve error handling with specific ImportError catching
- Reduce code complexity by removing redundant checks and logging
- Streamline BytesIO object creation and return statement
- Enhance robustness when VideoFromFile is not available in ComfyUI
This commit is contained in:
jason.mei
2025-12-29 17:53:31 +08:00
parent bd7d00b1ce
commit 7a3091df10
+10 -32
View File
@@ -1,20 +1,21 @@
import time
import requests
import os
import tempfile
import io
from .modelverse_api.client import ModelverseClient
from comfy.comfy_types.node_typing import IO
# Import VideoFromFile class for ComfyUI video handling
try:
# Try the newer import path first
from comfy_extras.nodes_video import VideoFromFile
except ImportError:
try:
# Fallback to older import path
from comfy.model_management import VideoFromFile
except:
raise ImportError("VideoFromFile not found")
except ImportError:
# Fallback class when VideoFromFile is not available
class VideoFromFile:
def __init__(self, video_io):
self.video_io = video_io
self.video_data = video_io.getvalue() if hasattr(video_io, 'getvalue') else video_io
class Modelverse_WanAIT2V:
def __init__(self):
@@ -83,34 +84,11 @@ class Modelverse_WanAIT2V:
raise Exception(f"Unknown task status: {task_status}")
# 3. Download video
response = requests.get(video_url)
response = requests.get(video_url, timeout=120)
response.raise_for_status()
# Extract video data
video_data = response.content
if not video_data:
raise Exception("No video data was returned")
print("Video generation completed successfully")
print(f"Downloaded video data size: {len(video_data)} bytes")
# Convert video data to BytesIO object
video_io = io.BytesIO(video_data)
# Ensure the BytesIO object is at the beginning
video_io = io.BytesIO(response.content)
video_io.seek(0)
# Return VideoFromFile object
try:
video_obj = VideoFromFile(video_io)
print("VideoFromFile object created successfully")
return (video_obj,)
except Exception as e:
print(f"Error creating VideoFromFile object: {e}")
# If VideoFromFile fails, try returning the raw video data
# This is a fallback that might work with some ComfyUI versions
return (video_data,)
return (VideoFromFile(video_io),)
NODE_CLASS_MAPPINGS = {