75#define WIN32_API_ERROR(str) \
76 av_log(s1, AV_LOG_ERROR, str " (error %li)\n", GetLastError())
78#define REGION_WND_BORDER 3
91static LRESULT CALLBACK
100 hdc = BeginPaint(hwnd, &ps);
102 GetClientRect(hwnd, &
rect);
103 FrameRect(hdc, &
rect, GetStockObject(BLACK_BRUSH));
106 FrameRect(hdc, &
rect, GetStockObject(WHITE_BRUSH));
109 FrameRect(hdc, &
rect, GetStockObject(BLACK_BRUSH));
114 return DefWindowProc(hwnd, msg, wparam, lparam);
133 HRGN region_interior =
NULL;
136 DWORD style = WS_POPUP | WS_VISIBLE;
137 DWORD ex = WS_EX_LAYERED | WS_EX_NOACTIVATE | WS_EX_TOOLWINDOW |
138 WS_EX_TOPMOST | WS_EX_TRANSPARENT;
143 AdjustWindowRectEx(&
rect, style, FALSE, ex);
152 "(error %li)\n", GetLastError());
158 region = CreateRectRgn(0, 0,
163 CombineRgn(region, region, region_interior, RGN_DIFF);
164 if (!SetWindowRgn(
hwnd, region, FALSE)) {
166 "(error %li)\n", GetLastError());
171 DeleteObject(region_interior);
174 SetLayeredWindowAttributes(
hwnd, 0, 0xFF, LWA_ALPHA);
176 ShowWindow(
hwnd, SW_SHOW);
181 while (GetMessage(&msg,
NULL, 0, 0)) {
182 DispatchMessage(&msg);
190 DeleteObject(region);
192 DeleteObject(region_interior);
267 const char *filename = s1->
url;
281 if (!strncmp(filename,
"title=", 6)) {
282 wchar_t *name_w =
NULL;
285 if(utf8towchar(
name, &name_w)) {
298 "Can't find window '%s', aborting.\n",
name);
304 "Can't show region when grabbing a window.\n");
307 }
else if (!strcmp(filename,
"desktop")) {
309 }
else if (!strncmp(filename,
"hwnd=", 5)) {
313 hwnd = (HWND)(intptr_t) strtoull(
name, &p, 0);
315 if (p ==
NULL || p ==
name || p[0] !=
'\0')
318 "Invalid window handle '%s', must be a valid integer.\n",
name);
324 "Please use \"desktop\", \"title=<windowname>\" or \"hwnd=<hwnd>\" to specify your target.\n");
341 desktophorzres = GetDeviceCaps(
source_hdc, DESKTOPHORZRES);
342 desktopvertres = GetDeviceCaps(
source_hdc, DESKTOPVERTRES);
345 GetClientRect(
hwnd, &virtual_rect);
347 virtual_rect.left = virtual_rect.left * desktophorzres / horzres;
348 virtual_rect.right = virtual_rect.right * desktophorzres / horzres;
349 virtual_rect.top = virtual_rect.top * desktopvertres / vertres;
350 virtual_rect.bottom = virtual_rect.bottom * desktopvertres / vertres;
353 virtual_rect.left = GetSystemMetrics(SM_XVIRTUALSCREEN);
354 virtual_rect.top = GetSystemMetrics(SM_YVIRTUALSCREEN);
355 virtual_rect.right = (virtual_rect.left + GetSystemMetrics(SM_CXVIRTUALSCREEN)) * desktophorzres / horzres;
356 virtual_rect.bottom = (virtual_rect.top + GetSystemMetrics(SM_CYVIRTUALSCREEN)) * desktopvertres / vertres;
372 if (
clip_rect.left < virtual_rect.left ||
375 clip_rect.bottom > virtual_rect.bottom) {
377 "Capture area (%li,%li),(%li,%li) extends outside window area (%li,%li),(%li,%li)",
380 virtual_rect.left, virtual_rect.top,
381 virtual_rect.right, virtual_rect.bottom);
389 "Found window %s, capturing %lix%lix%i at (%li,%li)\n",
396 "Capturing whole desktop as %lix%lix%i at (%li,%li)\n",
417 bmi.bmiHeader.biSize =
sizeof(BITMAPINFOHEADER);
420 bmi.bmiHeader.biPlanes = 1;
421 bmi.bmiHeader.biBitCount = bpp;
422 bmi.bmiHeader.biCompression = BI_RGB;
423 bmi.bmiHeader.biSizeImage = 0;
424 bmi.bmiHeader.biXPelsPerMeter = 0;
425 bmi.bmiHeader.biYPelsPerMeter = 0;
426 bmi.bmiHeader.biClrUsed = 0;
427 bmi.bmiHeader.biClrImportant = 0;
443 GetObject(
hbmp,
sizeof(BITMAP), &bmp);
454 (bpp <= 8 ? (1 << bpp) : 0) *
sizeof(RGBQUAD) ;
505#define CURSOR_ERROR(str) \
506 if (!gdigrab->cursor_error_printed) { \
507 WIN32_API_ERROR(str); \
508 gdigrab->cursor_error_printed = 1; \
511 ci.cbSize =
sizeof(ci);
513 if (GetCursorInfo(&ci)) {
514 HCURSOR icon = CopyCursor(ci.hCursor);
524 info.hbmColor =
NULL;
526 if (ci.flags != CURSOR_SHOWING)
533 icon = CopyCursor(LoadCursor(
NULL, IDC_ARROW));
536 if (!GetIconInfo(icon, &info)) {
549 pos.x =
pos.x * desktophorzres / horzres;
550 pos.y =
pos.y * desktopvertres / vertres;
557 pos.x = ci.ptScreenPos.x * desktophorzres / horzres -
clip_rect.left - info.xHotspot;
558 pos.y = ci.ptScreenPos.y * desktopvertres / vertres -
clip_rect.top - info.yHotspot;
562 ci.ptScreenPos.x, ci.ptScreenPos.y,
pos.x,
pos.y);
572 DeleteObject(info.hbmMask);
574 DeleteObject(info.hbmColor);
599 BITMAPFILEHEADER bfh;
643 bfh.bfSize = file_size;
648 memcpy(
pkt->data, &bfh,
sizeof(bfh));
654 (RGBQUAD *) (
pkt->data +
sizeof(bfh) +
sizeof(
gdigrab->
bmi.bmiHeader)));
677 ReleaseDC(
s->hwnd,
s->source_hdc);
679 DeleteDC(
s->dest_hdc);
681 DeleteObject(
s->hbmp);
683 DeleteDC(
s->source_hdc);
688#define OFFSET(x) offsetof(struct gdigrab, x)
689#define DEC AV_OPT_FLAG_DECODING_PARAM
701 .class_name =
"GDIgrab indev",
714 .priv_data_size =
sizeof(
struct gdigrab),
const FFInputFormat ff_gdigrab_demuxer
gdi grabber device demuxer declaration
static int read_header(FFV1Context *f, RangeCoder *c)
static int gdigrab_read_close(AVFormatContext *s1)
Closes gdi frame grabber (public device demuxer API).
static void gdigrab_region_wnd_destroy(AVFormatContext *s1, struct gdigrab *gdigrab)
Cleanup/free the region outline window.
static LRESULT CALLBACK gdigrab_region_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
Callback to handle Windows messages for the region outline window.
#define REGION_WND_BORDER
#define CURSOR_ERROR(str)
#define WIN32_API_ERROR(str)
static int gdigrab_read_packet(AVFormatContext *s1, AVPacket *pkt)
Grabs a frame from gdi (public device demuxer API).
static int gdigrab_read_header(AVFormatContext *s1)
Initializes the gdi grab device demuxer (public device demuxer API).
static void paint_mouse_pointer(AVFormatContext *s1, struct gdigrab *gdigrab)
Paints a mouse pointer in a Win32 image.
static DWORD WINAPI gdigrab_region_wnd_task(LPVOID opaque)
Run the region outline window loop.
static const AVClass gdigrab_class
static int gdigrab_region_wnd_init(struct gdigrab *gdigrab)
Start the region outline window thread.
@ AV_OPT_TYPE_IMAGE_SIZE
Underlying C type is two consecutive integers.
@ AV_OPT_TYPE_VIDEO_RATE
Underlying C type is AVRational.
@ AV_OPT_TYPE_INT
Underlying C type is int.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
#define LIBAVUTIL_VERSION_INT
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
@ AV_CLASS_CATEGORY_DEVICE_VIDEO_INPUT
Memory handling functions.
Describe the class of an AVClass context structure.
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
enum AVMediaType codec_type
General type of the encoded data.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
int flags
Flags modifying the (de)muxer behaviour.
char * url
input or output URL.
void * priv_data
Format private data.
This structure stores compressed data.
Rational number (pair of numerator and denominator).
AVCodecParameters * codecpar
Codec parameters associated with this stream.
AVRational avg_frame_rate
Average framerate.
GDI Device Demuxer context.
HDC dest_hdc
Destination, source-compatible DC.
int height
Height of the grab frame (private option)
int show_region
Draw border (private option)
HWND hwnd
Handle of the window for the grab.
int frame_size
Size in bytes of the frame pixel data.
int offset_y
Capture y offset (private option)
HBITMAP hbmp
Information on the bitmap captured.
AVRational time_base
Time base.
int width
Width of the grab frame (private option)
RECT clip_rect
The subarea of the screen or window to clip.
AVRational framerate
Capture framerate (private option)
HANDLE region_thread
Region window thread.
HDC source_hdc
Source device context.
int offset_x
Capture x offset (private option)
DWORD region_thread_id
Region window thread ID.
void * buffer
The buffer containing the bitmap image data.
int64_t time_frame
Current time.
HANDLE region_init
Region window ready signal.
BITMAPINFO bmi
Information describing DIB format.
int draw_mouse
Draw mouse cursor (private option)
volatile LONG region_result
Region window status, 0 success.
int header_size
Size in bytes of the DIB header.
static void error(const char *err)
int av_usleep(unsigned usec)
Sleep for a period of time.
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
int64_t av_gettime(void)
Get the current time in microseconds.
#define WaitForSingleObject(a, b)