def save_video(frames_dict, fps=13): frame_keys = sorted([key for key in six.iterkeys(frames_dict)]) grid_dim = 2 # int(math.ceil(math.sqrt(len(frame_keys)) / 2.0)) clips = [] for frame_key in frame_keys: h, w, _ = frames_dict[frame_key][0].shape h += 40 w += 40 # title = TextClip(str(frame_key), color='black', fontsize=25, method='label') # title.set_position(("center", "top")) animation = ImageSequenceClip(frames_dict[frame_key], fps=fps) animation = animation.on_color(size=(w, h), color=(255, 255, 255)) # animation.set_position(("center", "bottom")) # video = CompositeVideoClip([animation, title], size=(h, w)) # clips.append(clips_array([[title], [animation]])) # clips_array([[title], [animation]])) clips.append(animation) # clips_array([[title], [animation]])) arranged_clips = [] start = 0 i = 0 while start < len(clips): arranged_clips.append(clips[i * grid_dim:(i + 1) * grid_dim]) i += 1 start = i * grid_dim under = len(arranged_clips[0]) - len(arranged_clips[-1]) if under > 0: for i in range(under): arranged_clips[-1].append(arranged_clips[-1][-1]) final_clip = clips_array(arranged_clips) #final_clip.write_videofile("data_3_14_results_output.mp4", codec='mpeg4') final_clip.write_videofile("results_output.mp4", codec='libx264')