Created
May 15, 2023 21:57
-
-
Save blackspike/b0ba36ed12ac2e0e66020bb1b15fe83b 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
// Record | |
export async function record() { | |
// reset() | |
play() | |
$video = null | |
console.log('record called') | |
const canvas = document.getElementById('canvas') | |
const videoStream = canvas.captureStream(60) | |
const mediaRecorder = new MediaRecorder(videoStream, { | |
videoBitsPerSecond: 5000000 // Double the default quality from 2.5Mbps to 5Mbps | |
}) | |
let chunks = [] | |
mediaRecorder.ondataavailable = function (e) { | |
chunks.push(e.data) | |
} | |
mediaRecorder.onstop = function (e) { | |
const blob = new Blob(chunks, { type: 'video/mp4' }) | |
chunks = [] | |
const videoURL = URL.createObjectURL(blob) | |
$video = videoURL | |
} | |
mediaRecorder.ondataavailable = function (e) { | |
chunks.push(e.data) | |
} | |
mediaRecorder.start() | |
setTimeout(function () { | |
mediaRecorder.stop() | |
$recording = false | |
}, animTimeline.duration - 1000) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment