mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-02-13 23:12:35 +08:00
fixed a small bug
This commit is contained in:
parent
73cdb32659
commit
aaa3bcc233
@ -428,4 +428,4 @@ class Gemma2_2B(BaseLlama, torch.nn.Module):
|
|||||||
self.num_layers = config.num_hidden_layers
|
self.num_layers = config.num_hidden_layers
|
||||||
|
|
||||||
self.model = Llama2_(config, device=device, dtype=dtype, ops=operations)
|
self.model = Llama2_(config, device=device, dtype=dtype, ops=operations)
|
||||||
self.dtype = dtype
|
self.dtype = dtype
|
||||||
|
|||||||
@ -89,7 +89,7 @@ class VideoFromFile(VideoInput):
|
|||||||
return stream.width, stream.height
|
return stream.width, stream.height
|
||||||
raise ValueError(f"No video stream found in file '{self.__file}'")
|
raise ValueError(f"No video stream found in file '{self.__file}'")
|
||||||
|
|
||||||
def get_duration(self, retrun_frames = False) -> float:
|
def get_duration(self) -> float:
|
||||||
"""
|
"""
|
||||||
Returns the duration of the video in seconds.
|
Returns the duration of the video in seconds.
|
||||||
|
|
||||||
@ -100,16 +100,14 @@ class VideoFromFile(VideoInput):
|
|||||||
self.__file.seek(0)
|
self.__file.seek(0)
|
||||||
with av.open(self.__file, mode="r") as container:
|
with av.open(self.__file, mode="r") as container:
|
||||||
if container.duration is not None:
|
if container.duration is not None:
|
||||||
return float(container.duration / av.time_base) if not retrun_frames\
|
return float(container.duration / av.time_base)
|
||||||
else float(container.duration / av.time_base), float(container.duration)
|
|
||||||
|
|
||||||
# Fallback: calculate from frame count and frame rate
|
# Fallback: calculate from frame count and frame rate
|
||||||
video_stream = next(
|
video_stream = next(
|
||||||
(s for s in container.streams if s.type == "video"), None
|
(s for s in container.streams if s.type == "video"), None
|
||||||
)
|
)
|
||||||
if video_stream and video_stream.frames and video_stream.average_rate:
|
if video_stream and video_stream.frames and video_stream.average_rate:
|
||||||
return float(video_stream.frames / video_stream.average_rate) if not retrun_frames\
|
return float(video_stream.frames / video_stream.average_rate)
|
||||||
else float(video_stream.frames / video_stream.average_rate), float(video_stream.frames)
|
|
||||||
|
|
||||||
# Last resort: decode frames to count them
|
# Last resort: decode frames to count them
|
||||||
if video_stream and video_stream.average_rate:
|
if video_stream and video_stream.average_rate:
|
||||||
@ -119,8 +117,7 @@ class VideoFromFile(VideoInput):
|
|||||||
for _ in packet.decode():
|
for _ in packet.decode():
|
||||||
frame_count += 1
|
frame_count += 1
|
||||||
if frame_count > 0:
|
if frame_count > 0:
|
||||||
return float(frame_count / video_stream.average_rate) if not retrun_frames\
|
return float(frame_count / video_stream.average_rate)
|
||||||
else float(frame_count / video_stream.average_rate), float(frame_count)
|
|
||||||
|
|
||||||
raise ValueError(f"Could not determine duration for file '{self.__file}'")
|
raise ValueError(f"Could not determine duration for file '{self.__file}'")
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user