Go to the documentation of this file.
66 const int plane =
s->alpha ? 3 : 0;
88 (
int []) { 32, 32, 1 }, 0);
91 VK_SHADER_STAGE_COMPUTE_BIT);
95 .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
96 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
100 .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
101 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
112 s->time_base =
inlink->time_base;
113 s->black_min_duration =
s->black_min_duration_time /
av_q2d(
s->time_base);
128 if ((black_end -
s->black_start) >=
s->black_min_duration) {
130 "black_start:%s black_end:%s black_duration:%s\n",
143 uint64_t nb_black_pixels = 0;
149 ratio = (
double) nb_black_pixels / (
link->w *
link->h);
152 "frame:%"PRId64
" picture_black_ratio:%f pts:%s t:%s type:%c\n",
157 if (ratio >=
s->picture_black_ratio_th) {
159 s->black_start = in->
pts;
179 VkImageMemoryBarrier2 img_bar[4];
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;
206 VK_BUFFER_USAGE_TRANSFER_DST_BIT |
207 VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
210 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
211 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
212 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
222 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
223 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
227 VK_IMAGE_LAYOUT_GENERAL, VK_NULL_HANDLE);
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);
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,
250 .bufferMemoryBarrierCount = 1,
253 vk->CmdFillBuffer(exec->buf, sum_vk->buf, 0, sum_vk->size, 0x0);
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,
272 .bufferMemoryBarrierCount = 1,
276 sum_vk, 0, sum_vk->size,
277 VK_FORMAT_UNDEFINED));
281 0,
sizeof(push_data), &push_data);
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],
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,
303 .bufferMemoryBarrierCount = 1,
309 s->last_pts = in->pts;
365 #define OFFSET(x) offsetof(BlackDetectVulkanContext, x)
366 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
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 },
398 .
p.
name =
"blackdetect_vulkan",
400 .p.priv_class = &blackdetect_vulkan_class,
static av_cold int init_filter(AVFilterContext *ctx)
enum AVColorRange color_range
MPEG vs JPEG YUV range.
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
void ff_vk_shader_free(FFVulkanContext *s, FFVulkanShader *shd)
Free a shader.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
uint8_t * data
The data buffer.
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.
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
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
const FFFilter ff_vf_blackdetect_vulkan
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
int ff_vk_filter_init(AVFilterContext *avctx)
General lavfi IO functions.
@ AVCOL_RANGE_JPEG
Full range content.
int64_t last_pts
pts of the last filtered frame
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
const unsigned int ff_blackdetect_comp_spv_len
FFVkExecContext * ff_vk_exec_get(FFVulkanContext *s, FFVkExecPool *pool)
Retrieve an execution pool.
void ff_vk_uninit(FFVulkanContext *s)
Frees main context.
#define SPEC_LIST_ADD(name, idx, val_bits, val)
const char * name
Filter name.
void ff_vk_exec_bind_shader(FFVulkanContext *s, FFVkExecContext *e, const FFVulkanShader *shd)
Bind a shader.
A link between two filters.
static int config_output(AVFilterLink *outlink)
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
int ff_vk_exec_add_dep_frame(FFVulkanContext *s, FFVkExecContext *e, AVFrame *f, VkPipelineStageFlagBits2 wait_stage, VkPipelineStageFlagBits2 signal_stage)
Link properties exposed to filter code, but not external callers.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
void * priv
private data for use by the filter
AVVulkanDeviceQueueFamily * qf
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.
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)
int ff_vk_shader_register_exec(FFVulkanContext *s, FFVkExecPool *pool, FFVulkanShader *shd)
Register a shader with an exec pool.
A filter pad used for either input or output.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
#define FILTER_OUTPUTS(array)
static FilterLink * ff_filter_link(AVFilterLink *link)
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
void ff_vk_exec_wait(FFVulkanContext *s, FFVkExecContext *e)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
static AVFormatContext * ctx
void ff_vk_exec_pool_free(FFVulkanContext *s, FFVkExecPool *pool)
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
int64_t black_min_duration
minimum duration of detected black, expressed in timebase units
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
AVBufferPool * sum_buf_pool
const unsigned char ff_blackdetect_comp_spv_data[]
Rational number (pair of numerator and denominator).
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
int ff_vk_filter_config_output(AVFilterLink *outlink)
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.
#define SPEC_LIST_CREATE(name, max_length, max_size)
static void blackdetect_vulkan_uninit(AVFilterContext *avctx)
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
AVFILTER_DEFINE_CLASS(blackdetect_vulkan)
double black_min_duration_time
minimum duration of detected black, in seconds
enum AVPictureType pict_type
Picture type of the frame.
int(* init)(AVBSFContext *ctx)
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
double picture_black_ratio_th
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.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
#define i(width, name, range_min, range_max)
uint32_t slice_sum[SLICES]
#define AVFILTER_FLAG_HWDEVICE
The filter can create hardware frames using AVFilterContext.hw_device_ctx.
#define AV_NUM_DATA_POINTERS
#define AV_NOPTS_VALUE
Undefined timestamp value.
AVRational time_base
Time base for the timestamps in this frame.
AVFilterContext * src
source filter
int64_t black_start
pts start time of the first black picture
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.
static void report_black_region(AVFilterContext *ctx, int64_t black_end)
#define AV_LOG_INFO
Standard information.
char av_get_picture_type_char(enum AVPictureType pict_type)
Return a single letter to describe the given picture type pict_type.
static void uninit(AVBSFContext *ctx)
int ff_vk_exec_start(FFVulkanContext *s, FFVkExecContext *e)
Start/submit/wait an execution.
const char * name
Pad name.
static const AVFilterPad blackdetect_vulkan_outputs[]
static int blackdetect_vulkan_filter_frame(AVFilterLink *link, AVFrame *in)
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.
int ff_vk_shader_add_push_const(FFVulkanShader *shd, int offset, int size, VkShaderStageFlagBits stage)
Add/update push constants for execution.
#define FILTER_INPUTS(array)
AVVulkanDeviceQueueFamily * ff_vk_qf_find(FFVulkanContext *s, VkQueueFlagBits dev_family, VkVideoCodecOperationFlagBitsKHR vid_ops)
Chooses an appropriate QF.
enum AVPixelFormat input_format
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.
#define AV_PIX_FMT_FLAG_XYZ
The pixel format contains XYZ-like data (as opposed to YUV/RGB/grayscale).
static const AVFilterPad blackdetect_vulkan_inputs[]
AVDictionary * metadata
metadata.
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
static void evaluate(AVFilterLink *link, AVFrame *in, const BlackDetectBuf *sum)
static const AVOption blackdetect_vulkan_options[]
int ff_vk_filter_config_input(AVFilterLink *inlink)
AVFilter p
The public AVFilter.
A reference to a data buffer.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
void ff_vk_exec_discard_deps(FFVulkanContext *s, FFVkExecContext *e)
static const int16_t alpha[]
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
int ff_vk_exec_submit(FFVulkanContext *s, FFVkExecContext *e)
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
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.
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.
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.