» Create your own screencast

Recently I've seen a lot of screencasts in the Planet Ubuntu RSS feed. A screencast is an embeded flash video of your desktop, often used in tutorials instead of screenshots. I wondered if I could make these online flash videos myself; turns out, it's pretty easy! So in this article I will cover how to install the video capturing tool, how to use it, how to convert the video to a flash video (flv) file, and finally how to embed a flash player in your site just like YouTube. Create your own screencasts in 5 easy steps!

About this article

In this article I'm going to teach you how to create screencasts on Ubuntu Feisty, this may or may not work on other systems, I just haven't been able to test it. So no warranties, everything is on your own risk. That also goes for the script I provide. Some basic knowledge about system administration and webdeveloping is required.

Step 1: Install recordMyDesktop

There are other tools like Wink, but this one is nice and simple. How to install? Easy, just open a terminal and type:

aptitude -y update
aptitude -y install gtk-recordmydesktop

Done! Now to run recordMyDesktop click on: Applications -> Sound & Video -> gtk-recordMyDesktop.

Step 2: Record

You can do it like this:

Get the Flash Player to see this player.

gtk-recordMyDesktop will also install a little icon in your system tray. Click the icon once to easily start and stop recording.

Step 3: Convert to FLV

For this we need a recent version the FFmpeg tool. The right version does not come standard with Ubuntu Feisty, so I created a script to install the newest FFmpeg version. Don't worry, this won't hurt much! To install & run that script, just paste the following in a terminal:

wget -O- "http://kevin.vanzonneveld.net/download/movie2flv.bash/" > ./movie2flv.bash
chmod a+x ./movie2flv.bash
./movie2flv.bash

The first time the script runs it installs FFmpeg in your home directory like: /home/kevin/ffmpeg, to avoid conflicts with older FFmpeg versions that apt might have installed on your system.

The second time it directly converts your new .ogg recording to a valid .flv file, like this:

./movie2flv.bash record.ogg

Get the Flash Player to see this player.

And then 2 new files are generated. One .png (a single frame from the video for thumbnailing purposes) and one .flv, that you can later embed in your website, just like I did here.

Step 4: Acquiring a good flash player

I've found an awesome FLV player by Jeroen Wijering that's got many advantages:

  • easy to setup
  • easy to customize
  • free (for non commercial use, otherwise $15)
  • plugins available for almost every CMS (WordPress, Drupal, etc)

So let's just download the player, unzip it, and upload it to your site at /jw_flv_player

Step 5: Integrating the player

I want to show you 4 different ways to embed this player with your video into your site just pick one that you like:

Method 1: Just use plain HTML (rookie)

Like this:

<p id="player1"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</p>
<script type="text/javascript">
    var s1 = new SWFObject("/jw_flv_player/flvplayer.swf","single","300","170","7");
    s1.addParam("allowfullscreen","true");
    s1.addVariable("file","/media/video.flv");
    s1.addVariable("image","/media/video.png");
    s1.write("player1");
</script>

Or Method 2: CMS plugin (difficulty depends)

Support can be found via the FLV player website

Or Method 3: Flexible PHP function (expert)

In PHP this could look something like this:

function showFlvPlayer($png_preview,$options=false){
    // init
    global $blog_cfg;
    if(!isset($blog_cfg)) $blog_cfg=array();
    if(!$options) $options=array();
    if(!isset($options["width"])) $options["width"] = ceil(320*1.5);
    if(!isset($options["height"])) $options["height"] = ceil(240*1.5);
 
    if(!isset($blog_cfg["flv_player_cnt"])){
        $blog_cfg["flv_player_cnt"] = 0;
    } else{
        $blog_cfg["flv_player_cnt"]++;
    }
 
    $buf = "";
    $buf .= "<div
        class=\"flv_video\"
        style=\"height:".$options["height"]."px;width:".$options["width"]."px;\"
        id=\"player".$blog_cfg["flv_player_cnt"]."\"";
    $buf .= ">";
        $buf .= "<a href=\"http://www.macromedia.com/go/getflashplayer\">Get the Flash Player</a> to see this player.";
    $buf .= "</div>\n";
    $buf .= "<script type=\"text/javascript\">\n";
        $buf .= "var s".$blog_cfg["flv_player_cnt"]." = new SWFObject(\"/jw_flv_player/flvplayer.swf\",\"single\",\"".$options["width"]."\",\"".$options["height"]."\",\"7\");\n";
        $buf .= "s".$blog_cfg["flv_player_cnt"].".addParam(\"allowfullscreen\",\"true\");\n";
        $buf .= "s".$blog_cfg["flv_player_cnt"].".addVariable(\"file\",\"".str_replace(".png",".flv",$png_preview)."\");\n";
        $buf .= "s".$blog_cfg["flv_player_cnt"].".addVariable(\"image\",\"".str_replace(".png",".png",$png_preview)."\");\n";
        $buf .= "s".$blog_cfg["flv_player_cnt"].".addVariable(\"height\",\"".$options["height"]."\");\n";
        $buf .= "s".$blog_cfg["flv_player_cnt"].".addVariable(\"width\",\"".$options["width"]."\");\n";
        $buf .= "s".$blog_cfg["flv_player_cnt"].".addVariable(\"overstretch\",\"true\");\n";
        $buf .= "s".$blog_cfg["flv_player_cnt"].".write(\"player".$blog_cfg["flv_player_cnt"]."\");\n";
    $buf .= "</script>\n";
 
    return $buf;
}

