Record desktop in Linux using ffmpeg

Step 1: Install PulseAudio Volume Control and ffmpeg

Search your distribution’s software repository to install them. On a typical Ubuntu like OS the terminal command would be

$ sudo apt-get install pavucontrol ffmpeg

Step 2: Record

Use following command to record your desktop.

ffmpeg -f alsa -i default -f x11grab -s 1366x768 -r 30 -i :0.0 -sameq filename.avi


x11grab: Record the desktop
s: Size of the recording area (For true HD it would be 1920×1080 i.e 1080p). However, it depends upon your monitor resolution. Anything greater will fail, Use Displays to find the resolution.
r: Frame rate. If you intend to record game play videos, adjust the frame rate until you don’t get choppy output.
-f and -i: These two variable are for audio. If default does not work, use “pulse” instead.

Note: If the recording fails, try to change the format. E.g mpg, mkv etc.

Step 3: Switching between internal audio and microphone

While recording, open PulseAudio Volume Control (pavucontrol) and in the Recording section, switch between microphone and Internal audio (see figure below). Use “Built-in Audio Analog Stereo” for recording from microphone and “Monitor of Built-in Audio Analog Stereo” to record sound playing in your computer. Make sure you are actually recording the desktop to change these options, ffmpeg option does not show up in pavucontrol until you start the recording.


Step 4: Create a script

Create a script, say, so that you don’t have to remember it all the time. Create the bash file in a directory you use to add scripts e.g ~/bin (/home/username/bin) and add it to PATH variable in .bashrc as (export PATH=$PATH:~/bin). Content of that file would be something like this (Adjust resolution and other parameters as you prefer).

# Example output.avi


if [ $STR ]; then
echo "No file name specified, using out.avi"

#FILENAME="$(echo $FILENAME | sed 's/\ /\\ /g')";

echo "Recording into $FILENAME ...";

ffmpeg -f alsa -i default -f x11grab -s 1366x768 -r 30 -i :0.0 -sameq "$FILENAME"

Cheers !!



Filed under Uncategorized

7 responses to “Record desktop in Linux using ffmpeg

  1. Here’s my command, will automatically use your desktop size and the parameters are for YouTube. Adjust “-b:v 16384k” for desired bitrate video quality.

    ffmpeg -f alsa -i hw:0,0 -f x11grab -r 15 -s $(xwininfo -root | grep ‘geometry’ | awk ‘{print $2;}’) -i :0.0 -acodec wmav1 -vcodec flv -b:v 16384k output.avi

  2. Beaudy. Very simple and enough to play with and get yourself in trouble, but, also enough to get you going practically.

    Thank you

  3. cres2657

    Reblogged this on Lost Packets.

  4. Reblogged this on Ace Worldwide Services and commented:
    Just great and ideal for the use!

  5. jayscustomcreations

    Awesome. Thanks!

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s