Recording screencasts on Linux
• 263 words • 2 min • updated
⚠️ This post is over one year old. It may no longer be up to date or relevant. Opinions may have changed.
One-line self-documenting functions, put this into your shell init file:
shell
# ffmpeg x11 screencasting
# it will just record video: no audio
# dimensions of your screen are automatically calculated
_ffmpeg-screencast() {
ffmpeg -f x11grab -s $(xdpyinfo | awk '/dimensions:/ {print $2}') -r 25 -i :0.0 -qscale 0 $HOME/ffmpeg-out-$(date '+%Y-%m-%d-%H-%M-%S').mkv
}
# ffmpeg x11 screencasting with audio
# it supersedes the previous function
# source of the audio is determined with `pavucontrol`: open it then go to the "recording" tab. You can select between the microphone or your computer as audio sources
_ffmpeg-screencast-audio() {
ffmpeg -f alsa -i pulse -acodec pcm_s16le -f x11grab -s $(xdpyinfo | awk '/dimensions:/ {print $2}') -r 25 -i :0.0 -qscale 0 $HOME/ffmpeg-out-$(date '+%Y-%m-%d-%H-%M-%S').mkv
}Observations #
- If you want to get this automatically, you might be interested in my dotfiles repo. In particular, inspect the .alias file, where those functions are located (at least at the time of this post; things change).
- Audio recording works best with Pulse Audio (citation needed). I haven’t tested with alsa only.
- Pavucontrol is just a fancy interface for configuring pulseaudio, but there are others.
- Tweak those parameters…ffmpeg is a really powerful tool.
- I tested this on the i3 window manager, and it works beautifully. I tested some GUI screencasting programs on it before and the results were poor.
- Source of this script: a merge of several ones on the web.
Oh yes, and you can stop the screen capturing with the ‘q’ key or with a classical Control-C.
Edit: thanks Victor for a small improvement with awk in the above
functions.