prthm11 commited on
Commit
7b107a3
·
verified ·
1 Parent(s): cbb3597

Update templates/test_streaming_index.html

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