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

117
Views
¿Por qué cambiar de Canvas a OffScreenCanvas mejora el rendimiento de drawImage y getImageData?

Estoy ejecutando un proceso en tiempo real desde la transmisión de medios en vivo de la cámara web, lo que requiere que el FPS permanezca alrededor de 30 FPS. getImageData fue uno de mis principales cuellos de botella, requería alrededor de 22 ms para extraer el objeto ImageData del lienzo, dejándome solo 11 ms para realizar mis otras operaciones.

Aquí hay un fragmento simple de lo que tenía antes.

 video = document.createElement("video"); inputCanvas = document.createElement("canvas"); inputCanvas.width = width; inputCanvas.height = height; inputCanvasCtx = inputCanvas.getContext("2d"); video.width = width; video.height = height; video.srcObject = stream; // And using the requestVideoFrameCallback API, whenever a frame is presented, this callback is triggered function onFrame(now, metadata){ inputCanvasCtx.drawImage(video, 0, 0);; // Get frame from our canvas. frame = inputCanvasCtx.getImageData(0,0,inputCanvas.width, inputCanvas.height); // Other computations }

Después de hacer este simple cambio en mi configuración, sin cambiar nada más, logré extraer el cuadro en 11 ms , la mitad del tiempo que tomaba antes, y no puedo entender por qué. Solo convertí el lienzo normal en un lienzo fuera de pantalla en dos líneas.

 video = document.createElement("video"); inputCanvas = document.createElement("canvas"); inputCanvas.width = width; inputCanvas.height = height; offscreen = inputCanvas.transferControlToOffscreen(); // Changed line inputCanvasCtx = offscreen.getContext("2d"); // Changed line video.width = width; video.height = height; video.srcObject = stream;

Agradecería cualquier idea sobre este asunto.

about 4 years ago · Juan Pablo Isaza
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!