Created
November 13, 2021 18:16
-
-
Save fakenickels/41fd6d161402519e8660daae33f759a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<style> | |
#canvas { | |
border: 1px solid black; | |
background-color: white; | |
} | |
</style> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/RecordRTC/5.5.6/RecordRTC.js"></script> | |
<p>Paste your SVG base64 or source here</p> | |
<p> | |
<textarea rows="30" id="svg" cols="100"></textarea> | |
</p> | |
<p> | |
<button id="record" type="button">Record</button> | |
<button id="stop" disabled=true type="button">Stop recording</button> | |
</p> | |
<p>Preview:</p> | |
<p> | |
<canvas width="1012" height="506" id="canvas"></canvas> | |
</p> | |
<image | |
id="input" | |
style="opacity: 0" | |
src="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAxMiIgaGVpZ2h0PSI1MDYiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9J2h0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsnPgoKICA8IS0tIFRoZSBjYW52YXMgZm9yIG91ciBwYXR0ZXJuIC0tPgogIDxyZWN0IHg9IjAiIHk9IjAiIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9IndoaXRlIiAvPgogIDxyZWN0IHg9IjAiIHk9IjAiIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InVybCgjZ3JhZGllbnQpIiAvPgoKICA8ZyBjbGlwLXBhdGg9InVybCgjY2xpcDBfOTk6MikiPgogICAgPHBhdGggb3BhY2l0eT0iMC42IiBkPSJNNTA5LjUgMjg1LjVINTFNNTA5LjUgMTg4Ljc1SDUxTTUxIDE0MC4zNzVINTA5LjVNNTA5LjUgMjM3LjEyNUg1MU01MSAzODIuMjVINTA5LjVNNTA5LjUgMzM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bml0cz0idXNlclNwYWNlT25Vc2UiPgogICAgICA8c3RvcCBvZmZzZXQ9IjAuMDE2NDAyNSIgc3RvcC1jb2xvcj0iI0YzQzMxNyIgc3RvcC1vcGFjaXR5PSIwLjgxIiAvPgogICAgICA8c3RvcCBvZmZzZXQ9IjAuNzEzNTQyIiBzdG9wLWNvbG9yPSIjRDVERUNFIiBzdG9wLW9wYWNpdHk9IjAuMjM1OTAxIiAvPgogICAgICA8c3RvcCBvZmZzZXQ9IjAuNzY1NjI1IiBzdG9wLWNvbG9yPSIjNzlDRkE2IiBzdG9wLW9wYWNpdHk9IjAuMDU1NzU4MyIgLz4KICAgICAgPHN0b3Agb2Zmc2V0PSIxIiBzdG9wLWNvbG9yPSIjQzNGQkY3IiBzdG9wLW9wYWNpdHk9IjAiIC8+CiAgICA8L2xpbmVhckdyYWRpZW50PgogICAgPHBhdGggaWQ9InRleHQtcGF0aC1hIiBkPSJNNzcgMjRIOTQyQzk1Ny40NjQgMjQgOTcwIDM2LjUzNiA5NzAgNTJWNDU0Qzk3MCA0NjkuNDY0IDk1Ny40NjQgNDgyIDk0MiA0ODJINzdDNjEuNTM2IDQ4MiA0OSA0NjkuNDY0IDQ5IDQ1NFY1MkM0OSAzNi41MzYgNjEuNTM2IDI0IDc3IDI0WiIgLz4KICAgIDxjbGlwUGF0aCBpZD0iY2xpcDBfOTk6MiI+CiAgICAgIDxyZWN0IHdpZHRoPSIxMDEyIiBoZWlnaHQ9IjUwNiIgZmlsbD0id2hpdGUiIC8+CiAgICA8L2NsaXBQYXRoPgogIDwvZGVmcz4KPC9zdmc+Cg==" | |
/> | |
<script type="text/javascript"> | |
var textarea = document.getElementById('svg'); | |
var img = document.getElementById('input'); | |
textarea.addEventListener('change', () => { | |
img.src = "data:image/svg+xml;base64," + textarea.value; | |
}) | |
</script> | |
<script type="text/javascript"> | |
var canvas = document.getElementById("canvas"); | |
var ctx = canvas.getContext("2d"); | |
var img = document.getElementById("input"); | |
var data = [], | |
stream = canvas.captureStream(), | |
recorder = new MediaRecorder(stream, { mimeType: "video/webm" }); | |
var height; | |
var width; | |
recorder.ondataavailable = function (event) { | |
if (event.data && event.data.size) { | |
data.push(event.data); | |
} | |
}; | |
img.onload = () => { | |
width = canvas.width = img.width; | |
height = canvas.height = img.height; | |
} | |
function download() { | |
var blob = new Blob(data, { | |
type: "video/webm", | |
}); | |
var url = URL.createObjectURL(blob); | |
var a = document.createElement("a"); | |
document.body.appendChild(a); | |
a.style = "display: none"; | |
a.href = url; | |
a.download = "test.webm"; | |
a.click(); | |
window.URL.revokeObjectURL(url); | |
} | |
var isRecording = false; | |
var timerId; | |
function loop() { | |
if (isRecording) { | |
// fills the background with white | |
recorder.requestData(); | |
ctx.clearRect(0, 0, canvas.width, canvas.height); | |
ctx.fillStyle = "white"; | |
ctx.fillRect(0, 0, height, width); | |
ctx.drawImage(img, 0, 0); | |
} | |
requestAnimationFrame(loop); | |
} | |
// fills the background with white | |
ctx.fillStyle = "white"; | |
ctx.fillRect(0, 0, height, width); | |
ctx.drawImage(img, 0, 0); | |
loop() | |
var recordButton = document.getElementById("record"); | |
var stopButton = document.getElementById("stop"); | |
recordButton.addEventListener("click", function () { | |
isRecording = true; | |
recordButton.setAttribute("disabled", "disabled"); | |
stopButton.removeAttribute("disabled"); | |
recorder.start(); | |
}); | |
stopButton.addEventListener("click", function () { | |
isRecording = false; | |
recorder.stop(); | |
download(); | |
recordButton.removeAttribute("disabled"); | |
stopButton.setAttribute("disabled", "disabled"); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment