History

avfilter/scale_vulkan: add dynamic crop region and aspect ratio match

The scale_vulkan filter initializes the shader once, with the crop region set by the original frame. However, subsequent frames may specify a different crop region than the first frame. This change updates the cropping to match the behavior present on the other hardware frame scale filters. The scale filter should also allow negative values that respect aspect ratio, similar to other scale filters.

Koushik Dutta committed 1 year ago

Commit 252fc2e1 parent 19c95ec1 file · +20 −6Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/vf_scale_vulkan.c+20−6
@@ -46,6 +46,10 @@ typedef struct ScaleVulkanContext { · 45 unmodified lines
4646 /* Push constants / options */
4747 struct {
4848 float yuv_matrix[4][4];
49+ int crop_x;
50+ int crop_y;
51+ int crop_w;
52+ int crop_h;
4953 } opts;
5054
5155 char *out_format_string;
@@ -121,10 +125,6 @@ static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in) · 69 unmodified lines
121125 FFVkSPIRVCompiler *spv;
122126 FFVulkanDescriptorSetBinding *desc;
123127
124− int crop_x = in->crop_left;
125− int crop_y = in->crop_top;
126− int crop_w = in->width - (in->crop_left + in->crop_right);
127− int crop_h = in->height - (in->crop_top + in->crop_bottom);
128128 int in_planes = av_pix_fmt_count_planes(s->vkctx.input_format);
129129
130130 switch (s->scaler) {
@@ -159,6 +159,10 @@ static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in) · 28 unmodified lines
159159
160160 GLSLC(0, layout(push_constant, std430) uniform pushConstants { );
161161 GLSLC(1, mat4 yuv_matrix; );
162+ GLSLC(1, int crop_x; );
163+ GLSLC(1, int crop_y; );
164+ GLSLC(1, int crop_w; );
165+ GLSLC(1, int crop_h; );
162166 GLSLC(0, }; );
163167 GLSLC(0, );
164168
@@ -205,8 +209,8 @@ static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in) · 40 unmodified lines
205209 GLSLC(1, ivec2 size; );
206210 GLSLC(1, ivec2 pos = ivec2(gl_GlobalInvocationID.xy); );
207211 GLSLF(1, vec2 in_d = vec2(%i, %i); ,in->width, in->height);
208− GLSLF(1, vec2 c_r = vec2(%i, %i) / in_d; ,crop_w, crop_h);
209− GLSLF(1, vec2 c_o = vec2(%i, %i) / in_d; ,crop_x,crop_y);
212+ GLSLC(1, vec2 c_r = vec2(crop_w, crop_h) / in_d; );
213+ GLSLC(1, vec2 c_o = vec2(crop_x, crop_y) / in_d; );
210214 GLSLC(0, );
211215
212216 if (s->vkctx.output_format == s->vkctx.input_format) {
@@ -286,6 +290,11 @@ static int scale_vulkan_filter_frame(AVFilterLink *link, AVFrame *in) · 73 unmodified lines
286290 if (!s->initialized)
287291 RET(init_filter(ctx, in));
288292
293+ s->opts.crop_x = in->crop_left;
294+ s->opts.crop_y = in->crop_top;
295+ s->opts.crop_w = in->width - (in->crop_left + in->crop_right);
296+ s->opts.crop_h = in->height - (in->crop_top + in->crop_bottom);
297+
289298 RET(ff_vk_filter_process_simple(&s->vkctx, &s->e, &s->shd, out, in,
290299 s->sampler, &s->opts, sizeof(s->opts)));
291300
@@ -327,6 +336,11 @@ static int scale_vulkan_config_output(AVFilterLink *outlink) · 35 unmodified lines
327336 if (err < 0)
328337 return err;
329338
339+ ff_scale_adjust_dimensions(inlink, &vkctx->output_width, &vkctx->output_height, 0, 1);
340+
341+ outlink->w = vkctx->output_width;
342+ outlink->h = vkctx->output_height;
343+
330344 if (s->out_format_string) {
331345 s->vkctx.output_format = av_get_pix_fmt(s->out_format_string);
332346 if (s->vkctx.output_format == AV_PIX_FMT_NONE) {

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