FFmpeg
vsrc_gfxcapture.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include "config.h"
20 
21 #include "libavutil/internal.h"
22 #include "libavutil/opt.h"
23 #include "avfilter.h"
24 #include "filters.h"
25 
26 #include "vsrc_gfxcapture.h"
27 
28 #define OFFSET(x) offsetof(GfxCaptureContext, x)
29 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
30 static const AVOption gfxcapture_options[] = {
31  { "window_title", "ECMAScript regular expression to match against the window title. "
32  "Supports PCRE style (?i) prefix for case-insensitivity.",
33  OFFSET(window_text), AV_OPT_TYPE_STRING, { .str = NULL }, 0, INT_MAX, FLAGS },
34  { "window_class", "as window_title, but against the window class",
35  OFFSET(window_class), AV_OPT_TYPE_STRING, { .str = NULL }, 0, INT_MAX, FLAGS },
36  { "window_exe", "as window_title, but against the windows executable name",
37  OFFSET(window_exe), AV_OPT_TYPE_STRING, { .str = NULL }, 0, INT_MAX, FLAGS },
38  { "monitor_idx", "index of the monitor to capture", OFFSET(monitor_idx), AV_OPT_TYPE_INT, { .i64 = GFX_MONITOR_IDX_DEFAULT }, GFX_MONITOR_IDX_DEFAULT, INT_MAX, FLAGS, .unit = "monitor_idx" },
39  { "window", "derive from selected window", 0, AV_OPT_TYPE_CONST, { .i64 = GFX_MONITOR_IDX_WINDOW }, 0, 0, FLAGS, .unit = "monitor_idx" },
40  { "capture_cursor", "capture mouse cursor", OFFSET(capture_cursor), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, FLAGS },
41  { "capture_border", "capture full window border", OFFSET(capture_border), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
42  { "display_border", "display yellow border around captured window",
43  OFFSET(display_border), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
44  { "max_framerate", "set maximum capture frame rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, { .str = "60" }, 0.001, 1000, FLAGS },
45  { "hwnd", "pre-existing HWND handle", OFFSET(user_hwnd), AV_OPT_TYPE_UINT64, { .i64 = 0 }, 0, UINT64_MAX, FLAGS },
46  { "hmonitor", "pre-existing HMONITOR handle", OFFSET(user_hmonitor), AV_OPT_TYPE_UINT64, { .i64 = 0 }, 0, UINT64_MAX, FLAGS },
47  { "width", "force width of the output frames, negative values round down the width to the nearest multiple of that number",
48  OFFSET(canvas_width), AV_OPT_TYPE_INT, { .i64 = 0 }, INT_MIN, INT_MAX, FLAGS },
49  { "height", "force height of the output frames, negative values round down the height to the nearest multiple of that number",
50  OFFSET(canvas_height), AV_OPT_TYPE_INT, { .i64 = 0 }, INT_MIN, INT_MAX, FLAGS },
51  { "crop_left", "number of pixels to crop from the left of the captured area",
52  OFFSET(crop_left), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS },
53  { "crop_top", "number of pixels to crop from the top of the captured area",
54  OFFSET(crop_top), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS },
55  { "crop_right", "number of pixels to crop from the right of the captured area",
56  OFFSET(crop_right), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS },
57  { "crop_bottom", "number of pixels to crop from the bottom of the captured area",
58  OFFSET(crop_bottom), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS },
59  { "premultiplied", "return premultiplied alpha frames", OFFSET(premult_alpha), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
60  { "resize_mode", "capture source resize behavior", OFFSET(resize_mode), AV_OPT_TYPE_INT, { .i64 = GFX_RESIZE_CROP }, 0, GFX_RESIZE_NB - 1, FLAGS, .unit = "resize_mode" },
61  { "crop", "crop or add black bars into frame", 0, AV_OPT_TYPE_CONST, { .i64 = GFX_RESIZE_CROP }, 0, 0, FLAGS, .unit = "resize_mode" },
62  { "scale", "scale source to fit initial size", 0, AV_OPT_TYPE_CONST, { .i64 = GFX_RESIZE_SCALE }, 0, 0, FLAGS, .unit = "resize_mode" },
63  { "scale_aspect", "scale source to fit initial size while preserving aspect ratio",
64  0, AV_OPT_TYPE_CONST, { .i64 = GFX_RESIZE_SCALE_ASPECT }, 0, 0, FLAGS, .unit = "resize_mode" },
65  { "scale_mode", "scaling algorithm", OFFSET(scale_mode), AV_OPT_TYPE_INT, { .i64 = GFX_SCALE_BILINEAR }, 0, GFX_SCALE_NB - 1, FLAGS, .unit = "scale_mode" },
66  { "point", "use point scaling", 0, AV_OPT_TYPE_CONST, { .i64 = GFX_SCALE_POINT }, 0, 0, FLAGS, .unit = "scale_mode" },
67  { "bilinear", "use bilinear scaling", 0, AV_OPT_TYPE_CONST, { .i64 = GFX_SCALE_BILINEAR }, 0, 0, FLAGS, .unit = "scale_mode" },
68  { "bicubic", "use bicubic scaling", 0, AV_OPT_TYPE_CONST, { .i64 = GFX_SCALE_BICUBIC }, 0, 0, FLAGS, .unit = "scale_mode" },
69  { "output_fmt", "desired output format", OFFSET(out_fmt), AV_OPT_TYPE_INT, { .i64 = AV_PIX_FMT_BGRA }, 0, INT_MAX, FLAGS, .unit = "output_fmt" },
70  { "8bit", "output default 8 Bit format", 0, AV_OPT_TYPE_CONST, { .i64 = AV_PIX_FMT_BGRA }, 0, 0, FLAGS, .unit = "output_fmt" },
71  { "bgra", "output 8 Bit BGRA", 0, AV_OPT_TYPE_CONST, { .i64 = AV_PIX_FMT_BGRA }, 0, 0, FLAGS, .unit = "output_fmt" },
72  { "10bit", "output default 10 Bit format", 0, AV_OPT_TYPE_CONST, { .i64 = AV_PIX_FMT_X2BGR10 }, 0, 0, FLAGS, .unit = "output_fmt" },
73  { "x2bgr10", "output 10 Bit X2BGR10", 0, AV_OPT_TYPE_CONST, { .i64 = AV_PIX_FMT_X2BGR10 }, 0, 0, FLAGS, .unit = "output_fmt" },
74  { "16bit", "output default 16 Bit format", 0, AV_OPT_TYPE_CONST, { .i64 = AV_PIX_FMT_RGBAF16 }, 0, 0, FLAGS, .unit = "output_fmt" },
75  { "rgbaf16", "output 16 Bit RGBAF16", 0, AV_OPT_TYPE_CONST, { .i64 = AV_PIX_FMT_RGBAF16 }, 0, 0, FLAGS, .unit = "output_fmt" },
76  { NULL }
77 };
78 
79 AVFILTER_DEFINE_CLASS(gfxcapture);
80 
81 static const AVFilterPad gfxcapture_outputs[] = {
82  {
83  .name = "default",
84  .type = AVMEDIA_TYPE_VIDEO,
85  .config_props = ff_gfxcapture_config_props,
86  },
87 };
88 
90  .p.name = "gfxcapture",
91  .p.description = NULL_IF_CONFIG_SMALL("Capture graphics/screen content as a video source"),
92  .p.priv_class = &gfxcapture_class,
93  .p.inputs = NULL,
94  .p.flags = AVFILTER_FLAG_HWDEVICE,
95  .priv_size = sizeof(GfxCaptureContext),
100  .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
101  .activate = ff_gfxcapture_activate,
102 };
opt.h
gfxcapture_outputs
static const AVFilterPad gfxcapture_outputs[]
Definition: vsrc_gfxcapture.c:81
AV_OPT_TYPE_VIDEO_RATE
@ AV_OPT_TYPE_VIDEO_RATE
Underlying C type is AVRational.
Definition: opt.h:315
gfxcapture_options
static const AVOption gfxcapture_options[]
Definition: vsrc_gfxcapture.c:30
AVOption
AVOption.
Definition: opt.h:429
AV_PIX_FMT_BGRA
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:102
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:220
GFX_RESIZE_CROP
@ GFX_RESIZE_CROP
Definition: vsrc_gfxcapture.h:29
GFX_RESIZE_NB
@ GFX_RESIZE_NB
Definition: vsrc_gfxcapture.h:32
GFX_SCALE_BILINEAR
@ GFX_SCALE_BILINEAR
Definition: vsrc_gfxcapture.h:37
ff_vsrc_gfxcapture
const FFFilter ff_vsrc_gfxcapture
Definition: vsrc_gfxcapture.c:89
AVFilterPad
A filter pad used for either input or output.
Definition: filters.h:39
FFFilter
Definition: filters.h:266
ff_gfxcapture_uninit
av_cold void ff_gfxcapture_uninit(AVFilterContext *avctx) NOEXCEPT
Definition: vsrc_gfxcapture_winrt.cpp:1500
ff_gfxcapture_init
av_cold int ff_gfxcapture_init(AVFilterContext *avctx) NOEXCEPT
Definition: vsrc_gfxcapture_winrt.cpp:1511
filters.h
OFFSET
#define OFFSET(x)
Definition: vsrc_gfxcapture.c:28
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:264
NULL
#define NULL
Definition: coverity.c:32
GFX_SCALE_NB
@ GFX_SCALE_NB
Definition: vsrc_gfxcapture.h:39
ff_gfxcapture_activate
int ff_gfxcapture_activate(AVFilterContext *avctx) NOEXCEPT
Definition: vsrc_gfxcapture_winrt.cpp:1526
GfxCaptureContext
Definition: vsrc_gfxcapture.h:47
GFX_SCALE_POINT
@ GFX_SCALE_POINT
Definition: vsrc_gfxcapture.h:36
GFX_MONITOR_IDX_DEFAULT
@ GFX_MONITOR_IDX_DEFAULT
Definition: vsrc_gfxcapture.h:44
FF_FILTER_FLAG_HWFRAME_AWARE
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
Definition: filters.h:207
FLAGS
#define FLAGS
Definition: vsrc_gfxcapture.c:29
AV_PIX_FMT_X2BGR10
#define AV_PIX_FMT_X2BGR10
Definition: pixfmt.h:614
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
AVFILTER_FLAG_HWDEVICE
#define AVFILTER_FLAG_HWDEVICE
The filter can create hardware frames using AVFilterContext.hw_device_ctx.
Definition: avfilter.h:188
AV_PIX_FMT_D3D11
@ AV_PIX_FMT_D3D11
Hardware surfaces for Direct3D11.
Definition: pixfmt.h:336
uninit
static void uninit(AVBSFContext *ctx)
Definition: pcm_rechunk.c:68
internal.h
GFX_RESIZE_SCALE
@ GFX_RESIZE_SCALE
Definition: vsrc_gfxcapture.h:30
AVFilterPad::name
const char * name
Pad name.
Definition: filters.h:45
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(gfxcapture)
GFX_RESIZE_SCALE_ASPECT
@ GFX_RESIZE_SCALE_ASPECT
Definition: vsrc_gfxcapture.h:31
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
avfilter.h
vsrc_gfxcapture.h
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
FFFilter::p
AVFilter p
The public AVFilter.
Definition: filters.h:270
AV_PIX_FMT_RGBAF16
#define AV_PIX_FMT_RGBAF16
Definition: pixfmt.h:624
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:327
GFX_SCALE_BICUBIC
@ GFX_SCALE_BICUBIC
Definition: vsrc_gfxcapture.h:38
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition: opt.h:276
ff_gfxcapture_config_props
int ff_gfxcapture_config_props(AVFilterLink *outlink) NOEXCEPT
Definition: vsrc_gfxcapture_winrt.cpp:1541
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
FILTER_SINGLE_PIXFMT
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
Definition: filters.h:253
GFX_MONITOR_IDX_WINDOW
@ GFX_MONITOR_IDX_WINDOW
Definition: vsrc_gfxcapture.h:43
AV_OPT_TYPE_UINT64
@ AV_OPT_TYPE_UINT64
Underlying C type is uint64_t.
Definition: opt.h:294