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

481
Vistas
How to capture image from both front and rear camera using JavaScript?

I am trying to build an application that can capture an image from the front and rear camera simultaneously (on a mobile device). I have experience with the library p5.js, which will allow me to take a picture from either the front or rear camera. Does anyone have an idea, example or suggestion for how to achieve the functionality of capturing an image from both cameras?

It seems as though the Media Capture and Streams API only allows a binary selection of either 'user' or 'environment' for the facingMode. This also seems to be the case for the p5.js library. Does anyone have an idea or example of what to do when the goal is to capture an image from the front and rear camera simultaneously?

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

0

You can definitely capture either camera by specifying the appropriate constraint. You can also enumerate and capture any of the available cameras if constraints don't work (although note that device enumeration will not work until after the user has consented to allow your page to access the camera). Unfortunately due to a limitation in WebKit, on iPhones it is not possible to actually simultaneously capture both the front and rear cameras. You can alternate between them, but the performance is not ideal.

    function setup() {
      createCanvas(400, 400);
    }

    let environmentCam;
    let isDrawing = false;
    function draw() {
      if (!isDrawing) {
        isDrawing = true;

        // Mobile Safari can only capture one camera at a time
        // https://bugs.webkit.org/show_bug.cgi?id=179363
        // capture user then environment, this may be slow
        let userCam =
          createCapture(
            { video: { facingMode: "user" } },
            async () => {
              if (environmentCam) {
                environmentCam.remove();
              }
              // give the camera time to focus
              await delay(100);
              image(userCam, 0, 0, width / 2, height);
              environmentCam = createCapture(
                { video: { facingMode: "environment" } },
                async () => {
                  userCam.remove();
                  // give the camera time to focus
                  await delay(100);
                  image(environmentCam, width / 2, 0, width / 2, height);
                  isDrawing = false;
                }
              )
            }
          );
      }
    }

    function delay(ms) {
      return new Promise(resolve => {
        setTimeout(resolve, ms);
      });
    }
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