How to setup ffmpeg for the same record method which is used in OBS studio "replay buffer" feature (recording of last X seconds continuously)?

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:

  1. begin video recording which will be finished only after some particular action (e.g. hotkey is pushed)
  2. 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.ts

This 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.mp4

or

ffplay list.m3u8

The 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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like