Jump to: navigation, search



Creating screencasts (screencapture)

Several methods for creating screencasts in (K)Ubuntu Linux exist.

FFMPEG with x11grab

Recent versions of FFMPEG include x11grab, a module for screen capture. This method gives the best results for screencaptures and is one of the the most flexible methods, allowing a variety of audio inputs and audiovisual output formats.

Run FFMPEG with x11grab

  • The command for 2 channel audio recording using the ALSA input is:
ffmpeg -f alsa -ac 2 -ab 192k -i pulse -f x11grab -s 1024x768 -r 30 -i :0.0 -acodec pcm_s16le -vcodec libx264 -vpre lossless_ultrafast -threads 0 /home/user/capturedvideo.avi

The order of the options is important (since some options override others). -f alsa indicates the alsa audio input (an alternative is oss). -ac 2 indicates 2 channel recording (use -ac 1 for mono). -ab 192k means 192 kb/sec audio, which may be too high for your needs. (128k is average). -i pulse indicates to use Pulse Audio (assuming you have it set up) for audio input. -i :0.0 means to capture screen 0.0 (the primary screen). -acodec pcm_s16le means to save with lossless 16-bit audio encoding (which gives a large file). You can use another audio format (such as libmp3lame) here if you wish, or re-encode later when you do processing/convert to your final desired format. Also see the FFMPEG x11grab documentation for other options.

You can also capture to a video codec other than libx264 (although without the corresponding quality of H.264/X264). In a command terminal, type ffmpeg -formats E to see which video codecs your version of FFMPEG supports. For example, to create an .avi file with an XVID video codec and an Mp3 audio codec, use the command:

ffmpeg -f alsa -ac 2 -ab 128k -i pulse -f x11grab -s 1024x768 -r 30 -i :0.0 -acodec libmp3lame -vcodec mpeg4 -vtag xvid /home/user/capturedvideo.avi

However, I find the quality to be far superior if the capture is done in H.264/X264 and then converted to the (much smaller and more universal) XVID format in a separate step afterwards.

  • Of course, the command can be used as a Menu item. When creating a Menu item, make sure the "Advanced -> Run in terminal" box is ticked.
  • To stop the recording, enter "CTRL-C" (or "q" in earlier versions) in the terminal window in which FFMPEG/x11grab is running.
  • If you have xwininfo installed (installed already in Debian/(K)Ubuntu), you can replace
-s 1024x768
-s $(xwininfo -root | awk '/geometry/ {print $2}')
in order to automatically capture whatever-sized screen you have. The command would then be:
ffmpeg -f alsa -ac 2 -ab 192k -i pulse -f x11grab -s $(xwininfo -root | awk '/geometry/ {print $2}') -r 30 -i :0.0 -acodec pcm_s16le -vcodec libx264 -vpre lossless_ultrafast -threads 0 /home/user/capturedvideo.avi
  • A benefit of using Pulse Audio is that several inputs can be combined, allowing both microphone input and music input, for example. The relative volumes can be controlled using Pulse Audio Volume Control (sudo apt-get install pavucontrol).
  • If you do not have Pulse Audio installed, you can capture from the primary audio input card by replacing
-i pulse
-i hw:0,0
-i /dev/dsp
  • It is possible to record only part of the screen by specifying an offset from the upper left corner of the screen. Use the option :0.0+10,20 where 10 is an example of a x-offset from the left of the screen and 20 is an example of the Y offset from the top of the screen. Also specify the size of the area to recorded, for example -s 320x240. A complete command might then be
ffmpeg -f alsa -ac 2 -ab 128k -i pulse -f x11grab -s 320x240 -r 30 -i :0.0+10,20 -acodec libmp3lame -vcodec mpeg4 -vtag xvid /home/user/capturedvideo.avi
  • After completing the screencapture, you can then edit and convert it to the desired final format, using FFMPEG (perhaps with the WinFF GUI), mencoder (with or without a front-end such as Avidemux), or a standalone video editor. Some examples of conversion methods are here.


kX11grab is the KDE version of QtX11grab, a frontend for FFMPEG/x11grab screengrabs. It is in alpha stage and does not yet work well.

  • Install kx11grab:
sudo apt-get install kx11grab
  • Start kX11grab:
K menu -> Utilities -> kx11grab

Install the newest version of FFMPEG with x11grab

  • Older repository-supplied versions of FFMPEG did not have X11grab nor X264 support in them. If you have a very old installation, you can install the newest version of FFMPEG and X264 using the instructions from this thread.

Note: The current, updated versions of FFMPEG in Lucid, Maverick, and Natty are all compiled with x11grab and X264 capabilities. On my Lucid machine, X264 version 85 is already installed, and on Natty, version 106 is already installed. The newest version of X264 (as of 8-2011) is version 116.

