Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaume-chervet committed Apr 17, 2024
1 parent e8ab6c8 commit e9f112b
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/SlightCapture/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,42 @@ const _startCaptureStream = (resolve, iVideo ) => (stream) => {
const startCaptureAsync = cv =>(constraints, iVideo) => {
return new Promise((resolve, error) => {
navigator.mediaDevices.getUserMedia(constraints)
.then( _startCaptureStream(resolve, iVideo) ).catch(function(err) {
.then(function (stream) {
if ("srcObject" in iVideo) {
iVideo.srcObject = stream;
} else {
iVideo.src = window.URL.createObjectURL(stream);
}

stream.getTracks().forEach(function(track) {
track.enabled = true;
});

iVideo.onloadedmetadata = async function (e) {
await iVideo.play();
let stream_settings = stream.getVideoTracks()[0].getSettings();

let src = new cv.Mat(stream_settings.height, stream_settings.width, cv.CV_8UC4);
iVideo.height = iVideo.videoHeight;
iVideo.width = iVideo.videoWidth;
let videoCapture = new cv.VideoCapture(iVideo);

const stopStreamTracks = () => {
stream.getTracks().forEach(function(track) {
track.stop();
track.enabled = true;
});
}

resolve({ videoCapture, src, stopStreamTracks});

}
}).catch(function(err) {
console.error(err.name + ": " + err.message);
error(err);
});
});

}
const initTemplateAsync = (cv) => async (file) => {
const convertedFile = await blobToBase64Async(file);
Expand Down

0 comments on commit e9f112b

Please sign in to comment.