Доброе время суток! Имеется код на локальном сервере, он рабочий и проигрываемое видео сриншотится и сохраняется если видео находится непосредственно на локальном сервере, но стоит добавить видео из вне(Youtube в моем случае) то происходит ошибка-Uncaught DOMException: Failed to execute ‘toDataURL’ on ‘HTMLCanvasElement’: Tainted canvases may not be exported
Хотел повторить http://episodate.ru/youtubescreenshots Как изображение можно сохранить и избежать этой ошибке в моем случае
var cnv = document.getElementById('canvas'); var ctx = cnv.getContext('2d'); var video = document.querySelector('video'); var context = cnv.getContext('2d'); var w, h, ratio; video.addEventListener('loadedmetadata', function() { ratio = video.videoWidth / video.videoHeight; w = video.videoWidth - 100; h = parseInt(w / ratio, 10); cnv.width = w; cnv.height = h; }, false); function snap() { ctx.fillRect(0, 0, w, h); // Grab the image from the video ctx.drawImage(video, 0, 0, w, h); }
//сохраняем по клику на скрин
var sCan = function(cnv){ var imgg = cnv.toDataURL('image/png').replace('data:image/png;base64,', ''); var s = new XMLHttpRequest(); s.open('POST', 'script.php', true); s.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); s.onreadystatechange = function (){ if(s.readyState == 4){ console.log(s.responseText); } } s.send('imgg='+imgg); } cnv.onclick = function(){ sCan(cnv) }