Created
April 28, 2022 13:13
-
-
Save mariorcardoso/8ced71ba7abc13a76ba732027a66dd59 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const imageCapture = async ({ | |
videoRef, | |
}: ImageCaptureInput): Promise<string | undefined> => { | |
try { | |
const videoElem = videoRef.current; | |
if (!videoElem) throw Error("Video HTML element not defined"); | |
let mediaStream = videoElem.srcObject as MediaStream; | |
if (!mediaStream) throw Error("Video MediaStream not defined"); | |
const track = mediaStream.getVideoTracks()[0]; | |
const image = generateImageWithCanvas(track, videoElem); | |
// const image = await generateImageWithImageCapture(mediaStreamTrack); | |
mediaStream.getTracks().forEach((track) => track.stop()); | |
return image; | |
} catch (error) { | |
console.error("imageCapture error: " + error); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment