feat(wan_ai_i2v): simplify video handling and improve error management
- Remove unused imports (os, tempfile) to reduce dependencies - Simplify VideoFromFile import fallback logic by removing unnecessary comments - Remove get_dimensions() method from VideoFromFile wrapper class - Consolidate video download logic and remove redundant error handling - Increase download timeout from 60s to 120s for better reliability - Remove verbose print statements for cleaner logging - Simplify video data processing by directly using response.content - Streamline return statement to directly instantiate VideoFromFile - Remove fallback video_data return path for consistent API behavior - Improve code readability and maintainability through simplification
This commit is contained in:
+5
-41
@@ -1,29 +1,20 @@
|
||||
import time
|
||||
import requests
|
||||
import os
|
||||
import tempfile
|
||||
import io
|
||||
from .modelverse_api.client import ModelverseClient
|
||||
from .modelverse_api.utils import image_to_base64
|
||||
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 ImportError:
|
||||
# Final fallback - create a simple wrapper
|
||||
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
|
||||
|
||||
def get_dimensions(self):
|
||||
# Return default dimensions if we can't determine them
|
||||
return (1280, 720) # width, height
|
||||
|
||||
class Modelverse_WanAII2V:
|
||||
def __init__(self):
|
||||
@@ -157,38 +148,11 @@ class Modelverse_WanAII2V:
|
||||
raise Exception(f"Task timed out after {max_retries * 5} seconds")
|
||||
|
||||
# 3. Download video
|
||||
print(f"Downloading video from: {video_url}")
|
||||
try:
|
||||
response = requests.get(video_url, timeout=60)
|
||||
response.raise_for_status()
|
||||
except requests.exceptions.RequestException as e:
|
||||
raise Exception(f"Failed to download video: {e}")
|
||||
|
||||
# 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
|
||||
response = requests.get(video_url, timeout=120)
|
||||
response.raise_for_status()
|
||||
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 = {
|
||||
|
||||
Reference in New Issue
Block a user