Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

174
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!