feat(vidu,wan_ai): add video dimension extraction with av library

- Add `get_dimensions()` method to VideoFromFile fallback class across all vidu and wan_ai modules
- Implement PyAV (av) library integration to extract video width and height from container streams
- Add dimension caching with `_width` and `_height` attributes to avoid redundant parsing
- Implement fallback dimensions (1280x720) when video parsing fails
- Add proper stream seeking to reset file position after dimension extraction
- Update requirements.txt to include av library dependency
- Ensure consistent video dimension handling across vidu_t2v, vidu_i2v, vidu_ref2v, vidu_startend2v, vidu_extend, wan_ai_t2v, and wan_ai_i2v modules
This commit is contained in:
jason.mei
2025-12-29 18:11:04 +08:00
parent 20093d1c40
commit c2d2ec96b2
8 changed files with 128 additions and 2 deletions
+18
View File
@@ -15,10 +15,28 @@ except ImportError:
try:
from comfy.model_management import VideoFromFile
except ImportError:
import av
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
self._width = None
self._height = None
def get_dimensions(self):
if self._width is None:
self.video_io.seek(0)
try:
container = av.open(self.video_io)
stream = container.streams.video[0]
self._width = stream.width
self._height = stream.height
container.close()
except:
self._width, self._height = 1280, 720
self.video_io.seek(0)
return (self._width, self._height)
MODELS = ["viduq2-pro", "viduq2-turbo"]
+18
View File
@@ -15,10 +15,28 @@ except ImportError:
try:
from comfy.model_management import VideoFromFile
except ImportError:
import av
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
self._width = None
self._height = None
def get_dimensions(self):
if self._width is None:
self.video_io.seek(0)
try:
container = av.open(self.video_io)
stream = container.streams.video[0]
self._width = stream.width
self._height = stream.height
container.close()
except:
self._width, self._height = 1280, 720
self.video_io.seek(0)
return (self._width, self._height)
MODELS = ["viduq2-pro", "viduq2-turbo"]
+18
View File
@@ -16,10 +16,28 @@ except ImportError:
try:
from comfy.model_management import VideoFromFile
except ImportError:
import av
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
self._width = None
self._height = None
def get_dimensions(self):
if self._width is None:
self.video_io.seek(0)
try:
container = av.open(self.video_io)
stream = container.streams.video[0]
self._width = stream.width
self._height = stream.height
container.close()
except:
self._width, self._height = 1280, 720
self.video_io.seek(0)
return (self._width, self._height)
ASPECT_RATIOS = ["16:9", "9:16", "3:4", "4:3", "1:1"]
+18
View File
@@ -15,10 +15,28 @@ except ImportError:
try:
from comfy.model_management import VideoFromFile
except ImportError:
import av
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
self._width = None
self._height = None
def get_dimensions(self):
if self._width is None:
self.video_io.seek(0)
try:
container = av.open(self.video_io)
stream = container.streams.video[0]
self._width = stream.width
self._height = stream.height
container.close()
except:
self._width, self._height = 1280, 720
self.video_io.seek(0)
return (self._width, self._height)
MODELS = ["viduq2-pro", "viduq2-turbo"]
+18
View File
@@ -14,10 +14,28 @@ except ImportError:
try:
from comfy.model_management import VideoFromFile
except ImportError:
import av
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
self._width = None
self._height = None
def get_dimensions(self):
if self._width is None:
self.video_io.seek(0)
try:
container = av.open(self.video_io)
stream = container.streams.video[0]
self._width = stream.width
self._height = stream.height
container.close()
except:
self._width, self._height = 1280, 720
self.video_io.seek(0)
return (self._width, self._height)
ASPECT_RATIOS = ["16:9", "9:16", "3:4", "4:3", "1:1"]
+18
View File
@@ -11,10 +11,28 @@ except ImportError:
try:
from comfy.model_management import VideoFromFile
except ImportError:
import av
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
self._width = None
self._height = None
def get_dimensions(self):
if self._width is None:
self.video_io.seek(0)
try:
container = av.open(self.video_io)
stream = container.streams.video[0]
self._width = stream.width
self._height = stream.height
container.close()
except:
self._width, self._height = 1280, 720
self.video_io.seek(0)
return (self._width, self._height)
class Modelverse_WanAII2V:
def __init__(self):
+18 -1
View File
@@ -11,11 +11,28 @@ except ImportError:
try:
from comfy.model_management import VideoFromFile
except ImportError:
# Fallback class when VideoFromFile is not available
import av
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
self._width = None
self._height = None
def get_dimensions(self):
if self._width is None:
self.video_io.seek(0)
try:
container = av.open(self.video_io)
stream = container.streams.video[0]
self._width = stream.width
self._height = stream.height
container.close()
except:
self._width, self._height = 1280, 720
self.video_io.seek(0)
return (self._width, self._height)
class Modelverse_WanAIT2V:
def __init__(self):
+2 -1
View File
@@ -1,3 +1,4 @@
requests >= 2.32.4
pillow >= 11
openai >= 1.107.0
openai >= 1.107.0
GitPython==3.1.45