How to display videos inline in Google Colab

1.First of all

Keep a reminder of the code that displays the video inline in Google Colab.

2. How to do

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

n1uuj-idvrq.gif

Recommended Posts

How to display videos inline in Google Colab
How to use Google Test in C
How to display multiplication table in python
How to display Hello world in python
How to display formulas in latex when using sympy (> = 1.4) in Google Colaboratory
How to display Map using Google Map API (Android)
[Google Colab] I want to display multiple images side by side in tiles
How to use VS Code (code server) with Google Colab in just 3 lines
How to get the notebook name you are currently using in Google Colab
How to load files in Google Drive with Google Colaboratory
How to install Google Test / Google Mock in Visual Studio 2019
How to display multiple images of galaxies in tiles
How to display DataFrame as a table in Markdown
How to use Spacy Japanese model in Google Colaboratory
How to develop in Python
How to use Google Colaboratory
How to extract any appointment in Google Calendar with Python
[Google Colab] How to interrupt learning and then resume it
[Python] How to do PCA in Python
How to handle session in SQLAlchemy
How to write soberly in pandas
How to use SQLite in Python
How to convert 0.5 to 1056964608 in one shot
[Memo] How to use Google MµG
How to reflect CSS in Django
How to kill processes in bulk
How to use Mysql in python
How to wrap C in Python
How to use ChemSpider in Python
How to use PubChem in Python
How to run TensorFlow 1.0 code in 2.0
How to handle Japanese in Python
How to log in to Docker + NGINX
How to call PyTorch in Julia
How to display legend marks in one with Python 2D plot
How to display bytes in the same way in Java and Python
How to use calculated columns in CASTable
How to display the progress bar (tqdm)
[Rails] google maps api How to post and display including map information
How to access environment variables in Python
[Python] How to display random numbers (random module)
How to dynamically define variables in Python
How to do R chartr () in Python
How to use mecab, neologd-ipadic on colab
How to convert csv to tsv in CLI
How to update Google Sheets from Python
[Itertools.permutations] How to put permutations in Python
[Colab] How to copy a huge dataset
How to work with BigQuery in Python
How to use Google Assistant on Windows 10
How to execute commands in jupyter notebook
How to do'git fetch --tags' in GitPython
How to get a stacktrace in python
How to display emoji on Manjaro Linux
How to extract polygon area in Python
How to search Google Drive with Google Colaboratory
How to reassign index in pandas dataframe
How to check opencv version in python
How to display python Japanese with lolipop
How to download youtube videos with youtube-dl
How to enable SSL (TLS) in Apache