<p>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.</p>

<p>Basic template is</p>

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

<p><code>WxH</code> should be set to the camera's resolution and <code>FPS</code> to its framerate.</p>

<p>And the 2nd command which is run 5 seconds after the trigger.</p>

<pre><code>ffmpeg -i Streamingoutput -t 30 snippet.mp4
</code></pre>

CC BY-SA 4.0
2021-02-23T13:44:50.603Z
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?
Parth Choudhary
CC BY-SA 3.0
2016-05-27T19:35:47.627Z
2016-05-27T19:35:47.627Z
Gyan
<p>need some advice to solve the problem </p>

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

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

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

<p>the similar idea is covered by ffmpeg wiki (<a href="https://trac.ffmpeg.org/wiki/Capture/Lightning" rel="nofollow">https://trac.ffmpeg.org/wiki/Capture/Lightning</a>) but I can't get this working in any command configuration</p>

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

<p>any ideas would be appreciated</p>

CC BY-SA 3.0
2016-05-27T04:49:16.127Z
What did you try with filters?
Gyan
CC BY-SA 3.0
2016-05-27T19:20:10.503Z
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
<ffmpeg><video-capture><live-recording>
ffmpeg buffered recording
Mr Z
# ffmpeg buffered recording

(Asked by: username_0 on 2016-05-26)

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

**Tags:** ffmpeg, video-capture, live-recording

> **Comments:**
> **username_1**: What did you try with filters?  
> **username_0**: 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)  

---

## 1 answers

### Answer by username_1 on 2016-05-27. Score: 0 | Accepted answer

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

> **Comments:**
> **username_2**: 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?  

---

