06 February 2009

Screencasting with mencoder

I didn't made many screencasts, but the most usual complaint I hear is about the lack of a soundtrack, people request a spoken explanation for the actions happening on screen or at least some music. Now way I will include a spoken audio track, but since I know about acceptable music with a clear license, I can do that.

So for a recent screencast I tried to silence the critics by adding a music track, which by consequence forced me to add a "credits" screen, to satisfy the license requirements (CC-BY-SA), resulting in a somewhat complicated editing operation, something deserving to be documented and shared. Keep in mind that my target was to upload the file to YouTube, so a number of compromises were considered acceptable.

Now tot he tools: PiTiVi is crap and I don't say it lightly, not only it lacks the features I needed (and will document in the following paragraphs), but the only thing it seems able to do is crash as soon as I hit the "Redner project" button, so my only option was to use the arcane but efficient Mencoder, cutting some corners, like using DivX as a video codec, mp3 as audio coded and AVI as a container. If someone can come with an alternate recipe, keeping the formats Free, I will use that in the future, if the solution involves a GTK GUI, most likely I exclusively use that...

So back to the screencast. I recorded it with gtk-RecordMyDesktop, even if Istanbul has a better user interface, its recording is worse: it uses an predefined low quality setting, resulting in a bad looking video and high CPU usage during recording. With RecordMyDesktop set at 100% quality level, you get a smooth recording and a very crisp looking video, nice to have for an original.

So the first step is to transcode the image to MPEG4 (DivX) and at the same time reduce the resolution to 800x500, people will not see it at 1680x1050 (my full screen size) on YouTube and the file size is too large anyway (note: no additional parameters for video encoding, since it will be transcoded to Flash at a worse quality anyway):
mencoder screencast.ogv -oac copy -ovc lavc -vf scale=800:500 -o screencast.avi

My video was too long, 18 minutes, much over the 10 minutes limit allowed by YouTube, so my trick was to speed it up (3 times). Being lazy, I just increased the frame rate, didn't care too much about the file size, as I will upload it just one single time:
mencoder screencast.avi -oac copy -ovc copy -speed 3 -o screencast-fast.avi

For the credits screen I prepared a PNG with Inkscape and multiplied it as many times as the number of frames I needed - 10 seconds at 45 fps = 450 copies (10 seconds is a bit too much, and the 45 fps is the results of the lazy speed-up in the previous step):
seq -w 1 450| while read i; do cp frame.png "frame_0$i.png"; done

Then convert all those PNGs in a video with the same codec and frame rate as my screencast:
mencoder "mf://*.png" -ovc lavc -mf fps=45 -o ending.avi

The next step is to merge the two videos and the image is ready:
mencoder -oac copy -ovc copy screencast-fast.avi ending.avi -o screencast-end.avi

I needed properly licensed music, so I used a track from the Denied by Reign album by Severed Fifth, namely War, which has about the same time duration as my video part. In the same step with adding the music, I transcoded it from Ogg Vorbis to mp3 (as required by the AVI container):
mencoder screencast-end.avi -o screencast-final.avi -ovc copy -oac mp3lame -audiofile severedfifth-deniedbyreign-war.ogg

And that is all, upload to YouTube and enjoy.

11 comments:

  1. Richard Querin and I use mencoder almost exclusively to encode our Inkscape screencasts. Hard to beat mencoder's efficiency.

    On the other hand, we also use Blender for personal video projects. Even though you achieved what you wanted with mencoder, perhaps give Blender a college try for your next project. It is really easy to use once you get past the initial shock of the interface.

    Here's a short screencast on Blender video editing that Richard made recently. Expect more to come.

    http://screencasters.heathenx.org/_misc/bve/bve_01.html

    ReplyDelete
  2. I happen to use Kino for all my video editing, the previous comment is intriguing, but blender does not run very well on the i965 chip unfortunately.
    I have edited some screencasts as well as some personal videos and uploaded all to youtube ( here )

    ReplyDelete
  3. malwkgad, I knew Kino works only with the DV format, so do you have to convert from Theora to DV and then back to Theora?

    ReplyDelete
  4. @heathenx: Wow! at the first look the Blender interface looks scarier than the terminal :p

    ReplyDelete
  5. I've used xvidcap with success for a while to generate flv based screencasts.

    ReplyDelete
  6. @len.ro: but xvidcap is a replacement only for the recordmydesktop/istanbul part (and arguably a worse replacement, since it can produce only "non-Free" formats). the real problem is how you edit the video after that.

    ReplyDelete
  7. Nicu, you just gave the perfect recipe for a very useful but missing software from Linux.

    - splitting, cutting, joining video
    - adding texts on frames and in between frames, on a black screen
    - adding effects between videos and frames

    If there is such a program, I'd like a link to it.

    The best I've found so far that's close to this is avidemux, but it only works with avis and I can't add text or effects.

    ReplyDelete
  8. Alexandru, Cinelerra may be an option, but I didn't had much luck with it.

    ReplyDelete
  9. Alexandru and Nicu,

    - splitting, cutting, joining video
    - adding texts on frames and in between frames, on a black screen
    - adding effects between videos and frames

    Blender can do all of that with the aid of Inkscape to handle the title screens. I just put together a 15 video project in Blender over the weekend complete with titles screens between video segments and effects. After Blender exported my video (using FFMpeg) then I used DeVeDe to make DVD's of the whole thing. Blender never stumbled once.

    Go to http://www.totallyblended.com/NEW_INDEX/tutes/tutes.html, scroll down and find the "Video Editing" series. There are 3 videos to watch. You'll be surprised how easy Blender is to use. ;)

    ReplyDelete
  10. @nicu you are right, you cannot edit the flv file. For editing the screencasts I've saved mpeg files and edited them with avidemux2 then re-encoded them to flv using memcoder of course.

    ReplyDelete
  11. Instead of sending you a mail as per your polite request, I opted for posting a comment. Thank you a lot. FFMPEG has a weird bug where input from .ogg cannot be properly "-vcodec copy"'ed so I'm resorting to other options :)

    ReplyDelete