From http://sourceforge.net/p/mjpg-streamer/code/HEAD/tree/ r182