javascript - HTML5 video screenshot via canvas using CORS -
i have issue getting screenshots of videos in chrome, , i've exhausted internets , stackoverflow answers on it; no luck.
no matter try, when try use canvas element take screenshot of video on different domain, or different port, end failed execute 'todataurl' on 'htmlcanvaselement': tainted canvases may not exported. error.
here setup:
web app url
http://client.myapp.com/home.html
cdn urls (i've tried both)
http://client.myapp.com:8181/somevideo.mp4
http://cdn.myapp.com/somevideo.mp4
headers sent mp4 cdn:
accept-ranges:bytes access-control-allow-origin:* access-control-expose-headers:x-ms-request-id,server,x-ms-version,content-type,last-modified,etag,x-ms-lease-status,x-ms-lease-state,x-ms-blob-type,accept-ranges,content-length,date,transfer-encoding content-length:5253832 content-range:bytes 48-5253879/5253880 content-type:video/mp4 date:sat, 06 feb 2016 17:24:05 gmt etag:"0x8d32e3edb17ec00" last-modified:fri, 05 feb 2016 15:13:08 gmt server:windows-azure-blob/1.0 microsoft-httpapi/2.0 x-ms-blob-type:blockblob x-ms-lease-state:available x-ms-lease-status:unlocked x-ms-request-id:88d3aaef-0629-4316-995f-021aa0153c32 x-ms-version:2015-04-05 i have:
- added
crossorigin="anonymous"video element, makes video fail load altogether - tried same domain on different port (as above)
- ensured
access-control-allow-origincoming*(as above) - i don't believe drm screenshot works fine if copy exact same video file web app , load locally
- run through answers this question, images not videos anyway , answers describe previous points
yet, still blasted error.
edit
added code:
var getscreenshotdataurl = function(video, canvas, type) { type = type || "image/jpeg"; var context = canvas.getcontext("2d"); var w = video.videowidth; var h = video.videoheight; canvas.width = w; canvas.height = h; context.fillrect(0, 0, w, h); context.drawimage(video, 0, 0, w, h); video.crossorigin = "anonymous";// makes no difference return canvas.todataurl(type); } please help.
i have answered own question.
what horrible headache have.
the problem lies somewhere in nuanced specification of html5 video crossorigin/cors specification.
i tested in chrome , edge, here need know @ time of writing:
chrome
loading html5 video fail if have crossorigin set, video being served port other 80 and not using https:
this fail
client @ http://www.myapp.com/player.html:
<video crossorigin="anonymous" src="http://cdn.myapp.com:81/video.mp4"></video> this succeed
client @ http://www.myapp.com/player.html:
<video crossorigin="anonymous" src="https://cdn.myapp.com:81/video.mp4"></video> chrome , edge
getimagedata() , todataurl() security blocked unless:
- crossorigin set
anonymousoruse-credentials(as defined here) before video loaded. if late, still fail.
all
finally, if going set crossorigin in javascript, sure use correct casing javascript property: crossorigin (not crossorigin)
Comments
Post a Comment