Raspberry Pi Stream Webcam to Apache Server
To Stream Webcam to an Apache Server on the Raspberry Pi you need to have already:
After you have done this you are ready to start.
First Step – Install FFmpeg
You should download, compile and install FFmpeg, a cross platform solution for streaming and recording including the codec you will need.
Remove any existing installation:
apt-get remove ffmpeg
Get the git installation link from the FFmpeg git page here.
I have included the link in the following commands:
git clone git://source.ffmpeg.org/ffmpeg.git
Once this has completed, move into the directory and compile the source.
cd ffmpeg
./configure
make
make install
This can (and probably will) take hours on the Raspberry Pi so I recommend you put this in a script and run it over night or go watch a film.
Step 2 – Install crtmpserver
This can be done with apt-get.
apt-get install crtmpserver
but you will need to do some configuration, edit the following file:
/etc/crtmpserver/applications/flvplayback.lua
Add/change the following setings:
validateHandshake=false,
keyframeSeek=false,
seekGranularity=0.1
clientSideBuffer=30
And finally restart the service:
service crtmpserver restart
Final Step – Web setup
Install jwplayer on your web server. You can get this at: http://www.longtailvideo.com/, once you have downloaded it, extract the files in:
/var/www/jwplayer
Create an example webpage to display your webcam stream:
<html> <head> <title>Raspberry Pi Webcam Streaming</title> </head> <body> <div id="video-jwplayer_wrapper" style="position: relative; display: block; width: 960px; height: 540px;"> <object type="application/x-shockwave-flash" data="/jwplayer/jwplayer.flash.swf" width="100%" height="100%" bgcolor="#000000" id="video-jwplayer" name="video-jwplayer" tabindex="0"> <param name="allowfullscreen" value="true"> <param name="allowscriptaccess" value="always"> <param name="seamlesstabbing" value="true"> <param name="wmode" value="opaque"> </object> <div id="video-jwplayer_aspect" style="display: none;"></div> <div id="video-jwplayer_jwpsrv" style="position: absolute; top: 0px; z-index: 10;"></div> </div> <script src="/jwplayer/jwplayer.js"></script> <script type="text/javascript"> jwplayer('video-jwplayer').setup({ flashplayer:"/jwplayer/jwplayer.flash.swf" , file:"rtmp://" + window.location.hostname + "/flvplayback/flv:myStream.flv" , autoStart: true , rtmp:{ bufferlength:0.1 } , deliveryType: "streaming" , width: 960 , height: 540 , player: { modes: { linear: { controls:{ stream:{ manage:false , enabled: false } } } } } , shows: { streamTimer: { enabled: true , tickRate: 100 } } }); </script> </body> </html>
Now check it works! Make sure you connect to it locally and not remotely. (192.168.* address).
To start the stream run the following command:
raspivid -t 0 -w 960 -h 540 -fps 25 -b 500000 -vf -o - | ffmpeg -i - -vcodec copy -an -f flv -metadata streamName=myStream tcp://0.0.0.0:6666
You should see a video stream similar to the image below:
(Yes, the webcam is pointed at the wall).
If you want to make this webcam stream accessible remotely, you need to port forward port 1935 to the raspberry pi.
Voila, now you can Stream Webcam to Apache Server on the Raspberry Pi.
Plus i am using it and it works wonders
works like a charm, only problem now is getting jwplayer
ReplyDeletei get this error:
ReplyDeletepi@raspberrypi ~ $ raspivid -t 0 -w 960 -h 540 -fps 25 -b 500000 -vf -o - | ffmpeg -i - -vcodec copy -an -f flv -metadata streamName=myStream tcp://0.0.0.0:6666
-bash: raspivid: command not found
ffmpeg version N-62748-gb3c0d01 Copyright (c) 2000-2014 the FFmpeg developers
built on Apr 27 2014 21:48:47 with gcc 4.6 (Debian 4.6.3-8+rpi1)
configuration:
libavutil 52. 79.100 / 52. 79.100
libavcodec 55. 59.100 / 55. 59.100
libavformat 55. 37.101 / 55. 37.101
libavdevice 55. 13.100 / 55. 13.100
libavfilter 4. 4.100 / 4. 4.100
libswscale 2. 6.100 / 2. 6.100
libswresample 0. 18.100 / 0. 18.100
pipe:: Invalid data found when processing input
great tut by the way almost everything worked as expected