To Stream Webcam to an Apache Server on the Raspberry Pi you need to have already:
- Installed Apache – See this post.
- Installed the Camera Module – See this post.
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
/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:
Raspberry Pi Webcam Streaming
(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