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

117
Visualizações
High CPU Usage from Canvas CaptureStream

Context

I've been working on building a virtual-backgrounds feature for web environments, and as part of that I'm taking in a webcam feed (MediaStreamTrack), doing some image-processing in WebGL and outputting the processed video frames to a canvas.

Problem

As soon as you call captureStream() on the canvas (or, any canvas it seems), the CPU usage starts to spike (on my Linux device, from 20% to 60%).

I've re-created a simplified version of this problem here, with a simple animation and a call to canvas.captureStream():

const canvas = document.querySelector('#canvas-target');
const animation = new CanvasAnimation(canvas.getContext('2d'));
animation.start();
// Starts an animation on canvas

function captureStream(){

   let stream  = canvas.captureStream();
   const video = document.querySelector('#stream-output');

   // Create canvas stream, feed it to video
   video.srcObject = stream;

   // CPU starts to go up here
   video.play();
}

See Codepen for the full example: https://codepen.io/sb2702/pen/MWogaeo

The main factors that seem to affect CPU usage are frame-rate and resolution - so,

  1. I assume that the browser is just doing a lot of work under the hood to re-encode the video stream into a media stream.

  2. The "quick" answer is to just restrict the framerate and/or resolution

My primary question is - am I missing something else fundamental about canvas, captureStream - etc.., and is there some much more CPU efficient way of generating a MediaStreamTrack with output from a Canvas?

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