File size: 1,277 Bytes
7b107a3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
<!DOCTYPE html>
<html>
<head>
<title>Live Stream</title>
</head>
<body>
<h1>Live Camera Stream</h1>
<video id="video" autoplay></video>
<img id="serverStream" src="/video_feed" style="max-width: 80%; border:1px solid black;">
<script>
const video = document.getElementById('video');
// Access webcam
navigator.mediaDevices.getUserMedia({ video: true })
.then(stream => {
video.srcObject = stream;
const canvas = document.createElement('canvas');
const context = canvas.getContext('2d');
// Capture and send frames
setInterval(() => {
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
context.drawImage(video, 0, 0, canvas.width, canvas.height);
const dataUrl = canvas.toDataURL('image/jpeg');
fetch('/upload_frame', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ image: dataUrl })
});
}, 100); // Send every 100ms (~10 FPS)
});
</script>
</body>
</html>
|