[FFmpeg-devel] [PATCHv2] Add Win32 GDI-based screen grabbing

Calvin Walton calvin.walton at kepstin.ca
Mon Dec 2 18:08:35 CET 2013

On Mon, 2013-12-02 at 17:36 +0100, Christophe Gisquet wrote:
> Hi,
> 2013/12/2 Calvin Walton <calvin.walton at kepstin.ca>:
> > +    if (!strncmp(filename, "title=", 6)) {
> > +        name = filename + 6;
> > +        hwnd = FindWindow(NULL, name);
> > +        if (!hwnd) {
> > +            av_log(s1, AV_LOG_ERROR,
> > +                   "Can't find window '%s', aborting.\n", name);
> > +            ret = AVERROR(EIO);
> > +            goto error;
> > +        }
> You probably weren't affected for some reason, but I remember having
> issues with the window thumbnails from the taskbar being captured
> instead of the actual window. I don't remember how I solved this
> (checking window size or class maybe?)

I'll admit that I didn't give this bit particularly heavy testing; I'm
mostly interested in the full-desktop and region capture modes.

> Also, this is awfully slow if I remember correctly. I don't know what
> the expected method would be nowadays (ie not a 15yo one).

Yes, I found on my Windows 8 laptop that I could only manage around
5-6fps capture speed. Acceptable for what I want to do, but an
implementation using newer APIs would probably be better.

The current "state of the art" appears to be using DirectX; either
grabbing the screen back- or front-buffer or redirecting rendering to an
off-screen buffer. This obviously only captures desktop apps on Windows
Vista or newer when running in composited mode (DWM). I didn't go that
way because I was mostly interested in getting something (anything)
working, and adapting this older code was the fastest way forwards.

Curiously enough, the GDI capture actually performs better in Wine than
it does on my real Windows system.

Calvin Walton <calvin.walton at kepstin.ca>

More information about the ffmpeg-devel mailing list