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, s->qf->num*4, 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, 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  AVBufferRef *sum_buf = NULL;
186  FFVkBuffer *sum_vk;
187 
188  BlackDetectBuf *sum;
189  BlackDetectPushData push_data;
190 
191  if (in->color_range == AVCOL_RANGE_JPEG || s->alpha) {
192  push_data.threshold = s->pixel_black_th;
193  } else {
195  const int depth = desc->comp[0].depth;
196  const int ymin = 16 << (depth - 8);
197  const int ymax = 235 << (depth - 8);
198  const int imax = (1 << depth) - 1;
199  push_data.threshold = (s->pixel_black_th * (ymax - ymin) + ymin) / imax;
200  }
201 
202  if (!s->initialized)
203  RET(init_filter(ctx));
204 
205  err = ff_vk_get_pooled_buffer(vkctx, &s->sum_buf_pool, &sum_buf,
206  VK_BUFFER_USAGE_TRANSFER_DST_BIT |
207  VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
208  NULL,
209  sizeof(BlackDetectBuf),
210  VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
211  VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
212  VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
213  if (err < 0)
214  return err;
215  sum_vk = (FFVkBuffer *)sum_buf->data;
216  sum = (BlackDetectBuf *) sum_vk->mapped_mem;
217 
218  exec = ff_vk_exec_get(vkctx, &s->e);
219  ff_vk_exec_start(vkctx, exec);
220 
221  RET(ff_vk_exec_add_dep_frame(vkctx, exec, in,
222  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
223  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
224  RET(ff_vk_create_imageviews(vkctx, exec, in_views, in, FF_VK_REP_FLOAT));
225 
226  ff_vk_shader_update_img_array(vkctx, exec, &s->shd, in, in_views, 0, 0,
227  VK_IMAGE_LAYOUT_GENERAL, VK_NULL_HANDLE);
228 
229  ff_vk_frame_barrier(vkctx, exec, in, img_bar, &nb_img_bar,
230  VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
231  VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
232  VK_ACCESS_SHADER_READ_BIT,
233  VK_IMAGE_LAYOUT_GENERAL,
234  VK_QUEUE_FAMILY_IGNORED);
235 
236  /* zero sum buffer */
237  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
238  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
239  .pBufferMemoryBarriers = &(VkBufferMemoryBarrier2) {
240  .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2,
241  .srcStageMask = VK_PIPELINE_STAGE_2_NONE,
242  .dstStageMask = VK_PIPELINE_STAGE_2_TRANSFER_BIT,
243  .dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
244  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
245  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
246  .buffer = sum_vk->buf,
247  .size = sum_vk->size,
248  .offset = 0,
249  },
250  .bufferMemoryBarrierCount = 1,
251  });
252 
253  vk->CmdFillBuffer(exec->buf, sum_vk->buf, 0, sum_vk->size, 0x0);
254 
255  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
256  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
257  .pImageMemoryBarriers = img_bar,
258  .imageMemoryBarrierCount = nb_img_bar,
259  .pBufferMemoryBarriers = &(VkBufferMemoryBarrier2) {
260  .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2,
261  .srcStageMask = VK_PIPELINE_STAGE_2_TRANSFER_BIT,
262  .dstStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
263  .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
264  .dstAccessMask = VK_ACCESS_2_SHADER_STORAGE_READ_BIT |
265  VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT,
266  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
267  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
268  .buffer = sum_vk->buf,
269  .size = sum_vk->size,
270  .offset = 0,
271  },
272  .bufferMemoryBarrierCount = 1,
273  });
274 
275  RET(ff_vk_shader_update_desc_buffer(&s->vkctx, exec, &s->shd, 0, 1, 0,
276  sum_vk, 0, sum_vk->size,
277  VK_FORMAT_UNDEFINED));
278 
279  ff_vk_exec_bind_shader(vkctx, exec, &s->shd);
280  ff_vk_shader_update_push_const(vkctx, exec, &s->shd, VK_SHADER_STAGE_COMPUTE_BIT,
281  0, sizeof(push_data), &push_data);
282 
283  vk->CmdDispatch(exec->buf,
284  FFALIGN(in->width, s->shd.lg_size[0]) / s->shd.lg_size[0],
285  FFALIGN(in->height, s->shd.lg_size[1]) / s->shd.lg_size[1],
286  s->shd.lg_size[2]);
287 
288  vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
289  .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
290  .pBufferMemoryBarriers = &(VkBufferMemoryBarrier2) {
291  .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2,
292  .srcStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
293  .dstStageMask = VK_PIPELINE_STAGE_2_HOST_BIT,
294  .srcAccessMask = VK_ACCESS_2_SHADER_STORAGE_READ_BIT |
295  VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT,
296  .dstAccessMask = VK_ACCESS_HOST_READ_BIT,
297  .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
298  .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
299  .buffer = sum_vk->buf,
300  .size = sum_vk->size,
301  .offset = 0,
302  },
303  .bufferMemoryBarrierCount = 1,
304  });
305 
306  RET(ff_vk_exec_submit(vkctx, exec));
307  ff_vk_exec_wait(vkctx, exec);
308  evaluate(link, in, sum);
309  s->last_pts = in->pts;
310 
311  av_buffer_unref(&sum_buf);
312  return ff_filter_frame(outlink, in);
313 
314 fail:
315  if (exec)
316  ff_vk_exec_discard_deps(&s->vkctx, exec);
317  av_frame_free(&in);
318  av_buffer_unref(&sum_buf);
319  return err;
320 }
321 
323 {
324  BlackDetectVulkanContext *s = avctx->priv;
325  FFVulkanContext *vkctx = &s->vkctx;
326 
327  /* the input link may be gone here: during graph teardown the upstream
328  * filter can be freed first. Use the cached pts of the last frame */
329  if (s->initialized)
330  report_black_region(avctx, s->last_pts);
331 
332  ff_vk_exec_pool_free(vkctx, &s->e);
333  ff_vk_shader_free(vkctx, &s->shd);
334 
335  av_buffer_pool_uninit(&s->sum_buf_pool);
336 
337  ff_vk_uninit(&s->vkctx);
338 
339  s->initialized = 0;
340 }
341 
342 static int config_output(AVFilterLink *outlink)
343 {
344  AVFilterContext *ctx = outlink->src;
345  BlackDetectVulkanContext *s = ctx->priv;
346  FFVulkanContext *vkctx = &s->vkctx;
348 
349  if (s->alpha && !(desc->flags & AV_PIX_FMT_FLAG_ALPHA)) {
350  av_log(ctx, AV_LOG_ERROR, "Input format %s does not have an alpha channel\n",
352  return AVERROR(EINVAL);
353  }
354 
355  if (desc->flags & (AV_PIX_FMT_FLAG_RGB | AV_PIX_FMT_FLAG_XYZ) ||
356  !(desc->flags & AV_PIX_FMT_FLAG_PLANAR)) {
357  av_log(ctx, AV_LOG_ERROR, "Input format %s is not planar YUV\n",
359  return AVERROR(EINVAL);
360  }
361 
362  return ff_vk_filter_config_output(outlink);
363 }
364 
365 #define OFFSET(x) offsetof(BlackDetectVulkanContext, x)
366 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
368  { "d", "set minimum detected black duration in seconds", OFFSET(black_min_duration_time), AV_OPT_TYPE_DOUBLE, {.dbl=2}, 0, DBL_MAX, FLAGS },
369  { "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 },
370  { "picture_black_ratio_th", "set the picture black ratio threshold", OFFSET(picture_black_ratio_th), AV_OPT_TYPE_DOUBLE, {.dbl=.98}, 0, 1, FLAGS },
371  { "pic_th", "set the picture black ratio threshold", OFFSET(picture_black_ratio_th), AV_OPT_TYPE_DOUBLE, {.dbl=.98}, 0, 1, FLAGS },
372  { "pixel_black_th", "set the pixel black threshold", OFFSET(pixel_black_th), AV_OPT_TYPE_DOUBLE, {.dbl=.10}, 0, 1, FLAGS },
373  { "pix_th", "set the pixel black threshold", OFFSET(pixel_black_th), AV_OPT_TYPE_DOUBLE, {.dbl=.10}, 0, 1, FLAGS },
374  { "alpha", "check alpha instead of luma", OFFSET(alpha), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
375  { NULL }
376 };
377 
378 AVFILTER_DEFINE_CLASS(blackdetect_vulkan);
379 
381  {
382  .name = "default",
383  .type = AVMEDIA_TYPE_VIDEO,
384  .filter_frame = &blackdetect_vulkan_filter_frame,
385  .config_props = &ff_vk_filter_config_input,
386  },
387 };
388 
390  {
391  .name = "default",
392  .type = AVMEDIA_TYPE_VIDEO,
393  .config_props = &config_output,
394  },
395 };
396 
398  .p.name = "blackdetect_vulkan",
399  .p.description = NULL_IF_CONFIG_SMALL("Detect video intervals that are (almost) black."),
400  .p.priv_class = &blackdetect_vulkan_class,
401  .p.flags = AVFILTER_FLAG_HWDEVICE,
402  .priv_size = sizeof(BlackDetectVulkanContext),
408  .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
409 };
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:710
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:2845
BlackDetectVulkanContext::pixel_black_th
double pixel_black_th
Definition: vf_blackdetect_vulkan.c:41
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:1068
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3456
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
RET
#define RET(x)
Definition: vulkan.h:68
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
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:459
ff_vf_blackdetect_vulkan
const FFFilter ff_vf_blackdetect_vulkan
Definition: vf_blackdetect_vulkan.c:397
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:561
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:777
BlackDetectVulkanContext::last_pts
int64_t last_pts
pts of the last filtered frame
Definition: vf_blackdetect_vulkan.c:45
AVOption
AVOption.
Definition: opt.h:429
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:568
ff_vk_uninit
void ff_vk_uninit(FFVulkanContext *s)
Frees main context.
Definition: vulkan.c:2871
BlackDetectBuf
Definition: vf_blackdetect_vulkan.c:55
SPEC_LIST_ADD
#define SPEC_LIST_ADD(name, idx, val_bits, val)
Definition: vulkan.h:86
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:220
ff_vk_exec_bind_shader
void ff_vk_exec_bind_shader(FFVulkanContext *s, FFVkExecContext *e, const FFVulkanShader *shd)
Bind a shader.
Definition: vulkan.c:2822
config_output
static int config_output(AVFilterLink *outlink)
Definition: vf_blackdetect_vulkan.c:342
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:800
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3496
AVFilterContext::priv
void * priv
private data for use by the filter
Definition: avfilter.h:289
BlackDetectVulkanContext::qf
AVVulkanDeviceQueueFamily * qf
Definition: vf_blackdetect_vulkan.c:36
fail
#define fail()
Definition: checkasm.h:225
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:2773
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:2085
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:2638
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
av_cold
#define av_cold
Definition: attributes.h:119
FFFilter
Definition: filters.h:267
s
#define s(width, name)
Definition: cbs_vp9.c:198
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:267
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:573
FF_VK_REP_FLOAT
@ FF_VK_REP_FLOAT
Definition: vulkan.h:451
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:231
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:299
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
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
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
BlackDetectVulkanContext::sum_buf_pool
AVBufferPool * sum_buf_pool
Definition: vf_blackdetect_vulkan.c:38
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
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
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:2411
SPEC_LIST_CREATE
#define SPEC_LIST_CREATE(name, max_length, max_size)
Definition: vulkan.h:76
blackdetect_vulkan_uninit
static void blackdetect_vulkan_uninit(AVFilterContext *avctx)
Definition: vf_blackdetect_vulkan.c:322
FFVkBuffer::mapped_mem
uint8_t * mapped_mem
Definition: vulkan.h:134
FFVulkanContext
Definition: vulkan.h:312
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:551
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:551
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:2812
FFVulkanDescriptorSetBinding
Definition: vulkan.h:112
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
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:188
AV_NUM_DATA_POINTERS
#define AV_NUM_DATA_POINTERS
Definition: frame.h:460
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:247
FFVulkanShader
Definition: vulkan.h:225
AVFrame::time_base
AVRational time_base
Time base for the timestamps in this frame.
Definition: frame.h:576
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:365
FFVkExecContext
Definition: vulkan.h:145
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:2786
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_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
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:580
BlackDetectVulkanContext::e
FFVkExecPool e
Definition: vf_blackdetect_vulkan.c:35
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:389
blackdetect_vulkan_filter_frame
static int blackdetect_vulkan_filter_frame(AVFilterLink *link, AVFrame *in)
Definition: vf_blackdetect_vulkan.c:171
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:2002
FFVulkanContext::vkfn
FFVulkanFunctions vkfn
Definition: vulkan.h:316
FFVkExecPool
Definition: vulkan.h:290
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:1509
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:286
FFVkExecContext::buf
VkCommandBuffer buf
Definition: vulkan.h:156
FFVulkanContext::input_format
enum AVPixelFormat input_format
Definition: vulkan.h:363
ff_vk_shader_add_descriptor_set
int ff_vk_shader_add_descriptor_set(FFVulkanContext *s, FFVulkanShader *shd, const FFVulkanDescriptorSetBinding *desc, int nb, int singular, int print_to_shader_only)
Add descriptor to a shader.
Definition: vulkan.c:2538
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:380
AVFrame::metadata
AVDictionary * metadata
metadata.
Definition: frame.h:737
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:274
blackdetect_vulkan_options
static const AVOption blackdetect_vulkan_options[]
Definition: vf_blackdetect_vulkan.c:367
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
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
ff_vk_exec_discard_deps
void ff_vk_exec_discard_deps(FFVulkanContext *s, FFVkExecContext *e)
Definition: vulkan.c:612
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: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
FLAGS
#define FLAGS
Definition: vf_blackdetect_vulkan.c:366
FFVkBuffer
Definition: vulkan.h:125
timestamp.h
ff_vk_exec_submit
int ff_vk_exec_submit(FFVulkanContext *s, FFVkExecContext *e)
Definition: vulkan.c:925
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:275
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:2128
BlackDetectVulkanContext
Definition: vf_blackdetect_vulkan.c:31
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:1306
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:3376