If you want the most current version of FFMPEG and the H.264 / X264 video codec, however, then compile and install new versions using these instructions (recreated here).

  • Uninstall x264, libx264-dev, and ffmpeg:
sudo apt-get remove ffmpeg x264 libx264-dev
  • Install dependencies needed for retrieving, compiling, and running the new versions (you may need to ensure the Universe and Multiverse repositories are enabled):
sudo apt-get update
sudo apt-get install build-essential checkinstall git libfaac-dev libjack-jackd2-dev
sudo apt-get install libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libsdl1.2-dev libtheora-dev
sudo apt-get install libva-dev libvdpau-dev libvorbis-dev libx11-dev libxfixes-dev libxvidcore-dev texi2html
sudo apt-get install yasm zlib1g-dev
  • Retrieve, compile, and install a new version of the X264 video codec from VideoLAN (makers of VLC). (Note: Ubuntu normally installs x264 in /usr/bin/x264.):
git clone git://
cd x264
./configure --enable-static
sudo checkinstall --pkgname=x264 --pkgversion="3:$(./|awk -F'[" ]' '/POINT/{print $4"+git"$5}')" --backup=no --deldoc=yes --fstrans=no --default
Note: Git uses port 9418 by default. Make sure the Git port is unblocked in your firewall. The last command will build a .deb package named something similar to /home/user/x264/x264_0.116.2074+git2641b9e-1_i386.deb. The installed package can be removed later, if desired, using dpkg -r x264.
  • Retrieve, compile, and install a recent version of FFMPEG. (Note: Ubuntu normally installs FFMPEG in /usr/bin/ffmpeg and related modules in /usr/bin/ffplay, /usr/bin/ffprobe, /usr/bin/ffserver, and /usr/bin/qt-faststart.):
git clone git://
cd ffmpeg
./configure --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-nonfree --enable-postproc --enable-version3 --enable-x11grab
sudo checkinstall --pkgname=ffmpeg --pkgversion="5:$(date +%Y%m%d%H%M)-git" --backup=no --deldoc=yes --fstrans=no --default
hash x264 ffmpeg ffplay ffprobe
Note: Git uses port 9418 by default. Make sure the Git port is unblocked in your firewall. The second-to-last command will build a .deb package named something similar to /home/user/ffmpeg/ffmpeg_201109031233-git-1_i386.deb. The installed package can be removed later, if desired, using dpkg -r ffmpeg.
  • Some programs may expect ffmpeg to be in /usr/bin, so create a symbolic link:
sudo ln -s /home/user/ffmpeg/ffmpeg /usr/bin/ffmpeg

Add a webcam to a screencast

  • To show your webcam in your screencast, install one of three webcam applications:
  • Cheese (sudo apt-get install cheese) is a Gnome-based webcam application with many options and a re-sizable window.
  • Kamoso (sudo apt-get install kamoso) is a KDE-based webcam application.
  • Xawtv (sudo apt-get install xawtv) is a Gtk-based application. Because the Xawtv window can be arranged so that only the webcam image is shown, it is my favorite webcam display for screencasts. (Click on "X" in the window bar -> Advanced -> No Border (ticked) .)

Any of these applications can be used in (K)Ubuntu.

Start the desired application until your webcam is showing. Position the webcam image on your desktop as desired. Now start your screencapture and the webcam window will be included.

Record microphone and speaker output simultaneously

This example assumes Pulse Audio is installed on the system. This was tested on Natty.

  • Make sure PulseAudio Volume Control is installed:
sudo apt-get install pavucontrol
  • Start FFMPEG/x11grab as above:
ffmpeg -f alsa -ac 2 -ab 192k -i pulse -f x11grab -s $(xwininfo -root | awk '/geometry/ {print $2}') -r 30 -i :0.0 -acodec pcm_s16le -vcodec libx264 -vpre lossless_ultrafast -threads 0 /home/user/capturedvideo.avi
  • Start an audio application (such as Audacious, Amarok, Rhythmbox, etc.) so that some audio output is playing through the speakers.
  • Start PulseAudio Volume Control:
Menu -> Multimedia -> PulseAudio Volume Control
  • Select as an input "Monitor of Internal Audio Analog Stereo":
PulseAudio Volume Control -> Input Devices -> Show: All Input Devices
-> Make sure Monitor of Internal Audio Analog Stereo is not muted (click on speaker icon)
  • Make sure your microphone is plugged in.
  • Select as an input "Internal Audio Analog Stereo: Analog Microphone":
PulseAudio Volume Control -> Input Devices -> Show: All Input Devices
-> Make sure "Monitor of Internal Audio Analog Stereo: Port: Analog Microphone " is not muted (click on speaker icon)
  • Make sure the "Internal Audio Analog Stereo" device is selected for the ALSA plug-in [ffmpeg] application:
