How to make screencasts in Ubuntu Linux

Create videos from recording the screen in Linux

Published:
Last modified:

Overview

This article shows different alternatives to create screencasts (video screen capture) in Ubuntu Linux.

Most differences between them reside in the capability of recording audio while recording the screen or not.

Record type

Screen

ffmpeg

Capture X11 screen with ffmpeg and x11grab.

For example to grab from :0.0 using ffmpeg:

ffmpeg -f x11grab -framerate 25 -video_size cif -i :0.0 out.mpg

Grab at position 10,20:

ffmpeg -f x11grab -framerate 25 -video_size cif -i :0.0+10,20 out.mpg

Capture without audio:

ffmpeg -f x11grab -r 25 -s 1280x720 -i :0.0+0,24 -vcodec libx264 -preset ultrafast -crf 0 -threads 0 video.mkv

Capture a specific window or region of the screen (requires slop):

#!/bin/bash
slop=$(slop -f "%x %y %w %h %g %i") || exit 1
read -r X Y W H G ID < <(echo $slop)
ffmpeg -f x11grab -s "$W"x"$H" -i :0.0+$X,$Y -f alsa -i pulse ~/video.webm

When running the above script, you can make the selection of the region you want to record with drawing a rectangle in the screen and then it starts to record.

The above command uses ALSA1 to capture audio, it can be done like: ... -f alsa -ac 2 -i hw:0 video.mkv.

Or using pulse as input device: ... -f pulse -ac 2 -i default video.mkv.

More info for ffmpeg capturing screen: https://trac.ffmpeg.org/wiki/Capture/Desktop

Parameters
[hostname]:display_number.screen_number[+x_offset,y_offset]
  • Where hostname:display_number.screen_number specifies the X11 display name of the screen to grab from. hostname can be omitted, and defaults to localhost. The environment variable DISPLAY contains the default display name.

  • x_offset and y_offset specify the offsets of the grabbed area with respect to the top-left border of the X11 screen. They default to 0.

  • preset: Install x264 presets with sudo apt install x264, then list available presents with x264 –help

    - ultrafast,superfast,veryfast,faster,fast
    - medium,slow,slower,veryslow,placebo
    
    • Rate control
      • --crf <float> Quality-based VBR (0-51) [23.0]

Use the xdpyinfo program for getting basic information about the properties of your X11 display (e.g. grep for “name” or “dimensions”).

Compress to mp4

Compress and convert to MP4 format (specially for Youtube):

ffmpeg -i video.mkv -vcodec libx264 -vpre hq -crf 22 -threads 0 video.mp4
Reference

Peek

A screen recorder capable of generating animated GIFs, WebM and MP4 videos..

sudo add install peek

Console

asciinema

Record console with asciinema which generates a .json file, and then convert it to a .gif or video like .mp4.

To install in Ubuntu: pip3 install –user asciinema

  • Record terminal and upload it to asciinema.org: asciinema rec
  • Record terminal to local file: asciinema rec demo.cast
  • Record terminal and upload it to asciinema.org, specifying title: asciinema rec -t “My git tutorial”
  • Record terminal to local file, limiting idle time to max 2.5 sec: asciinema rec -i 2.5 demo.cast
  • Replay terminal recording from local file: asciinema play demo.cast

Then install asciicast2gif which “Generate GIF animations from asciicasts (asciinema recordings)”

Audio + Video

recterm

There is a BASH script that combines the usage of *asciinema and sox for recording audio and automatically combines them into a video with ffmpeg

Open Broadcaster Studio

OBS Studio:

sudo add-apt-repository ppa:obsproject/obs-studio
sudo apt-get update && sudo apt-get install obs-studio

Indicators

Mouse and keyboard usage can be highlighted in the recording area using one of these programs:

Mouse

key-mon package makes it possible to highlight mouse pointer with key-mon –visible_click

Keys

Pressed keys can be highlighted with the package screenkey: https://gitlab.com/wavexx/screenkey


$ mkdir -P ~/local/share
$ cd ~/local/share/
~/local/share$ git clone https://gitlab.com/wavexx/screenkey.git
Cloning into 'screenkey'...
remote: Enumerating objects: 1205, done.
remote: Counting objects: 100% (1205/1205), done.
remote: Compressing objects: 100% (379/379), done.
remote: Total 1205 (delta 810), reused 1199 (delta 807)
Receiving objects: 100% (1205/1205), 295.11 KiB | 584.00 KiB/s, done.
Resolving deltas: 100% (810/810), done.
~/local/share$ cd ~/
$ ln -s ~/local/share/screenkey/screenkey ~/bin/

screenkey is also available as a package in a more basic version

  • sudo apt install screenkey
  • Replaces original key-mon (last update on 2014)

A java-based alternative to key-mon: kmcaster: “Java-based on-screen display (OSD) for keyboard and mouse events”

Audio

SOX can be used to start the audio recording separately while we start recording the terminal.

sudo apt install sox

Obsolete

Many articles and tutorials around recommend these projects that are currently unmaintained, still shipped with popular distros like Ubuntu:

  • recordMyDesktop: last release on 2008.

Conclusion

This is a list I have compiled while looking for a simple solution to record screencasts in Linux. There are a lot of different approaches depending specifically what your goals are, this is why I grouped them in the above topics, so I hope this is useful to you too.

After trying many of them over time, my current preferred way to record screencasts is with the usage of ffmpeg and their related commands, no graphical interface can beat the power it gives to know its (rather complex) parameters, but once you get familiar with it, it is the best solution.

This is the script combining the above tools to select a region, record audio and also show which keys are pressed:

#!/bin/bash
# It shows screenkey's config window to select the region where keys
# will be displayed
screenkey --show-settings &

# Ask the user for the region to record (it should contain the above region)
slop=$(slop -f "%x %y %w %h %g %i") || exit 1
read -r X Y W H G ID < <(echo $slop)
ffmpeg -f x11grab -s "$W"x"$H" -i :0.0+$X,$Y -f alsa -i pulse ~/video.webm

Resources


  1. ALSA (Advanced Linux Sound Architecture) output device. https://ffmpeg.org/ffmpeg-devices.html#alsa-1 More complex examples at: https://trac.ffmpeg.org/wiki/Capture/ALSA ↩︎

Uruguay
Marcelo Canina
I'm Marcelo Canina, a developer from Uruguay. I build websites and web-based applications from the ground up and share what I learn here.
comments powered by Disqus


How to record your screen, audio and console in Ubuntu Linux generating videos or animated gifs.

Clutter-free software concepts.
Translations English Español

Except as otherwise noted, the content of this page is licensed under CC BY-NC-ND 4.0 . Terms and Policy.

Powered by SimpleIT Hugo Theme

·