When it comes to screencasting (recording video of your desktop), most people will think of a desktop software with proper user interface. For Linux, we have covered several tools such as Kazam and Screentoaster. What many people do not know is that you can screencast from the command line as well, via FFMPEG. It’s a simple (and very long) configurable command that lets you record video of your desktop.
Installing FFMPEG
FFMPEG are available in most distro’s repositories. Install it with the command below:
Ubuntu
sudo apt-get install ffmpeg
Fedora
sudo yum install ffmpeg
OpenSUSE
sudo zypper install ffmpeg
Arch Linux
sudo pacman -S ffmpeg
Can’t find it in your distributions’ repositories? You may need to download it directly from ffmpeg.org and install it that way.
Customizing the command
Before screencasting can happen, the command needs to be customized to suit your needs. The command below has no specified resolution, will screencast at 30 FPS and outputs the file in the .MKV format.
ffmpeg -f alsa -ac 2 -i pulse -f x11grab -r 30 -s YxZ -i :0.0 -acodec pcm_s16le -vcodec libx264 -preset ultrafast -crf 0 -threads 0 output.mkv
Find your screen’s native resolution and replace the YxZ
with it (e.g: 1920×1080). Not happy with only 30 frames per second? Change -r 30
to your desired FPS.
Screencasting
Screencasting is as simple as pasting the command above (one you’ve modified it to suit you) into a terminal. While the command is running, you’ll be able to know exactly what FFMPEG is doing. You’ll notice something similar to the image below.
That’s basically it. With that long command, you’re screencasting. Want to stop the capture? Press the “q” key or close the terminal window entirely. It’ll print out information about the recording that just finished. This information is great as it can tell you everything that happened during the process.
video:3245kB audio:6451kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.933424% [libx264 @ 0xc35d40] frame I:4 Avg QP: 0.00 size:311776 [libx264 @ 0xc35d40] frame P:985 Avg QP: 0.00 size: 2107 [libx264 @ 0xc35d40] mb I I16..4: 100.0% 0.0% 0.0% [libx264 @ 0xc35d40] mb P I16..4: 30.5% 0.0% 0.0% P16..4: 0.0% 0.0% 0.0% 0.0% 0.0% skip:69.5% [libx264 @ 0xc35d40] coded y,u,v intra: 0.6% 0.1% 0.1% inter: 0.0% 0.0% 0.0% [libx264 @ 0xc35d40] i16 v,h,dc,p: 99% 1% 0% 0% [libx264 @ 0xc35d40] kb/s:806.15
Switching FFMPEG audio inputs
Like all applications, FFMPEG taps into Pulse Audio. This means it can be manipulated. By default, all applications recording take sound input via the default sound device. If your computer has a microphone (or one plugged in), FFMPEG will automatically record sound from it and add it to your screencast. If this is something you don’t want, you can change it.
Install Pulse Audio Volume Control. It’s a very popular tool and thus is in most popular distro repositories. In Ubuntu (or Ubuntu-based distros), you can install it with the following command:
sudo apt-get install pavucontrol
For other distro, you just have to search for “pavucontrol” in your package manage and install it. Once installed, start an FFMPEG screencast and open “Pulse Audio Volume Control.” Inside the tool, click on the recording tab.
In the recording tab, click the Built-in Audio Analog Stereo button. It’ll bring up a selection menu.
In the menu, select Monitor of Built-in Audio Analog Stereo. This will make FFMPEG record your system sound instead of your computer’s microphone. This trick is great if you’re looking to record gameplay or anything that requires audio.
Conclusion
FFMPEG is an amazing tool that can do many, many things. Screencasting is just one of its abilities. Few alternatives to it can even capture high-quality footage while offering great performance. The command line is awesome because with it you can be as precise as you want. You can specify what you want to accomplish and see it appear before your eyes.
Derrik Diener is a freelance technology blogger.
Subscribe to our newsletter!
Our latest tutorials delivered straight to your inbox
Sign up for all newsletters.
By signing up, you agree to our Privacy Policy and European users agree to the data transfer policy. We will not share your data and you can unsubscribe at any time. Subscribe