I think you can, but it's a bit complicated. I'd suggest using something like Peek (for Linux), ScreenToGif (for Windows) or LICEcap (for Windows and Mac) if you want something simpler and more straighforward.
I didn't know about LICEcap. Thank you.