mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2026-09-03 18:17:06 +08:00
[bugfix] Ensure video frame count is divisible by 32 for Moonvalley (#226)
This commit is contained in:
parent
304606a645
commit
3a44b64eae
@ -241,13 +241,21 @@ def trim_video(video: VideoInput, duration_sec: float) -> VideoInput:
|
|||||||
audio_stream.layout = stream.layout
|
audio_stream.layout = stream.layout
|
||||||
logging.info(f"Added audio stream: {stream.sample_rate}Hz, {stream.channels} channels")
|
logging.info(f"Added audio stream: {stream.sample_rate}Hz, {stream.channels} channels")
|
||||||
|
|
||||||
|
# Calculate target frame count that's divisible by 32
|
||||||
|
fps = input_container.streams.video[0].average_rate
|
||||||
|
estimated_frames = int(duration_sec * fps)
|
||||||
|
target_frames = (estimated_frames // 32) * 32 # Round down to nearest multiple of 32
|
||||||
|
|
||||||
|
if target_frames == 0:
|
||||||
|
raise ValueError("Video too short: need at least 32 frames for Moonvalley")
|
||||||
|
|
||||||
frame_count = 0
|
frame_count = 0
|
||||||
audio_frame_count = 0
|
audio_frame_count = 0
|
||||||
|
|
||||||
# Decode and re-encode video frames
|
# Decode and re-encode video frames
|
||||||
if video_stream:
|
if video_stream:
|
||||||
for frame in input_container.decode(video=0):
|
for frame in input_container.decode(video=0):
|
||||||
if frame.time >= duration_sec:
|
if frame_count >= target_frames:
|
||||||
break
|
break
|
||||||
|
|
||||||
# Re-encode frame
|
# Re-encode frame
|
||||||
@ -259,7 +267,7 @@ def trim_video(video: VideoInput, duration_sec: float) -> VideoInput:
|
|||||||
for packet in video_stream.encode():
|
for packet in video_stream.encode():
|
||||||
output_container.mux(packet)
|
output_container.mux(packet)
|
||||||
|
|
||||||
logging.info(f"Encoded {frame_count} video frames")
|
logging.info(f"Encoded {frame_count} video frames (target: {target_frames})")
|
||||||
|
|
||||||
# Decode and re-encode audio frames
|
# Decode and re-encode audio frames
|
||||||
if audio_stream:
|
if audio_stream:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user