Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

173
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda