Screencasting in Linux!
Wednesday February 11, 2009
I’m excited. I love learning stuff, I really do. I just did a 12-minute screencast for work, and I think I’ve finally figured out how to get everything to fit together nicely. I’d never done a screencast before–not on any platform–but being that I needed to showcase some development work that I’ve done for the next release of VMware Workstation/Player, and being that I’m working from home for the time being, I needed to get this all working in Linux, and as I said, I think I’ve finally figured it out, woot!
For starters, I used qt-recordMyDesktop to capture the full-screen (1600×1200 resolution) video. I wanted to use it to also capture the audio portion of the screencast at the same time, but when I tried doing so, the audio was really choppy and out of sync. I mostly blame pulseaudio, but also the fact that I did this all on my puny little laptop, and I think that the system just wasn’t able to keep up with me, recording a nested Xephyr session with 4 fake Xinerama monitors (thanks again for that beauty, Lubos!), at 1600×1200 resolution. So I told qt-RecordMyDesktop to not capture audio and what I ended up with was a beautiful 1600×1200 Ogg/Theora .ogv file. We’ll call it demo-video.ogv.
Next, I recorded my voice, doing a monologue of what was happening in the screencast, using my laptop’s internal mic (not the greatest quality, but I don’t have a real microphone, *sigh*), and audacity (oh, and this is nice… audacity doesn’t work with pulseaudio whatsoever). This I saved in mp3 format. We’ll call it demo-audio.mp3.
The next magical trick, obviously, would be to combine the audio and video files into a single movie file, right? Well, all of the questions/answers that Google found me (even though I searched for “mencoder combine audio video”) were examples using ffmpeg. So I gave it a shot. And I’m sure there must be a way to do it, but for the life of me, I couldn’t get ffmpeg to combine my 80-meg demo-video.ogv file and my 10-meg demo-audio.mp3 file in a high quality and problem-free output file. The closest I think I got was this: “ffmpeg -sameq -i demo-video.ogv -i demo-audio.mp3 demo_full.mp4”, but that combined my 80-meg video and 10-meg audio file into a 350-meg mp4 file. Zoinks, Shaggie!! That’ll never do!
I finally stumbled upon the “-audiofile” parameter to mencoder and there was much rejoicing in Agrabah (not to mention Massachusetts). What I ended up with is this little mencoder incantation that seems to work beautifully. And, the resultant file is only 62 megs (80m + 10m == 62m !?!), so I’m sure there’s some loss of quality in there somewhere, but for the life of me, I can’t see it. Here’s what I used:
mencoder -sws 9 -vf pullup,softskip,scale=1600:1200,harddup,unsharp=l3x3:0.7 -oac faac -faacopts br=128:mpeg=4:object=2:raw -channels 2 -srate 48000 -ovc lavc -lavcopts aglobal=1:vglobal=1:vcodec=mpeg4:acodec=libfaac:abitrate=128:vbitrate=1000 -of lavf demo-video.ogv -audiofile demo-audio.mp3 -o demo_full.mp4
So, there you have it. Screencasting, done 100% in Linux. I wish I could show you the results, because I’m pretty darned please with them, but sadly, I cannot (nor do I have a spot to stick 62 megs of mp4 =;P).
I hope this helps some other poor soul, ’cause I couldn’t find much in the way of tutorials for doing this. I’d be very interested to hear what others think of this, as well as any other suggestions for doing screencasting in Linux. I know Aaron’s been doing something along these lines, and I’d be curious to see how this compares to his method. Also, any improvements to my mencoder line (yeah, I’m sure some stuff in there might be redundant or weird), or finding out what the ffmpeg equivalent of my mencoder line is would be greatly appreciated.
Nice post! But are you really serious about the ‘no place to upload it’ part? Because the internet is full of free good file hosts….
http://www.mediafire.com
http://www.drop.ip
http://www.box.net
and so on, just take your pick, upload and paste link. It’s a no-brainer. Learn to make good use of the internet.
(also there are video hosting sites like youtube and vimeo.com heh)
Or, if you like, I can give you some space on my web server. I have to admit I’m very interested in the result of all that media file manipulation….
You actually reencoded audio from mp3 to aac and video from OGG Theora to mpeg4 (ASP). This is why the file is smaller but you probably lost a lot of quality in this process.
It would be better (easier) if you would encode audio to OGG Vorbis in the first step instead of MP3 and then you could combine both to OGG container via GStreamer (I don’t know if MP3 would work with Vorbis) or you could combine them to Matroska.
For example:
gst-launch filesrc location=audiofile.mp3 ! mux. filesrc location=videofile.ogv ! oggdemux ! mux. matroskamux name=mux ! filesink location=result.mkv
or if you have both as Vorbis and Theora:
gst-launch filesrc location=audiofile.oga ! oggdemux ! mux. filesrc location=videofile.ogv ! oggdemux ! mux. oggmux name=mux ! filesink location=result.ogg
You may want to look at kdenlive (kdenlive.sf.net) for video editing
…or you cuold just simply use Kdenlive for all that stuff…
Just a couple of points. Don’t blame pulseaudio for the loss of sync in recordmydesktop. It’s _always_ been like that, since before pulseaudio was started.
Another video conversion tool you might want to look at is Handbrake (http://handbrake.fr). It’s GPL and has a nice graphical frontend to ffmpeg. One especially neat feature is the ability to have “profiles” to target specific devices (ipod touch for example). Another handy feature is the capability to queue up video conversions.
Worth a look.
I recently made some screencasts here at work, using gtk-recordmydesktop and the sound recorder app in ubuntu 8.10 – like you I found the built-in sound recording of recordmydesktop to be choppy, but running the two apps simultaneously was fine. Weird.
I’d also recommend kdenlive for the editing / transcoding – I’ve spent the last week trying to put together presentations for running on MacBooks and kdenlive has been a godsend for all the transcoding work, especially with the huge variety of output transcodings that Just Work.
the package ogmtools provides a program called ogmmerge. If your working with ogg audio and theora video it will join them all together for you into a single video file.
ogmmerge -o out.ogm audio.ogg vidoe.ogv
Presto!
you can even add other audio tracks ie other languages to your screencasts by specifying more than one audio file.
…Of course thats only good if you want an ogm video file.
You need my patch for Audacity http://cvs.fedoraproject.org/viewvc/rpms/audacity/devel/audacity-1.3.5-portaudio-non-mmap-alsa.patch?revision=1.1&view=markup to get it to work with PulseAudio. (The same patch also applies to the upstream PortAudio v19. It adds support for non-mmap ALSA devices such as PulseAudio’s ALSA plugin.) For Fedora 10, there’s a patched audacity in updates-testing. For Ubuntu 8.10 “Intrepid Ibex”, see: https://launchpad.net/~diwic/+archive/ppa . Mandriva also has a testing package somewhere. For other distros, I don’t know.