In this case you can upload your video.flv and video.png to let's say /media, and then call the function like this:

// customize using an $options array, this can be easily expanded
$options = array();
$options["width"] = 320;
$options["height"] = 200;
// show the player
echo showFlvPlayer("/media/video.png",$options){

Or Method 4: Replace images with FLV players on the FLY (guru)

Or, if you're really in for a challenge, you could just add the png images as <IMG> tag with the class: flv_video, and write a regex that automatically replaces all of those images with FLV players like this!

// don't waste resources if "flv_video" cannot be found:
if(substr_count($article,"flv_video")){
    $article = preg_replace_callback(
        '/<img(.+?)src=\"(.+?)\"(.+?)class=\"flv_video\"(.+?)\/>/is',
        create_function(
            '$matches',
            'return showFlvPlayer($matches[2]);'
        ),
        $article
    );
}
echo $article;

This method relies on the function in method 3. Because the showFlvPlayer function reuses the "flv_video" class, you can modify the look and feel with CSS like this:

div.flv_video{
margin: 10px auto;
width: 320px;
height: 240px;
}

Step 6:

There is no step 6, You're in business! :)


Like this article?

   Then Digg it!
Or use another bookmark button below to show your support &
help me spread the word.


tags: ubuntu, video, php, blog, youtube, flash, flv, ffmpeg, screencast
category: How to - Desktop
read: 18,461 times

Add comment

» Currently away on vacation. I can reply your message the 24th of July 2008. Please post anyway and check back then. Thank you!

for syntax highlighting

[CODE="Javascript"]
your_code_here();
[/CODE]

Replace "Javascript"
with "php", "text", etc.
code (to make sure you are not a spammer)

Comments

#11. Garry on 08 April 2008

Garrywhat about sounds?
Write me on http://pipes.yahoo.com/pipes/pipe.info?_id=b4e6a52026ee011f79bf00e012be548a

#10. Ben on 29 March 2008

BenCool. Thanks for a greatr lesson i used this technique on my site http://cheap-mp3.us

#9. Kevin on 20 November 2007

Kevin@Issue: Very cool dude, seems like you guys had a cool night by the fire in that house. Looks great. And with the windmills and all, I can really see the resemblance. Thanks, wasn't boring at all ;)

#8. Issue on 19 November 2007

IssueThanks a lot, the first time I saw this wallpaper was in a lost project folder into the fedora's ftp but you know well that without a keyword is really difficult to search an image so I forgot it until I saw it again in your post, let me share with you why I'm so interested, it remembers me a real location, a lonely and abandoned house on the top of the extremely windy hills near Pitou (small village at the south of France on the Mediterranean coast) where I stayed during a crazy night, of course the wallpaper is just the naïve vision of that
Here the file containing the pictures I was talking about if you are curious too

http://brainstormingproject.free.fr/RealSeasonsAutumn.tar.gz

... [more] thanks again and forgive my annoying story

#7. Kevin on 14 November 2007

Kevin@Issue: No problem, I really like it as well. I found it at deviantART at http://-kol.deviantart.com/ But that link seems to be dead right now. The wallpaper is called: Seasons - Autumn, and is available in all kinds of resolutions and seasons if you search with Google.

Here's a link I just found with some versions that still works: http://www.blogwaw.com/2007/02/seasons-autumn/

#6. Issue on 14 November 2007

Issuei m really sorry for this stupid question, but where have you found your video\\\'s wallpaper?

#5. Hone on 24 October 2007

HoneI added some instructions if you can\'t get mp3 codex working.

You basically have to reinstall from the svn version and enable mp3 support.

You also have to have lame and lame development library installed.
... [more]
http://dev.honewatson.com/easy-ubuntu-screencasting-feisty-gutsy-gibbon-usb-headset/

#4. wgw on 20 October 2007

wgwMy installed ffmpeg has the mp3 codex, but the svn version does not. So the tweak for sound does not seem to work. I'm sure it is a small matter to tell ffmpeg where the codex is, but I have not found it!

As well, I notice that the image here is unreadable. Could be a question of compression.

#3. TyphoidHippo on 13 October 2007

TyphoidHippoSweeeeeeeeeeeet!!

Great tutorial!

#2. Kevin on 12 September 2007

Kevin@ mike: Good question. recordMyDesktop can record the sound of your audio device, so it's stored in the .ogg file.
But ffmpeg needs other arguments to include the sound in the .flv file.

So edit my movie2flv.bash file, and change:
'-an'
... [more]
in the function ffm_Convert2FLV(), to:
'-acodec mp3 -ar 22050 -ab 64'

without the quotes.

#1. mike on 07 September 2007

mikewhat about audio?