Skip to content

Add support for videos #955

Open
Open

Description

@Guangyi-Zhang

Description

IMO, one of the biggest pains in Tex is its support for videos.
Previously, it could work with the help of Flash and media9 pacakge, but not anymore since Flash gets outdated.
So far, the only two options in Tex is an unstable hack (try it, and you will see how frequently videos get stuck in any popular PDF viewer),

OR

the animate package that manipulates a whole seq of frames (it takes SO long to compile and the PDF size easily reaches 100 MB while mp4 is only 1MB).

Use Case

Videos have been more and more important in presenting technical content, see e.g., 3b1b and Manim.
I wish Typst could take this into serious consideration.

Activity

  1. added
    feature request
    on Apr 24, 2023
  2. u-fischer commented on Apr 24, 2023

    @u-fischer

    IMO, one of the biggest pains in Tex is its support for videos.

    The problem is not in LaTeX. If you have examples of PDF with well working embedded videos build with some other tool it would be quite straightforward to transfer that to LaTeX but imho such examples still don't exist (at least that was the situation last year, but I don't think that much happened here).

  3. Enivex commented on Apr 24, 2023

    @Enivex
    Collaborator

    Are there even PDF readers that properly support video apart from Adobe Reader?

    I think your best bet would be waiting for HTML output. That should more easily be able to support interactive content.

  4. vbarrielle commented on Apr 24, 2023

    @vbarrielle

    Beamer supports adding videos with \usepackage{multimedia} then \movie{path/to/image}{path/to/video}. I've succsefully read that with okular, so it's not just Adobe Reader that supports it. The video is not really inside the pdf, it must be copied in a relative path to the pdf that matches the one in the command.

  5. Guangyi-Zhang commented on Apr 25, 2023

    @Guangyi-Zhang
    Author

    Yes, this could work, sometimes. It is similar to the hack I mentioned.
    In my experience, sometimes the video can't be played and gets stuck, and sometimes the video size is off when I enter the full screen mode. This can be catastrophic in a serious presentation.

    BTW, I usually use Foxit PDF viewer and it also supports videos.

  6. added
    pdf
    visualize
    on May 9, 2023
  7. reknih commented on May 9, 2023

    @reknih
    Member

    Due to the way PDF implements videos, these cannot interact with many layout features (rotations, overlapping containers etc.) and must always be rendered as rectangles on top of all other content.

  8. lumpiluk commented on Aug 2, 2023

    @lumpiluk

    IMO, one of the biggest pains in Tex is its support for videos.

    The problem is not in LaTeX. If you have examples of PDF with well working embedded videos build with some other tool it would be quite straightforward to transfer that to LaTeX but imho such examples still don't exist (at least that was the situation last year, but I don't think that much happened here).

    LibreOffice Impress embeds videos automatically when doing a PDF export, and those videos seem to play without issues in Okular.

    I found the relevant issues for embedded videos and linked videos in a blog post from 2017.

  9. added
    good contribution
    on Sep 18, 2023
  10. awehrfritz commented on Feb 8, 2024

    @awehrfritz

    I had a brief look at this, and I believe the way LibreOffice implements this might be a viable solution for this here too.

    PDF specification:

    The LibreOffice implementation relies on the "Multimedia Features" specified in section 13.2 of the PDF 1.7 specification. The specification explicitly mentions that the media (e.g. videos) may be played with a variety of external players or the reader itself. Many PDF readers support this feature, include the Adobe Reader (for certain media types) or Okular (for a broad range of media types via the respective gstreamer or VLC backends).

    Linked videos:

    In particular, LibreOffice can add linked videos to a PDF file. Links can be of various type, including paths to local files. This was implemented here, and the resulting object in the PDF file looks like this:

    5 0 obj
    <</Type/Annot/Subtype/Screen/Rect[200.000 100.000 600.000 300.000]/A<</Type/Action /S/Rendition /AN 5 0 R /R<</Type/Rendition /S/MR /C<</Type/MediaClip /S/MCD 
    /D << /Type /Filespec /FS /URL /F (file:///path/to/video.mp4) >>
    /P <</TF (TEMPACCESS)>>/CT (video/mp4) /Alt [ () <FEFF> ] >>/P<</BE<</C true >>>>>>/OP 0 >>/P 1 0 R
    >>
    endobj
    

    Embedded videos:

    LibreOffice can also embed video files directly into a PDF file. This was implemented as an extension to the above implementation here, and the resulting object in the PDF file looks like this:

    5 0 obj
    <</Type/Annot/Subtype/Screen/Rect[200.000 100.000 600.000 300.000]/A<</Type/Action /S/Rendition /AN 5 0 R /R<</Type/Rendition /S/MR /C<</Type/MediaClip /S/MCD 
    /D << /Type /Filespec /F (<embedded file>) /EF << /F 6 0 R >> >>
    /P <</TF (TEMPACCESS)>>/CT (video/mp4) /Alt [ () <FEFF> ] >>/P<</BE<</C true >>>>>>/OP 0 >>/P 1 0 R
    >>
    endobj
    

    The main difference here is in the /Type /Filespec, which for the linked video is /FS /URL /F and the embedded file /F (<embedded file>) /EF.

    It is worth to note that pdf-writer has support for embedded files already (typst/pdf-writer@ba040ac), and linked files seem to be supported as well (#2695).

  11. awehrfritz commented on Feb 16, 2024

    @awehrfritz

    Now that typst/pdf-writer#31 is merged, does anyone (@reknih, @laurmaedje) have any pointers on how to add support for videos in typst?

    Like, I mean where in the code base should we start looking, or could find an implementation of similar features?

  12. reknih commented on Feb 17, 2024

    @reknih
    Member

    I think that there are a few things to consider here:

    • Most common PDF viewers except for Adobe Acrobat do not support videos. Over 50% of consumers of a PDF file with media will not be able to play it when opening it in their default viewer (Pdfium, pdf.js, Quartz). Hence, the videos should gracefully fall back to poster images, perhaps with a note that video content is available here. Likewise, the documentation should be written with this in mind. We will also need to fail PDF/A-2 export for files with video since multimedia is not allowed in these files.
    • The most commonly supported format is H.264 in MP4 containers. I think that Typst should check the magic numbers and such of a video file to verify that it will play. This means only supporting the H.264 codec and only MP4 containers, perhaps M4A, too. Including a video transcoding library in Typst is out of scope and will bloat the binary too much. However, Typst could be able to point the user to how to transcode their file, e.g. outputting the right ffmpeg command if that tool is detected on the system.
    • The functionality should be exposed in a video function that works similar to the image function with the additional capability of supplying a poster/fallback image. We want to add HTML export soon and the compatibility situation there looks quite different. Not only does HTML support more codecs (VP9, AV1, H.265), it also offers the possibility of linking video sources in multiple resolutions (one of which the browser automatically selects based on connectivity and viewport size). The API of the video function should be designed with this in mind. Ultimately, it would be best if the user could just specify an array of source files whose resolution and MIME types Typst will automatically detect to yield the right source tags or srcset attributes. It should also select the best H.264 video for the PDF.

    I think it would be best to come up with a plan for the user-facing API and how to process / identify video files. After that, you can be sure that your implementation has a good chance to be merged!

  13. leiserfg commented on May 10, 2024

    @leiserfg

    https://github.com/Cimbali/pympress supports playing videos, it sounds useful for slideshows and workbooks.

  14. Andrew15-5 commented on May 10, 2024

    @Andrew15-5
    Contributor

    Slideshows are already available via polylux.

    I didn't get the workbook part. A lot of graphical stuff can be created via cetz.

  15. leiserfg commented on May 10, 2024

    @leiserfg

    Slideshows are already available via polylux.

    I didn't get the workbook part. A lot of graphical stuff can be created via cetz.

    Yes, I'm aware of both, but I'm talking about videos no slideshows, today is common to play videos in the middle of slideshows and teaching (digital ) books

  16. awehrfritz commented on Jun 6, 2024

    @awehrfritz

    https://github.com/Cimbali/pympress supports playing videos, it sounds useful for slideshows and workbooks.

    Thanks for pointing out pympress, very interesting tool. They use Poppler to render PDF files and support VLC/Gstreamer to play videos (similar to other Poppler-based viewers like Okular).

    Otherwise, as @reknih pointed out that pdf.js doesn't support videos quite yet, but there was an early proof-of-concept implementation (mozilla/pdf.js#5450) which uses the html5 video element to render multimedia content in PDF files. While nobody seems to be actively working on this, it also doesn't seem an unsurmountable task to implement this as video in PDF files match nicely to the html5 video element.

  17. awehrfritz commented on Jun 6, 2024

    @awehrfritz

    I think it would be best to come up with a plan for the user-facing API and how to process / identify video files. After that, you can be sure that your implementation has a good chance to be merged!

    Thanks for your comments and view on this @reknih - very insightful and helpful to get started. I agree, there should be a clear user-facing API first, which probably requires a solid understanding of typst internals in the first place, and is thus a bit out of my comfort zone.

    However, I think such a user-facing API could be kept quite simple at first, and be extended later on. And while it would indeed be nice to support a whole range of video codecs, in practice H.264 in MP4 containers is probably still the most widely used one and also the most widely supported one, and thus maybe the best first target. Mapping such video support for PDF files to HTML is straight forward, since as you said, the HTML video tag is very versatile and pdf.js even had a proof-of-concept implementation (mozilla/pdf.js#5450).

    A comment on the use-cases for such multimedia support:

    • Personally, I use multimedia files in presentation slides, such as for teaching or scientific presentations such as in conferences.
    • I previously used the LaTeX multimedia package in beamer slides, which produces PDF files with links to the multimedia files. This is very similar to my implementation (Add video/multimedia support pdf-writer#31) or what LibreOffice does, though beamer + multimedia does not support embedding the multimedia files in the PDF itself.
    • A few years ago, I started using Quarto/reveal.js to create HTML slides which works otherwise real nice, but is cumbersome when sharing the slides with others since many people expect PDF and not HTML files. Having first-class support for PDF files is a very important feature and would give typst an edge over tools like Quarto + reveal.js.
  18. mrlogick commented on Nov 10, 2024

    @mrlogick

    Thanks guys for this amazing project. Video support is so important. If you manage to solve this, everyone would switch to Typst.

  19. luiswirth commented on Nov 23, 2024

    @luiswirth

    For presentation slides (à la beamer) it would be a game changer if we were able to write everything in typst and to include some videos and then export to HTML. I'm really hoping that this will become a reality. Then it's forever goodbye to powerpoint, google slides, etc.

  20. branaway commented on Jan 6, 2025

    @branaway

    A much needed feature. Please continue innovating...

  21. fbob commented on Mar 9, 2025

    @fbob

    This PR Add video/multimedia support #31 was merged on Feb 16, 2024.
    Any update on this feature ?
    Thanks.

  22. HackYardo commented on Apr 8, 2025

    @HackYardo

    There are concise tricks for X:

    • one GIF consists of several frames, use 2~4 jpg/png instead.
    • the same to MP4
    • use orthogonal views instead of 3D-MODEL
    • use score sheets instead of MUSIC

    although music, video, 3d-model and etc is useful and PDF standard supported.

  23. Enivex commented on Apr 8, 2025

    @Enivex
    Collaborator

    This PR Add video/multimedia support #31 was merged on Feb 16, 2024. Any update on this feature ? Thanks.

    As far as I know no one is working on this.

    although music, video, 3d-model and etc is useful and PDF standard supported

    Technically, although support outside of adobe reader is an extremely mixed bag

  24. knightnemo commented on Apr 20, 2025

    @knightnemo

    Really need this, fingers crossed

  25. Enivex commented on Apr 20, 2025

    @Enivex
    Collaborator

    Really need this, fingers crossed

    Keep in mind that everyone who has subscribed to this issue (including those that have commented) receive an email for every reply. Let's refrain from adding replies that do not add to the discussion.

  26. removed
    good contribution
    on Jul 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestpdfvisualize

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions