0

I have Jupyter Notebook tutorials that I used Matplotlibe and ipywidgets(interact) to display video with NumPy 3D format.

class JupyterDisplay():
 

    def __init__(self, video, median_filter_flag=False, color='gray', imgSizex=5, imgSizey=5, IntSlider_width='500px'):
        
        self.color = color
        self.video = video
        self.imgSizex = imgSizex
        self.imgSizey = imgSizey
        self.median_filter_flag = median_filter_flag

        interact(self.display, frame=widgets.IntSlider(min=0, max=self.video.shape[0] - 1, step=1, value=10,
                                                       layout=Layout(width=IntSlider_width),
                                                       readout_format='10', continuous_update=False,
                                                       description='Frame:'))

    def display(self, frame):
        fig = plt.figure(figsize=(self.imgSizex, self.imgSizey))
        ax = fig.add_axes([0, 0, 1, 1])

        if self.median_filter_flag:
            frame_v = median_filter(self.video[int(frame), :, :], 3)
        else:
            frame_v = self.video[int(frame), :, :]

        myplot = ax.imshow(frame_v, cmap=self.color)
        divider = make_axes_locatable(ax)
        cax = divider.append_axes("right", size="5%", pad=0.05)
        plt.colorbar(myplot, cax=cax)

        plt.show()

I want to create an HTML version from tutorials with sphinx make HTML. But the video is not visualized in the HTML version. What is the best way to display dynamic video in the HTML version?

I can create the mp4 from videos, but in this case, I need to have a conditional Jupyter cell to only run this part of the code when making HTML Sphinx used. Can you inform me how I should define this conditional cell?

HM_2020
  • 1
  • 2
  • Did you try: from IPython.display import Video Video("test.mp4") From: https://stackoverflow.com/questions/18019477/how-can-i-play-a-local-video-in-my-ipython-notebook – ItayBenHaim Mar 22 '21 at 12:40
  • Thank you! I know we can convert this to HTML but since this converter is too slow, I want to run the converter part only when I want to create HTML. Is there any automatic way that can detect these cells run to make HTML or by python kernel? – HM_2020 Mar 23 '21 at 06:19

0 Answers0