Go to the documentation of this file.
90 C(0,
void transition(
int idx, ivec2
pos,
float progress) )
92 C(1, vec4
a = texture(a_images[idx],
pos); )
93 C(1, vec4
b = texture(b_images[idx],
pos); )
94 C(1, imageStore(output_images[idx],
pos,
mix(
a,
b, progress)); )
99 C(0,
void transition(
int idx, ivec2
pos,
float progress) )
101 C(1, ivec2
size = imageSize(output_images[idx]); )
102 C(1,
int s =
int(
size.x * (1.0 - progress)); )
103 C(1, vec4
a = texture(a_images[idx],
pos); )
104 C(1, vec4
b = texture(b_images[idx],
pos); )
105 C(1, imageStore(output_images[idx],
pos,
pos.x >
s ?
b :
a); )
110 C(0,
void transition(
int idx, ivec2
pos,
float progress) )
112 C(1, ivec2
size = imageSize(output_images[idx]); )
113 C(1,
int s =
int(
size.x * progress); )
114 C(1, vec4
a = texture(a_images[idx],
pos); )
115 C(1, vec4
b = texture(b_images[idx],
pos); )
116 C(1, imageStore(output_images[idx],
pos,
pos.x >
s ?
a :
b); )
121 C(0,
void transition(
int idx, ivec2
pos,
float progress) )
123 C(1, ivec2
size = imageSize(output_images[idx]); )
124 C(1,
int s =
int(
size.y * (1.0 - progress)); )
125 C(1, vec4
a = texture(a_images[idx],
pos); )
126 C(1, vec4
b = texture(b_images[idx],
pos); )
127 C(1, imageStore(output_images[idx],
pos,
pos.y >
s ?
b :
a); )
132 C(0,
void transition(
int idx, ivec2
pos,
float progress) )
134 C(1, ivec2
size = imageSize(output_images[idx]); )
135 C(1,
int s =
int(
size.y * progress); )
136 C(1, vec4
a = texture(a_images[idx],
pos); )
137 C(1, vec4
b = texture(b_images[idx],
pos); )
138 C(1, imageStore(output_images[idx],
pos,
pos.y >
s ?
a :
b); )
142 #define SHADER_SLIDE_COMMON \
143 C(0, void slide(int idx, ivec2 pos, float progress, ivec2 direction) ) \
145 C(1, ivec2 size = imageSize(output_images[idx]); ) \
146 C(1, ivec2 pi = ivec2(progress * size); ) \
147 C(1, ivec2 p = pos + pi * direction; ) \
148 C(1, ivec2 f = p % size; ) \
149 C(1, f = f + size * ivec2(f.x < 0, f.y < 0); ) \
150 C(1, vec4 a = texture(a_images[idx], f); ) \
151 C(1, vec4 b = texture(b_images[idx], f); ) \
152 C(1, vec4 r = (p.y >= 0 && p.x >= 0 && size.y > p.y && size.x > p.x) ? a : b; ) \
153 C(1, imageStore(output_images[idx], pos, r); ) \
158 C(0,
void transition(
int idx, ivec2
pos,
float progress) )
160 C(1, slide(idx,
pos, progress, ivec2(0, -1)); )
166 C(0,
void transition(
int idx, ivec2
pos,
float progress) )
168 C(1, slide(idx,
pos, progress, ivec2(0, +1)); )
174 C(0,
void transition(
int idx, ivec2
pos,
float progress) )
176 C(1, slide(idx,
pos, progress, ivec2(+1, 0)); )
182 C(0,
void transition(
int idx, ivec2
pos,
float progress) )
184 C(1, slide(idx,
pos, progress, ivec2(-1, 0)); )
188 #define SHADER_CIRCLE_COMMON \
189 C(0, void circle(int idx, ivec2 pos, float progress, bool open) ) \
191 C(1, const ivec2 half_size = imageSize(output_images[idx]) / 2; ) \
192 C(1, const float z = dot(half_size, half_size); ) \
193 C(1, float p = ((open ? (1.0 - progress) : progress) - 0.5) * 3.0; ) \
194 C(1, ivec2 dsize = pos - half_size; ) \
195 C(1, float sm = dot(dsize, dsize) / z + p; ) \
196 C(1, vec4 a = texture(a_images[idx], pos); ) \
197 C(1, vec4 b = texture(b_images[idx], pos); ) \
198 C(1, imageStore(output_images[idx], pos, \
199 mix(open ? b : a, open ? a : b, \
200 smoothstep(0.f, 1.f, sm))); ) \
205 C(0,
void transition(
int idx, ivec2
pos,
float progress) )
207 C(1, circle(idx,
pos, progress,
true); )
213 C(0,
void transition(
int idx, ivec2
pos,
float progress) )
215 C(1, circle(idx,
pos, progress,
false); )
219 #define SHADER_FRAND_FUNC \
220 C(0, float frand(vec2 v) ) \
222 C(1, return fract(sin(dot(v, vec2(12.9898, 78.233))) * 43758.545); ) \
227 C(0,
void transition(
int idx, ivec2
pos,
float progress) )
229 C(1,
float sm =
frand(
pos) * 2.0 + (1.0 - progress) * 2.0 - 1.5; )
230 C(1, vec4
a = texture(a_images[idx],
pos); )
231 C(1, vec4
b = texture(b_images[idx],
pos); )
232 C(1, imageStore(output_images[idx],
pos, sm >= 0.5 ?
a :
b); )
237 C(0,
void transition(
int idx, ivec2
pos,
float progress) )
239 C(1, ivec2
size = imageSize(output_images[idx]); )
240 C(1,
float d =
min(progress, 1.0 - progress); )
241 C(1,
float dist =
ceil(d * 50.0) / 50.0; )
242 C(1,
float sq = 2.0 * dist *
min(
size.x,
size.y) / 20.0; )
245 C(1, vec4
a = texture(a_images[idx], vec2(sx, sy)); )
246 C(1, vec4
b = texture(b_images[idx], vec2(sx, sy)); )
247 C(1, imageStore(output_images[idx],
pos,
mix(
a,
b, progress)); )
252 C(0,
void transition(
int idx, ivec2
pos,
float progress) )
254 C(1, ivec2
size = imageSize(output_images[idx]); )
255 C(1,
float zw =
size.x * (1.0 - progress); )
256 C(1,
float zh =
size.y * (1.0 - progress); )
257 C(1, vec4
a = texture(a_images[idx],
pos); )
258 C(1, vec4
b = texture(b_images[idx],
pos); )
259 C(1, imageStore(output_images[idx],
pos, (
pos.y <= zh &&
pos.x <= zw) ?
a :
b); )
264 C(0,
void transition(
int idx, ivec2
pos,
float progress) )
266 C(1, ivec2
size = imageSize(output_images[idx]); )
267 C(1,
float zw =
size.x * (progress); )
268 C(1,
float zh =
size.y * (1.0 - progress); )
269 C(1, vec4
a = texture(a_images[idx],
pos); )
270 C(1, vec4
b = texture(b_images[idx],
pos); )
271 C(1, imageStore(output_images[idx],
pos, (
pos.y <= zh &&
pos.x > zw) ?
a :
b); )
276 C(0,
void transition(
int idx, ivec2
pos,
float progress) )
278 C(1, ivec2
size = imageSize(output_images[idx]); )
279 C(1,
float zw =
size.x * (1.0 - progress); )
280 C(1,
float zh =
size.y * (progress); )
281 C(1, vec4
a = texture(a_images[idx],
pos); )
282 C(1, vec4
b = texture(b_images[idx],
pos); )
283 C(1, imageStore(output_images[idx],
pos, (
pos.y > zh &&
pos.x <= zw) ?
a :
b); )
288 C(0,
void transition(
int idx, ivec2
pos,
float progress) )
290 C(1, ivec2
size = imageSize(output_images[idx]); )
291 C(1,
float zw =
size.x * (progress); )
292 C(1,
float zh =
size.y * (progress); )
293 C(1, vec4
a = texture(a_images[idx],
pos); )
294 C(1, vec4
b = texture(b_images[idx],
pos); )
295 C(1, imageStore(output_images[idx],
pos, (
pos.y > zh &&
pos.x > zw) ?
a :
b); )
324 void *spv_opaque =
NULL;
332 spv = ff_vk_spirv_init();
342 VK_SHADER_STAGE_COMPUTE_BIT,
350 .type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
353 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
358 .type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
361 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
365 .name =
"output_images",
366 .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
368 .mem_quali =
"writeonly",
371 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
377 GLSLC(0,
layout(push_constant, std430) uniform pushConstants { );
378 GLSLC(1,
float progress; );
382 VK_SHADER_STAGE_COMPUTE_BIT);
389 GLSLC(1, ivec2
pos = ivec2(gl_GlobalInvocationID.xy); );
392 GLSLC(2, transition(
i,
pos, progress); );
426 if (!
s->initialized) {
429 if (a_fc->
sw_format != b_fc->sw_format) {
431 "Currently the sw format of the first input needs to match the second!\n");
440 progress =
av_clipf((
float)(
s->pts -
s->start_pts) /
s->duration_pts,
444 (
AVFrame *[]){ frame_a, frame_b }, 2,
s->sampler,
464 if (inlink_a->
w != inlink_b->
w || inlink_a->
h != inlink_b->
h) {
466 "(size %dx%d) do not match the corresponding "
467 "second input link %s parameters (size %dx%d)\n",
476 "(%d/%d) does not match the corresponding "
477 "second input link %s timebase (%d/%d)\n",
512 s->inputs_offset_pts = -
frame->pts;
515 frame->pts +=
s->inputs_offset_pts;
522 s->inputs_offset_pts = -status_pts;
555 s->pts = peeked_frame->
pts;
563 if (
s->start_pts >
s->pts) {
580 s->inputs_offset_pts =
s->pts - frame_b->pts;
584 if (
s->pts -
s->start_pts >
s->duration_pts) {
649 return s->passthrough ?
654 #define OFFSET(x) offsetof(XFadeVulkanContext, x)
655 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
707 .
name =
"xfade_vulkan",
716 .priv_class = &xfade_vulkan_class,
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
static int mix(int c0, int c1)
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
static const char transition_dissolve[]
void ff_vk_shader_free(FFVulkanContext *s, FFVulkanShader *shd)
Free a shader.
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,...
static int xfade_frame(AVFilterContext *avctx, AVFrame *frame_a, AVFrame *frame_b)
static const char transition_wipeup[]
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
#define AVERROR_EOF
End of file.
uint8_t * data
The data buffer.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
int ff_vk_qf_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf, VkQueueFlagBits dev_family)
Chooses a QF and loads it into a context.
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
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
static const char transition_slideup[]
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define FILTER_INPUTS(array)
This structure describes decoded (raw) audio or video data.
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.
static float frand(int x, int y)
static const char * transitions_map[NB_TRANSITIONS]
static AVFrame * get_video_buffer(AVFilterLink *inlink, int w, int h)
@ AV_OPT_TYPE_DURATION
Underlying C type is int64_t.
static const char transition_wiperight[]
static int forward_frame(XFadeVulkanContext *s, AVFilterLink *inlink, AVFilterLink *outlink)
static const char transition_wipebl[]
void ff_vk_uninit(FFVulkanContext *s)
Frees main context.
static const char transition_wipebr[]
void(* uninit)(struct FFVkSPIRVCompiler **ctx)
const char * name
Filter name.
A link between two filters.
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
const AVFilter ff_vf_xfade_vulkan
Link properties exposed to filter code, but not external callers.
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
AVFrame * ff_default_get_video_buffer(AVFilterLink *link, int w, int h)
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
#define FF_FILTER_FORWARD_STATUS_BACK_ALL(outlink, filter)
Forward the status on an output link to all input links.
static const char transition_slideleft[]
const VkAllocationCallbacks * alloc
Custom memory allocator, else NULL.
void * priv
private data for use by the filter
int ff_vk_shader_register_exec(FFVulkanContext *s, FFVkExecPool *pool, FFVulkanShader *shd)
Register a shader with an exec pool.
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.
#define SHADER_FRAND_FUNC
A filter pad used for either input or output.
static const char transition_circleclose[]
s EdgeDetect Foobar g libavfilter vf_edgedetect c libavfilter vf_foobar c edit libavfilter and add an entry for foobar following the pattern of the other filters edit libavfilter allfilters and add an entry for foobar following the pattern of the other filters configure make j< whatever > ffmpeg ffmpeg i you should get a foobar png with Lena edge detected That s your new playground is ready Some little details about what s going which in turn will define variables for the build system and the C
AVFilterPad * input_pads
array of input pads
static __device__ float ceil(float a)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
static __device__ float floor(float a)
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
static const char transition_wipedown[]
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
void ff_vk_exec_pool_free(FFVulkanContext *s, FFVkExecPool *pool)
#define FILTER_OUTPUTS(array)
AVFrame * ff_inlink_peek_frame(AVFilterLink *link, size_t idx)
Access a frame in the link fifo without consuming it.
static const struct @465 planes[]
const char * ff_vk_shader_rep_fmt(enum AVPixelFormat pix_fmt, enum FFVkShaderRepFormat rep_fmt)
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
static const char transition_pixelize[]
AVFilterLink ** inputs
array of pointers to input links
static int activate(AVFilterContext *avctx)
static const char transition_circleopen[]
int ff_vk_filter_config_output(AVFilterLink *outlink)
static const char transition_wipetl[]
static const char transition_fade[]
static const AVFilterPad xfade_vulkan_outputs[]
static const AVOption xfade_vulkan_options[]
int ff_vk_exec_pool_init(FFVulkanContext *s, FFVkQueueFamilyCtx *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.
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
static FilterLink * ff_filter_link(AVFilterLink *link)
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
int ff_vk_filter_process_Nin(FFVulkanContext *vkctx, FFVkExecPool *e, FFVulkanShader *shd, AVFrame *out, AVFrame *in[], int nb_in, VkSampler sampler, void *push_src, size_t push_size)
Up to 16 inputs, one output.
int(* init)(AVBSFContext *ctx)
void ff_inlink_set_status(AVFilterLink *link, int status)
Set the status on an input link.
int ff_inlink_check_available_frame(AVFilterLink *link)
Test if a frame is available on the link.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define AVFILTER_FLAG_HWDEVICE
The filter can create hardware frames using AVFilterContext.hw_device_ctx.
#define SHADER_CIRCLE_COMMON
#define AV_NOPTS_VALUE
Undefined timestamp value.
AVFilterContext * src
source filter
int(* compile_shader)(FFVulkanContext *s, struct FFVkSPIRVCompiler *ctx, FFVulkanShader *shd, uint8_t **data, size_t *size, const char *entrypoint, void **opaque)
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
#define AVERROR_EXTERNAL
Generic error in an external library.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
int64_t inputs_offset_pts
AVFrame * ff_null_get_video_buffer(AVFilterLink *link, int w, int h)
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 layout
static const AVFilterPad xfade_vulkan_inputs[]
#define i(width, name, range_min, range_max)
int w
agreed upon image width
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.
const char * name
Pad name.
void(* free_shader)(struct FFVkSPIRVCompiler *ctx, void **opaque)
This struct describes a set or pool of "hardware" frames (i.e.
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
#define SHADER_SLIDE_COMMON
int ff_vk_shader_add_push_const(FFVulkanShader *shd, int offset, int size, VkShaderStageFlagBits stage)
Add/update push constants for execution.
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame.
static const char transition_slideright[]
int h
agreed upon image height
@ AV_OPT_TYPE_INT
Underlying C type is int.
static int config_props_output(AVFilterLink *outlink)
static av_cold int init_vulkan(AVFilterContext *avctx)
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
static const char transition_wipetr[]
int ff_vk_filter_config_input(AVFilterLink *inlink)
AVVulkanDeviceContext * hwctx
VkDevice act_dev
Active device.
int ff_vk_init_sampler(FFVulkanContext *s, VkSampler *sampler, int unnorm_coords, VkFilter filt)
Create a sampler.
static const char transition_wipeleft[]
the definition of that something depends on the semantic of the filter The callback must examine the status of the filter s links and proceed accordingly The status of output links is stored in the status_in and status_out fields and tested by the ff_outlink_frame_wanted() function. If this function returns true
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable.
AVFILTER_DEFINE_CLASS(xfade_vulkan)
static const char transition_slidedown[]
static av_cold void uninit(AVFilterContext *avctx)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.
AVFilterLink ** outputs
array of pointers to output links