How to make screencasts in Ubuntu Linux
Create videos from recording the screen in Linux
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 tolocalhost
. The environment variableDISPLAY
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]
- Rate control
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
- http://wiki.oz9aec.net/index.php/High_quality_screen_capture_with_Ffmpeg
- More info at X11 man page man X
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
- https://github.com/phw/peek
- https://github.com/rascoro1/recterm
- http://sox.sourceforge.net/
- http://wiki.oz9aec.net/index.php/High_quality_screen_capture_with_Ffmpeg
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 ↩︎
- Find out IP addresses from MACs in a Local Area NetworkMay 10, 2023
- Choose any key as the modifier in i3wm in 6 stepsJanuary 20, 2021
- Adding a swap memory to Linux from command line in 6 stepsApril 2, 2020
- Free up space in Linux (Ubuntu)March 27, 2020
- Switch between languages in Linux. 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
Ubuntu
- How to activate tap to click touchpad's feature in Ubuntu in 4 stepsMarch 4, 2021
- Difference between suspend and hibernate in Ubuntu and how to execute them from command lineApril 12, 2020
- 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
Unix Shell
- Connect to a Bluetooth device from command line in Ubuntu LinuxJune 23, 2020
- 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
Articles
Subcategories
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
·