Skip to content

Instantly share code, notes, and snippets.

@blackspike
Created May 15, 2023 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blackspike/b0ba36ed12ac2e0e66020bb1b15fe83b to your computer and use it in GitHub Desktop.
Save blackspike/b0ba36ed12ac2e0e66020bb1b15fe83b to your computer and use it in GitHub Desktop.
// 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