Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple videos side-by-side with IPython Display

I have been using the useful answer suggested in this StackOverflow post to view multiple videos at once in Jupyter Notebook. Essentially, HTML doesn't seem to be working but IPython does so something like this (given a list of filepaths to the desired videos) works magic:

from IPython import display

for filepath in filepaths:
    display.display(display.Video(filepath, embed=True))

Now I get all the videos displayed in the output. However, these videos are vertically stacked. There is a lot of space to the side and it would be ideal to place them side-by-side first rather than vertically so I can easily see them on the screen together. How can I do this?

like image 331
Vainmonde De Courtenay Avatar asked Sep 20 '25 08:09

Vainmonde De Courtenay


1 Answers

You can do this with ipywidgets: Display the videos within a ipywidgets.Output widget, and then use ipywidgets.GridspecLayout to arange your widgets. Here is an example:

from ipywidgets import Output, GridspecLayout
from IPython import display

grid = GridspecLayout(1, len(filepaths))

for i, filepath in enumerate(filepaths):
    out = Output()
    with out:
        display.display(display.Video(filepath, embed=True))
    grid[0, i] = out

grid
like image 65
zaphod Avatar answered Sep 21 '25 23:09

zaphod