5

Today I learned of a Windows-only product today called the Overwolf Replay HUD, which lets the user press a key to replay the last 20 seconds of happenings on their screen. It's meant for people playing or spectating fast-paced videogames who want to quickly review a hectic moment.

I'm trying to duplicate that behaviour on Linux. So far, I figure I could easily start ffmpeg (with -f x11grab) capture to a file in /tmp (which is memory-mapped), then use sxhkd to bind a keyboard shortcut to launch mpv to play the last 20 seconds of that file.

However, the rest of the recording would still be stored, and I'd eventually run out of RAM. How could I go about keeping only the last 20 seconds?

1
  • 1
    Some promising leads from reading around: ⓐ Open Broadcaster Software's internal ffmpeg fork has a replay buffer feature implemented in this commit. ⓑ Vanilla ffmpeg's -segment & co. can split a stream into separate files of specified length, which could just be pruned periodically to save space, but this may require rejoining files before playing them.
    – Anko
    Commented Jun 24, 2017 at 15:01

2 Answers 2

9

The segment muxer will work.

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.

1

OBS has a configurable replay buffer feature, that covers exactly what you want.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .