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 did you try with filters?
    – Gyan
    May 27, 2016 at 4:49
  • I was playing with setpts or itsoffset, but problem is that I want to avoid processing the video as received rtmp stream in h264 should be directly saved with any processing (just an idea about how it should work)
    – Mr Z
    May 27, 2016 at 19:20

1 Answer 1


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
  • Problem with this answer is ffmpeg concat doesn't wait for 30 seconds, it completes the concatenation fairly quickly and this fails. Is there a way to force it to concat it per second? Feb 23, 2021 at 13:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.