Harmanjit Singh
Harmanjit Singh

Reputation: 303

How to embed local Video in R Markdown?

I already know how to embed the youtube video in the R Markdown document. But Suppose I have offline video, that I do not want to publish, in mp4 or avi format. Is there a way to embed it in the document? Something like the following (taking inspiration from image embedding):

![Caption](vid/video1.mp4)

Upvotes: 20

Views: 16246

Answers (4)

stahlmanDesign
stahlmanDesign

Reputation: 64

It also works to use an image tag

<img src="movie.mp4" type="video/mp4"/>

Upvotes: 0

Tung
Tung

Reputation: 28441

Using iframe worked for me

```{r}
video_path  <- "vid/"
video_files <- list.files(video_path,
                         pattern = "\\.mp4$",
                         recursive = TRUE,
                         all.files = FALSE,
                         full.names = TRUE)
```

<iframe width="720" height="480" src="`r video_files[1]`" align="middle" frameborder="0" allowfullscreen></iframe>

Upvotes: 2

Daniel Pl&#225;cido
Daniel Pl&#225;cido

Reputation: 9

See the code

![](https://www.yoursite.com/miniature.png)](https://www.youtube.com/watch?v=xyz)

See the code

Upvotes: -2

Mat D.
Mat D.

Reputation: 628

This worked for me:

Slide With Code
========================================================
<video width="320" height="240" controls>
  <source src="movie.mp4" type="video/mp4">
</video>

If you remove the width and height, and enable

autosize: true

R takes care of the size of the video.

Upvotes: 22

Related Questions