So I recently got back into the Pi as I could now use the PiSU to do a few things.
I saw a Logitech c110 webcam and decided to pick that up to test out the mjpeg world of webcams.
I started off with a fresh re-install of Raspbian Server Edition (RSE), and found that the instructions in Part 1 don’t work any more. Not sure why that is, but I’m assuming there’s an issue in the code somewhere for ffmpeg so I ended up using git to get the source code to build.
First step is to install git, as RSE didn’t include git.
I was root when I ran the rest of these commands, so if you’re not root, either sudo bash to become root, or just prepend sudo to everything
apt-get install git
Once git was installed, I went into /usr/src to download the source.
cd /usr/src
git clone git://source.ffmpeg.org/ffmpeg.git
Git retrieved the source code I needed to build ffmpeg from scratch, which is next up !
*Note*
If you need sound for ffmpeg, you will need to also install the libasound2-dev package which enables ALSA.
cd ffmpeg
./configure
make && make install
*Note* Compiling ffmpeg on the Pi will take a while, I left it running overnight to let it finish up. */Note*
Once ffmpeg was compiled and installed, I followed the same steps as before to setup ffmpeg.
I’ll repost the config that I used here –
Port 80
BindAddress 0.0.0.0
MaxClients 10
MaxBandwidth 50000
NoDaemon
<Feed webcam.ffm>
file /tmp/webcam.ffm
FileMaxSize 10M
</Feed>
<Stream webcam.mjpeg>
Feed webcam.ffm
Format mjpeg
VideoSize 320x240
VideoFrameRate 10
VideoBitRate 20000
VideoQMin 1
VideoQMax 10
</Stream>
<Stream stat.html>
Format status
</Stream>
And the script file I use to start ffserver and ffmpeg
ffserver -f /etc/ff.conf & ffmpeg -v quiet -r 5 -s 320x240 -f video4linux2 -i /dev/video0 http://localhost/webcam.ffm
When I tried streaming, I found out that the webcam only supports 30fps and 15fps, so the driver automatically forces it to 15fps.
For some reason, ffserver also has trouble streaming mjpeg when the source is also mjpeg.
To stream straight mjpeg, I used the -vcodec mjpeg
parameter by itself in the script to start ffmpeg. The output of ffmpeg shows that it is definitely streaming straight mjpeg but for some reason I can’t tap into the stream.
Looking at the ffmpeg/ffserver status page, it shows that ffserver is definitely pushing data to my devices, so I’m unsure as to what is happening there.
When I was streaming it from raw -> mjpeg, it could stream on my laptop via VLC but not on my Android Mobile.
I’m currently looking into why it might be doing this, but I’m stumped 🙁
Streaming from raw video -> mjpeg isn’t very cpu intensive for the Pi but it can’t keep up streaming at a good fps on the Logitech Webcam. I tried it on the lowest resolution possible which is 176×144 and I still had a ~2 second delay.
I tried some of my other cheaper webcams which didn’t have mjpeg format and they fared a bit better than the Logitech one in the Raw department, possibly due to the fact that the Logitech forced 15fps.
CPU usage was around 20% with the 176×144 resolution with a cheap webcam, and 25% with the Logitech c110
Almost doubling the resolution to 320×240 resulted in barely any video on the Logitech with ffmpeg stalling altogether, and not streaming to ffserver at all, and the same for the cheap webcam.
I seem to recall in older versions of ffmpeg and Raspbian that the cheaper webcams could still stream well at 320×240, so I’m unsure as to whether it’s ffmpeg causing issues or Raspbian now.
That’s all from me for now, hopefully this post helps someone get their webcams up and running 🙂