Have a look at Motion project -
http://motion.sourceforge.net.
Live viewing is possible with the right web browser and the proper configuration of the webcam features. You can record combinations of motion-only videos, stills every N seconds and a stop-motion movie based on still every N seconds. They have recently started to support buffered frames, so that you can grab N frames from the buffer before a motion event is triggered.
The documentation is well-maintained and up-to-date, and there is a very active mailing list as well.