Commit 08909fb5 authored by Calvin Walton's avatar Calvin Walton Committed by Michael Niedermayer

Add Win32 GDI-based screen grabbing

Based on original code by Christophe Gisquet in 2010, updated to work
with current ffmpeg APIs.

Supports grabbing a single window or an area of the screen, including
support for multiple monitors (Windows does funky stuff with negative
coordinates here).

I've moved most of the configuration to AVOptions; the input file name
is now only the string "desktop", or "title=<windowname>" to select a
single window. The AVOptions are the same as x11grab where possible.

Code has been added to support a "show_region" mode, like x11grab, which
will draw a rectangle on the screen around the area being captured.

Instead of duplicating code for paletted image handling, I make use of
the GDI API's ability to output DIB (BMP) images, which can be run
through ffmpeg's existing BMP decoder.
Signed-off-by: 's avatarCalvin Walton <calvin.walton@kepstin.ca>
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent f359bac2
...@@ -14,6 +14,7 @@ version <next>: ...@@ -14,6 +14,7 @@ version <next>:
- QTKit input device - QTKit input device
- improvments to OpenEXR image decoder - improvments to OpenEXR image decoder
- support decoding 16-bit RLE SGI images - support decoding 16-bit RLE SGI images
- GDI screen grabbing for Windows
version 2.2: version 2.2:
......
...@@ -2349,6 +2349,9 @@ dv1394_indev_deps="dv1394" ...@@ -2349,6 +2349,9 @@ dv1394_indev_deps="dv1394"
dv1394_indev_select="dv_demuxer" dv1394_indev_select="dv_demuxer"
fbdev_indev_deps="linux_fb_h" fbdev_indev_deps="linux_fb_h"
fbdev_outdev_deps="linux_fb_h" fbdev_outdev_deps="linux_fb_h"
gdigrab_indev_deps="CreateDIBSection"
gdigrab_indev_extralibs="-lgdi32"
gdigrab_indev_select="bmp_decoder"
iec61883_indev_deps="libiec61883" iec61883_indev_deps="libiec61883"
jack_indev_deps="jack_jack_h sem_timedwait" jack_indev_deps="jack_jack_h sem_timedwait"
lavfi_indev_deps="avfilter" lavfi_indev_deps="avfilter"
...@@ -4741,6 +4744,8 @@ require Xext X11/extensions/XShm.h XShmCreateImage -lXext && ...@@ -4741,6 +4744,8 @@ require Xext X11/extensions/XShm.h XShmCreateImage -lXext &&
require Xfixes X11/extensions/Xfixes.h XFixesGetCursorImage -lXfixes && require Xfixes X11/extensions/Xfixes.h XFixesGetCursorImage -lXfixes &&
{ enabled xlib || die "ERROR: Xlib not found"; } { enabled xlib || die "ERROR: Xlib not found"; }
check_func_headers "windows.h" CreateDIBSection "$gdigrab_indev_extralibs"
enabled vaapi && enabled vaapi &&
check_lib va/va.h vaInitialize -lva || check_lib va/va.h vaInitialize -lva ||
disable vaapi disable vaapi
......
...@@ -1088,6 +1088,7 @@ performance on systems without hardware floating point support). ...@@ -1088,6 +1088,7 @@ performance on systems without hardware floating point support).
@item Video4Linux2 @tab X @tab X @item Video4Linux2 @tab X @tab X
@item VfW capture @tab X @tab @item VfW capture @tab X @tab
@item X11 grabbing @tab X @tab @item X11 grabbing @tab X @tab
@item Win32 grabbing @tab X @tab
@end multitable @end multitable
@code{X} means that input/output is supported. @code{X} means that input/output is supported.
......
...@@ -192,6 +192,81 @@ ffmpeg -f fbdev -frames:v 1 -r 1 -i /dev/fb0 screenshot.jpeg ...@@ -192,6 +192,81 @@ ffmpeg -f fbdev -frames:v 1 -r 1 -i /dev/fb0 screenshot.jpeg
See also @url{http://linux-fbdev.sourceforge.net/}, and fbset(1). See also @url{http://linux-fbdev.sourceforge.net/}, and fbset(1).
@section gdigrab
Win32 GDI-based screen capture device.
This device allows you to capture a region of the display on Windows.
There are two options for the input filename:
@example
desktop
@end example
or
@example
title=@var{window_title}
@end example
The first option will capture the entire desktop, or a fixed region of the
desktop. The second option will instead capture the contents of a single
window, regardless of its position on the screen.
For example, to grab the entire desktop using @command{ffmpeg}:
@example
ffmpeg -f gdigrab -framerate 6 -i desktop out.mpg
@end example
Grab a 640x480 region at position @code{10,20}:
@example
ffmpeg -f gdigrab -framerate 6 -offset_x 10 -offset_y 20 -video_size vga -i desktop out.mpg
@end example
Grab the contents of the window named "Calculator"
@example
ffmpeg -f gdigrab -framerate 6 -i title=Calculator out.mpg
@end example
@subsection Options
@table @option
@item draw_mouse
Specify whether to draw the mouse pointer. Use the value @code{0} to
not draw the pointer. Default value is @code{1}.
@item framerate
Set the grabbing frame rate. Default value is @code{ntsc},
corresponding to a frame rate of @code{30000/1001}.
@item show_region
Show grabbed region on screen.
If @var{show_region} is specified with @code{1}, then the grabbing
region will be indicated on screen. With this option, it is easy to
know what is being grabbed if only a portion of the screen is grabbed.
Note that @var{show_region} is incompatible with grabbing the contents
of a single window.
For example:
@example
ffmpeg -f gdigrab -show_region 1 -framerate 6 -video_size cif -offset_x 10 -offset_y 20 -i desktop out.mpg
@end example
@item video_size
Set the video frame size. The default is to capture the full screen if @file{desktop} is selected, or the full window size if @file{title=@var{window_title}} is selected.
@item offset_x
When capturing a region with @var{video_size}, set the distance from the left edge of the screen or desktop.
Note that the offset calculation is from the top left corner of the primary monitor on Windows. If you have a monitor positioned to the left of your primary monitor, you will need to use a negative @var{offset_x} value to move the region to that monitor.
@item offset_y
When capturing a region with @var{video_size}, set the distance from the top edge of the screen or desktop.
Note that the offset calculation is from the top left corner of the primary monitor on Windows. If you have a monitor positioned above your primary monitor, you will need to use a negative @var{offset_y} value to move the region to that monitor.
@end table
@section iec61883 @section iec61883
FireWire DV/HDV input device using libiec61883. FireWire DV/HDV input device using libiec61883.
......
...@@ -26,6 +26,7 @@ OBJS-$(CONFIG_FBDEV_INDEV) += fbdev_dec.o \ ...@@ -26,6 +26,7 @@ OBJS-$(CONFIG_FBDEV_INDEV) += fbdev_dec.o \
fbdev_common.o fbdev_common.o
OBJS-$(CONFIG_FBDEV_OUTDEV) += fbdev_enc.o \ OBJS-$(CONFIG_FBDEV_OUTDEV) += fbdev_enc.o \
fbdev_common.o fbdev_common.o
OBJS-$(CONFIG_GDIGRAB_INDEV) += gdigrab.o
OBJS-$(CONFIG_IEC61883_INDEV) += iec61883.o OBJS-$(CONFIG_IEC61883_INDEV) += iec61883.o
OBJS-$(CONFIG_JACK_INDEV) += jack_audio.o timefilter.o OBJS-$(CONFIG_JACK_INDEV) += jack_audio.o timefilter.o
OBJS-$(CONFIG_LAVFI_INDEV) += lavfi.o OBJS-$(CONFIG_LAVFI_INDEV) += lavfi.o
......
...@@ -53,6 +53,7 @@ void avdevice_register_all(void) ...@@ -53,6 +53,7 @@ void avdevice_register_all(void)
REGISTER_INDEV (DSHOW, dshow); REGISTER_INDEV (DSHOW, dshow);
REGISTER_INDEV (DV1394, dv1394); REGISTER_INDEV (DV1394, dv1394);
REGISTER_INOUTDEV(FBDEV, fbdev); REGISTER_INOUTDEV(FBDEV, fbdev);
REGISTER_INDEV (GDIGRAB, gdigrab);
REGISTER_INDEV (IEC61883, iec61883); REGISTER_INDEV (IEC61883, iec61883);
REGISTER_INDEV (JACK, jack); REGISTER_INDEV (JACK, jack);
REGISTER_INDEV (LAVFI, lavfi); REGISTER_INDEV (LAVFI, lavfi);
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment