Keep a reminder of the code that displays the video inline in Google Colab.
Use ** imageio ** to load the video and break it into frames. Then, use the familiar ** matplotlib ** ** animationtion ** to animate it and send it to ** HTML5 ** to display the video inline.
import imageio
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from skimage.transform import resize
from IPython.display import HTML
def display_video(video):
fig = plt.figure(figsize=(3,3)) #Display size specification
mov = []
for i in range(len(video)): #Append videos one by one to mov
img = plt.imshow(video[i], animated=True)
plt.axis('off')
mov.append([img])
#Animation creation
anime = animation.ArtistAnimation(fig, mov, interval=50, repeat_delay=1000)
plt.close()
return anime
video = imageio.mimread('./sample/00.mp4') #Loading video
video = [resize(frame, (256, 256))[..., :3] for frame in video] #Size adjustment (if necessary)
HTML(display_video(video).to_html5_video()) #Inline video display in HTML5
Recommended Posts