HTML Live Video Streaming Via WebSockets
phoboslab.org
phoboslab.org
This uses requestAnimationFrame, and lets me set the max framerate I want. Since I'm just watching my dog Mischa and she sleeps most of the time, I set it to 0.5fps which keeps my cpu usage around 1%.
<div>
<img id="mischacam" />
<br />
<span id="time"/>
</div>
<script type="text/javascript">
var camURL = "....";
var msPerFrame = 2000;
var loading = false;
function update(timestamp) {
if (loading) return;
loading = true;
lastFrameTime = timestamp;
$("#mischacam").attr("src", camURL + "/snapshot.cgi?_=" + Math.random());
$("#time").html(new Date().toString());
}
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
function( callback ){
window.setTimeout(callback, 1000 / 60);
};
})();
var lastFrameTime;
function animloop(timestamp){
if (lastFrameTime == null) lastFrameTime = timestamp;
if (timestamp - lastFrameTime > msPerFrame)
update(timestamp);
requestAnimFrame(animloop);
}
$(document).ready(function () {
$("#mischacam").on("load", function () { loading = false; });
animloop(0);
});
</script>Out of curiosity, why do you append a random number between 0 and 1 to the URL?
I agree that this is a huge hack and just serving JPGs would be much easier, but this hack turned out to work pretty well.
"Streaming video through WebSocket (thus over http upgrade) through a plain-tcp-to-websocket-proxy on top of...".
It feels over-engineered and like TCP-Sockets are a revolution. I know, we can't easily expose plain-socket because of security but still... What's next? UDP for 2018? Socket-binding for 2022?
(Nice work though)
It's just crazy how the standard is slow to come up with new basic APIs.
I mean, you can make a P2P video streaming application since 1995 using straightforward architecture in a desktop App using less cpu, less middleware and less engineering.
It's free too, how are you making money? Thanks for making it! (Now I just need something for streaming video between laptops, between laptop and mobile device. I find it very annoying how FaceTime doesn't let you call yourself from one device to another.)
http://theiopage.blogspot.co.uk/2013/04/enabling-hardware-h2...
Would be great to integrate this with the node app.
Also, great hack, it seems so obvious, but is actually pretty great.