0

I have a raspberry pi and I want to stream webcam video from it. I want to make it compatible with my Windows Mobile phone (or any other device with a browser), so mjpeg streaming is out of the question. In fact, I wasn't able to find a format that would work when streaming from linux. On my Windows machine I used WebcamXP to stream webcam video and it worked fine - the software dumps jpegs into a folder and in the browser there's a simple js script which fetches these jpegs every 40ms. It's not a "pretty" solution, but I want to achieve the same thing on my raspberrypi.

The problem is, that I can't find any software that would dump jpegs into a folder at >1fps. I know that mplayer and vlc can do this, but they output images that are green-ish and I couldn't find a way to make them look right (I tried for days). Interestingly, motion and fswebcam output good video without any configuration, but they don't support dumping jpegs quickly enough - they can only make a snapshot once every second.

Assuming I can't find a way to fix video in mplayer/vlc, there are two ways to solve this: 1. Find a program/utility that dumps the images correctly 2. Convert stream from motion to jpegs

Setting up a server and writing the js script is not a problem, I only need to get a steady stream of jpegs from my webcam into a folder.

3
  • Looks like a copycat of a bad workaround. Why not ask for a Windows compatible streaming solution here? (I see this is you first question.) Commented Sep 6, 2015 at 10:36
  • If your phone supports html5 canvas and WebSockets there are solutions with real video from ffmpeg.
    – meuh
    Commented Sep 6, 2015 at 15:10
  • @Thomas Erker I agree that it's an ugly solution, but I want this to work everywhere. The fps isn't really important. I know I've tried various encodings and nothing really worked.
    – tomasp
    Commented Sep 6, 2015 at 18:02

1 Answer 1

0

In the end I made it work with mplayer. Turns out it mplayer just had invalid hue and saturation values. No idea why, but I've seen other people complain about it too. This is the command I ended up using:

mplayer -really-quiet -tv driver=v4l2:height=320:width=240:quality=1:hue=35:saturation=-80:brightness=99:contrast=-88:fps=8:device=/dev/video0 tv:// -vo jpeg -saturation -50 -contrast -3 &

It dumps jpegs to a folder at 8fps, which is enough for my needs.

Along with this script I run a script which deletes images older than 8 seconds from the folder. I used 8 seconds to keep cpu usage low, as that's a valuable resource on the pi:

cd /home/pi/webcam_frames

while true; do
find . -not -newermt '-8 seconds' -delete
sleep 8;
done

And a script that creates a symlink to the latest image 10 times a second.

cd /home/pi/public

sleep 2
rm -rf latest.jpg

while true; do
ln -s -f /home/pi/webcam_frames/`ls -rt /home/pi/webcam_frames | tail -n1` latest.jpg
sleep 0.1
done

This symlink is in public directory which is made available from a browser via nodejs:

var express = require('express'),
app = express(),
port = 8888;

app.use(express.static('/home/pi/public'));
app.listen(port);

I have a simple html+js page which fetches the symlinked image from nodejs a few times a second and thus I have 5-8fps video which works on every device which can handle javascript.

It's an ugly solution with an ugly result, but it's exactly what I needed.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .