PDA

View Full Version : Qt Screencast



jgrauman
13th June 2009, 21:55
Hello,

I was wondering if anyone has any ideas of how to record and playback a screencast from within Qt. At this point sound is *not* a must. I would like it to be a Qt only solution, and thus cross-platform. I should mention I do not need it to record other programs except Qt ones. In other words, I would like to add a module to my program that records and plays screencasts of that program and not other programs. Thanks!

Josh

auryce74
14th June 2009, 00:16
If you want to produce an actual video (avi / mpeg / flash / etc.), I don't think you can have a Qt only solution, because Qt doesn't have any video encoding capabilities (at least none that I'm aware of). Phonon (http://doc.qtsoftware.com/4.5/phonon-overview.html) is part of Qt, but it is only for playback of multimedia content.

Independent open source cross-platform tools and libraries for video encoding do exist however.

Qt on it's own can help you collect the image data itself though: you could set up a QTimer that periodically grabs a screenshot using QPixmap::grabWindow or QPixmap::grabWidget.

To then get a video from this image sequence, you might:

Save the images to png using QPixmap::save, and then call an external tool using QProcess to to the transcoding. Mencoder or ffmpeg might be good choices, see for example:
http://electron.mit.edu/~gsteele/ffmpeg/
http://personal.cscs.ch/~mvalle/mencoder/mencoder.html
http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-enc-images.html



Alternatively, use an existing encoder library in your program, and use it's API to initiate the transcoding yourself, ideally "on-the-fly" while grabbing image data from the screen. Some possible libraries are:

libavcodec (http://de.wikipedia.org/wiki/Libavcodec) (ffmpeg, mencoder, vlc and other progs also use this library). Documentation for how to use it seems scarce, however; maybe have a look at:

http://www.ffmpeg.org/general.html#SEC25
http://cekirdek.pardus.org.tr/~ismail/ffmpeg-docs/output-example_8c-source.html

x264 (http://www.videolan.org/developers/x264.html) (used in vlc). Even less documentation unfortunetaly. Look at source code, and also read:

http://mailman.videolan.org/pipermail/x264-devel/2009-February/005632.html

GStreamer (http://en.wikipedia.org/wiki/GStreamer)
(other people on this forum might know other / better libraries...)



Once you have a proper video file, you can use Phonon (http://doc.qtsoftware.com/4.5/phonon-overview.html) for playback in your Qt application.

If the whole video encoding part seems too much of a hassle, and all you want is to replay the screencast within you Qt app, then maybe you can get away with just storing the image sequence as png's or similar (as mentioned under the first bullet point above), and then at a later time "replay" them by implementing your own primitive image sequence player (e.g., reimplement QWidget::paintEvent to draw the current image, with a QTimer to consecutively mark the next image as current, and some kind of framework running in the background to continuously load the next few pictures into memory while releasing old memory).
However, note that this is just an idea - I don't know if you will achieve good playback performance with this approach, and at least the space usage on disk will be really large (for longer screencasts).
It would be 100% Qt though... ;-)

I hope I could be of some help

auryce74