Linux screen recorder, screencasting with FFmpeg

FFmpeg is a quite handy app to quickly record the desktop or create a screencast in Linux, immensely useful to create tutorial videos.

I’ve never found the recordmydesktop app of any use, serious performance issue, screen tearing and lots of gtk related dependencies for the GUI version, gtk-recordmydesktop. While VLC could record screen in Linux, but it over kills the purpose, little screen tearing issue too.

With FFmpeg, you could customize almost every parameter to record your screen. It’s capable of encoding the captured video on the fly to a wide range of formats, quite efficiently.


Install FFmpeg

FFmpeg is a quite mature software, already available in the software repository of almost every UNIX like distros. If you want compile the latest from source code, get them from here.

  • In Debian, Ubuntu, Linux Mint or any Debian derivative, install it with apt-get
      sudo apt-get install ffmpeg mkvtoolnix 
  • In any Arch Linux based distro, install it with pacman
     sudo pacman -Syu && sudo pacman -S ffmpeg mkvtoolnix-cli 


Screen recording with FFmpeg

You may want to record the desktop only, no audio or record the desktop with audio and webcam. Lets have a quick look in some differnet FFmpeg options

  1. -f  , used to set audio/video format
  2. -s , size of the frame, Width x Height
  3. -r , video frame rate, in Hz
  4. -i , input device
  5. -vcodec  , video encoding codec
  6. -acoddec , audio encoding codec
  7. -threads , no. of threads in the process
  8. -ac , no. of audio channel
  9. -vpre , video preset
  10. -codecs , list all available codecs

Record desktop only

 ffmpeg -f x11grab  -s 1366x768 -i :0.0 -r 25 -vcodec libx264  output.mkv 

This will start recodding the desktop, output video will be in mkv format and encoded with H.264 codec. In my case, encoding the video with vp8 or vp9 (libvpx) video codec results very high CPU use and some frame drops.

To find display resolution , you could use xrandr , and embed this command in the final script

 xrandr -q --current | grep '*' | awk '{print$1}' 

Record desktop with sound

For recording with sound, first you have to find proper sound monitoring interface, I’m using pulseaudio for this purpose.

List available sound sources

 pactl list sources short 

You should notice an audio output ending with .monitor. In my case it’s alsa_output.pci-0000_00_1b.0.analog-stereo.monitor , I’m using a little shell script for recording the desktop

# FFmppeg Linux screen recorder
REC_iface=$(pactl list sources short | awk '{print$2}' | grep 'monitor')
SCREEN_res=$(xrandr -q --current | grep '*' | awk '{print$1}')

ffmpeg -f pulse -i $REC_iface -ac 2 -acodec vorbis 
-f x11grab -r 25 -s $SCREEN_res -i :0.0 -vcodec libx264 output.mkv

Record cord desktop with sound and webcam

First use ffplay to display the webcam, then start recording the desktop with the script above.

 ffplay -f video4linux2 -i /dev/video0 -video_size 320x240 

You may want to hide the ffplay window title bar to make it more clear in appearance.


Vokoscreen, FFmpeg based GUI screen recorder for Linux

Vokoscreen is for those who want an easy to use GUI screen recorder without compromising performance and usability, I could not find  single glitch in this software.linux screen recorder vokoscreen

  • For Debian or any Debian based distro like Ubuntu, Kali Linux, install it with apt-get
     sudo apt-get install vokoscreen 
  • Vokoscrreen  is available in AUR for any Arch Linux based distro, install it with
     sudo yaourt -S vokoscreen 

Using it very simple, just few clicks to create an awesome screencast. Vokoscreen is capable of recording full screen, a window or a select area with sound and webcam.


No doubt FFmpeg is a great tool for recording the desktop, also very useful to convert audio/video to different formats or serve the recorded video over network in realtime with FFserver.

Am I missing something important in this tutorial ? What could be a better alternative ? Just drop a comment, I’d would like to hear from you. If you find this tutorial useful, please feel free to share it.

Leave a Reply

Your email address will not be published. Required fields are marked *