Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

181
Vistas
p5.js Í How do I play first N frames as images in a loop?

In the code below I want to:

  1. save the first 5 seconds of the camera capture as frames
  2. then each time round the draw() loop I want to draw the 1st frame on the canvas, then the 2nd one on the next draw loop, etc. until I reach the end and start back from the top.

However, this is not working and I believe it's because the imageData of each frame is an data:image/octet-stream;base64,.... String which I'm not sure how to draw on the canvas.

const FRAME_RATE = 10
const CAPTURE_DURATION = 5 // secs

let framesCaptured = []
let i = 0

function setup() {
  frameRate(FRAME_RATE)
  
  let video = createCapture(VIDEO)
  
  video.hide()
  
  createCanvas(640, 480)
  
  saveFrames('frames', 'png', CAPTURE_DURATION, FRAME_RATE, (frames) => {
    framesCaptured = frames.map(({ imageData }) => {
      return imageData
    })
  })
}

function draw() {

  if (i < framesCaptured.length) {
    image(loadImage(framesCaptured[i]), 0, 0)
    i = i === framesCaptured.length - 1 ? 0 : i+1
  }
}

Btw, it's important that I have access to and loop through individual frame-images, because I will later be sending those to the server.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

LoadImage can handle base64 encoded images, but you have to add "data:image/png;base64," in front of the string. you could try loadImage("data:image/png;base64,"+framesCaptured[i])

( https://p5js.org/reference/#/p5/loadImage )

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda