Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 Canvas - How does the origin-clean flag get set to false?

I started working with HTML5 Canvas and Video and I keep having this problem: I try demos and experiments but I can't view them unless I upload them to my web server. At the moment this doesn't pose a huge problem because I'm working with comparatively small files, but I'm actually preparing a bigger project, and this problem would become quite inconvenient very quickly. And also I would just like to get my facts straight. I have been working with both, my own created videos and those from demos. I worked with videos I encoded ages ago and I worked with videos I encoded a minute before using them in my code. It's always the same result, using the HTML5 Video container works, using video inside Canvas doesn't, Canvas just doesn't display any video (unless, like I mentioned, I upload them to a server).

This is the information I found so far:

http://html5doctor.com/video-canvas-magic/

http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#security-with-canvas-elements

(and a little bit of information on w3, but I'm not allowed to post more than two links)

From what I understand, my canvas must be tainted and my files don't appear to be 'origin-clean', but this is all I have been able to figure out. I don't understand why.

Does anybody know more about this and can explain how and why this works?

like image 211
chuls Avatar asked Nov 05 '22 02:11

chuls


1 Answers

There's a strict separation within browsers between anything loaded from http:// and anything loaded from a file:// URI. This is actually pretty sensible, otherwise random pages you loaded from the web would be able read files off your harddrive. There are several additional restrictions that apply to file:// URIs themselves, again these are aimed at not letting files you've downloaded from the web having free run of your harddrive.

Having said all that, if your HTML file and the videos are all sitting in the same directory on your harddrive then everything should still work as all these conditions should be met.

If you're still having problems, one useful approach for local development is to use a lightweight web server. Personally I use Python's SimpleHTTPServer because it was already installed on my machine, but there are many others - often web development frameworks (eg. Ruby on Rails) come with them built in.

like image 88
robertc Avatar answered Nov 09 '22 12:11

robertc