Creating Screencasts in Linux

Categories: KDE
Tags: No Tags
Comments: 13 Comments
Published on: June 10, 2012

 

 

Recording screencasts and post-processing them for publishing on sites like YouTube or as HTML5 videos was a tedious and error-prone task for me up until some months ago: Recording software like recordMyDesktop, istanbul or xvidcap didn’t produce good results, if working at all. Video editors like avidemux, cinelerra, kdenlive or kino were lacking important features, had a cumbersome user interface or crashed in the twinkling of an eye.

Fortunately things changed when I discovered that ffmpeg works great for taking raw screencasts and when kdenlive 0.8.2 was released. Kdenlive had always been a promising application: A solid set of features, more than I probably ever need, arranged in a convenient user interface. Yet I was never able to accomplish even the simplest task with it in earlier versions — it almost certainly crashed somewhere in between. This behavior has changed significantly in recent versions – I’ve produced a bunch of videos with it now without a single crash. And from what you can read in the web, this seems to be a common observation. Good work, kdenlive developers!

In the remainder I’ll describe my workflow for producing screencasts for upload to YouTube. It can easily be adjusted for other sites like blip.tv, vimeo or HTML5 videos.

Prerequisites

Please install ffmpeg – any version should be fine and your distribution surely has packages for it. Also install kdenlive, but take care to get version 0.8.2.1 or later. It’s available in Ubuntu 12.04 Precise (universe) or Debian testing for example.

Recording Raw Screencasts

I’ll assume you’re going to record a screencast of a specific application window. Usually you’re able to resize that and it makes much sense to optimize its size for the end presentation. Best results for YouTube are achieved with an aspect ratio of 16:9. Corresponding video sizes are shown in the following table (second column):

Name 16:9 4:3 Bitrate
1080p (Full HD) 1920×1080 1440×1080 8000 kbps
720p (HD) 1280×720 960×720 5000 kbps
480p 854×480 640×480 2500 kbps
360p 640×360 480×360 1000 kbps

Now change the size of the window to record to your favorite size from the table above. One good way to achieve that is to use KWin (right-click on the window title, Advanced, Special Window Settings, Size & Position). You also need to know/change the position of the window. Again, KWin comes in handy:

Remember (or note down) the values and apply the settings. Afterwards it’s time to start recording the screencast.

ffmpeg -f x11grab -show_region 1 -y -r 25 -s 1280x720 -i :0.0+100,200 -vcodec ffv1 screencast.avi

Let’s review all the parameters briefly.

-f x11grab
Enables screen recording.
-show_region 1
Indicates the recording region on the screen. The indicator itself is not recorded.
-y
The video screencast.avi will be overwritten, if it exists.
-r 25
The video is recorded with a framerate of 25 (frames per second).
-s 1280x720
The size of the video. It should correspond to the size you set via kwin above, and ideally also corresponds to one of the YouTube formats in the table above.
-i :0.0+100,200
100,200 is the x,y position of the top left corner of the region to record. This should correspond to the position you set via kwin above. :0.0 tells ffmpeg which display and which screen to record. Normally you can leave it as :0.0.
-vcodec ffv1
A losless, ffmpeg-builtin video codec is used.

Change the parameters as needed (you probably have to change 1280×720 and 100,200 and can leave the rest as is) and start ffmpeg. It will start recording the screencast immediately. To stop recording, hit Ctrl+C in the shell where ffmpeg is running. The raw screencast will be called screencast.avi and can be viewed with e.g. mplayer.

Possibly you have to repeat this step several times to find optimal settings. If the video stutters, record to a faster drive, use a smaller video size or lower the framerate. Don’t use a framerate lower than 25 though. If the video stutters because your hard drive is too slow and you don’t have a faster one, you can also try to use a different codec than ffv1. Try

ffmpeg -f x11grab -show_region 1 -y -r 25 -s 1280x720 -i :0.0+100,200 -b 8000000 screencast.webm

Post-processing for Publishing

