# Why loadVideo() is not available?

**URL:** https://discourse.processing.org/t/why-loadvideo-is-not-available/31622
**Category:** Beginners
**Created:** [August 8, 2021, 8:29am UTC](https://discourse.processing.org/t/why-loadvideo-is-not-available/31622 "2021-08-08T08:29:07Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![matsuda](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/matsuda/32/14181_2.png) [@matsuda](https://discourse.processing.org/u/matsuda)
#### Post date: [August 8, 2021, 8:29am UTC](https://discourse.processing.org/t/why-loadvideo-is-not-available/31622/1 "2021-08-08T08:29:07Z")

</div>

Hi there  
We can deal with an image using loadImage() and also using createImg().  
However, in case of video, we can use createVideo() but “loadVideo()” is not available.  
It seems to be inconsistent.  
Is there any reason not to support loadVideo()?  
Could anyone help me to understand that?

Thanks

---

<div class="post-metadata">

### Author: ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)
#### Post date: [August 8, 2021, 4:48pm UTC](https://discourse.processing.org/t/why-loadvideo-is-not-available/31622/2 "2021-08-08T16:48:01Z")

</div>

hi! welcome to the forum!

`loadImage` and `createImg` are actually completely different functions. `loadImage` actually fetches the image from web, and stores the pixels in JavaScript (kind of). You can use it to draw on canvas, but you cannot use it in the other parts of the webpage. `createImg` is to make an `<image>` object on the webpage (like the Processing logo on this page). You can use this object within the canvas and also you can move it around outside the canvas.

The case of the video is somewhat tricky. Videos have so many formats and you cannot simply store the pixels. Also some videos are huge (more than a gigabyte) so it’s not realistic to load the whole thing in preload. That’s why p5.js uses the browser’s power to optimize loading the video, which is to create a `<video>` object using `createVideo`.

---

<div class="post-metadata">

### Author: ![matsuda](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/matsuda/32/14181_2.png) [@matsuda](https://discourse.processing.org/u/matsuda)
#### Post date: [August 14, 2021, 6:35am UTC](https://discourse.processing.org/t/why-loadvideo-is-not-available/31622/3 "2021-08-14T06:35:07Z")

</div>

Thanks,  
It’s interesting point.

> Also some videos are huge (more than a gigabyte) so it’s not realistic to load the whole thing in preload.

I think it depends on applications.  
In case of a game, application might want to wait for loading some videos (might be short videos) for game objects (e.g. splits) before starting the game.

---

<div class="post-metadata">

### Author: ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)
#### Post date: [August 14, 2021, 2:05pm UTC](https://discourse.processing.org/t/why-loadvideo-is-not-available/31622/4 "2021-08-14T14:05:11Z")

</div>

I understand but that’s not my point. p5.js (or client side JavaScript in general) cannot live without a browser. And p5.js uses browser features to load video. You may be able to go around by using webassembly to load videos, but I guess you don’t need it (and you shouldn’t) in most cases. I hope it helps.

> **[r/WebAssembly - Video Playback on WASM](https://www.reddit.com/r/WebAssembly/comments/lkx162/video_playback_on_wasm/)**
>
> 15 votes and 6 comments so far on Reddit

---

<div class="post-metadata">

### Author: ![matsuda](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/matsuda/32/14181_2.png) [@matsuda](https://discourse.processing.org/u/matsuda)
#### Post date: [August 24, 2021, 5:41am UTC](https://discourse.processing.org/t/why-loadvideo-is-not-available/31622/5 "2021-08-24T05:41:49Z")

</div>

Hi,  
Thanks.  
Can I expect setup() to be called after finishing loading a video when createVideo() is called in preload()?

```auto
let video;
function preload(){
  video = createVideo("foo.mp4");
}
function setup(){
  print("loading done");
  video.loop();
}

```

---

<div class="post-metadata">

### Author: ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)
#### Post date: [August 24, 2021, 3:50pm UTC](https://discourse.processing.org/t/why-loadvideo-is-not-available/31622/6 "2021-08-24T15:50:04Z")

</div>

I don’t think so because `createVideo` creates a video element. You need to look into video API on MDN because, again, it is not implemented in p5.js but it’s about the web API.

Video is loaded “on demand” so for example, [`loadeddata`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/loadeddata_event) is already triggered when the current frame is loaded (not the entire video). [`canplaythrough`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/canplaythrough_event) seems to be the closest but I don’t know if it guarantees that the entire data is loaded or it predicts that the data will be loaded with the current bandwidth.

---

<div class="post-metadata">

### Author: ![matsuda](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/matsuda/32/14181_2.png) [@matsuda](https://discourse.processing.org/u/matsuda)
#### Post date: [August 25, 2021, 2:51am UTC](https://discourse.processing.org/t/why-loadvideo-is-not-available/31622/7 "2021-08-25T02:51:57Z")

</div>

Thanks.  
It’s very clear.
