RasPiCam & HTML5 Live Video Streaming via WebSockets


13 posts
by Ithorion » Thu Apr 17, 2014 8:51 pm
Hello,

I'm trying to make an HTML5 Live Video Streaming via Websocket.

I follow the tutorial : http://phoboslab.org/log/2013/09/html5- ... websockets
I successfully manage to install NodeJS, ffmpeg. However i'm running in a problem : I have a Raspberry Camera attached to the GPU, he is using a USB Camera.
I can't access the raspberry Camera as he does /dev/video0

The code to launch ffmpeg stream isn't working :
Code: Select all
ffmpeg -s 640x480 -f video4linux2 -i /dev/video0 -f mpeg1video \
-b 800k -r 30 http://example.com:8082/yourpassword/640/480/


Does anybody has a solution ? I tried to use
Code: Select all
raspivid -o - -t 9999999 -w 800 -h 600 --hflip | ffmpeg ... ... ...

However, i don't know how to pipe the stream from raspivid to ffmpeg.

After days of search, i finally seek for help here !

It'd be a huge help if any of you could help me solve this problem.
Thanks in advance !
Posts: 7
Joined: Thu Apr 17, 2014 8:41 pm
by punktea » Thu Apr 17, 2014 11:01 pm
It is hard to guess what your problem is since you did not explain how it failed, listing error messages will help.
The tutorial in phoboslab.org worked for me. If you want to use /dev/video0, you need to install v4l2 driver first
viewtopic.php?f=43&t=62364#
Otherwise, you can use raspicam and pipe to ffmpeg as follows:
raspivid -n -t 0 -o - | ffmpeg -y -i - -c:v copy ...
Once you get past this hurdle, you need to make sure that port 8082 is opened at the other end. Use telnet to check:
telnet example.com 8082
Posts: 21
Joined: Thu Jul 18, 2013 8:55 am
by Ithorion » Sat Apr 19, 2014 9:54 am
Thanks punktea !
I installed v4l2, but i didn't manage to use only ffmpeg. So i used raspivid as you said :
Code: Select all
raspivid -t 0 -w 320 -h 240 -fps 20 -vf -o - | ffmpeg -y -i pipe:0 -s 320x240 -f video4linux2 -f mpeg1video -b 400k -r 30 http://127.0.0.1:8082/monmdp/320/240/

My problem is that i have like 10s of latency but i'd like it under 200ms !
and on the tutorial i posted (http://phoboslab.org/log/2013/09/html5- ... websockets)
he says that he manage to get something around 100ms which would be awesome for me !
Does it come from the raspivid ?!
Thanks for your reply !
Posts: 7
Joined: Thu Apr 17, 2014 8:41 pm
by Ithorion » Sat Apr 19, 2014 11:27 am
Would you know how to skip parts if the camera stream is late ?!
I now that after having it smooth i want to use OpenCV to do some live transform on the stream !

The thing is, i rode the doc on OpenCV & Raspberry
http://picamera.readthedocs.org/en/release-1.3/recipes1.html#capturing-to-an-opencv-object
But i don't know how to send my stream to my webapp with websocket in Python like he'd do with NodeJS !
Posts: 7
Joined: Thu Apr 17, 2014 8:41 pm
by towolf » Sat Apr 19, 2014 11:44 am
Seems really weird to not use the hardware encoder and instead encode to mpeg1 with software and then decode mpeg1 with JavaScript, when browsers nowadays all support H264.
Posts: 421
Joined: Fri Jan 18, 2013 2:11 pm
by Ithorion » Sat Apr 19, 2014 11:47 am
Well I know, was just trying to find a way to make this tutorial work as he says he got a 100ms latency !

But if you know an other solution that'd allow me to use OpenCV functions on the Stream i'm listening :s
Posts: 7
Joined: Thu Apr 17, 2014 8:41 pm
by punktea » Sat Apr 19, 2014 12:31 pm
I don't know exactly how small the latency is but it is definitely less then 0.5s. The setup I tried was streaming Pi to my PC where I ran web server and nodejs. When I have time later on, I'll try the same configuration you have, i.e run everything on the Pi to see how well the CPU is holding up. This is the only solution I found that can stream near real-time (25fps, no buffering, sub-second latency) to android phone and I've tried damn near everything on this forum. Resolution is low but looks real good on a cell phone.
Posts: 21
Joined: Thu Jul 18, 2013 8:55 am
by Ithorion » Sat Apr 19, 2014 1:15 pm
Ok, to answer to my first question, and to be able to access to the Pi Camera through /dev/video0,
and therefore run the command :
Code: Select all
ffmpeg -s 320x240 -f video4linux2 -i /dev/video0 -f mpeg1video -b 800k -r 30 http://127.0.0.1:8082/monmdp/320/240/


I installed video4linux2 &
I followed the instructions on : "How to install or upgrade UV4L on Raspbian (for the Raspberry Pi)"
http://www.linux-projects.org/modules/sections/index.php?op=viewarticle&artid=14

And In the end, I get as promised the 100ms latency (more or less stable) !

Next Step for me : add OpenCV in Betwin.
Attachments
2014-04-19-14.33.14.jpg
Chrono Init
2014-04-19-14.33.14.jpg (42.51 KiB) Viewed 19233 times
2014-04-19-14.35.22.jpg
difference through the cam
2014-04-19-14.35.22.jpg (60.62 KiB) Viewed 19233 times
Posts: 7
Joined: Thu Apr 17, 2014 8:41 pm
by Ithorion » Sat Apr 19, 2014 1:18 pm
Thanks for helping Punktea !! :)
In the end, i Indeed want to send it over Wifi to a SmartPhone !
Take care !
Posts: 7
Joined: Thu Apr 17, 2014 8:41 pm
by Zoidbergus » Thu May 01, 2014 9:45 pm
Hello,
I have followed your guide and installed everything needed but I am getting an error saying:

"The device does not support the streaming I/O method.",
and
/dev/video0: function not implemented (the file is there, it is working with mpeg1video)

I used:

sudo uv4l --sched-rr --driver raspicam --auto-video_nr --encoding h264 --width 320 --height 240 --framerate 25 --extension-presence=1

and its still not working with -f video4linux2 .. could you please post your uv4l command to make /dev/video0 file ?

Thanks in advance. :)
Posts: 2
Joined: Thu May 01, 2014 5:36 pm
by Ithorion » Fri May 02, 2014 4:41 pm
Zoidbergus wrote:Hello,
I have followed your guide and installed everything needed but I am getting an error saying:

"The device does not support the streaming I/O method.",
and
/dev/video0: function not implemented (the file is there, it is working with mpeg1video)

I used:

sudo uv4l --sched-rr --driver raspicam --auto-video_nr --encoding h264 --width 320 --height 240 --framerate 25 --extension-presence=1

and its still not working with -f video4linux2 .. could you please post your uv4l command to make /dev/video0 file ?

Thanks in advance. :)


Hey !!

As i said, have you followed the steps here :

http://www.linux-projects.org/modules/s ... e&artid=14

After that i was able to do my ffmpeg command !

I know that i had the /dev/video0 file here at the begining without it working and getting the same error you have !

Good luck !
Posts: 7
Joined: Thu Apr 17, 2014 8:41 pm
by Zoidbergus » Wed May 07, 2014 5:19 pm
Thank you for your reply,

I tried everything and here is where I got :
-I am using raspberry pi camera, apache server, debian (latest wheezy).
-streaming method from: http://phoboslab.org/log/2013/09/html5- ... websockets
-I have installed video4linux2, uv4l. uv4l-raspicam.
-installed from: http://www.linux-projects.org/modules/s ... e&artid=14

And this is what I do:
Code: Select all
sudo pkill uv4l             //to kill previous driver
sudo uv4l --sched-rr --driver raspicam --auto-video_nr --encoding h264 --width 320 --height 240 --framerate 25 --extension-presence=1
                            //create new /dev/video0
sudo modprobe bcm2835-v4l2  // somehow the stream only works with video4linux2 module loaded manually

and I get it to stream using exactly your ffmpeg parameters:
Code: Select all
ffmpeg -t 30 -s 320x240 -f video4linux2 -i /dev/video0 -f mpeg1video -b 800k -r 30 http://127.0.0.1:8082/raspberry/320/240/

However I get latency about 0,5-1 s, and while running command ffmpeg, terminal throws errors:
PTS (numbers), DTS (numbers), st:0 invalid dropping

Sometimes it freezes the stream and I have to restart the terminal.
I dont mind the latency that much, but those errors concern me.

Did you encounter this problem ? Does someone know how to fix it ?

I'm enclosing my time difference between camera and stream.
Attachments
P1060640.JPG
P1060640.JPG (42.91 KiB) Viewed 18679 times
Posts: 2
Joined: Thu May 01, 2014 5:36 pm
by su13 » Sat May 24, 2014 7:49 am
when i try to install ws uing "npm install ws" , i get the following error

npm http GET registry.npmjs.org/ws

npm ERR! Error: failed to fetch from registry: ws
npm ERR! at /usr/share/npm/lib/utils/npm-registry-client/get.js:139:12
npm ERR! at cb (/usr/share/npm/lib/utils/npm-registry-client/request.js:31:9)
npm ERR! at Request._callback (/usr/share/npm/lib/utils/npm-registry-client/request.js:136:18)
npm ERR! at Request.callback (/usr/lib/nodejs/request/main.js:119:22)
npm ERR! at Request.<anonymous> (/usr/lib/nodejs/request/main.js:212:58)
npm ERR! at Request.emit (events.js:88:20)
npm ERR! at ClientRequest.<anonymous> (/usr/lib/nodejs/request/main.js:209:10)
npm ERR! at ClientRequest.emit (events.js:67:17)
npm ERR! at ClientRequest.onError (/usr/lib/nodejs/request/tunnel.js:164:21)
npm ERR! at ClientRequest.g (events.js:156:14)
npm ERR! You may report this log at:
npm ERR! <bugs.debian.org/npm>
npm ERR! or use
npm ERR! reportbug --attach /home/suresh/npm-debug.log npm
npm ERR!
npm ERR! System Linux 3.8.0-39-generic
npm ERR! command "node" "/usr/bin/npm" "install" "ws"
npm ERR! cwd /home/suresh
npm ERR! node -v v0.6.12
npm ERR! npm -v 1.1.4
npm ERR! message failed to fetch from registry: ws
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/suresh/npm-debug.log
npm not ok

can anyone tell me why this happens???

thanks in advance.
Posts: 1
Joined: Sat May 24, 2014 7:47 am