A huge topic on its own, so I don’t really want to start writing much here, but just leave a couple of recommendations:

  • If you recorded to .webm above, you can upload the video directly to YouTube
  • If you recorded to .avi with ffv1 codec or if you want to add some background music, effects, title clip etc, I strongly recommend giving kdenlive a try.
  • If you recorded to .avi with ffv1 codec and don’t want to use kdenlive for some reason, you can convert it using ffmpeg on the command line:
    ffmpeg -i screencast.avi -b 8000000 screencast.webm

    The value for -b should correspond to the bitrate in the table above, here 8000000 = 8000 kbps. Now upload screencast.webm.

  • If you’re looking for some background music, jamendo.com is worth a try.

Wondering why this appears on planet KDE? The answer is simple: I want to see more screencasts here! (GSoC/SoK students, I’m looking at you!) :-)

13 Comments
  1. Wonko says:

    Thanks for this nice piece of information!

  2. Richard says:

    Very nice information, thanks!

  3. erik says:

    useful tip, but, you have to admit that it’s just crazy, for us geek it’s simple, but this limit most of the common people… it doesn’t exist a simple (and working) software for doing screencast under linux :(

  4. Markus says:

    Very easy and useful, thanks. But what about recording audio at the same time (preferably into the .avi)?

  5. Nick says:

    also, if you don’t care about UI animation effects, and the point of the screencast is educational, then i suggest trying wink, which makes small-sized flash videos, or its open source equivalent skreener: http://code.google.com/p/skreener/ qt-based, and it generates SVG.

  6. Aaron Seigo says:

    aha, another option for screecap: ffmpeg! thanks for informative posting…

    i will echo the comments of others and wish there was an easier way of doing this. i think that’s one of the appeals of recordMyDesktop: the UI makes it pretty simple to get started.

    and yet even it really misses a lot of things.

    i dream of a kwin plugin that uses ffmpeg and does the window resizing and all that jazz, using ffmpeg in the background just as you did here but with a nice, simple UI. that would be so fantastic! there used to be a kwin screen recording plugin but it bitrotted and the library it used fell out of devel IIRC.

    anyways .. i might just try ffmpeg for my next screencast.

    and yes, kdenlive has matured very, very nicely in the last year! kudos to that team.

  7. Eugenio says:

    Sorry for the offtopic, but, is that marble showing flightgear planes movement? Where could I get that? I couldn’t find anything about that. Thanks.

  8. My ffmpeg command:

    sleep 6s && ffmpeg -ac 2 -f x11grab -r 30 -s 1100×800 -i :0.0+4,80 -acodec pcm_s16le -vcodec libx264 -threads 0 screencast_2.mkv

  9. regeya says:

    @erik:

    Yes, such a piece of software exists.

    http://recordmydesktop.sourceforge.net/about.php

    It is likely available on your distribution of choice.

  10. CTown says:

    Thanks for this tip!

  11. erik says:

    @regeya I know it, but it’s not maintained anymore (last version from 2008!) and it has few bugs (most of the times the output is not fluid)… also for the UX it could be much better (try to select a specific part of the screen, you’ll need to do it more times before do it right)

  12. Dennis Nienhüser says:

    @Markus: You can record e.g. the microphone at the same using something like “-f alsa -ac 2 -i pulse -acodec pcm_s16le” as additional options in the ffmpeg call. See also Manuels comment.

    @Eugenio: Yes, it’s flightgear. Marble has support for it now (i.e. Marble can show the GPS position of a flightgear plane). It will be part of the Marble 1.4 release (KDE 4.9), see http://edu.kde.org/marble/current_1.4.php (the announcement is unfinished yet).

    I agree with everyone that a nice GUI would be lovely. There’s a nice similar feature builtin qmlviewer (IIRC it uses ffmpeg behind the scenes), but it’s not general purpose.

  13. Eugenio says:

    Thanks Dennis, really nice update of the blog’s theme by the way.

Comments are closed.

Welcome , today is Friday, October 24, 2014