# Webcam input three.js

**URL:** <https://discourse.threejs.org/t/webcam-input-three-js/1500>\
**Category:** Questions\
**Tags:** webcam, video-texture\
**Created:** [December 23, 2017, 6:50pm UTC](https://discourse.threejs.org/t/webcam-input-three-js/1500 "2017-12-23T18:50:38Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![zrama](https://avatars.discourse-cdn.com/v4/letter/z/b487fb/32.png) [@zrama](https://discourse.threejs.org/u/zrama)\
**Post date:** [December 23, 2017, 6:50pm UTC](https://discourse.threejs.org/t/webcam-input-three-js/1500/1 "2017-12-23T18:50:38Z")

</div>

Hi there,

I’d like to use webcam input for my next project. I’ve seen some examples but is there somewhere a good and clear tutorial or source code that I can look at? So far I’ve not found anything that is helpful for me.

Many thanks in advance

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [December 24, 2017, 10:54am UTC](https://discourse.threejs.org/t/webcam-input-three-js/1500/2 "2017-12-24T10:54:21Z")

</div>

I’ve created a little fiddle that might be helpful. The code uses [THREE.VideoTexture](https://threejs.org/docs/#api/textures/VideoTexture) in order to display the video stream of the webcam as a texture on a simple plane.

> **[three.js webcam input - JSFiddle - Code Playground](https://jsfiddle.net/r51jgqdf/)**
>
> Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle code editor.

---

<div class="post-metadata">

**Author:** ![EliasHasle](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/eliashasle/32/3010_2.png) [@EliasHasle](https://discourse.threejs.org/u/EliasHasle)\
**Post date:** [December 28, 2017, 10:30am UTC](https://discourse.threejs.org/t/webcam-input-three-js/1500/3 "2017-12-28T10:30:22Z")

</div>

There are some pitfalls. In my experience (mostly on Chrome), the webcam can only be accessed over https. Not even locally, with Chrome’s --allow-file-access-from-files. Maybe there exists some flag that will do the trick.

---

<div class="post-metadata">

**Author:** ![zrama](https://avatars.discourse-cdn.com/v4/letter/z/b487fb/32.png) [@zrama](https://discourse.threejs.org/u/zrama)\
**Post date:** [December 28, 2017, 4:15pm UTC](https://discourse.threejs.org/t/webcam-input-three-js/1500/5 "2017-12-28T16:15:50Z")

</div>

The idea is to create a texture with this image so that the webcam input merges with it if that makes any sense?? ![camtexture](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/1X/065824f5bd887b5aa709b18c437f5b2ec21512e3.gif)

[https://www.yuichiroharai.com/experiments/fluid/](https://www.yuichiroharai.com/experiments/fluid/) \<— a bit like this but with the image above…

---

<div class="post-metadata">

**Author:** ![EliasHasle](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/eliashasle/32/3010_2.png) [@EliasHasle](https://discourse.threejs.org/u/EliasHasle)\
**Post date:** [October 22, 2018, 8:16pm UTC](https://discourse.threejs.org/t/webcam-input-three-js/1500/6 "2018-10-22T20:16:57Z")

</div>

Mugen87’s solution is now deprecated. Try this:

```javascript
var videoTexture, videoSettings;

navigator.mediaDevices.getUserMedia({video: true}).then(function(stream) {
	videoSettings = stream.getVideoTracks()[0].getSettings();
	let video = document.createElement("video");
	Object.assign(video, {
		srcObject: stream,
		//height: videoSettings.height,
		//width: videoSettings.width,
		autoplay: true
	});
	//document.body.appendChild(video);
	videoTexture = new THREE.VideoTexture(video);
	videoTexture.minFilter = THREE.LinearFilter;
	init();
	}
	).catch(function(error){console.error(error);});

```

Now the videoTexture containing the live webcam can basically be treated as any other texture, so that you can blend it with other images in a shader, apply post-processing etc. 🙂

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [October 22, 2018, 8:37pm UTC](https://discourse.threejs.org/t/webcam-input-three-js/1500/7 "2018-10-22T20:37:31Z")

</div>

@EliasHasle Thanks for updating!

There is also an example now. The next release `R98` will use the latest code for using a media stream as a source object for a video texture: [https://threejs.org/examples/#webgl\_materials\_video\_webcam](https://threejs.org/examples/#webgl_materials_video_webcam)

---

<div class="post-metadata">

**Author:** ![jrlazz](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/jrlazz/32/64383_2.png) [@jrlazz](https://discourse.threejs.org/u/jrlazz)\
**Post date:** [November 24, 2023, 8:38pm UTC](https://discourse.threejs.org/t/webcam-input-three-js/1500/9 "2023-11-24T20:38:03Z")

</div>

Hi Michael,  
Please, is there any alternative for rev 156.  
I could not connect my PC camera.  
PS: works in [Webcam ghost effect](https://eliashasle.github.io/ghost_webcam.html)  
 ![eliashaste](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/2/0/205fb14a37863abcedf9b933863ffd0128ce6dad.jpeg)

---

<div class="post-metadata">

**Author:** ![Lawrence3DPK](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/lawrence3dpk/32/29184_2.png) [@Lawrence3DPK](https://discourse.threejs.org/u/Lawrence3DPK)\
**Post date:** [November 24, 2023, 9:06pm UTC](https://discourse.threejs.org/t/webcam-input-three-js/1500/10 "2023-11-24T21:06:10Z")

</div>

> [@Mugen87](#):
>
> [three.js examples](https://threejs.org/examples/#webgl_materials_video_webcam)

@jrlazz are you referring to this example [three.js examples](https://threejs.org/examples/#webgl_materials_video_webcam)? this should work as expected in the latest versions, have you previously denied permissions for webcam access? also if you can let us know which browser / system you’re using? if this is not the example in question could you elaborate on which part of the thread you’re referring to?

---

<div class="post-metadata">

**Author:** ![Lawrence3DPK](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/lawrence3dpk/32/29184_2.png) [@Lawrence3DPK](https://discourse.threejs.org/u/Lawrence3DPK)\
**Post date:** [November 24, 2023, 9:09pm UTC](https://discourse.threejs.org/t/webcam-input-three-js/1500/11 "2023-11-24T21:09:46Z")

</div>

@jrlazz

> [@Mugen87](#):
>
> [Edit fiddle - JSFiddle - Code Playground](https://jsfiddle.net/LmwrxLdy/2/)

if it’s this codepen example, here’s an updated version that uses r158…

> **[Edit fiddle - JSFiddle - Code Playground](https://jsfiddle.net/forerun/ny0v6kcm/2/)**
>
> Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle code editor.

---

<div class="post-metadata">

**Author:** ![jrlazz](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/jrlazz/32/64383_2.png) [@jrlazz](https://discourse.threejs.org/u/jrlazz)\
**Post date:** [November 24, 2023, 9:12pm UTC](https://discourse.threejs.org/t/webcam-input-three-js/1500/12 "2023-11-24T21:12:54Z")

</div>

Thank You Lawrence… Now I saw many images. 🙂  
Here:  
[https://threejs.org/examples/#webgl\_materials\_video\_webcam](https://threejs.org/examples/#webgl_materials_video_webcam)

 ![webcam_three](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/a/7/a778a0e0051d2dca09feebd2d172361cc5dc17b5.jpeg)

---

<div class="post-metadata">

**Author:** ![jrlazz](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/jrlazz/32/64383_2.png) [@jrlazz](https://discourse.threejs.org/u/jrlazz)\
**Post date:** [November 24, 2023, 9:14pm UTC](https://discourse.threejs.org/t/webcam-input-three-js/1500/13 "2023-11-24T21:14:57Z")

</div>

Hi Lawrence,  
In fiddle I did not see.  
I will try to get the code to run the page locally.  
Thank You very much!

After copying and running locally I did not see the camera image. 🙄  
I will try to see if some changes bring it.

In Firefox:  
Uncaught (in promise) TypeError: URL.createObjectURL: Argument 1 is not valid for any of the 1-argument overloads.

In Chrome:  
Uncaught (in promise) TypeError: Failed to execute ‘createObjectURL’ on ‘URL’: Overload resolution failed.

Thank You for the attention!

---

<div class="post-metadata">

**Author:** ![jrlazz](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/jrlazz/32/64383_2.png) [@jrlazz](https://discourse.threejs.org/u/jrlazz)\
**Post date:** [November 26, 2023, 1:51am UTC](https://discourse.threejs.org/t/webcam-input-three-js/1500/14 "2023-11-26T01:51:23Z")

</div>

@Lawrence3DPK

Please take a look at this page, made after many experiences, and write me if it worked correctly.

the link

> **[ontv.html](https://jrlazz.github.io/anim/ontv.html)**

the link was corrected 😉

---

<div class="post-metadata">

**Author:** ![EliasHasle](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/eliashasle/32/3010_2.png) [@EliasHasle](https://discourse.threejs.org/u/EliasHasle)\
**Post date:** [January 8, 2024, 5:38pm UTC](https://discourse.threejs.org/t/webcam-input-three-js/1500/15 "2024-01-08T17:38:57Z")

</div>

It says page not found.

I am glad my old ghost effect demo worked for you, though. Did the recording function work too? And if so, on what platform/browser? Because I had to report a bug regarding that to the Google Chrome devs, now ages ago.

---

<div class="post-metadata">

**Author:** ![jrlazz](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/jrlazz/32/64383_2.png) [@jrlazz](https://discourse.threejs.org/u/jrlazz)\
**Post date:** [January 9, 2024, 1:03am UTC](https://discourse.threejs.org/t/webcam-input-three-js/1500/16 "2024-01-09T01:03:01Z")

</div>

Hi @EliasHasle …

I have corrected the link:

> **[ontv.html](https://jrlazz.github.io/anim/ontv.html)**

There were two points after the link…

Please confirm if it works!

PS: There is another post about it:

> [@Live on an old TV set, with webcam and animated canvas textures](https://discourse.threejs.org/t/live-on-an-old-tv-set-with-webcam-and-animated-canvas-textures/58612):
>
> Live on an old TV set, with webcam and animated canvas textures Much based in video (mp4) as texture for a plane, and partially based on [Webcam ghost effect](https://eliashasle.github.io/ghost_webcam.html) the link: Three.js Forever !!! Jose Roberto Lazzareschi … jrlazz … November, 27, 2023
