I'm trying to record a svg animation using javascript/html. This is what i've tried so far:
<canvas id="canv">
<svg width="370" height="370" viewBox="0 0 370 370" fill="none" xmlns="http://www.w3.org/2000/svg">
<!-- my svg is here, full code is below because i don't think it's important -->
</svg>
</canvas>
<style>
@keyframes animation{
from{
opacity: 0;
transform: translateY(20%);
}to{
opacity: 1;
transform: translateY(0);
}
}
#bubbles{
animation: animation 1s linear;
}
</style>
<script>
const canvas = document.getElementById("canv")
var videoStream = canvas.captureStream(30);
const render = () => {
videoStream.getVideoTracks()[0].requestFrame();
}
setInterval(render, 33)
var mediaRecorder = new MediaRecorder(videoStream);
var chunks = [];
mediaRecorder.ondataavailable = function(e) {
chunks.push(e.data);
};
mediaRecorder.onstop = function(e) {
var blob = new Blob(chunks, { 'type' : 'video/mp4' });
chunks = [];
var videoURL = URL.createObjectURL(blob);
video.src = videoURL;
};
mediaRecorder.start();
setTimeout(() => {
mediaRecorder.stop();
}, 1000)
</script>
I have got the source code from https://medium.com/@amatewasu/how-to-record-a-canvas-element-d4d0826d3591 and i'm using firefox. full source: https://paste.gg/p/anonymous/89d475bc50bc469dad827a620d3f7c02