ffmpeg buffered recording
What you can do is add a blank 30 second segment in front of the camera stream, and then use the method in the ffmpeg wiki.

Basic template is

ffmpeg -f lavfi -i color=black:WxH:r=FPS:d=30 -i camera_input \
       -filter_complex "[0][1]concat[v]" -map "[v]" StreamingOutput


WxH should be set to the camera's resolution and FPS to its framerate.

And the 2nd command which is run 5 seconds after the trigger.

ffmpeg -i Streamingoutput -t 30 snippet.mp4