Here's something I came up with for live streaming from a camera. It's crude but it works in all browsers.
I don't know how you access the Raspberry pi camera but the example below shows how to access a built-in web cam in linux:
Encode your camera to a updateing image file with ffmpeg:
ffmpeg -analyzeduration 0 -i /dev/video0 -update 1 -q 1 -r 5 -y /video/feed/1.jpg
Read the image file with php and output contents on change:
<?php
session_start();
session_write_close();
$imgFile = '/video/feed/1.jpg';
$img = (file_get_contents($imgFile));
$lastImgSize = $_SESSION['imageSize'];
while (true) {
usleep(20000);
$img = (file_get_contents($imgFile));
$imgSize = strlen($img);
if ($lastImgSize != $imgSize) {
break;
}
}
session_start();
header("Content-type: image/jpg");
$_SESSION['imageSize'] = $imgSize;
echo $img;
exit;
Reload the image with javascript, the php will deliver a new image when available:
<img id="feed" src>
<script>
img = new Image
function f() {
img.src = "img.php?rnd=" + Date.now();
img.onload = function() {
feed.src = img.src;
setTimeout(function() {
f();
}, 50);
};
img.onerror = function() {
setTimeout(function() {
f();
}, 50);
};
}
f();
</script>
If you're looking for something a bit fancier:
Take a look at flowplayer which supports live streaming from a rtmp / hls source, both can be encoded with ffmpeg.
Or fancier still Dashcast a linux / windows streaming service which encodes live streams in the html5 mpeg-DASH format currently supported by ie and chrome, firefox support is on the way