Image widget Video#

Example showing how to scroll through one or more videos using the ImageWidget

image widget single video
# test_example = true

import fastplotlib as fpl
import imageio.v3 as iio
import numpy as np


movie = iio.imread("imageio:cockatoo.mp4")

# Ignore and do not use the next 2 lines
# for the purposes of docs gallery generation we subsample and only use 15 frames
movie_sub = movie[:15, ::12, ::12].copy()
del movie

iw = fpl.ImageWidget(movie_sub, rgb=True, figure_kwargs={"size": (700, 560)})

# ImageWidget supports setting window functions the `time` "t" or `volume` "z" dimension
# These can also be given as kwargs to `ImageWidget` during instantiation
# to set a window function, give a dict in the form of {dim: (func, window_size)}
iw.window_funcs = {"t": (np.mean, 5)}

# change the window size
iw.window_funcs = {"t": (np.mean, 2)}

# change the function
iw.window_funcs = {"t": (np.max, 2)}

# or reset it
iw.window_funcs = None

iw.show()

figure = iw.figure

# NOTE: fpl.loop.run() should not be used for interactive sessions
# See the "JupyterLab and IPython" section in the user guide
if __name__ == "__main__":
    print(__doc__)
    fpl.loop.run()

Total running time of the script: (0 minutes 4.769 seconds)

Gallery generated by Sphinx-Gallery