MyST-Parser icon indicating copy to clipboard operation
MyST-Parser copied to clipboard

proposal for a html_video extension

Open parmentelat opened this issue 1 year ago • 9 comments

Context

this is a follow-up to https://github.com/executablebooks/jupyter-book/issues/1249

Proposal

in essence, the proposal is to create a new html_video extension that would behave much like html_image and would let users insert raw video html tags the main effect being - as far as I am concerned - for the referred media file to be copied over in the jb build area

Tasks and updates

  • [ ] agree on the relevance
  • [ ] fine-tune the definition of the expected behaviour;
    in particular the <video> tag differs a bit from <img> in that it allows for a src attribute, but also to insert <source>-tagged children in a way that makes it a little more complex to deal with
  • [ ] update documentation and examples

parmentelat avatar Dec 11 '22 10:12 parmentelat

Heya, have you seen https://github.com/sphinx-contrib/video

chrisjsewell avatar Mar 01 '23 06:03 chrisjsewell

In my use case, I teach using live interactive notebooks with embedded <video> elements, so regular Jupyter/RISE needs to understand it. Then I use Jupyter Book to publish the rendered content as a reference for students (with Thebe and Binder in case they want to interact, or they clone the repo locally). html_image has been essential to be able to render/position within Jupyter/RISE while getting correct output on the class website. But <video> path handling is currently broken and I've been hacking my _build outputs with sed to repair the paths. I would love to see html_video even if only to avoid this manual path hacking.

jedbrown avatar Dec 07 '23 05:12 jedbrown

FWIW the way I do it on my end is to

  • store the video content in _static
  • insert it in the notebook in a code cell that reads
    from ipywidgets import Video
    Video.from_file("_static/thevideo.mp4", autoplay=False)
    

this turns out to render in both jlab and jupyter book, without the need for messing with paths (except of course for the constraint to store the video in _static which I agree is a moderate pain)

parmentelat avatar Dec 07 '23 13:12 parmentelat

@chrisjsewell the reference to sphinx-contrib/video is interesting but IIUC the example relies on ReST rather than MyST

.. video:: _static/video.mp4

are you suggesting that we can use

```{video} _static/thevideo.mp4
```

instead ? and if yes, would that work even if the video is not under _static, like we can do with {image} ?

parmentelat avatar Dec 07 '23 13:12 parmentelat

are you suggesting that we can use

yep exactly; there should be no reason it does not work exactly like for RST (the same as for every other directive)

I haven't had a chance to try out though, maybe you can report back

chrisjsewell avatar Dec 19 '23 09:12 chrisjsewell

so it feels like I must be doing something very wrong, because:

I create a notebook and add this in a cell

this one is under `_static/`

```{video} _static/under-static.mp4
```

this one is under `media/`

```{video} media/under-media.mp4

so first in JupyterLab with jupyterlab-myst it renders like this

image

then in the output of jupyter book I see this

image

parmentelat avatar Dec 19 '23 16:12 parmentelat

correction: once I add sphinxcontrib.video to sphinx's extra_extensions, I am getting this in the jupyter book output: the video under _static gets properly packaged in the html output but not the one under another folder, specifically here ./media/

is there something else I need to do to improve these results ?

image

parmentelat avatar Dec 19 '23 23:12 parmentelat

to be exhaustive, here's the versions that I have installed

pip list | grep -Ei 'myst|sphinx'
jupyterlab_myst               2.1.0
myst-nb                       0.17.2
myst-parser                   0.18.1
pydata-sphinx-theme           0.14.4
Sphinx                        5.0.2
sphinx-book-theme             1.0.1
sphinx-comments               0.0.3
sphinx-copybutton             0.5.2
sphinx_design                 0.3.0
sphinx-exercise               0.4.1
sphinx_external_toc           0.3.1
sphinx-jupyterbook-latex      0.5.2
sphinx-multitoc-numbering     0.1.3
sphinx-rtd-theme              2.0.0
sphinx-thebe                  0.2.1
sphinx-togglebutton           0.3.2
sphinxcontrib-applehelp       1.0.7
sphinxcontrib-bibtex          2.5.0
sphinxcontrib-devhelp         1.0.5
sphinxcontrib-htmlhelp        2.0.4
sphinxcontrib-jquery          4.1
sphinxcontrib-jsmath          1.0.1
sphinxcontrib-mermaid         0.9.2
sphinxcontrib-qthelp          1.0.6
sphinxcontrib-serializinghtml 1.1.9
sphinxcontrib-video           0.2.0

parmentelat avatar Dec 20 '23 13:12 parmentelat

finally I just noticed that with the one combo that does work (within jupyter book output, referring to a video stored under _static) I can't seem to change the size of the rendered

parmentelat avatar Dec 20 '23 13:12 parmentelat