Skip to content

Commit 5df1427

Browse files
authored
Fix audio extraction and truncation bugs (Comfy-Org#12652)
Bug report in Comfy-Org#12651 - to_skip fix: Prevents negative array slicing when the start offset is negative. - __duration check: Prevents the extraction loop from breaking after a single audio chunk when the requested duration is 0 (which is a sentinel for unlimited).
1 parent d1d53c1 commit 5df1427

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

comfy_api/latest/_input_impl/video_types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,15 +272,15 @@ def get_components_internal(self, container: InputContainer) -> VideoComponents:
272272
has_first_frame = False
273273
for frame in frames:
274274
offset_seconds = start_time - frame.pts * audio_stream.time_base
275-
to_skip = int(offset_seconds * audio_stream.sample_rate)
275+
to_skip = max(0, int(offset_seconds * audio_stream.sample_rate))
276276
if to_skip < frame.samples:
277277
has_first_frame = True
278278
break
279279
if has_first_frame:
280280
audio_frames.append(frame.to_ndarray()[..., to_skip:])
281281

282282
for frame in frames:
283-
if frame.time > start_time + self.__duration:
283+
if self.__duration and frame.time > start_time + self.__duration:
284284
break
285285
audio_frames.append(frame.to_ndarray()) # shape: (channels, samples)
286286
if len(audio_frames) > 0:

0 commit comments

Comments
 (0)