Livestream webcam with NodeJS from raspberry pi, HOW! (websocket)

So i-am doing some fun things,
I've made my traxxas RC car run with Raspberry pi, Arduino and a web interface and its working great!!(using NodeJS and websocket)

However now all that's been done i want to add some more.
and what's better than a CAMERA :D right? yeahh.... going all NSA here..

Anyway, so i want to stream webcam attached to the RPi to a HTML page (on phone).
How do i do such a thing? i-am using NodeJS with websocket.

The webcam is only 480p and quality does not really matter to me (low latency is a nice thing to have)

Hardware,
Raspberry pi 2 model B (running NOOBS)
generic driverless USB webcam 480p
WiFi dongle
(the rest does not matter)

Software,
Noobs (OS)
Node with express, serial and socket.io

What i want,

Webcam-->RPi-->magic-and-websocket-server-->WiFi - - >Phone/computer-->webpage-with-webcam-live-video

Please some one help me!

You can use ffserver to make a webm stream or similar but that will get you a lot of latency.

However I found this blog post that shows how to use Web Sockets to stream video in real time. That will give you one webserver that you stream to and another a web socket server to view on, then you can just embed the video stream in your normal web interface.

Edit: Tried it and it works well, there is a noticeable latency but nothing like when using a regular video stream. Hope it works equally well with the performance of a Raspberry Pi.

thank you very much, i'll try the last one as i did not like the first method.

How much lag did you have? <1s?

The first method had so much latency that it would have been unusable with an RC car.

Yes, the second method gave less than a third of a second in latency. Edit: Actually I get no noticeable difference when I view the camera directly.

1 Like

awesome, i-am currently having a hard time with installing ffmpeg the way they described but i'll try my best.
(i think it's installing ffmpeg? its installing something atleast hahaha)

Yes, all you need is ffmpeg and that script from jsmpeg.

it installed succesfully, i think i can figure the rest out on my own. otherwise i'll keep up to date.
Thank you very much.

No problem, the stream-example.html file contains example code that should be all you need to embed the stream into your web interface.

jep but i got -bash ffmpeg: command not found.
So i-am following this guide to installing ffmpeg at the moment.

@3 install ffmpeg

Are you sure that you didn't get any errors before that?

Luckily you don't need to build it from source, see this thread. Raspbian does not have ffmpeg in its package repositories, instead it has a fork called libav that you can install with sudo apt-get install libav-tools. The equivalent command to ffmpeg will then be avconv, the command line arguments should be exactly the same.

nope no errors.
useful :D thank you

Fuck yes it's all working.
Thank you very much.

1 Like