History

avfilter/vsrc_ddagrab: make output format user configurable

Timo Rothenpieler committed 4 years ago

Commit 38595eb1 parent f0abd072 files · +44 −1Browse files

Unified · Split

2 files
  1. doc/filters.texi +16 −0
  2. libavfilter/vsrc_ddagrab.c +28 −1
doc/filters.texi+16−0
@@ -26531,6 +26531,22 @@ Horizontal offset of the captured video. · 26530 unmodified lines
2653126531 @item offset_y
2653226532 Vertical offset of the captured video.
2653326533
26534+@item output_fmt
26535+Desired filter output format.
26536+Defaults to 8 Bit BGRA.
26537+
26538+It accepts the following values:
26539+@table @samp
26540+@item auto
26541+Passes all supported output formats to DDA and returns what DDA decides to use.
26542+@item 8bit
26543+@item bgra
26544+8 Bit formats always work, and DDA will convert to them if neccesary.
26545+@item 10bit
26546+@item x2bgr10
26547+Filter initialization will fail if 10 bit format is requested but unavailable.
26548+@end table
26549+
2653426550 @end table
2653526551
2653626552 @subsection Examples
libavfilter/vsrc_ddagrab.c+28−1
@@ -97,6 +97,7 @@ typedef struct DdagrabContext { · 96 unmodified lines
9797 int height;
9898 int offset_x;
9999 int offset_y;
100+ int out_fmt;
100101 } DdagrabContext;
101102
102103 #define OFFSET(x) offsetof(DdagrabContext, x)
@@ -108,6 +109,12 @@ static const AVOption ddagrab_options[] = { · 5 unmodified lines
108109 { "video_size", "set video frame size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, { .str = NULL }, 0, 0, FLAGS },
109110 { "offset_x", "capture area x offset", OFFSET(offset_x), AV_OPT_TYPE_INT, { .i64 = 0 }, INT_MIN, INT_MAX, FLAGS },
110111 { "offset_y", "capture area y offset", OFFSET(offset_y), AV_OPT_TYPE_INT, { .i64 = 0 }, INT_MIN, INT_MAX, FLAGS },
112+ { "output_fmt", "desired output format", OFFSET(out_fmt), AV_OPT_TYPE_INT, { .i64 = DXGI_FORMAT_B8G8R8A8_UNORM }, 0, INT_MAX, FLAGS, "output_fmt" },
113+ { "auto", "let dda pick its preferred format", 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, 0, INT_MAX, FLAGS, "output_fmt" },
114+ { "8bit", "only output default 8 Bit format", 0, AV_OPT_TYPE_CONST, { .i64 = DXGI_FORMAT_B8G8R8A8_UNORM }, 0, INT_MAX, FLAGS, "output_fmt" },
115+ { "bgra", "only output 8 Bit BGRA", 0, AV_OPT_TYPE_CONST, { .i64 = DXGI_FORMAT_B8G8R8A8_UNORM }, 0, INT_MAX, FLAGS, "output_fmt" },
116+ { "10bit", "only output default 10 Bit format", 0, AV_OPT_TYPE_CONST, { .i64 = DXGI_FORMAT_R10G10B10A2_UNORM }, 0, INT_MAX, FLAGS, "output_fmt" },
117+ { "x2bgr10", "only output 10 Bit X2BGR10", 0, AV_OPT_TYPE_CONST, { .i64 = DXGI_FORMAT_R10G10B10A2_UNORM }, 0, INT_MAX, FLAGS, "output_fmt" },
111118 { NULL }
112119 };
113120
@@ -208,6 +215,16 @@ static av_cold int init_dxgi_dda(AVFilterContext *avctx) · 94 unmodified lines
208215 DXGI_FORMAT_R10G10B10A2_UNORM,
209216 DXGI_FORMAT_B8G8R8A8_UNORM
210217 };
218+ int nb_formats = FF_ARRAY_ELEMS(formats);
219+
220+ if(dda->out_fmt == DXGI_FORMAT_B8G8R8A8_UNORM) {
221+ formats[0] = DXGI_FORMAT_B8G8R8A8_UNORM;
222+ nb_formats = 1;
223+ } else if (dda->out_fmt) {
224+ formats[0] = dda->out_fmt;
225+ formats[1] = DXGI_FORMAT_B8G8R8A8_UNORM;
226+ nb_formats = 2;
227+ }
211228
212229 IDXGIOutput_Release(dxgi_output);
213230 dxgi_output = NULL;
@@ -219,7 +236,7 @@ static av_cold int init_dxgi_dda(AVFilterContext *avctx) · 5 unmodified lines
219236 hr = IDXGIOutput5_DuplicateOutput1(dxgi_output5,
220237 (IUnknown*)dda->device_hwctx->device,
221238 0,
222− FF_ARRAY_ELEMS(formats),
239+ nb_formats,
223240 formats,
224241 &dda->dxgi_outdupl);
225242 IDXGIOutput5_Release(dxgi_output5);
@@ -242,6 +259,11 @@ static av_cold int init_dxgi_dda(AVFilterContext *avctx) · 16 unmodified lines
242259 #else
243260 {
244261 #endif
262+ if (dda->out_fmt && dda->out_fmt != DXGI_FORMAT_B8G8R8A8_UNORM) {
263+ av_log(avctx, AV_LOG_ERROR, "Only 8 bit output supported with legacy API\n");
264+ return AVERROR(ENOTSUP);
265+ }
266+
245267 hr = IDXGIOutput_QueryInterface(dxgi_output, &IID_IDXGIOutput1, (void**)&dxgi_output1);
246268 IDXGIOutput_Release(dxgi_output);
247269 dxgi_output = NULL;
@@ -704,6 +726,11 @@ static int ddagrab_config_props(AVFilterLink *outlink) · 456 unmodified lines
704726 if (ret < 0)
705727 return ret;
706728
729+ if (dda->out_fmt && dda->raw_format != dda->out_fmt) {
730+ av_log(avctx, AV_LOG_ERROR, "Requested output format unavailable.\n");
731+ return AVERROR(ENOTSUP);
732+ }
733+
707734 dda->width -= FFMAX(dda->width - dda->raw_width + dda->offset_x, 0);
708735 dda->height -= FFMAX(dda->height - dda->raw_height + dda->offset_y, 0);
709736

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t