pimterry / raspivid-stream

Raspberry pi cam video, as a stream you can send straight to web clients
MIT License
38 stars 7 forks source link

raspivid-stream

Raspberry pi cam video, as a stream you can send straight to web clients.

The first request for a stream starts the camera recording and streams from there.

All subsequent calls will be given a stream starting with the initial parameter frames (so it's renderable, but starting the actual video frames from the current time.

You should be able to pass the output client-side into a renderer like Broadway.js, or h264-live-player (broadway + logic + canvas renderer) and immediately get live streaming video. See pi-cam for a simple working demo.

Installation

npm install raspivid-stream

Usage

Server-side:

var raspividStream = require('raspivid-stream');

var videoStream = raspividStream();

// To stream over websockets:
videoStream.on('data', (data) => {
    ws.send(data, { binary: true }, (error) => { if (error) console.error(error); });
});

Client-side:

<script type="text/javascript" src="https://rawgit.com/131/h264-live-player/master/vendor/dist/http-live-player.js"></script>
<script>
    var canvas = document.createElement("canvas");
    document.body.appendChild(canvas);

    var wsavc = new WSAvcPlayer(canvas, "webgl");

    wsavc.connect(YOUR_WEBSOCKET_URL);
</script>