1 回答
TA贡献1784条经验 获得超2个赞
要显示单个视频,您必须从列表中删除图像 -cols = []
而不是cols = [source]
我无法测试它,但它的工作原理是这样的
使用视频文件名创建 5x5 列表
读取每个视频并转换为帧列表
使用索引来连接行中的帧并将行连接到单个图像。
通过这种方式,它会创建显示为动画的图像列表。
all_filenames = [
# row 1
[
'/content/gdrive/My Drive/first-order-motion-model/video1.mp4',
'/content/gdrive/My Drive/first-order-motion-model/video2.mp4',
'/content/gdrive/My Drive/first-order-motion-model/video3.mp4',
'/content/gdrive/My Drive/first-order-motion-model/video4.mp4',
'/content/gdrive/My Drive/first-order-motion-model/video5.mp4',
],
# row 2
[
'/content/gdrive/My Drive/first-order-motion-model/other1.mp4',
'/content/gdrive/My Drive/first-order-motion-model/other2.mp4',
'/content/gdrive/My Drive/first-order-motion-model/other3.mp4',
'/content/gdrive/My Drive/first-order-motion-model/other4.mp4',
'/content/gdrive/My Drive/first-order-motion-model/other5.mp4',
],
# row 3
# etc.
]
# --- load all videos and convert every video to list of frames ---
all_videos = []
for row in all_filenames:
row_videos = []
for filename in row:
# read video
video = imageio.mimread(filename)
# convert to list of frames
frames = [resize(frame, (256, 256))[..., :3] for frame in video]
# keep it in row
row_videos.append(frames)
# keep row in `all_videos`
all_videos.append(row_videos)
# --- concatenate list 5x5 to images ---
def display(all_videos):
fig = plt.figure(figsize=(4*5, 4*5))
all_images = []
for i in range(len(all_videos[0][0])): # use len of first video in first row but it would rather use `min()` for all videos
col_images = []
for row in all_videos:
row_images = []
for video in row:
row_images.append(video[i])
# concatenate every row
row_img = np.concatenate(row_images, axis=1)
col_images.append(row_img)
# concatenate rows to single images
col_img = np.concatenate(col_images, axis=0)
img = plt.imshow(col_img, animated=True)
plt.axis('off')
all_images.append([img])
ani = animation.ArtistAnimation(fig, all_images, interval=50, repeat_delay=1000)
plt.close()
return ani
HTML(display(all_videos).to_html5_video())
添加回答
举报