ffmpeg buffered recording need some advice to solve the problem 

ffmpeg is receiving the nonstop live stream (rtmp source) from camera monitoring entry gates 

after trigger is fired (gate/door is open) I need to create the 30sec videofile saved to HDD

I mean this 30 sec as 25 seconds of video before trigger was fired and some 5 seconds after trigger

the similar idea is covered by ffmpeg wiki (https://trac.ffmpeg.org/wiki/Capture/Lightning) but I can't get this working in any command configuration

I was playing with filters, buffering etc too but still no luck ;-((

any ideas would be appreciated
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