FFmpeg
vf_blackdetect_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 <float.h>
22 #include "libavutil/opt.h"
23 #include "libavutil/timestamp.h"
24 #include "vulkan_filter.h"
25 
26 #include "filters.h"
27 
28 extern const unsigned char ff_blackdetect_comp_spv_data[];
29 extern const unsigned int ff_blackdetect_comp_spv_len;
30 
31 typedef struct BlackDetectVulkanContext {
33 
39 
42  int alpha;
43 
44  int64_t black_start; ///< pts start time of the first black picture
45  int64_t last_pts; ///< pts of the last filtered frame
46  double black_min_duration_time; ///< minimum duration of detected black, in seconds
47  int64_t black_min_duration; ///< minimum duration of detected black, expressed in timebase units
50 
51 typedef struct BlackDetectPushData {
52  float threshold;
54 
55 typedef struct BlackDetectBuf {
56 #define SLICES 16
57  uint32_t slice_sum[SLICES];
59 
61 {
62  int err;
64  FFVulkanContext *vkctx = &s->vkctx;
65  const AVFilterLink *inlink = ctx->inputs[0];
66  const int plane = s->alpha ? 3 : 0;
67 
68  const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(s->vkctx.input_format);
69  if (pixdesc->flags & AV_PIX_FMT_FLAG_RGB) {
70  av_log(ctx, AV_LOG_ERROR, "RGB inputs are not supported\n");
71  return AVERROR(ENOTSUP);
72  }
73 
74  s->qf = ff_vk_qf_find(vkctx, VK_QUEUE_COMPUTE_BIT, 0);
75  if (!s->qf) {
76  av_log(ctx, AV_LOG_ERROR, "Device has no compute queues\n");
77  err = AVERROR(ENOTSUP);
78  goto fail;
79  }
80 
81  RET(ff_vk_exec_pool_init(vkctx, s->qf, &s->e, FF_VK_DEFAULT_EXEC_CONTEXTS, 0, 0, 0, NULL));
82 
83  SPEC_LIST_CREATE(sl, 2, 2*sizeof(uint32_t))
84  SPEC_LIST_ADD(sl, 0, 32, plane);
85  SPEC_LIST_ADD(sl, 1, 32, SLICES);
86 
87  ff_vk_shader_load(&s->shd, VK_SHADER_STAGE_COMPUTE_BIT, sl,
88  (int []) { 32, 32, 1 }, 0);
89 
91  VK_SHADER_STAGE_COMPUTE_BIT);
92 
94  { /* input_img */
95  .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
96  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
97  .elems = av_pix_fmt_count_planes(s->vkctx.input_format),
98  },
99  { /* sum_buffer */
100  .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
101  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
102  }
103  };
104  ff_vk_shader_add_descriptor_set(vkctx, &s->shd, desc, 2, 0);
105 
106  RET(ff_vk_shader_link(vkctx, &s->shd,
108  ff_blackdetect_comp_spv_len, "main"));
109 
110  RET(ff_vk_shader_register_exec(vkctx, &s->e, &s->shd));
111 
112  s->time_base = inlink->time_base;
113  s->black_min_duration = s->black_min_duration_time / av_q2d(s->time_base);
114  s->black_start = AV_NOPTS_VALUE;
115  s->initialized = 1;
116 
117 fail:
118  return err;
119 }
120 
122 {
123  BlackDetectVulkanContext *s = ctx->priv;
124 
125  if (s->black_start == AV_NOPTS_VALUE)
126  return;
127 
128  if ((black_end - s->black_start) >= s->black_min_duration) {
130  "black_start:%s black_end:%s black_duration:%s\n",
131  av_ts2timestr(s->black_start, &s->time_base),
132  av_ts2timestr(black_end, &s->time_base),
133  av_ts2timestr(black_end - s->black_start, &s->time_base));
134  }
135 }
136 
137 static void evaluate(AVFilterLink *link, AVFrame *in,
138  const BlackDetectBuf *sum)
139 {
140  AVFilterContext *ctx = link->dst;
141  BlackDetectVulkanContext *s = ctx->priv;
143  uint64_t nb_black_pixels = 0;
144  double ratio;
145 
146  for (int i = 0; i < FF_ARRAY_ELEMS(sum->slice_sum); i++)
147  nb_black_pixels += sum->slice_sum[i];
148 
149  ratio = (double) nb_black_pixels / (link->w * link->h);
150 
152  "frame:%"PRId64" picture_black_ratio:%f pts:%s t:%s type:%c\n",
153  inl->frame_count_out, ratio,
154  av_ts2str(in->pts), av_ts2timestr(in->pts, &in->time_base),
156 
157  if (ratio >= s->picture_black_ratio_th) {
158  if (s->black_start == AV_NOPTS_VALUE) {
159  s->black_start = in->pts;
160  av_dict_set(&in->metadata, "lavfi.black_start",
161  av_ts2timestr(in->pts, &in->time_base), 0);
162  }
163  } else if (s->black_start != AV_NOPTS_VALUE) {
165  av_dict_set(&in->metadata, "lavfi.black_end",
166  av_ts2timestr(in->pts, &in->time_base), 0);
167  s->black_start = AV_NOPTS_VALUE;
168  }
169 }
170 
172 {
173  int err;
174  AVFilterContext *ctx = link->dst;
175  BlackDetectVulkanContext *s = ctx->priv;
176  AVFilterLink *outlink = ctx->outputs[0];
177 
178  VkImageView in_views[AV_NUM_DATA_POINTERS];
179  VkImageMemoryBarrier2 img_bar[4];
180  int nb_img_bar = 0;
181 
182  FFVulkanContext *vkctx = &s->vkctx;
183  FFVulkanFunctions *vk = &vkctx->vkfn;
184  FFVkExecContext *exec = NULL;
185  FFVkBuffer *sum_vk = NULL;
186 
187  BlackDetectBuf *sum;
188  BlackDetectPushData push_data;
189 
190  if (in->color_range == AVCOL_RANGE_JPEG || s->alpha) {
191  push_data.threshold = s->pixel_black_th;
192  } else {
194  const int depth = desc->comp[0].depth;
195  const int ymin = 16 << (depth - 8);
196  const int ymax = 235 << (depth - 8);
197  const int imax = (1 << depth) - 1;
198  push_data.threshold = (s->pixel_black_th * (ymax - ymin) + ymin) / imax;
199  }
200 
201  if (!s->initialized)
202  RET(init_filter(ctx));
203 
204  err = ff_vk_get_pooled_buffer(vkctx, &s->sum_buf_pool, &sum_vk,
205  VK_BUFFER_USAGE_TRANSFER_DST_BIT |
206  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
207  NULL,
208  sizeof(BlackDetectBuf),
209  VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
210  VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
211  VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
212  if (err < 0)
213  return err;
214  sum = (BlackDetectBuf *) sum_vk->mapped_mem;
215 
216  exec = ff_vk_exec_get(vkctx, &s->e);
217  ff_vk_exec_start(vkctx, exec);
218 
219  RET(ff_vk_exec_add_dep_frame(vkctx, exec, in,
220  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
221  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
222  RET(ff_vk_create_imageviews(vkctx, exec, in_views, in, FF_VK_REP_FLOAT));
223 
224  ff_vk_shader_update_img_array(vkctx, exec, &s->shd, in, in_views, 0, 0,
225  VK_IMAGE_LAYOUT_GENERAL, VK_NULL_HANDLE);
226 
227  ff_vk_frame_barrier(vkctx, exec, in, img_bar, &nb_img_bar,
228  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
229  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
230  VK_ACCESS_SHADER_READ_BIT,
231  VK_IMAGE_LAYOUT_GENERAL,
232  VK_QUEUE_FAMILY_IGNORED);
233 
234  /* zero sum buffer */
235  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
236  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
237  .pBufferMemoryBarriers = &(VkBufferMemoryBarrier2) {
238  .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2,
239  .srcStageMask = VK_PIPELINE_STAGE_2_NONE,
240  .dstStageMask = VK_PIPELINE_STAGE_2_TRANSFER_BIT,
241  .dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
242  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
243  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
244  .buffer = sum_vk->buf,
245  .size = sum_vk->size,
246  .offset = 0,
247  },
248  .bufferMemoryBarrierCount = 1,
249  });
250 
251  vk->CmdFillBuffer(exec->buf, sum_vk->buf, 0, sum_vk->size, 0x0);
252 
253  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
254  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
255  .pImageMemoryBarriers = img_bar,
256  .imageMemoryBarrierCount = nb_img_bar,
257  .pBufferMemoryBarriers = &(VkBufferMemoryBarrier2) {
258  .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2,
259  .srcStageMask = VK_PIPELINE_STAGE_2_TRANSFER_BIT,
260  .dstStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
261  .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
262  .dstAccessMask = VK_ACCESS_2_SHADER_STORAGE_READ_BIT |
263  VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT,
264  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
265  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
266  .buffer = sum_vk->buf,
267  .size = sum_vk->size,
268  .offset = 0,
269  },
270  .bufferMemoryBarrierCount = 1,
271  });
272 
273  RET(ff_vk_shader_update_desc_buffer(&s->vkctx, exec, &s->shd, 0, 1, 0,
274  sum_vk, 0, sum_vk->size,
275  VK_FORMAT_UNDEFINED));
276 
277  ff_vk_exec_bind_shader(vkctx, exec, &s->shd);
278  ff_vk_shader_update_push_const(vkctx, exec, &s->shd, VK_SHADER_STAGE_COMPUTE_BIT,
279  0, sizeof(push_data), &push_data);
280 
281  vk->CmdDispatch(exec->buf,
282  FFALIGN(in->width, s->shd.lg_size[0]) / s->shd.lg_size[0],
283  FFALIGN(in->height, s->shd.lg_size[1]) / s->shd.lg_size[1],
284  s->shd.lg_size[2]);
285 
286  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
287  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
288  .pBufferMemoryBarriers = &(VkBufferMemoryBarrier2) {
289  .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2,
290  .srcStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
291  .dstStageMask = VK_PIPELINE_STAGE_2_HOST_BIT,
292  .srcAccessMask = VK_ACCESS_2_SHADER_STORAGE_READ_BIT |
293  VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT,
294  .dstAccessMask = VK_ACCESS_HOST_READ_BIT,
295  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
296  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
297  .buffer = sum_vk->buf,
298  .size = sum_vk->size,
299  .offset = 0,
300  },
301  .bufferMemoryBarrierCount = 1,
302  });
303 
304  RET(ff_vk_exec_submit(vkctx, exec));
305  ff_vk_exec_wait(vkctx, exec);
306  evaluate(link, in, sum);
307  s->last_pts = in->pts;
308 
309  av_refstruct_unref(&sum_vk);
310  return ff_filter_frame(outlink, in);
311 
312 fail:
313  if (exec)
314  ff_vk_exec_discard_deps(&s->vkctx, exec);
315  av_frame_free(&in);
316  av_refstruct_unref(&sum_vk);
317  return err;
318 }
319 
321 {
322  BlackDetectVulkanContext *s = avctx->priv;
323  FFVulkanContext *vkctx = &s->vkctx;
324 
325  /* the input link may be gone here: during graph teardown the upstream
326  * filter can be freed first. Use the cached pts of the last frame */
327  if (s->initialized)
328  report_black_region(avctx, s->last_pts);
329 
330  ff_vk_exec_pool_free(vkctx, &s->e);
331  ff_vk_shader_free(vkctx, &s->shd);
332 
333  av_refstruct_pool_uninit(&s->sum_buf_pool);
334 
335  ff_vk_uninit(&s->vkctx);
336 
337  s->initialized = 0;
338 }
339 
340 static int config_output(AVFilterLink *outlink)
341 {
342  AVFilterContext *ctx = outlink->src;
343  BlackDetectVulkanContext *s = ctx->priv;
344  FFVulkanContext *vkctx = &s->vkctx;
346 
347  if (s->alpha && !(desc->flags & AV_PIX_FMT_FLAG_ALPHA)) {
348  av_log(ctx, AV_LOG_ERROR, "Input format %s does not have an alpha channel\n",
350  return AVERROR(EINVAL);
351  }
352 
353  if (desc->flags & (AV_PIX_FMT_FLAG_RGB | AV_PIX_FMT_FLAG_XYZ) ||
354  !(desc->flags & AV_PIX_FMT_FLAG_PLANAR)) {
355  av_log(ctx, AV_LOG_ERROR, "Input format %s is not planar YUV\n",
357  return AVERROR(EINVAL);
358  }
359 
360  return ff_vk_filter_config_output(outlink);
361 }
362 
363 #define OFFSET(x) offsetof(BlackDetectVulkanContext, x)
364 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
366  { "d", "set minimum detected black duration in seconds", OFFSET(black_min_duration_time), AV_OPT_TYPE_DOUBLE, {.dbl=2}, 0, DBL_MAX, FLAGS },
367  { "black_min_duration", "set minimum detected black duration in seconds", OFFSET(black_min_duration_time), AV_OPT_TYPE_DOUBLE, {.dbl=2}, 0, DBL_MAX, FLAGS },
368  { "picture_black_ratio_th", "set the picture black ratio threshold", OFFSET(picture_black_ratio_th), AV_OPT_TYPE_DOUBLE, {.dbl=.98}, 0, 1, FLAGS },
369  { "pic_th", "set the picture black ratio threshold", OFFSET(picture_black_ratio_th), AV_OPT_TYPE_DOUBLE, {.dbl=.98}, 0, 1, FLAGS },
370  { "pixel_black_th", "set the pixel black threshold", OFFSET(pixel_black_th), AV_OPT_TYPE_DOUBLE, {.dbl=.10}, 0, 1, FLAGS },
371  { "pix_th", "set the pixel black threshold", OFFSET(pixel_black_th), AV_OPT_TYPE_DOUBLE, {.dbl=.10}, 0, 1, FLAGS },
372  { "alpha", "check alpha instead of luma", OFFSET(alpha), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
373  { NULL }
374 };
375 
376 AVFILTER_DEFINE_CLASS(blackdetect_vulkan);
377 
379  {
380  .name = "default",
381  .type = AVMEDIA_TYPE_VIDEO,
382  .filter_frame = &blackdetect_vulkan_filter_frame,
383  .config_props = &ff_vk_filter_config_input,
384  },
385 };
386 
388  {
389  .name = "default",
390  .type = AVMEDIA_TYPE_VIDEO,
391  .config_props = &config_output,
392  },
393 };
394 
396  .p.name = "blackdetect_vulkan",
397  .p.description = NULL_IF_CONFIG_SMALL("Detect video intervals that are (almost) black."),
398  .p.priv_class = &blackdetect_vulkan_class,
399  .p.flags = AVFILTER_FLAG_HWDEVICE,
400  .priv_size = sizeof(BlackDetectVulkanContext),
406  .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
407 };
init_filter
static av_cold int init_filter(AVFilterContext *ctx)
Definition: vf_blackdetect_vulkan.c:60
AVFrame::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: frame.h:723
BlackDetectVulkanContext::shd
FFVulkanShader shd
Definition: vf_blackdetect_vulkan.c:37
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:2614
BlackDetectVulkanContext::pixel_black_th
double pixel_black_th
Definition: vf_blackdetect_vulkan.c:41
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1068
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3460
RET
#define RET(x)
Definition: vulkan.h:37
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:357
av_cold
#define av_cold
Definition: attributes.h:119
int64_t
long long int64_t
Definition: coverity.c:34
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
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:208
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:64
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:472
ff_vf_blackdetect_vulkan
const FFFilter ff_vf_blackdetect_vulkan
Definition: vf_blackdetect_vulkan.c:395
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:574
ff_vk_filter_init
int ff_vk_filter_init(AVFilterContext *avctx)
General lavfi IO functions.
Definition: vulkan_filter.c:233
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:783
BlackDetectVulkanContext::last_pts
int64_t last_pts
pts of the last filtered frame
Definition: vf_blackdetect_vulkan.c:45
AVOption
AVOption.
Definition: opt.h:428
FILTER_SINGLE_PIXFMT
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
Definition: filters.h:254
filters.h
ff_blackdetect_comp_spv_len
const unsigned int ff_blackdetect_comp_spv_len
BlackDetectVulkanContext::initialized
int initialized
Definition: vf_blackdetect_vulkan.c:34
float.h
ff_vk_exec_get
FFVkExecContext * ff_vk_exec_get(FFVulkanContext *s, FFVkExecPool *pool)
Retrieve an execution pool.
Definition: vulkan.c:571
ff_vk_uninit
void ff_vk_uninit(FFVulkanContext *s)
Frees main context.
Definition: vulkan.c:2638
BlackDetectBuf
Definition: vf_blackdetect_vulkan.c:55
SPEC_LIST_ADD
#define SPEC_LIST_ADD(name, idx, val_bits, val)
Definition: vulkan.h:55
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:219
ff_vk_exec_bind_shader
void ff_vk_exec_bind_shader(FFVulkanContext *s, FFVkExecContext *e, const FFVulkanShader *shd)
Bind a shader.
Definition: vulkan.c:2591
config_output
static int config_output(AVFilterLink *outlink)
Definition: vf_blackdetect_vulkan.c:340
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:777
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3500
AVFilterContext::priv
void * priv
private data for use by the filter
Definition: avfilter.h:288
BlackDetectVulkanContext::qf
AVVulkanDeviceQueueFamily * qf
Definition: vf_blackdetect_vulkan.c:36
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:2542
ff_vk_frame_barrier
void ff_vk_frame_barrier(FFVulkanContext *s, FFVkExecContext *e, AVFrame *pic, VkImageMemoryBarrier2 *bar, int *nb_bar, VkPipelineStageFlags2 src_stage, VkPipelineStageFlags2 dst_stage, VkAccessFlagBits2 new_access, VkImageLayout new_layout, uint32_t new_qf)
Definition: vulkan.c:2027
imax
static int imax(const int a, const int b)
Definition: internal.h:160
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:2407
AVFilterPad
A filter pad used for either input or output.
Definition: filters.h:40
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
FFFilter
Definition: filters.h:267
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:265
ff_filter_link
static FilterLink * ff_filter_link(AVFilterLink *link)
Definition: filters.h:199
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
Definition: opt.h:266
av_q2d
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
ff_vk_exec_wait
void ff_vk_exec_wait(FFVulkanContext *s, FFVkExecContext *e)
Definition: vulkan.c:590
FF_VK_REP_FLOAT
@ FF_VK_REP_FLOAT
Definition: vulkan.h:431
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:231
AVRefStructPool
AVRefStructPool is an API for a thread-safe pool of objects managed via the RefStruct API.
Definition: refstruct.c:183
AV_PIX_FMT_FLAG_ALPHA
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
Definition: pixdesc.h:147
ctx
static AVFormatContext * ctx
Definition: movenc.c:49
ff_vk_exec_pool_free
void ff_vk_exec_pool_free(FFVulkanContext *s, FFVkExecPool *pool)
Definition: vulkan.c:310
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
BlackDetectPushData::threshold
float threshold
Definition: vf_blackdetect_vulkan.c:52
ff_vk_get_pooled_buffer
int ff_vk_get_pooled_buffer(FFVulkanContext *ctx, AVRefStructPool **buf_pool, FFVkBuffer **buf, VkBufferUsageFlags usage, void *create_pNext, size_t size, VkMemoryPropertyFlagBits mem_props)
Initialize a pool and create AVBufferRefs containing FFVkBuffer.
Definition: vulkan.c:1256
fail
#define fail
Definition: test.h:478
BlackDetectVulkanContext::black_min_duration
int64_t black_min_duration
minimum duration of detected black, expressed in timebase units
Definition: vf_blackdetect_vulkan.c:47
NULL
#define NULL
Definition: coverity.c:32
ff_blackdetect_comp_spv_data
const unsigned char ff_blackdetect_comp_spv_data[]
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
SLICES
#define SLICES
Definition: vf_blackdetect_vulkan.c:56
BlackDetectPushData
Definition: vf_blackdetect_vulkan.c:51
ff_vk_filter_config_output
int ff_vk_filter_config_output(AVFilterLink *outlink)
Definition: vulkan_filter.c:209
ff_vk_shader_link
int ff_vk_shader_link(FFVulkanContext *s, FFVulkanShader *shd, const char *spirv, size_t spirv_len, const char *entrypoint)
Link a shader into an executable.
Definition: vulkan.c:2267
SPEC_LIST_CREATE
#define SPEC_LIST_CREATE(name, max_length, max_size)
Definition: vulkan.h:45
blackdetect_vulkan_uninit
static void blackdetect_vulkan_uninit(AVFilterContext *avctx)
Definition: vf_blackdetect_vulkan.c:320
FFVkBuffer::mapped_mem
uint8_t * mapped_mem
Definition: vulkan.h:103
FFVulkanContext
Definition: vulkan.h:290
AVPixFmtDescriptor::flags
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:94
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(blackdetect_vulkan)
BlackDetectVulkanContext::black_min_duration_time
double black_min_duration_time
minimum duration of detected black, in seconds
Definition: vf_blackdetect_vulkan.c:46
AVFrame::pict_type
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:564
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:608
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
BlackDetectVulkanContext::picture_black_ratio_th
double picture_black_ratio_th
Definition: vf_blackdetect_vulkan.c:40
ff_vk_shader_update_push_const
void ff_vk_shader_update_push_const(FFVulkanContext *s, FFVkExecContext *e, FFVulkanShader *shd, VkShaderStageFlagBits stage, int offset, size_t size, void *src)
Update push constant in a shader.
Definition: vulkan.c:2581
FFVulkanDescriptorSetBinding
Definition: vulkan.h:81
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:88
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
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
BlackDetectBuf::slice_sum
uint32_t slice_sum[SLICES]
Definition: vf_blackdetect_vulkan.c:57
AVFILTER_FLAG_HWDEVICE
#define AVFILTER_FLAG_HWDEVICE
The filter can create hardware frames using AVFilterContext.hw_device_ctx.
Definition: avfilter.h:187
AV_NUM_DATA_POINTERS
#define AV_NUM_DATA_POINTERS
Definition: frame.h:473
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:247
FFVulkanShader
Definition: vulkan.h:206
AVFrame::time_base
AVRational time_base
Time base for the timestamps in this frame.
Definition: frame.h:589
BlackDetectVulkanContext::black_start
int64_t black_start
pts start time of the first black picture
Definition: vf_blackdetect_vulkan.c:44
OFFSET
#define OFFSET(x)
Definition: vf_blackdetect_vulkan.c:363
FFVkExecContext
Definition: vulkan.h:128
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:2555
report_black_region
static void report_black_region(AVFilterContext *ctx, int64_t black_end)
Definition: vf_blackdetect_vulkan.c:121
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:221
av_refstruct_unref
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
Definition: refstruct.c:120
av_get_picture_type_char
char av_get_picture_type_char(enum AVPictureType pict_type)
Return a single letter to describe the given picture type pict_type.
Definition: utils.c:40
BlackDetectVulkanContext::alpha
int alpha
Definition: vf_blackdetect_vulkan.c:42
FF_VK_DEFAULT_EXEC_CONTEXTS
#define FF_VK_DEFAULT_EXEC_CONTEXTS
Definition: vulkan.h:121
ff_vk_exec_start
int ff_vk_exec_start(FFVulkanContext *s, FFVkExecContext *e)
Start/submit/wait an execution.
Definition: vulkan.c:599
s
uint8_t s
Definition: llvidencdsp.c:39
BlackDetectVulkanContext::e
FFVkExecPool e
Definition: vf_blackdetect_vulkan.c:35
uninit
static av_cold void uninit(AVBitStreamFilterContext *ctx)
Definition: lcevc_merge.c:135
AVFilterPad::name
const char * name
Pad name.
Definition: filters.h:46
blackdetect_vulkan_outputs
static const AVFilterPad blackdetect_vulkan_outputs[]
Definition: vf_blackdetect_vulkan.c:387
ff_vk_shader_add_descriptor_set
void ff_vk_shader_add_descriptor_set(FFVulkanContext *s, FFVulkanShader *shd, const FFVulkanDescriptorSetBinding *desc, int nb, int singular)
Add descriptor to a shader.
Definition: vulkan.c:2373
blackdetect_vulkan_filter_frame
static int blackdetect_vulkan_filter_frame(AVFilterLink *link, AVFrame *in)
Definition: vf_blackdetect_vulkan.c:171
BlackDetectVulkanContext::sum_buf_pool
AVRefStructPool * sum_buf_pool
Definition: vf_blackdetect_vulkan.c:38
BlackDetectVulkanContext::time_base
AVRational time_base
Definition: vf_blackdetect_vulkan.c:48
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:1958
FFVulkanContext::vkfn
FFVulkanFunctions vkfn
Definition: vulkan.h:294
FFVkExecPool
Definition: vulkan.h:268
ff_vk_shader_add_push_const
int ff_vk_shader_add_push_const(FFVulkanShader *shd, int offset, int size, VkShaderStageFlagBits stage)
Add/update push constants for execution.
Definition: vulkan.c:1443
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:264
ff_vk_qf_find
AVVulkanDeviceQueueFamily * ff_vk_qf_find(FFVulkanContext *s, VkQueueFlagBits dev_family, VkVideoCodecOperationFlagBitsKHR vid_ops)
Chooses an appropriate QF.
Definition: vulkan.c:297
FFVkExecContext::buf
VkCommandBuffer buf
Definition: vulkan.h:139
FFVulkanContext::input_format
enum AVPixelFormat input_format
Definition: vulkan.h:343
AV_PIX_FMT_FLAG_XYZ
#define AV_PIX_FMT_FLAG_XYZ
The pixel format contains XYZ-like data (as opposed to YUV/RGB/grayscale).
Definition: pixdesc.h:163
blackdetect_vulkan_inputs
static const AVFilterPad blackdetect_vulkan_inputs[]
Definition: vf_blackdetect_vulkan.c:378
AVFrame::metadata
AVDictionary * metadata
metadata.
Definition: frame.h:750
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
evaluate
static void evaluate(AVFilterLink *link, AVFrame *in, const BlackDetectBuf *sum)
Definition: vf_blackdetect_vulkan.c:137
AVFilterContext
An instance of a filter.
Definition: avfilter.h:273
blackdetect_vulkan_options
static const AVOption blackdetect_vulkan_options[]
Definition: vf_blackdetect_vulkan.c:365
desc
const char * desc
Definition: libsvtav1.c:83
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:271
BlackDetectVulkanContext::vkctx
FFVulkanContext vkctx
Definition: vf_blackdetect_vulkan.c:32
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
av_refstruct_pool_uninit
static void av_refstruct_pool_uninit(AVRefStructPool **poolp)
Mark the pool as being available for freeing.
Definition: refstruct.h:292
ff_vk_exec_discard_deps
void ff_vk_exec_discard_deps(FFVulkanContext *s, FFVkExecContext *e)
Definition: vulkan.c:636
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
alpha
static const int16_t alpha[]
Definition: ilbcdata.h:55
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:326
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
FLAGS
#define FLAGS
Definition: vf_blackdetect_vulkan.c:364
FFVkBuffer
Definition: vulkan.h:94
timestamp.h
ff_vk_exec_submit
int ff_vk_exec_submit(FFVulkanContext *s, FFVkExecContext *e)
Definition: vulkan.c:881
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVVulkanDeviceQueueFamily
Definition: hwcontext_vulkan.h:33
av_ts2str
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: timestamp.h:54
FFVulkanFunctions
Definition: vulkan_functions.h:276
ff_vk_shader_load
int ff_vk_shader_load(FFVulkanShader *shd, VkPipelineStageFlags stage, VkSpecializationInfo *spec, uint32_t wg_size[3], uint32_t required_subgroup_size)
Initialize a shader object.
Definition: vulkan.c:2070
BlackDetectVulkanContext
Definition: vf_blackdetect_vulkan.c:31
av_get_pix_fmt_name
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:3380