Skip to content

Instantly share code, notes, and snippets.

@mariorcardoso
Created April 28, 2022 13:13
Show Gist options
  • Save mariorcardoso/8ced71ba7abc13a76ba732027a66dd59 to your computer and use it in GitHub Desktop.
Save mariorcardoso/8ced71ba7abc13a76ba732027a66dd59 to your computer and use it in GitHub Desktop.
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