Skip to content

Instantly share code, notes, and snippets.

@avinayak
Last active September 23, 2020 10:03
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 avinayak/dd656b3b60e13ba831ab1b9e638d8cc1 to your computer and use it in GitHub Desktop.
Save avinayak/dd656b3b60e13ba831ab1b9e638d8cc1 to your computer and use it in GitHub Desktop.
recording p5js skecthes in editor.p5js.org
### Add the snippet below in sketch.js
### optional: convert to mp4 using ffmpeg -fflags +genpts -i input.webm -r 24 out.mp4
function record(){chunks.length=0;let e=document.querySelector("#defaultCanvas0").captureStream(300),t=new MediaRecorder(e);t.ondataavailable=(e=>{e.data.size&&chunks.push(e.data)}),t.onstop=exportVideo,setTimeout(()=>{t.stop()},1e4),t.start()}function exportVideo(e){var t=new Blob(chunks),o=document.createElement("video");o.id="recorded",o.controls=!0,o.src=URL.createObjectURL(t),document.body.appendChild(o),o.play()}chunks=[],record();
@avinayak
Copy link
Author

function record(){chunks.length=0;let e=document.querySelector("#defaultCanvas0").captureStream(300),t=new MediaRecorder(e);t.ondataavailable=(e=>{e.data.size&&chunks.push(e.data)}),t.onstop=exportVideo,setTimeout(()=>{t.stop()},1e4),t.start()}function exportVideo(e){var t=new Blob(chunks),o=document.createElement("video");o.id="recorded",o.controls=!0,o.src=URL.createObjectURL(t),document.body.appendChild(o),o.play()}chunks=[],record();

@avinayak
Copy link
Author

ffmpeg -i 0908ccc8-62d1-42f9-8968-380ccd97c9a4.webm -crf 23 video.mp4

loseless

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment