添加下一个样式即可
css
#left {
transform: rotateY(180deg);
}
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>js通过浏览器调用摄像头</title>
<style>
#left {
transform: rotateY(180deg);
}
</style>
</head>
<body>
<div class="banner">
<video id="left" width="500px" height="500px" autoPlay="autoplay" controls="controls"></video>
<video id="right" width="500px" height="500px" autoPlay="autoplay" controls="controls"></video>
</div>
</body>
<script>
let leftVideo = document.getElementById('left');
let rightVideo = document.getElementById('right');
function getMedia() {
let constraints = {
video: { width: 400, height: 500 },
audio: false
};
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
navigator.mediaDevices.getUserMedia(
constraints,
function(stream) {
leftVideo.src = stream;
leftVideo.play();
},
function(error) {
console.log(error);
}
).then(function(MediaStream) {
leftVideo.srcObject = MediaStream;
leftVideo.play();
});
}
getMedia();
// 当开始播放的时候哦从一个video标签中获取流并将流传给其他的video标签
leftVideo.onplay = function () {
rightVideo.srcObject = leftVideo.captureStream()
}
</script>
</html>