Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <span class="error"></span>
<label for="interval">Time between images in seconds: </label>
<input id="interval" type="text" value="1" min="1" pattern="\d+">
<button id="start">Start</button>
<label for="hideVid">Hide video element: </label>
<input id="hideVid" type="checkbox">
<video autoplay muted playsinline></video>
  Images captured: <span id="image_count">0</span>
<button id="stop" disabled>Stop & Show Images</button>
<div id="images"></div>




                // show an error if not supported
if (typeof MediaStreamTrackProcessor === "undefined") {
  const supportError =
    "MediaStreamTrackProcessor is not supported by your browser";
  const errorSpan = document.querySelector("span.error"); = "color:red;font-size:larger;font-weight:bold";
  errorSpan.innerText = supportError;

const startBtn = document.querySelector("button#start");
const stopBtn = document.querySelector("button#stop");
const hideVid = document.querySelector("input#hideVid");
const intervalSec = document.querySelector("input#interval");
const videoElem = document.querySelector("video");
const imageCountSpan = document.querySelector("span#image_count");
const imagesDiv = document.querySelector("div#images");
const storage = []; // Use this array as our database
let stream, captureInterval;

hideVid.onclick = () => (videoElem.hidden = hideVid.checked);
startBtn.onclick = async () => {
  startBtn.disabled = true;

  stream = await navigator.mediaDevices.getUserMedia({ video: true });
  videoElem.onplaying = () =>
    console.log("video playing stream:", videoElem.srcObject);
  videoElem.srcObject = stream;

  const [track] = stream.getVideoTracks();
  const processor = new MediaStreamTrackProcessor(track);
  const reader = await processor.readable.getReader();

  async function readFrame() {
    const { value: frame, done } = await;
    // value = frame
    if (frame) {
      const bitmap = await createImageBitmap(frame);
      // frame.close();
    if (done) clearInterval(captureInterval);

  stopBtn.disabled = false;
  const interval =
    (parseInt(intervalSec.value) >= 1 ? intervalSec.value * 1 : 1) * 1000;
  captureInterval = setInterval(async () => await readFrame(), interval);

stopBtn.onclick = () => {
  // close the camera
  stream.getTracks().forEach((track) => track.stop());

  // Display each image
  async function showImages() {
    const bitmap = storage.shift();
    const width = bitmap.width;
    const height = bitmap.height;

    const canvas = document.createElement("canvas");
    canvas.width = width;
    canvas.height = height;
    const ctx = canvas.getContext("bitmaprenderer");

    if (storage.length > 0) await showImages();

  console.log("stored images");