Record your Linux Desktop with ffmpeg and slop to any format
Published: 17-03-2021 | Author: Remy van Elst | Text only version of this article
❗ This post is over two years old. It may no longer be up to date. Opinions may have changed.
Table of Contents
This two-line shell script allows you to record a region of your linux desktop to a video file, or a
ffmpeg. I use it often when a screenshot is not enough, or when you need to explain a sequence of events to someone.
Here is a
.gif recorded of my current KDE desktop:
Recently I removed all Google Ads from this site due to their invasive tracking, as well as Google Analytics. Please, if you found this content useful, consider a small donation using any of the options below:
I'm developing an open source monitoring app called Leaf Node Monitoring, for windows, linux & android. Go check it out!
Consider sponsoring me on Github. It means the world to me if you show your appreciation and you'll help pay the server costs.
You can also sponsor me by getting a Digital Ocean VPS. With this referral link you'll get $100 credit for 60 days.
This script was adapted from the examples given in the
Recording with slop and ffmpeg
By combining two programs,
slop, to get the screen region to record, and
to do the actual recording, you can select a region of your screen to record, in
ffmpeg supports. I often do it as a
slop is an application that queries for a selection from the user and prints the region to
stdout. It grabs the mouse and turns it into a crosshair, lets the user click and drag to
make a selection (or click on a window) while drawing a pretty box around it, then finally
prints the selection's dimensions to stdout.
ffmpeg is a very fast audio and video converter, also able to do live stuff and in this case, record
the desktop. Both tools are in the Ubuntu repository, so you can install them with the package manager:
apt install slop ffpmeg
Place the following in a script, I named it
geometry=$(slop -f "-video_size %wx%h -i :0.0+%x,%y")
ffmpeg -framerate 30 -f x11grab $geometry "$1"
Make sure it is in your
$PATH so you can execute it in any terminal. I have the folder
$HOME/bin in my
$PATH, which is where all my scripts live, including this one. You can
$PATH in multiple places, but I have it in my
Try it out in your shell, by typing:
Your cursor changes to a crosshair which you use to select a region. Then recording starts, until you
kill the shell command with
If you specify a different extension, the video save format will reflect that:
.gif files are rather large, the image at the top of this page is almost 50 MB whereas the same
.mkv is about 0,5 MB.