Capture gameplay as a game feature?

Hey there guys!

I’m thinking of adding a feature of social media share for my game, so I was wondering if there is any way to make a 7 seconds video (or GIF) of the last 7 second of your run.

Thank you in advance!