Go to the documentation of this file.
72 #define WIN32_API_ERROR(str) \
73 av_log(s1, AV_LOG_ERROR, str " (error %li)\n", GetLastError())
75 #define REGION_WND_BORDER 3
88 static LRESULT CALLBACK
97 hdc = BeginPaint(hwnd, &ps);
99 GetClientRect(hwnd, &
rect);
100 FrameRect(hdc, &
rect, GetStockObject(BLACK_BRUSH));
103 FrameRect(hdc, &
rect, GetStockObject(WHITE_BRUSH));
106 FrameRect(hdc, &
rect, GetStockObject(BLACK_BRUSH));
111 return DefWindowProc(hwnd, msg, wparam, lparam);
129 HRGN region_interior =
NULL;
131 DWORD style = WS_POPUP | WS_VISIBLE;
132 DWORD ex = WS_EX_TOOLWINDOW | WS_EX_TOPMOST | WS_EX_TRANSPARENT;
137 AdjustWindowRectEx(&
rect, style, FALSE, ex);
141 hwnd = CreateWindowEx(ex, WC_DIALOG,
NULL, style,
rect.left,
rect.top,
150 GetClientRect(hwnd, &
rect);
151 region = CreateRectRgn(0, 0,
156 CombineRgn(region, region, region_interior, RGN_DIFF);
157 if (!SetWindowRgn(hwnd, region, FALSE)) {
163 DeleteObject(region_interior);
167 ShowWindow(hwnd, SW_SHOW);
175 DeleteObject(region);
177 DeleteObject(region_interior);
213 while (PeekMessage(&msg, hwnd, 0, 0, PM_REMOVE)) {
214 DispatchMessage(&msg);
236 const char *filename = s1->
url;
250 if (!strncmp(filename,
"title=", 6)) {
251 wchar_t *name_w =
NULL;
254 if(utf8towchar(
name, &name_w)) {
267 "Can't find window '%s', aborting.\n",
name);
273 "Can't show region when grabbing a window.\n");
276 }
else if (!strcmp(filename,
"desktop")) {
278 }
else if (!strncmp(filename,
"hwnd=", 5)) {
282 hwnd = (HWND) strtoull(
name, &p, 0);
284 if (p ==
NULL || p ==
name || p[0] !=
'\0')
287 "Invalid window handle '%s', must be a valid integer.\n",
name);
293 "Please use \"desktop\", \"title=<windowname>\" or \"hwnd=<hwnd>\" to specify your target.\n");
310 desktophorzres = GetDeviceCaps(
source_hdc, DESKTOPHORZRES);
311 desktopvertres = GetDeviceCaps(
source_hdc, DESKTOPVERTRES);
314 GetClientRect(
hwnd, &virtual_rect);
316 virtual_rect.left = virtual_rect.left * desktophorzres / horzres;
317 virtual_rect.right = virtual_rect.right * desktophorzres / horzres;
318 virtual_rect.top = virtual_rect.top * desktopvertres / vertres;
319 virtual_rect.bottom = virtual_rect.bottom * desktopvertres / vertres;
322 virtual_rect.left = GetSystemMetrics(SM_XVIRTUALSCREEN);
323 virtual_rect.top = GetSystemMetrics(SM_YVIRTUALSCREEN);
324 virtual_rect.right = (virtual_rect.left + GetSystemMetrics(SM_CXVIRTUALSCREEN)) * desktophorzres / horzres;
325 virtual_rect.bottom = (virtual_rect.top + GetSystemMetrics(SM_CYVIRTUALSCREEN)) * desktopvertres / vertres;
341 if (
clip_rect.left < virtual_rect.left ||
344 clip_rect.bottom > virtual_rect.bottom) {
346 "Capture area (%li,%li),(%li,%li) extends outside window area (%li,%li),(%li,%li)",
349 virtual_rect.left, virtual_rect.top,
350 virtual_rect.right, virtual_rect.bottom);
358 "Found window %s, capturing %lix%lix%i at (%li,%li)\n",
365 "Capturing whole desktop as %lix%lix%i at (%li,%li)\n",
386 bmi.bmiHeader.biSize =
sizeof(BITMAPINFOHEADER);
389 bmi.bmiHeader.biPlanes = 1;
390 bmi.bmiHeader.biBitCount = bpp;
391 bmi.bmiHeader.biCompression = BI_RGB;
392 bmi.bmiHeader.biSizeImage = 0;
393 bmi.bmiHeader.biXPelsPerMeter = 0;
394 bmi.bmiHeader.biYPelsPerMeter = 0;
395 bmi.bmiHeader.biClrUsed = 0;
396 bmi.bmiHeader.biClrImportant = 0;
412 GetObject(
hbmp,
sizeof(BITMAP), &bmp);
423 (bpp <= 8 ? (1 << bpp) : 0) *
sizeof(RGBQUAD) ;
474 #define CURSOR_ERROR(str) \
475 if (!gdigrab->cursor_error_printed) { \
476 WIN32_API_ERROR(str); \
477 gdigrab->cursor_error_printed = 1; \
480 ci.cbSize =
sizeof(ci);
482 if (GetCursorInfo(&ci)) {
483 HCURSOR icon = CopyCursor(ci.hCursor);
495 if (ci.flags != CURSOR_SHOWING)
502 icon = CopyCursor(LoadCursor(
NULL, IDC_ARROW));
505 if (!GetIconInfo(icon, &
info)) {
518 pos.x =
pos.x * desktophorzres / horzres;
519 pos.y =
pos.y * desktopvertres / vertres;
526 pos.x = ci.ptScreenPos.x * desktophorzres / horzres -
clip_rect.left -
info.xHotspot;
527 pos.y = ci.ptScreenPos.y * desktopvertres / vertres -
clip_rect.top -
info.yHotspot;
531 ci.ptScreenPos.x, ci.ptScreenPos.y,
pos.x,
pos.y);
541 DeleteObject(
info.hbmMask);
543 DeleteObject(
info.hbmColor);
568 BITMAPFILEHEADER bfh;
616 bfh.bfSize = file_size;
621 memcpy(
pkt->
data, &bfh,
sizeof(bfh));
650 ReleaseDC(
s->hwnd,
s->source_hdc);
652 DeleteDC(
s->dest_hdc);
654 DeleteObject(
s->hbmp);
656 DeleteDC(
s->source_hdc);
661 #define OFFSET(x) offsetof(struct gdigrab, x)
662 #define DEC AV_OPT_FLAG_DECODING_PARAM
687 .priv_data_size =
sizeof(
struct gdigrab),
static void error(const char *err)
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
#define AV_LOG_WARNING
Something somehow does not look correct.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
enum AVMediaType codec_type
General type of the encoded data.
static void gdigrab_region_wnd_destroy(AVFormatContext *s1, struct gdigrab *gdigrab)
Cleanup/free the region outline window.
static int gdigrab_read_packet(AVFormatContext *s1, AVPacket *pkt)
Grabs a frame from gdi (public device demuxer API).
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
HDC dest_hdc
Destination, source-compatible DC.
@ AV_OPT_TYPE_VIDEO_RATE
Underlying C type is AVRational.
int offset_y
Capture y offset (private option)
const FFInputFormat ff_gdigrab_demuxer
gdi grabber device demuxer declaration
AVRational avg_frame_rate
Average framerate.
int64_t time_frame
Current time.
HWND region_hwnd
Handle of the region border window.
int frame_size
Size in bytes of the frame pixel data.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int height
Height of the grab frame (private option)
static int gdigrab_read_close(AVFormatContext *s1)
Closes gdi frame grabber (public device demuxer API).
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
int flags
Flags modifying the (de)muxer behaviour.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int av_usleep(unsigned usec)
Sleep for a period of time.
#define WIN32_API_ERROR(str)
AVCodecParameters * codecpar
Codec parameters associated with this stream.
#define LIBAVUTIL_VERSION_INT
static int read_header(FFV1Context *f)
Describe the class of an AVClass context structure.
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.
BITMAPINFO bmi
Information describing DIB format.
Rational number (pair of numerator and denominator).
@ AV_OPT_TYPE_IMAGE_SIZE
Underlying C type is two consecutive integers.
#define REGION_WND_BORDER
const char * av_default_item_name(void *ptr)
Return the context name.
AVRational time_base
Time base.
int header_size
Size in bytes of the DIB header.
RECT clip_rect
The subarea of the screen or window to clip.
@ AV_CLASS_CATEGORY_DEVICE_VIDEO_INPUT
static void paint_mouse_pointer(AVFormatContext *s1, struct gdigrab *gdigrab)
Paints a mouse pointer in a Win32 image.
AVRational framerate
Capture framerate (private option)
HBITMAP hbmp
Information on the bitmap captured.
static int gdigrab_read_header(AVFormatContext *s1)
Initializes the gdi grab device demuxer (public device demuxer API).
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
char * url
input or output URL.
int offset_x
Capture x offset (private option)
int show_region
Draw border (private option)
HDC source_hdc
Source device context.
static const AVClass gdigrab_class
HWND hwnd
Handle of the window for the grab.
#define AV_LOG_INFO
Standard information.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
void * buffer
The buffer containing the bitmap image data.
int draw_mouse
Draw mouse cursor (private option)
static int gdigrab_region_wnd_init(AVFormatContext *s1, struct gdigrab *gdigrab)
Initialize the region outline window.
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
@ AV_OPT_TYPE_INT
Underlying C type is int.
GDI Device Demuxer context.
static void gdigrab_region_wnd_update(AVFormatContext *s1, struct gdigrab *gdigrab)
Process the Windows message queue.
int64_t av_gettime(void)
Get the current time in microseconds.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
This structure stores compressed data.
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
static const AVOption options[]
int width
Width of the grab frame (private option)
#define CURSOR_ERROR(str)
void * priv_data
Format private data.