Hacker News new | ask | show | jobs
by donatj 3837 days ago
Motion JPEG is arguably better suited to the task as the browser knows not to cache the previous frames by rule. It's actually designed for this exact purpose.

I made a little example project a few years back. The format is dead simple, keep the connection open, flush multiple JPEGS separated by a header. It's used pretty often by cheap security cameras and is supported by most browsers. It just seems to be not widely known about.

https://github.com/donatj/mjpeg-php

2 comments

I had a lot of fun making a little real-time visitor counter using Motion JPEG a few years ago! I was quite proud of that :)

The demo is still live:

http://drewgottlieb.net/2012/07/29/real-time-user-count.html

I've found MJPEG to be more bandwidth intensive, especially as the resolution increases however, since its flushing the full frame every time (whereas with GIF you could send just the differences between frames).
Would depend on what you're sending. If you take make good advantage of gif interframe transparency and are just sending small updates the result could be very small. That still leaves the problem unless I'm mistaken of the browser hanging on to the old gif frames.
Are you saying that retention is bad from a memory use perspective, or that there is a risk of looping mid-broadcast?
Memory use. If it thinks it might finish and need to loop it would hold on to all the frames it's received.