FFmpeg
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
vf_scdet_vulkan.c
Go to the documentation of this file.
1 /*
2  * Copyright 2025 (c) Niklas Haas
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "libavutil/avassert.h"
22 #include "libavutil/vulkan_spirv.h"
23 #include "libavutil/opt.h"
24 #include "libavutil/timestamp.h"
25 #include "vulkan_filter.h"
26 
27 #include "filters.h"
28 
29 typedef struct SceneDetectVulkanContext {
31 
37 
38  double threshold;
39  int sc_pass;
40 
41  int nb_planes;
42  double prev_mafd;
46 
47 typedef struct SceneDetectBuf {
48 #define SLICES 16
49  uint32_t frame_sad[SLICES];
51 
53 {
54  int err;
55  uint8_t *spv_data;
56  size_t spv_len;
57  void *spv_opaque = NULL;
59  FFVulkanContext *vkctx = &s->vkctx;
60  FFVulkanShader *shd;
61  FFVkSPIRVCompiler *spv;
63 
64  const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(s->vkctx.input_format);
65  const int lumaonly = !(pixdesc->flags & AV_PIX_FMT_FLAG_RGB) &&
66  (pixdesc->flags & AV_PIX_FMT_FLAG_PLANAR);
67  s->nb_planes = lumaonly ? 1 : av_pix_fmt_count_planes(s->vkctx.input_format);
68 
69  spv = ff_vk_spirv_init();
70  if (!spv) {
71  av_log(ctx, AV_LOG_ERROR, "Unable to initialize SPIR-V compiler!\n");
72  return AVERROR_EXTERNAL;
73  }
74 
75  s->qf = ff_vk_qf_find(vkctx, VK_QUEUE_COMPUTE_BIT, 0);
76  if (!s->qf) {
77  av_log(ctx, AV_LOG_ERROR, "Device has no compute queues\n");
78  err = AVERROR(ENOTSUP);
79  goto fail;
80  }
81 
82  RET(ff_vk_exec_pool_init(vkctx, s->qf, &s->e, s->qf->num*4, 0, 0, 0, NULL));
83  RET(ff_vk_shader_init(vkctx, &s->shd, "scdet",
84  VK_SHADER_STAGE_COMPUTE_BIT,
85  (const char *[]) { "GL_KHR_shader_subgroup_arithmetic" }, 1,
86  32, 32, 1,
87  0));
88  shd = &s->shd;
89 
91  {
92  .name = "prev_img",
93  .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
94  .mem_layout = ff_vk_shader_rep_fmt(s->vkctx.input_format, FF_VK_REP_UINT),
95  .mem_quali = "readonly",
96  .dimensions = 2,
97  .elems = av_pix_fmt_count_planes(s->vkctx.input_format),
98  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
99  }, {
100  .name = "cur_img",
101  .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
102  .mem_layout = ff_vk_shader_rep_fmt(s->vkctx.input_format, FF_VK_REP_UINT),
103  .mem_quali = "readonly",
104  .dimensions = 2,
105  .elems = av_pix_fmt_count_planes(s->vkctx.input_format),
106  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
107  }, {
108  .name = "sad_buffer",
109  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
110  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
111  .buf_content = "uint frame_sad[];",
112  }
113  };
114 
115  RET(ff_vk_shader_add_descriptor_set(vkctx, &s->shd, desc, 3, 0, 0));
116 
117  GLSLC(0, shared uint wg_sum; );
118  GLSLC(0, void main() );
119  GLSLC(0, { );
120  GLSLF(1, const uint slice = gl_WorkGroupID.x %% %u; ,SLICES);
121  GLSLC(1, const ivec2 pos = ivec2(gl_GlobalInvocationID.xy); );
122  GLSLC(1, wg_sum = 0; );
123  GLSLC(1, barrier(); );
124  for (int i = 0; i < s->nb_planes; i++) {
125  GLSLF(1, if (IS_WITHIN(pos, imageSize(cur_img[%d]))) { ,i);
126  GLSLF(2, uvec4 prev = imageLoad(prev_img[%d], pos); ,i);
127  GLSLF(2, uvec4 cur = imageLoad(cur_img[%d], pos); ,i);
128  GLSLC(2, uvec4 sad = abs(ivec4(cur) - ivec4(prev)); );
129  GLSLC(2, uint sum = subgroupAdd(sad.x + sad.y + sad.z); );
130  GLSLC(2, if (subgroupElect()) );
131  GLSLC(3, atomicAdd(wg_sum, sum); );
132  GLSLC(1, } );
133  }
134  GLSLC(1, barrier(); );
135  GLSLC(1, if (gl_LocalInvocationIndex == 0) );
136  GLSLC(2, atomicAdd(frame_sad[slice], wg_sum); );
137  GLSLC(0, } );
138 
139  RET(spv->compile_shader(vkctx, spv, &s->shd, &spv_data, &spv_len, "main",
140  &spv_opaque));
141  RET(ff_vk_shader_link(vkctx, &s->shd, spv_data, spv_len, "main"));
142 
143  RET(ff_vk_shader_register_exec(vkctx, &s->e, &s->shd));
144 
145  s->initialized = 1;
146 
147 fail:
148  if (spv_opaque)
149  spv->free_shader(spv, &spv_opaque);
150  if (spv)
151  spv->uninit(&spv);
152 
153  return err;
154 }
155 
156 static double evaluate(AVFilterContext *ctx, const SceneDetectBuf *buf)
157 {
158  SceneDetectVulkanContext *s = ctx->priv;
159  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->vkctx.input_format);
160  const AVFilterLink *inlink = ctx->inputs[0];
161  uint64_t count;
162  double mafd, diff;
163 
164  uint64_t sad = 0;
165  for (int i = 0; i < SLICES; i++)
166  sad += buf->frame_sad[i];
167 
168  av_assert2(s->nb_planes == 1 || !(desc->log2_chroma_w || desc->log2_chroma_h));
169  count = s->nb_planes * inlink->w * inlink->h;
170  mafd = (double) sad * 100.0 / count / (1ULL << desc->comp[0].depth);
171  diff = fabs(mafd - s->prev_mafd);
172  s->prev_mafd = mafd;
173 
174  return av_clipf(FFMIN(mafd, diff), 0.0, 100.0);
175 }
176 
178 {
179  int err;
180  AVFilterContext *ctx = link->dst;
181  SceneDetectVulkanContext *s = ctx->priv;
182  AVFilterLink *outlink = ctx->outputs[0];
183 
184  VkImageView prev_views[AV_NUM_DATA_POINTERS];
185  VkImageView cur_views[AV_NUM_DATA_POINTERS];
186  VkImageMemoryBarrier2 img_bar[8];
187  int nb_img_bar = 0;
188 
189  FFVulkanContext *vkctx = &s->vkctx;
190  FFVulkanFunctions *vk = &vkctx->vkfn;
191  FFVkExecContext *exec = NULL;
192  AVBufferRef *buf = NULL;
193  FFVkBuffer *buf_vk;
194 
195  SceneDetectBuf *sad;
196  double score = 0.0;
197  char str[64];
198 
199  if (!s->initialized)
200  RET(init_filter(ctx));
201 
202  av_frame_free(&s->prev);
203  s->prev = s->cur;
204  s->cur = av_frame_clone(in);
205  if (!s->prev)
206  goto done;
207 
208  RET(ff_vk_get_pooled_buffer(vkctx, &s->det_buf_pool, &buf,
209  VK_BUFFER_USAGE_TRANSFER_DST_BIT |
210  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
211  NULL,
212  sizeof(SceneDetectBuf),
213  VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
214  VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
215  VK_MEMORY_PROPERTY_HOST_COHERENT_BIT));
216  buf_vk = (FFVkBuffer *)buf->data;
217  sad = (SceneDetectBuf *) buf_vk->mapped_mem;
218 
219  exec = ff_vk_exec_get(vkctx, &s->e);
220  ff_vk_exec_start(vkctx, exec);
221 
222  RET(ff_vk_exec_add_dep_frame(vkctx, exec, s->prev,
223  VK_PIPELINE_STAGE_2_NONE,
224  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
225  RET(ff_vk_create_imageviews(vkctx, exec, prev_views, s->prev, FF_VK_REP_UINT));
226 
227  ff_vk_shader_update_img_array(vkctx, exec, &s->shd, s->prev, prev_views, 0, 0,
228  VK_IMAGE_LAYOUT_GENERAL, VK_NULL_HANDLE);
229 
230  ff_vk_frame_barrier(vkctx, exec, s->prev, img_bar, &nb_img_bar,
231  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
232  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
233  VK_ACCESS_SHADER_READ_BIT,
234  VK_IMAGE_LAYOUT_GENERAL,
235  VK_QUEUE_FAMILY_IGNORED);
236 
237  RET(ff_vk_exec_add_dep_frame(vkctx, exec, s->cur,
238  VK_PIPELINE_STAGE_2_NONE,
239  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
240  RET(ff_vk_create_imageviews(vkctx, exec, cur_views, s->cur, FF_VK_REP_UINT));
241 
242  ff_vk_shader_update_img_array(vkctx, exec, &s->shd, s->cur, cur_views, 0, 1,
243  VK_IMAGE_LAYOUT_GENERAL, VK_NULL_HANDLE);
244 
245  ff_vk_frame_barrier(vkctx, exec, s->cur, img_bar, &nb_img_bar,
246  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
247  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
248  VK_ACCESS_SHADER_READ_BIT,
249  VK_IMAGE_LAYOUT_GENERAL,
250  VK_QUEUE_FAMILY_IGNORED);
251 
252  /* zero buffer */
253  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
254  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
255  .pBufferMemoryBarriers = &(VkBufferMemoryBarrier2) {
256  .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2,
257  .srcStageMask = VK_PIPELINE_STAGE_2_NONE,
258  .dstStageMask = VK_PIPELINE_STAGE_2_TRANSFER_BIT,
259  .dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
260  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
261  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
262  .buffer = buf_vk->buf,
263  .size = buf_vk->size,
264  .offset = 0,
265  },
266  .bufferMemoryBarrierCount = 1,
267  });
268 
269  vk->CmdFillBuffer(exec->buf, buf_vk->buf, 0, buf_vk->size, 0x0);
270 
271  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
272  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
273  .pImageMemoryBarriers = img_bar,
274  .imageMemoryBarrierCount = nb_img_bar,
275  .pBufferMemoryBarriers = &(VkBufferMemoryBarrier2) {
276  .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2,
277  .srcStageMask = VK_PIPELINE_STAGE_2_TRANSFER_BIT,
278  .dstStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
279  .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
280  .dstAccessMask = VK_ACCESS_2_SHADER_STORAGE_READ_BIT |
281  VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT,
282  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
283  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
284  .buffer = buf_vk->buf,
285  .size = buf_vk->size,
286  .offset = 0,
287  },
288  .bufferMemoryBarrierCount = 1,
289  });
290 
291  RET(ff_vk_shader_update_desc_buffer(&s->vkctx, exec, &s->shd, 0, 2, 0,
292  buf_vk, 0, buf_vk->size,
293  VK_FORMAT_UNDEFINED));
294 
295  ff_vk_exec_bind_shader(vkctx, exec, &s->shd);
296 
297  vk->CmdDispatch(exec->buf,
298  FFALIGN(in->width, s->shd.lg_size[0]) / s->shd.lg_size[0],
299  FFALIGN(in->height, s->shd.lg_size[1]) / s->shd.lg_size[1],
300  s->shd.lg_size[2]);
301 
302  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
303  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
304  .pBufferMemoryBarriers = &(VkBufferMemoryBarrier2) {
305  .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2,
306  .srcStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
307  .dstStageMask = VK_PIPELINE_STAGE_2_HOST_BIT,
308  .srcAccessMask = VK_ACCESS_2_SHADER_STORAGE_READ_BIT |
309  VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT,
310  .dstAccessMask = VK_ACCESS_HOST_READ_BIT,
311  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
312  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
313  .buffer = buf_vk->buf,
314  .size = buf_vk->size,
315  .offset = 0,
316  },
317  .bufferMemoryBarrierCount = 1,
318  });
319 
320  RET(ff_vk_exec_submit(vkctx, exec));
321  ff_vk_exec_wait(vkctx, exec);
322  score = evaluate(ctx, sad);
323 
324 done:
325  snprintf(str, sizeof(str), "%0.3f", s->prev_mafd);
326  av_dict_set(&in->metadata, "lavfi.scd.mafd", str, 0);
327  snprintf(str, sizeof(str), "%0.3f", score);
328  av_dict_set(&in->metadata, "lavfi.scd.score", str, 0);
329 
330  if (score >= s->threshold) {
331  const char *pts = av_ts2timestr(in->pts, &link->time_base);
332  av_dict_set(&in->metadata, "lavfi.scd.time", pts, 0);
333  av_log(s, AV_LOG_INFO, "lavfi.scd.score: %.3f, lavfi.scd.time: %s\n",
334  score, pts);
335  }
336 
337  av_buffer_unref(&buf);
338  if (!s->sc_pass || score >= s->threshold)
339  return ff_filter_frame(outlink, in);
340  else {
341  av_frame_free(&in);
342  return 0;
343  }
344 
345 fail:
346  if (exec)
347  ff_vk_exec_discard_deps(&s->vkctx, exec);
348  av_frame_free(&in);
349  av_buffer_unref(&buf);
350  return err;
351 }
352 
354 {
355  SceneDetectVulkanContext *s = avctx->priv;
356  FFVulkanContext *vkctx = &s->vkctx;
357 
358  av_frame_free(&s->prev);
359  av_frame_free(&s->cur);
360 
361  ff_vk_exec_pool_free(vkctx, &s->e);
362  ff_vk_shader_free(vkctx, &s->shd);
363 
364  av_buffer_pool_uninit(&s->det_buf_pool);
365 
366  ff_vk_uninit(&s->vkctx);
367 
368  s->initialized = 0;
369 }
370 
371 #define OFFSET(x) offsetof(SceneDetectVulkanContext, x)
372 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
373 static const AVOption scdet_vulkan_options[] = {
374  { "threshold", "set scene change detect threshold", OFFSET(threshold), AV_OPT_TYPE_DOUBLE, {.dbl = 10.}, 0, 100., FLAGS },
375  { "t", "set scene change detect threshold", OFFSET(threshold), AV_OPT_TYPE_DOUBLE, {.dbl = 10.}, 0, 100., FLAGS },
376  { "sc_pass", "Set the flag to pass scene change frames", OFFSET(sc_pass), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, FLAGS },
377  { "s", "Set the flag to pass scene change frames", OFFSET(sc_pass), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, FLAGS },
378  { NULL }
379 };
380 
381 AVFILTER_DEFINE_CLASS(scdet_vulkan);
382 
384  {
385  .name = "default",
386  .type = AVMEDIA_TYPE_VIDEO,
387  .filter_frame = &scdet_vulkan_filter_frame,
388  .config_props = &ff_vk_filter_config_input,
389  },
390 };
391 
393  {
394  .name = "default",
395  .type = AVMEDIA_TYPE_VIDEO,
396  .config_props = &ff_vk_filter_config_output,
397  },
398 };
399 
401  .p.name = "scdet_vulkan",
402  .p.description = NULL_IF_CONFIG_SMALL("Detect video scene change"),
403  .p.priv_class = &scdet_vulkan_class,
404  .p.flags = AVFILTER_FLAG_HWDEVICE,
405  .priv_size = sizeof(SceneDetectVulkanContext),
411  .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
412 };
SceneDetectVulkanContext::det_buf_pool
AVBufferPool * det_buf_pool
Definition: vf_scdet_vulkan.c:36
scdet_vulkan_uninit
static void scdet_vulkan_uninit(AVFilterContext *avctx)
Definition: vf_scdet_vulkan.c:353
AVERROR
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
opt.h
ff_vk_shader_free
void ff_vk_shader_free(FFVulkanContext *s, FFVulkanShader *shd)
Free a shader.
Definition: vulkan.c:2921
ff_vk_shader_init
int ff_vk_shader_init(FFVulkanContext *s, FFVulkanShader *shd, const char *name, VkPipelineStageFlags stage, const char *extensions[], int nb_extensions, int lg_x, int lg_y, int lg_z, uint32_t required_subgroup_size)
Initialize a shader object, with a specific set of extensions, type+bind, local group size,...
Definition: vulkan.c:2054
AVBufferPool
The buffer pool.
Definition: buffer_internal.h:88
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1062
SceneDetectVulkanContext::prev
AVFrame * prev
Definition: vf_scdet_vulkan.c:43
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3341
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
RET
#define RET(x)
Definition: vulkan.h:66
ff_vk_exec_pool_init
int ff_vk_exec_pool_init(FFVulkanContext *s, AVVulkanDeviceQueueFamily *qf, FFVkExecPool *pool, int nb_contexts, int nb_queries, VkQueryType query_type, int query_64bit, const void *query_create_pnext)
Allocates/frees an execution pool.
Definition: vulkan.c:356
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(scdet_vulkan)
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:63
SceneDetectVulkanContext::vkctx
FFVulkanContext vkctx
Definition: vf_scdet_vulkan.c:30
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:262
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:410
ff_vk_filter_init
int ff_vk_filter_init(AVFilterContext *avctx)
General lavfi IO functions.
Definition: vulkan_filter.c:233
SceneDetectVulkanContext::prev_mafd
double prev_mafd
Definition: vf_scdet_vulkan.c:42
AVOption
AVOption.
Definition: opt.h:429
evaluate
static double evaluate(AVFilterContext *ctx, const SceneDetectBuf *buf)
Definition: vf_scdet_vulkan.c:156
ff_vk_exec_get
FFVkExecContext * ff_vk_exec_get(FFVulkanContext *s, FFVkExecPool *pool)
Retrieve an execution pool.
Definition: vulkan.c:547
ff_vk_uninit
void ff_vk_uninit(FFVulkanContext *s)
Frees main context.
Definition: vulkan.c:2962
FFVkSPIRVCompiler::uninit
void(* uninit)(struct FFVkSPIRVCompiler **ctx)
Definition: vulkan_spirv.h:32
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:215
AV_PIX_FMT_VULKAN
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
Definition: pixfmt.h:379
ff_vk_exec_add_dep_frame
int ff_vk_exec_add_dep_frame(FFVulkanContext *s, FFVkExecContext *e, AVFrame *f, VkPipelineStageFlagBits2 wait_stage, VkPipelineStageFlagBits2 signal_stage)
Definition: vulkan.c:779
SceneDetectVulkanContext::initialized
int initialized
Definition: vf_scdet_vulkan.c:32
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3381
AVFilterContext::priv
void * priv
private data for use by the filter
Definition: avfilter.h:284
u
#define u(width, name, range_min, range_max)
Definition: cbs_apv.c:83
fail
#define fail()
Definition: checkasm.h:196
vulkan_filter.h
ff_vk_shader_update_img_array
void ff_vk_shader_update_img_array(FFVulkanContext *s, FFVkExecContext *e, FFVulkanShader *shd, AVFrame *f, VkImageView *views, int set, int binding, VkImageLayout layout, VkSampler sampler)
Update a descriptor in a buffer with an image array.
Definition: vulkan.c:2798
ff_vk_shader_register_exec
int ff_vk_shader_register_exec(FFVulkanContext *s, FFVkExecPool *pool, FFVulkanShader *shd)
Register a shader with an exec pool.
Definition: vulkan.c:2561
ff_vk_shader_add_descriptor_set
int ff_vk_shader_add_descriptor_set(FFVulkanContext *s, FFVulkanShader *shd, FFVulkanDescriptorSetBinding *desc, int nb, int singular, int print_to_shader_only)
Add descriptor to a shader.
Definition: vulkan.c:2426
pts
static int64_t pts
Definition: transcode_aac.c:644
AVFilterPad
A filter pad used for either input or output.
Definition: filters.h:38
avassert.h
GLSLC
#define GLSLC(N, S)
Definition: vulkan.h:43
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
av_cold
#define av_cold
Definition: attributes.h:90
main
int main
Definition: dovi_rpuenc.c:38
FFFilter
Definition: filters.h:265
scdet_vulkan_filter_frame
static int scdet_vulkan_filter_frame(AVFilterLink *link, AVFrame *in)
Definition: vf_scdet_vulkan.c:177
s
#define s(width, name)
Definition: cbs_vp9.c:198
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
Definition: opt.h:267
ff_vk_exec_wait
void ff_vk_exec_wait(FFVulkanContext *s, FFVkExecContext *e)
Definition: vulkan.c:552
filters.h
ctx
AVFormatContext * ctx
Definition: movenc.c:49
av_frame_clone
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:481
SceneDetectVulkanContext::e
FFVkExecPool e
Definition: vf_scdet_vulkan.c:33
ff_vk_exec_pool_free
void ff_vk_exec_pool_free(FFVulkanContext *s, FFVkExecPool *pool)
Definition: vulkan.c:287
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:263
link
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 link
Definition: filter_design.txt:23
SceneDetectVulkanContext::sc_pass
int sc_pass
Definition: vf_scdet_vulkan.c:39
ff_vk_shader_rep_fmt
const char * ff_vk_shader_rep_fmt(enum AVPixelFormat pix_fmt, enum FFVkShaderRepFormat rep_fmt)
Definition: vulkan.c:1588
fabs
static __device__ float fabs(float a)
Definition: cuda_runtime.h:182
NULL
#define NULL
Definition: coverity.c:32
av_buffer_unref
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition: buffer.c:139
FLAGS
#define FLAGS
Definition: vf_scdet_vulkan.c:372
SceneDetectVulkanContext::nb_planes
int nb_planes
Definition: vf_scdet_vulkan.c:41
av_buffer_pool_uninit
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
Definition: buffer.c:328
ff_vk_filter_config_output
int ff_vk_filter_config_output(AVFilterLink *outlink)
Definition: vulkan_filter.c:209
double
double
Definition: af_crystalizer.c:132
abs
#define abs(x)
Definition: cuda_runtime.h:35
av_clipf
av_clipf
Definition: af_crystalizer.c:122
FFVkBuffer::mapped_mem
uint8_t * mapped_mem
Definition: vulkan.h:100
FFVulkanContext
Definition: vulkan.h:274
AVPixFmtDescriptor::flags
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:94
SceneDetectBuf::frame_sad
uint32_t frame_sad[SLICES]
Definition: vf_scdet_vulkan.c:49
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:206
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
av_ts2timestr
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: timestamp.h:83
FFVulkanDescriptorSetBinding
Definition: vulkan.h:74
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
AV_PIX_FMT_FLAG_RGB
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
Definition: pixdesc.h:136
AVFILTER_FLAG_HWDEVICE
#define AVFILTER_FLAG_HWDEVICE
The filter can create hardware frames using AVFilterContext.hw_device_ctx.
Definition: avfilter.h:183
AV_NUM_DATA_POINTERS
#define AV_NUM_DATA_POINTERS
Definition: frame.h:411
FFVulkanShader
Definition: vulkan.h:190
OFFSET
#define OFFSET(x)
Definition: vf_scdet_vulkan.c:371
AVFrame::time_base
AVRational time_base
Time base for the timestamps in this frame.
Definition: frame.h:527
SceneDetectVulkanContext::qf
AVVulkanDeviceQueueFamily * qf
Definition: vf_scdet_vulkan.c:34
diff
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
Definition: vf_paletteuse.c:166
FFVkSPIRVCompiler::compile_shader
int(* compile_shader)(FFVulkanContext *s, struct FFVkSPIRVCompiler *ctx, FFVulkanShader *shd, uint8_t **data, size_t *size, const char *entrypoint, void **opaque)
Definition: vulkan_spirv.h:28
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:59
FFVkExecContext
Definition: vulkan.h:111
ff_vk_shader_update_desc_buffer
int ff_vk_shader_update_desc_buffer(FFVulkanContext *s, FFVkExecContext *e, FFVulkanShader *shd, int set, int bind, int elem, FFVkBuffer *buf, VkDeviceSize offset, VkDeviceSize len, VkFormat fmt)
Update a descriptor in a buffer with a buffer.
Definition: vulkan.c:2811
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:221
FFVkSPIRVCompiler
Definition: vulkan_spirv.h:26
av_assert2
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:68
uninit
static void uninit(AVBSFContext *ctx)
Definition: pcm_rechunk.c:68
ff_vk_exec_start
int ff_vk_exec_start(FFVulkanContext *s, FFVkExecContext *e)
Start/submit/wait an execution.
Definition: vulkan.c:559
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
FF_VK_REP_UINT
@ FF_VK_REP_UINT
Definition: vulkan.h:412
SceneDetectVulkanContext::threshold
double threshold
Definition: vf_scdet_vulkan.c:38
ff_vk_frame_barrier
void ff_vk_frame_barrier(FFVulkanContext *s, FFVkExecContext *e, AVFrame *pic, VkImageMemoryBarrier2 *bar, int *nb_bar, VkPipelineStageFlags src_stage, VkPipelineStageFlags dst_stage, VkAccessFlagBits new_access, VkImageLayout new_layout, uint32_t new_qf)
Definition: vulkan.c:2011
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
ff_vk_shader_link
int ff_vk_shader_link(FFVulkanContext *s, FFVulkanShader *shd, uint8_t *spirv, size_t spirv_len, const char *entrypoint)
Link a shader into an executable.
Definition: vulkan.c:2351
SceneDetectVulkanContext
Definition: vf_scdet_vulkan.c:29
vulkan_spirv.h
AVFilterPad::name
const char * name
Pad name.
Definition: filters.h:44
SceneDetectVulkanContext::shd
FFVulkanShader shd
Definition: vf_scdet_vulkan.c:35
FFVkSPIRVCompiler::free_shader
void(* free_shader)(struct FFVkSPIRVCompiler *ctx, void **opaque)
Definition: vulkan_spirv.h:31
ff_vk_exec_bind_shader
void ff_vk_exec_bind_shader(FFVulkanContext *s, FFVkExecContext *e, FFVulkanShader *shd)
Bind a shader.
Definition: vulkan.c:2887
ff_vk_create_imageviews
int ff_vk_create_imageviews(FFVulkanContext *s, FFVkExecContext *e, VkImageView views[AV_NUM_DATA_POINTERS], AVFrame *f, enum FFVkShaderRepFormat rep_fmt)
Create an imageview and add it as a dependency to an execution.
Definition: vulkan.c:1928
SceneDetectBuf
Definition: vf_scdet_vulkan.c:47
FFVulkanContext::vkfn
FFVulkanFunctions vkfn
Definition: vulkan.h:278
FFVkExecPool
Definition: vulkan.h:252
pos
unsigned int pos
Definition: spdifenc.c:414
ff_vk_qf_find
AVVulkanDeviceQueueFamily * ff_vk_qf_find(FFVulkanContext *s, VkQueueFlagBits dev_family, VkVideoCodecOperationFlagBitsKHR vid_ops)
Chooses an appropriate QF.
Definition: vulkan.c:274
ff_vf_scdet_vulkan
const FFFilter ff_vf_scdet_vulkan
Definition: vf_scdet_vulkan.c:400
FFVkExecContext::buf
VkCommandBuffer buf
Definition: vulkan.h:122
GLSLF
#define GLSLF(N, S,...)
Definition: vulkan.h:53
SLICES
#define SLICES
Definition: vf_scdet_vulkan.c:48
AV_PIX_FMT_FLAG_PLANAR
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
Definition: pixdesc.h:132
scdet_vulkan_outputs
static const AVFilterPad scdet_vulkan_outputs[]
Definition: vf_scdet_vulkan.c:392
scdet_vulkan_options
static const AVOption scdet_vulkan_options[]
Definition: vf_scdet_vulkan.c:373
AVFilterContext
An instance of a filter.
Definition: avfilter.h:269
desc
const char * desc
Definition: libsvtav1.c:79
ff_vk_filter_config_input
int ff_vk_filter_config_input(AVFilterLink *inlink)
Definition: vulkan_filter.c:176
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
FFFilter::p
AVFilter p
The public AVFilter.
Definition: filters.h:269
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
init_filter
static av_cold int init_filter(AVFilterContext *ctx)
Definition: vf_scdet_vulkan.c:52
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
atomicAdd
#define atomicAdd(a, b)
Definition: cuda_runtime.h:37
ff_vk_exec_discard_deps
void ff_vk_exec_discard_deps(FFVulkanContext *s, FFVkExecContext *e)
Definition: vulkan.c:591
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:327
av_dict_set
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:86
SceneDetectVulkanContext::cur
AVFrame * cur
Definition: vf_scdet_vulkan.c:44
FFVkBuffer
Definition: vulkan.h:87
timestamp.h
ff_vk_exec_submit
int ff_vk_exec_submit(FFVulkanContext *s, FFVkExecContext *e)
Definition: vulkan.c:904
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVVulkanDeviceQueueFamily
Definition: hwcontext_vulkan.h:33
FILTER_SINGLE_PIXFMT
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
Definition: filters.h:252
snprintf
#define snprintf
Definition: snprintf.h:34
scdet_vulkan_inputs
static const AVFilterPad scdet_vulkan_inputs[]
Definition: vf_scdet_vulkan.c:383
FFVulkanFunctions
Definition: vulkan_functions.h:274
ff_vk_get_pooled_buffer
int ff_vk_get_pooled_buffer(FFVulkanContext *ctx, AVBufferPool **buf_pool, AVBufferRef **buf, VkBufferUsageFlags usage, void *create_pNext, size_t size, VkMemoryPropertyFlagBits mem_props)
Initialize a pool and create AVBufferRefs containing FFVkBuffer.
Definition: vulkan.c:1254