Circular buffer functionality

Added circular buffer functionality

This commit adds a circular buffer mode which allows the user to not write the video continuously to a file if they are interested in the last N seconds of video.  It records into memory continuously and only saves the last N seconds when a signal or keypress is received.

Fixed to make sure always gives valid video file!