Skip to main content

Raymii.org Raymii.org Logo

Quis custodiet ipsos custodes?
Home | About | All pages | Cluster Status | RSS Feed

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 .gif, using slop and 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:

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 slop README.

Recording with slop and ffmpeg

By combining two programs, slop, to get the screen region to record, and ffmpeg to do the actual recording, you can select a region of your screen to record, in any format ffmpeg supports. I often do it as a gif or .mp4.

slop is a small and simple tool that does one thing, the manpage describes it best:

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 recgif.sh:

#!/bin/bash
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 set the $PATH in multiple places, but I have it in my ~/.bashrc file:

PATH="/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/snap/bin:$HOME/bin:$HOME/.bin:$PATH"

Try it out in your shell, by typing:

recgif.sh test.gif

Your cursor changes to a crosshair which you use to select a region. Then recording starts, until you kill the shell command with CTRL+C.

If you specify a different extension, the video save format will reflect that:

recgif.sh test.mkv 

.gif files are rather large, the image at the top of this page is almost 50 MB whereas the same recording in .mkv is about 0,5 MB.

Tags: bash , desktop , ffmpeg , linux , shell , slop , snippets , video