I do like how OBS studio "replay buffer" feature works (recording of last X seconds continuously).
But it seems like over-sophisticated heavy application to be used for this only purpose.
As I understood, it uses ffmpeg for recording. And ffmpeg seem to support scripting (or configuring, I'm not sure which term fits better here).
So I tried to find some instructions on how to make it with ffmpeg scripting only (without OBS studio), but hadn't found clear and straightforward one yet.
So how to make ffmpeg to do this:
- begin video recording which will be finished only after some particular action (e.g. hotkey is pushed)
- each second delete part of recording which is older than 10 seconds.
1 Answer
You can split the recording to segments and use a playlist file to combine them later. See
Step 1:
ffmpeg -i input force_key_frames expr:gte(t,n_forced*4) -c:v libx264 -c:a aac -f segment -segment_time 4 -segment_wrap 6 -segment_list list.m3u8 -segment_list_size 6 seg%d.tsThis will save the recording in segments of 4 seconds. Once 6 segments have been written, the next segment will overwrite the first file. The playlist is updated accordingly.
Step 2:
ffmpeg -i list.m3u8 -c copy video.mp4or
ffplay list.m3u8The duration of the preserved footage is 20 < duration < 24.
If you want a complete solution that does this for you I have made a script for it
1