Spaces:
Runtime error
Runtime error
Download docs/embed.html from openscopelabs/cctv-object-detection: direct link, hf CLI and curl.
- Browser
- Download file 4.03 kB
-
https://huggingface.co/spaces/openscopelabs/cctv-object-detection/resolve/main/docs/embed.html
- Command line
-
hf download hf://spaces/openscopelabs/cctv-object-detection/docs/embed.html
-
curl -L -o embed.html https://huggingface.co/spaces/openscopelabs/cctv-object-detection/resolve/main/docs/embed.html
4.03 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8" /> | |
| <title>Cakra CCTV — pure embed</title> | |
| <style> | |
| html, body { margin:0; height:100%; background:#000; | |
| font: 12px ui-monospace, Menlo, Consolas, monospace; color:#9af; } | |
| #wrap { position:relative; height:100%; display:flex; align-items:center; | |
| justify-content:center; } | |
| video { max-width:100%; max-height:100%; display:block; background:#000; } | |
| #hud { position:absolute; top:8px; right:8px; padding:6px 10px; | |
| background:rgba(0,0,0,.6); border-radius:4px; } | |
| #hud b { color:#fff; } | |
| </style> | |
| </head> | |
| <body> | |
| <div id="wrap"> | |
| <video id="v" autoplay muted playsinline></video> | |
| <div id="hud"> | |
| <div>state: <b id="s">init</b></div> | |
| <div>buf ahead: <b id="b">—</b>s</div> | |
| <div>currentTime: <b id="t">—</b>s</div> | |
| <div>w x h: <b id="r">—</b></div> | |
| </div> | |
| </div> | |
| <script src="https://cdn.jsdelivr.net/npm/hls.js@1.5.13/dist/hls.min.js"></script> | |
| <script> | |
| const qs = new URLSearchParams(location.search); | |
| const base = qs.get("base") || "http://localhost:8000"; | |
| const id = qs.get("camera_id"); | |
| const v = document.getElementById("v"); | |
| const $ = (i) => document.getElementById(i); | |
| if (!id) { $("s").textContent = "missing ?camera_id="; } | |
| else { | |
| fetch(`${base}/api/v1/cameras/${id}/connect`, { method:"POST" }) | |
| .then(r => r.ok ? r.json() : Promise.reject(r.status)) | |
| .then(() => { | |
| const url = `${base}/api/v1/cameras/${id}/hls/playlist.m3u8`; | |
| if (Hls.isSupported()) { | |
| const hls = new Hls({ | |
| enableWorker: true, | |
| lowLatencyMode: false, | |
| liveSyncDurationCount: 999, | |
| liveMaxLatencyDurationCount: 1000, | |
| maxBufferLength: 30, | |
| maxMaxBufferLength: 60, | |
| backBufferLength: 0, | |
| liveDurationInfinity: true, | |
| manifestLoadingMaxRetry: 8, manifestLoadingRetryDelay: 500, | |
| levelLoadingMaxRetry: 8, levelLoadingRetryDelay: 500, | |
| fragLoadingMaxRetry: 4, fragLoadingRetryDelay: 500, | |
| }); | |
| hls.loadSource(url); hls.attachMedia(v); | |
| let anchored = false; | |
| hls.on(Hls.Events.LEVEL_LOADED, (_e,d) => { | |
| if (anchored) return; | |
| const frags = d?.details?.fragments; | |
| if (!frags?.length) return; | |
| anchored = true; | |
| v.currentTime = frags[0].start; | |
| // Wait for 5s buffer then play. | |
| $("s").textContent = "buffering"; | |
| const tick = () => { | |
| const ahead = v.buffered.length | |
| ? v.buffered.end(v.buffered.length-1) - v.currentTime : 0; | |
| if (ahead >= 5) { v.play(); } | |
| else { setTimeout(tick, 200); } | |
| }; | |
| tick(); | |
| }); | |
| } else if (v.canPlayType("application/vnd.apple.mpegurl")) { | |
| v.src = url; v.play(); | |
| } else { $("s").textContent = "browser no HLS"; } | |
| }) | |
| .catch(e => { $("s").textContent = "connect failed: " + e; }); | |
| } | |
| v.addEventListener("playing", () => $("s").textContent = "playing"); | |
| v.addEventListener("waiting", () => $("s").textContent = "buffering"); | |
| v.addEventListener("stalled", () => $("s").textContent = "stalled"); | |
| v.addEventListener("loadedmetadata", () => { | |
| $("r").textContent = v.videoWidth + " x " + v.videoHeight; | |
| }); | |
| // HUD telemetry: track buffer + currentTime over time so we can spot stalls. | |
| setInterval(() => { | |
| const ahead = v.buffered.length | |
| ? v.buffered.end(v.buffered.length-1) - v.currentTime : 0; | |
| $("b").textContent = ahead.toFixed(2); | |
| $("t").textContent = v.currentTime.toFixed(2); | |
| }, 200); | |
| // Expose a sample-collector for automated probing. | |
| window.__samples = []; | |
| setInterval(() => { | |
| const ahead = v.buffered.length | |
| ? v.buffered.end(v.buffered.length-1) - v.currentTime : 0; | |
| window.__samples.push({ | |
| t: performance.now(), | |
| ahead: +ahead.toFixed(3), | |
| ct: +v.currentTime.toFixed(3), | |
| paused: v.paused, | |
| state: $("s").textContent, | |
| }); | |
| if (window.__samples.length > 600) window.__samples.shift(); | |
| }, 100); | |
| </script> | |
| </body> | |
| </html> | |