PulseAudio Volume Control -> Recording -> ALSA plug-in [ffmpeg]: ALSA capture from: Internal Audio Analog Stereo


  • gtk-recordMyDesktop -- a one-step solution. Audio can be captured as well, including through the microphone (whichever inputs are enabled in the mixer/pulse audio system will be captured). Even a virtual machine like VirtualBox can send its audio through the Pulse Audio system, so it can also be captured. The recorded .ogv file can then be converted to a Flash video (.flv) with:
mencoder -ovc lavc -ofps 30 -oac mp3lame -af volnorm=1:0.5 your_file.ogv -o your_file.flv
or to an .avi (for use with Avidemux, for example):
mencoder -ovc lavc -ofps 30 -oac mp3lame -af volnorm=1:0.5 your_file.ogv -o your_file.avi
  • If mencoder is not installed:
sudo apt-get install mencoder

xvidcap with Audacity

Using VNC to capture another computer's screen

Troubleshooting tips

A method that has worked for me in the past is the method described using Avidemux. I use either gtk-recordMyDesktop or xvidcap to capture the video, as above (saving as an .avi). The problem for me is that Avidemux is rather particular about the audio formats it will accept. I have found that it will not accept many mp3 files (depending on the codec originally used to create the mp3 file). However, I have found that if I import any mp3 file into Audacity and then re-export it as an mp3, Audacity will re-encode it with a codec (libmp3lame) that Avidemux likes.

I can therefore combine the .avi video with the .mp3 audio (created by Audacity) using Avidemux.

Screencasts in Windows

Some users will run (K)Ubuntu in a virtual machine (VirtualBox, VMWare, QEMU) in Windows. For those users who wish to record a screencast, there are two good open source screen recording utilities:

  • CamStudio -- works similarly to gtk-recordMyDesktop, with capabilities of converting to Flash videos (.flv and .swf). Records audio and video with options for annotation and other effects.
  • Wink -- essentially a screen capture, it is good for animations with each frame individually constructed. It can output to a video file, including Flash videos.


Exercise: Slideshow with audio track

This may seem a bit cumbersome, but it works for me. If you have a better method please add it! (Note: I now use the FFMPEG with x11grab method at the top of this page. This method below was how I originally did it.)

  • Gwenview is installed by default in Kubuntu. I then install Avidemux, Audacity, gtk-recordMyDesktop, mencoder, ffmpeg, and kubuntu-restricted-extras.
  • Start gtk-recordMyDesktop but do not use the sound recording portion (leave the Sound Quality box unticked). I find that gtk-recordMyDesktop audio recording is choppy and therefore less than desirable for me (even on my dual-core 64-bit system with 3 Gb RAM).
  • Start Gwenview and find the folder with your pics that will be made into a slideshow. Start gtk-recordMyDesktop recording and the start the slideshow (Gwenview -> View - Start Slideshow). Record until all the slides have displayed. Then stop gtk-recordMyDesktop recording. The file will be saved as an .ogv file (such as MyRecordedFile.ogv).
  • Convert the .ogv file to an .avi file:
mencoder -ovc lavc -ofps 30 -oac mp3lame -af volnorm=1:0.5 MyRecordedFile.ogv -o MyRecordedFile.avi
  • Create your soundtrack from mp3's or recorded files using Audacity.
  • If you wish to join several mp3 files into a single mp3, you can concatenate them:
cat File1.mp3 File2.mp3 File3.mp3 > CombinedFile.mp3

Import the mp3 file into Audacity and edit as desired. Export the resulting edited file into a new mp3 file (such as MyAudacitySoundtrackFile.mp3). Even if you make no edits, you should re-export every mp3 using Audacity because Avidemux doesn't always recognize the codecs originally used to create many mp3s (but it always recognizes the mp3s exported by Audacity).

  • Open Avidemux. Open your video file (Avidemux -> File -> Open -> MyRecordedFile.avi).
  • If you wish to trim the file, move the A and B markers to the beginning and end of the desired segment.
  • Add the soundtrack you created with Audacity. (Avidemux -> Audio -> Main Track ... -> Audio Source: External MP3 -> External File: MyAudacitySoundtrackFile.mp3)
  • Save the file with the new soundtrack. (Avidemux -> File -> Save -> Save Video... -> MyNewCombinedFile.avi)

This file can be uploaded directly to YouTub or other sites, or you can convert it into a Flash video:

mencoder -ovc lavc -ofps 30 -oac mp3lame -af volnorm=1:0.5 MyNewCombinedFile.avi -o MyNewCombinedFile.flv

Conversion / Editing

Personal tools