Fix a potential issue when saving long videos

This commit is contained in:
Jacob Segal 2025-04-28 18:37:21 -07:00
parent 48f9eb3ec7
commit 5cc90dccc0

View File

@ -276,8 +276,9 @@ class VideoFromComponents(VideoInput):
for key, value in metadata.items():
output.metadata[key] = json.dumps(value)
frame_rate = Fraction(round(self.components.frame_rate * 1000), 1000)
# Create a video stream
video_stream = output.add_stream('h264', rate=self.components.frame_rate)
video_stream = output.add_stream('h264', rate=frame_rate)
video_stream.width = self.components.images.shape[2]
video_stream.height = self.components.images.shape[1]
video_stream.pix_fmt = 'yuv420p'
@ -305,7 +306,7 @@ class VideoFromComponents(VideoInput):
if audio_stream and self.components.audio:
# Encode audio
samples_per_frame = int(audio_sample_rate / self.components.frame_rate)
samples_per_frame = int(audio_sample_rate / frame_rate)
num_frames = self.components.audio['waveform'].shape[2] // samples_per_frame
for i in range(num_frames):
start = i * samples_per_frame