Create videos from recording the screen in Linux
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.
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
hostname:display_number.screen_numberspecifies the X11 display name of the screen to grab from.
hostnamecan be omitted, and defaults to
localhost. The environment variable
DISPLAYcontains the default display name.
x_offsetand 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]
- Rate control
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
- More info at X11 man page man X
A screen recorder capable of generating animated GIFs, WebM and MP4 videos..
sudo add install peek
Record console with asciinema which generates a
file, and then convert it to a
.gif or video like
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
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
sudo add-apt-repository ppa:obsproject/obs-studio sudo apt-get update && sudo apt-get install obs-studio
Mouse and keyboard usage can be highlighted in the recording area using one of these programs:
key-mon package makes it possible to highlight mouse pointer with key-mon –visible_click
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)
SOX can be used to start the audio recording separately while we start recording the terminal.
sudo apt install sox
Many articles and tutorials around recommend these projects that are currently unmaintained, still shipped with popular distros like Ubuntu:
- recordMyDesktop: last release on 2008.
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
- Free up space in Linux (Ubuntu)March 27, 2020
- Switch between languages in Linux with xkb. Write in multiple languages with same keyboard.March 21, 2020
- How to make Ubuntu display emojisFebruary 12, 2020
- Detect and mount USB devices in Linux from consoleJanuary 24, 2019
- How to make screencasts in Ubuntu Linux
- Using i3 window manager in LinuxJanuary 7, 2019
- Setting Up A Fresh Linux ServerAugust 25, 2018
- How To Download A Website With Wget The Right WayJune 30, 2017
- Replicate Installed Package Selections From One Ubuntu System To AnotherApril 24, 2017
- Using Clamav Antivirus In UbuntuJanuary 25, 2017
- How to Type Spanish Characters, Accents and Symbols in LinuxJune 6, 2016
- Solving Google Chrome's gpu-process error message in Ubuntu LinuxJanuary 7, 2019
- Solving Google Chrome's secret service operation error message in Ubuntu LinuxJanuary 7, 2019
- Start Emacs In Ubuntu The Right WayJune 10, 2017
- Add Infolinks Script To An Existing Website From Console With Sed CommandApril 4, 2017
- How to change all files permissions to 644 and directories to 755January 10, 2017
- Shell Redirect Output And Errors To The Null Device In BashDecember 9, 2016
- Prevent Running Of Duplicate Cron JobsDecember 8, 2016
- Delete All Backup Files Recursively In BashNovember 28, 2016
- Bash Script to Find Out If MySQL Is Running Or NotNovember 9, 2016