Last active
October 1, 2015 03:17
-
-
Save scrawlon/ff7afd87f81edb0ce004 to your computer and use it in GitHub Desktop.
code from the blog post: http://scrawlon.com/2015/07/26/control-your-webcam-with-html-and-javascript/
This file contains 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
<!DOCTYPE html> | |
<html lang="en-us"> | |
<head> | |
<meta charset="UTF-8"> | |
</head> | |
<body> | |
<video autoplay></video> | |
<script src="mirror.js"></script> | |
</body> | |
</html> |
This file contains 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
<style> | |
video { | |
/* mirror video */ | |
-webkit-transform: scaleX(-1); | |
transform: scaleX(-1); | |
} | |
</style> |
This file contains 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
(function() { | |
var video = document.getElementsByTagName('video')[0]; | |
var videoWidth = 1280; | |
var videoHeight = 720; | |
function activateWebcam(width, height) { | |
var compatibleBrowser = hasUserMedia(); | |
var videoResolution = getBrowserVideoSettings(compatibleBrowser, width, height); | |
if (compatibleBrowser) { | |
window.URL = window.URL || window.webkitURL; | |
navigator.getUserMedia({ | |
audio: false, | |
video: videoResolution | |
}, | |
function(stream) { | |
video.src = window.URL.createObjectURL(stream); | |
}, | |
function(err) { | |
console.log("The following error occured: " + err.name); | |
}); | |
} else { | |
console.log("getUserMedia not supported"); | |
} | |
} | |
function hasUserMedia() { | |
navigator.getUserMedia = navigator.getUserMedia || | |
navigator.webkitGetUserMedia || | |
navigator.mozGetUserMedia; | |
return navigator.getUserMedia; | |
} | |
function getBrowserVideoSettings(browser, width, height) { | |
if (browser === navigator.mozGetUserMedia) { | |
return { | |
width: width, | |
height: height | |
} | |
} else { | |
return { | |
mandatory: { | |
minWidth: width, | |
minHeight: height | |
} | |
} | |
} | |
} | |
activateWebcam(videoWidth, videoHeight); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment