Is it possible to apply custom visual effects (such as grayscale) to the input stream of a tag in HTML5/Javascript? My goal is to be able to display a filtered webcam’s output to the user, but the user should be able to pick from a variety of filters, not just grayscale.
All help is greatly appreciated and I always accept an answer!
The way to do it is to grab each frame of a
videoelement and process and then displaay it withcanvas. Here’s an example I did recently for my book (warning: I know there are some issues with this example in IE9 currently), which used a greyscale filter from HTML5 Rocks. The main loop looks something like this, assumevideois a reference to the element andcontextis a 2d canvas context,requestAnimFramecomes from Paul Irish:The
getUserMedia()function that Alex W mentions is only currently available in Opera and Chrome, you can read some blog posts about it and see some demos here. Once you’ve got a media stream you can pipe it into avideoelement and do exactly the same thing as above.