Revised version: Tue March 10, 2009
We use an Axis 206w and a 207w webcam at work. This camera has an build in webserver that serves an MJPEG (Motion JPEG video) stream. Later cams servers also MPEG4 streams, but the 206w doesn’t. It has an buildin .swf feed, but that one does not work on my browsers. Now I have a work around to use swf files. What I do is using FFmpeg to convert the MJPEG feed to swf and flv. I use a separate server, not the build in one on the cam!
(Just for explanation; 10.0.0.1 is my server and 10.0.0.106 is my camera)
What I did to make it all work… Installed the latest ffmpeg. (Downloaded the source, compiled it (./configure;make;make install;) Or on Debian Lenny I used the ‘unstable’ packages. (FFmpeg version 0.5-svn17737+3:0.svn20090303-1) I’ve tried older versions, even the ’stable’ Lenny version, but the swf would not load every time in my browsers. So when you have a good ffmpeg and ffserver, then comes the real trick… Configure your ffserver. Edit /etc/ffserver.conf , use this source:
# Port on which the server is listening. You must select a different # port from your standard HTTP web server if it is running on the same # computer. Port 8090 # Address on which the server is bound. Only useful if you have # several network interfaces. BindAddress 0.0.0.0 # Number of simultaneous HTTP connections that can be handled. It has # to be defined *before* the MaxClients parameter, since it defines the # MaxClients maximum limit. MaxHTTPConnections 2000 # Number of simultaneous requests that can be handled. Since FFServer # is very fast, it is more likely that you will want to leave this high # and use MaxBandwidth, below. MaxClients 1000 # This the maximum amount of kbit/sec that you are prepared to # consume when streaming to clients. MaxBandwidth 1000 # Access log file (uses standard Apache log file format) # '-' is the standard output. CustomLog - # Suppress that if you want to launch ffserver as a daemon. NoDaemon <Feed feed1.ffm> File /tmp/feed1.ffm #when remarked, no file is beeing created and the stream keeps working!! FileMaxSize 200K # Only allow connections from localhost to the feed. ACL allow 127.0.0.1 </Feed> # SWF output - great for testing <Stream test.swf> # the source feed Feed feed1.ffm # the output stream format - SWF = flash Format swf # this must match the ffmpeg -r argument VideoFrameRate 5 # another quality tweak VideoBitRate 320 # quality ranges - 1-31 (1 = best, 31 = worst) VideoQMin 1 VideoQMax 3 VideoSize 640x480 # wecams don't have audio NoAudio </Stream> # FLV output - good for streaming <Stream test.flv> # the source feed Feed feed1.ffm # the output stream format - FLV = FLash Video Format flv VideoCodec flv # this must match the ffmpeg -r argument VideoFrameRate 5 # another quality tweak VideoBitRate 320 # quality ranges - 1-31 (1 = best, 31 = worst) VideoQMin 1 VideoQMax 3 VideoSize 640x480 # wecams don't have audio NoAudio </Stream> <Stream stat.html> Format status </Stream> <Redirect index.html> # credits! URL http://ffmpeg.sourceforge.net/ </Redirect>
Now your done with your ffserver configuration. Now make a little shell script to start your converter. It uses
cCurl Wget to get the stream from the camera. But it could also be done with a php or perl script that opens a socket and parses the content to stout. Curl does that real fast, so I use that. Curl breaks some frames, I use wget now. I’ve made some crude scripts to keep the server up, even when something goes down. I’ve noticed that the server sometimes stops without warning. That is the reason I don’t use the ffserver in daemon mode. Also change the port 8090 when you have some other service running on that port, like OpenERP… (That was my first mistake ;)
Make a file called ’stream.sh’ and put the following source in:
#!/bin/bash while [ 1 ] do wget -nv -O - http://10.0.0.106/axis-cgi/mjpg/video.cgi | ffmpeg -er 4 -y -r 5 -f mjpeg -i - http://127.0.0.1:8090/feed1.ffm done
You can change http://10.0.0.106/axis-cgi/mjpg/video.cgi?resolution=320×240 to your own URL.
Now create a file server.sh and put this in:
#!/bin/bash while [ 1 ] do ffserver done
Now change the mod of the scripts so you can start them…
chmod +x stream.sh server.sh
And now your done, just start the the script with nohup so the process keeps running after you close your terminal…
nohup ./server.sh > /dev/null & nohup ./start.sh > /dev/null &
If you don’t use nohup, the converter parses all messages to stout. Easy for debugging ;)
Now just point your browser to your ffserver :
And it should work! Open a bottle of beer!
Here’s our webcam, viewing Alkmaardermeer, Akersloot, the Neterlands.
85 Responses to “Convert Axis webcam stream to Flash (.swf/.flv)”
Leave a Reply
You must be logged in to post a comment.