screencapture is known for screenshots, but it records video as well, and you can give it a time limit.
-v starts a recording you stop yourself. -V takes a number of seconds and stops on its own:
screencapture -V 20 -k ~/Desktop/demo.mov
That records 20 seconds of the screen to a QuickTime movie. -k draws a circle on every click, which helps when you show someone where to press. -g adds audio from the default microphone.
Because it is a command, it fits in a script. I like it for capturing a bug that only shows up when something else runs:
screencapture -V 15 ~/Desktop/bug.mov &
./reproduce-the-bug.sh
The & runs the recording in the background while the script does its thing.
The first run triggers the Screen Recording permission for your terminal app, under Privacy & Security. Until you allow it, recordings may show little more than the desktop background. The man page itself admits the tool is not very well documented, and options shift a little between macOS versions, so run screencapture -h to see what your version supports. Movies from a Retina screen get large quickly, so keep them short.
Further reading: screencapture man page (macOS)