Sunday, 26 September 2021

Change the whiteBalanceMode constraint after applying colorTemperature setting in media device

Hello everybody!

Currently, I'm working on the implementation of colorTemperature of a project, after the implementation I want to revoke the colorTemperature that I applied on it.

I'm able to change the colorTemperature, initially the colorTemperature is 0 and whiteBalanceMode is 'continuous'. However, after I change the colorTemperature to any allowed value, the whiteBalanceMode is auto changed to 'manual'. I cannot reset the colorTemperature to 0 again because the value is not allowed, neither can I reset the whiteBalanceMode to 'continuous' again with the similar code that I change colorTemperature.

The whole code as followed.

'use strict';

const video = document.querySelector('video');
const canvas = window.canvas = document.querySelector('canvas');
canvas.width = 480;
canvas.height = 360;

const constraints = {
  audio: false,
  video: true,
};

var currTracks = null;

function handleSuccess(stream) {
  const videoTracks = stream.getVideoTracks();
  currTracks = videoTracks;
  window.stream = stream; // make stream available to browser console
  video.srcObject = stream;
}

function handleError(error) {
  console.log('navigator.MediaDevices.getUserMedia error: ', error.message, error.name);
}

async function init(){
  await navigator.mediaDevices.getUserMedia(constraints).then(handleSuccess).catch(handleError);
  await changeEnv(currTracks,3600);
  setTimeout(function(){changeEnv(currTracks,5500)},1000);
}

async function changeEnv(tracks,compen) {

  console.log(tracks,performance.now());
  for (const track of tracks) {
    console.log('curr',track.getSettings());
    console.log('capab',track.getCapabilities());
    if (compen === 3600) {
      await track.applyConstraints({advanced:[{colorTemperature: compen}]});
    } else {
      await track.applyConstraints({advanced:[{whiteBalanceMode: 'continuous'}]});
    }
    console.log('curr',track.getSettings());
  } 
}
init();

Which I can call track.getCapabilities() on to get the capabilities.

{
    aspectRatio: {max: 4000, min: 0.0003333333333333333},
    colorTemperature: {max: 7000, min: 2850, step: 50},
    deviceId: "332d34c91861f97ba8f0e11f446da4566a1803539764dd67c1dfe036ef32fd97",
    exposureCompensation: {max: 2, min: -2, step: 0.10000000149011612},
    exposureMode: (2) ["continuous", "manual"],
    exposureTime: {max: 1250, min: 0, step: 0},
    facingMode: ["environment"],
    focusMode: (3) ["manual", "single-shot", "continuous"],
    frameRate: {max: 30, min: 0},
    groupId: "40f2953f5fae495c7471348c844e919762a3213019b271664d220d0aa617313c",
    height: {max: 3000, min: 1},
    iso: {max: 4000, min: 20, step: 1},
    resizeMode: (2) ["none", "crop-and-scale"],
    torch: true,
    whiteBalanceMode: (2) ["continuous", "manual"],
    width: {max: 4000, min: 1}
}

Copied from the Chromium console log.

Does anybody know how to change the whiteBalanceMode constraint to change back the device to continuous mode?



from Change the whiteBalanceMode constraint after applying colorTemperature setting in media device

No comments:

Post a Comment