Go to the documentation of this file.
92 C(0,
void transition(
int idx, ivec2
pos,
float progress) )
94 C(1, vec4
a = texture(a_images[idx],
pos); )
95 C(1, vec4
b = texture(b_images[idx],
pos); )
96 C(1, imageStore(output_images[idx],
pos,
mix(
a,
b, progress)); )
101 C(0,
void transition(
int idx, ivec2
pos,
float progress) )
103 C(1, ivec2
size = imageSize(output_images[idx]); )
104 C(1,
int s =
int(
size.x * (1.0 - progress)); )
105 C(1, vec4
a = texture(a_images[idx],
pos); )
106 C(1, vec4
b = texture(b_images[idx],
pos); )
107 C(1, imageStore(output_images[idx],
pos,
pos.x >
s ?
b :
a); )
112 C(0,
void transition(
int idx, ivec2
pos,
float progress) )
114 C(1, ivec2
size = imageSize(output_images[idx]); )
115 C(1,
int s =
int(
size.x * progress); )
116 C(1, vec4
a = texture(a_images[idx],
pos); )
117 C(1, vec4
b = texture(b_images[idx],
pos); )
118 C(1, imageStore(output_images[idx],
pos,
pos.x >
s ?
a :
b); )
123 C(0,
void transition(
int idx, ivec2
pos,
float progress) )
125 C(1, ivec2
size = imageSize(output_images[idx]); )
126 C(1,
int s =
int(
size.y * (1.0 - progress)); )
127 C(1, vec4
a = texture(a_images[idx],
pos); )
128 C(1, vec4
b = texture(b_images[idx],
pos); )
129 C(1, imageStore(output_images[idx],
pos,
pos.y >
s ?
b :
a); )
134 C(0,
void transition(
int idx, ivec2
pos,
float progress) )
136 C(1, ivec2
size = imageSize(output_images[idx]); )
137 C(1,
int s =
int(
size.y * progress); )
138 C(1, vec4
a = texture(a_images[idx],
pos); )
139 C(1, vec4
b = texture(b_images[idx],
pos); )
140 C(1, imageStore(output_images[idx],
pos,
pos.y >
s ?
a :
b); )
144 #define SHADER_SLIDE_COMMON \
145 C(0, void slide(int idx, ivec2 pos, float progress, ivec2 direction) ) \
147 C(1, ivec2 size = imageSize(output_images[idx]); ) \
148 C(1, ivec2 pi = ivec2(progress * size); ) \
149 C(1, ivec2 p = pos + pi * direction; ) \
150 C(1, ivec2 f = p % size; ) \
151 C(1, f = f + size * ivec2(f.x < 0, f.y < 0); ) \
152 C(1, vec4 a = texture(a_images[idx], f); ) \
153 C(1, vec4 b = texture(b_images[idx], f); ) \
154 C(1, vec4 r = (p.y >= 0 && p.x >= 0 && size.y > p.y && size.x > p.x) ? a : b; ) \
155 C(1, imageStore(output_images[idx], pos, r); ) \
160 C(0,
void transition(
int idx, ivec2
pos,
float progress) )
162 C(1, slide(idx,
pos, progress, ivec2(0, -1)); )
168 C(0,
void transition(
int idx, ivec2
pos,
float progress) )
170 C(1, slide(idx,
pos, progress, ivec2(0, +1)); )
176 C(0,
void transition(
int idx, ivec2
pos,
float progress) )
178 C(1, slide(idx,
pos, progress, ivec2(+1, 0)); )
184 C(0,
void transition(
int idx, ivec2
pos,
float progress) )
186 C(1, slide(idx,
pos, progress, ivec2(-1, 0)); )
190 #define SHADER_CIRCLE_COMMON \
191 C(0, void circle(int idx, ivec2 pos, float progress, bool open) ) \
193 C(1, const ivec2 half_size = imageSize(output_images[idx]) / 2; ) \
194 C(1, const float z = dot(half_size, half_size); ) \
195 C(1, float p = ((open ? (1.0 - progress) : progress) - 0.5) * 3.0; ) \
196 C(1, ivec2 dsize = pos - half_size; ) \
197 C(1, float sm = dot(dsize, dsize) / z + p; ) \
198 C(1, vec4 a = texture(a_images[idx], pos); ) \
199 C(1, vec4 b = texture(b_images[idx], pos); ) \
200 C(1, imageStore(output_images[idx], pos, \
201 mix(open ? b : a, open ? a : b, \
202 smoothstep(0.f, 1.f, sm))); ) \
207 C(0,
void transition(
int idx, ivec2
pos,
float progress) )
209 C(1, circle(idx,
pos, progress,
true); )
215 C(0,
void transition(
int idx, ivec2
pos,
float progress) )
217 C(1, circle(idx,
pos, progress,
false); )
221 #define SHADER_FRAND_FUNC \
222 C(0, float frand(vec2 v) ) \
224 C(1, return fract(sin(dot(v, vec2(12.9898, 78.233))) * 43758.545); ) \
229 C(0,
void transition(
int idx, ivec2
pos,
float progress) )
231 C(1,
float sm =
frand(
pos) * 2.0 + (1.0 - progress) * 2.0 - 1.5; )
232 C(1, vec4
a = texture(a_images[idx],
pos); )
233 C(1, vec4
b = texture(b_images[idx],
pos); )
234 C(1, imageStore(output_images[idx],
pos, sm >= 0.5 ?
a :
b); )
239 C(0,
void transition(
int idx, ivec2
pos,
float progress) )
241 C(1, ivec2
size = imageSize(output_images[idx]); )
242 C(1,
float d =
min(progress, 1.0 - progress); )
243 C(1,
float dist =
ceil(
d * 50.0) / 50.0; )
244 C(1,
float sq = 2.0 * dist *
min(
size.x,
size.y) / 20.0; )
247 C(1, vec4
a = texture(a_images[idx], vec2(sx, sy)); )
248 C(1, vec4
b = texture(b_images[idx], vec2(sx, sy)); )
249 C(1, imageStore(output_images[idx],
pos,
mix(
a,
b, progress)); )
254 C(0,
void transition(
int idx, ivec2
pos,
float progress) )
256 C(1, ivec2
size = imageSize(output_images[idx]); )
257 C(1,
float zw =
size.x * (1.0 - progress); )
258 C(1,
float zh =
size.y * (1.0 - progress); )
259 C(1, vec4
a = texture(a_images[idx],
pos); )
260 C(1, vec4
b = texture(b_images[idx],
pos); )
261 C(1, imageStore(output_images[idx],
pos, (
pos.y <= zh &&
pos.x <= zw) ?
a :
b); )
266 C(0,
void transition(
int idx, ivec2
pos,
float progress) )
268 C(1, ivec2
size = imageSize(output_images[idx]); )
269 C(1,
float zw =
size.x * (progress); )
270 C(1,
float zh =
size.y * (1.0 - progress); )
271 C(1, vec4
a = texture(a_images[idx],
pos); )
272 C(1, vec4
b = texture(b_images[idx],
pos); )
273 C(1, imageStore(output_images[idx],
pos, (
pos.y <= zh &&
pos.x > zw) ?
a :
b); )
278 C(0,
void transition(
int idx, ivec2
pos,
float progress) )
280 C(1, ivec2
size = imageSize(output_images[idx]); )
281 C(1,
float zw =
size.x * (1.0 - progress); )
282 C(1,
float zh =
size.y * (progress); )
283 C(1, vec4
a = texture(a_images[idx],
pos); )
284 C(1, vec4
b = texture(b_images[idx],
pos); )
285 C(1, imageStore(output_images[idx],
pos, (
pos.y > zh &&
pos.x <= zw) ?
a :
b); )
290 C(0,
void transition(
int idx, ivec2
pos,
float progress) )
292 C(1, ivec2
size = imageSize(output_images[idx]); )
293 C(1,
float zw =
size.x * (progress); )
294 C(1,
float zh =
size.y * (progress); )
295 C(1, vec4
a = texture(a_images[idx],
pos); )
296 C(1, vec4
b = texture(b_images[idx],
pos); )
297 C(1, imageStore(output_images[idx],
pos, (
pos.y > zh &&
pos.x > zw) ?
a :
b); )
326 void *spv_opaque =
NULL;
334 spv = ff_vk_spirv_init();
344 VK_SHADER_STAGE_COMPUTE_BIT, 0));
351 .type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
354 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
359 .type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
362 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
366 .name =
"output_images",
367 .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
369 .mem_quali =
"writeonly",
372 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
378 GLSLC(0,
layout(push_constant, std430) uniform pushConstants { );
379 GLSLC(1,
float progress; );
383 VK_SHADER_STAGE_COMPUTE_BIT);
390 GLSLC(1, ivec2
pos = ivec2(gl_GlobalInvocationID.xy); );
393 GLSLC(2, transition(
i,
pos, progress); );
428 if (!
s->initialized) {
431 if (a_fc->
sw_format != b_fc->sw_format) {
433 "Currently the sw format of the first input needs to match the second!\n");
442 progress =
av_clipf((
float)(
s->pts -
s->start_pts) /
s->duration_pts,
446 (
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",
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) {
650 return s->passthrough ?
655 #define OFFSET(x) offsetof(XFadeVulkanContext, x)
656 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
708 .
name =
"xfade_vulkan",
717 .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.
void ff_vk_pipeline_free(FFVulkanContext *s, FFVulkanPipeline *pl)
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[]
static int xfade_frame(AVFilterContext *avctx, AVFrame *frame_a, AVFrame *frame_b)
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
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.
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)
int ff_vk_filter_process_Nin(FFVulkanContext *vkctx, FFVkExecPool *e, FFVulkanPipeline *pl, AVFrame *out, AVFrame *in[], int nb_in, VkSampler sampler, void *push_src, size_t push_size)
Up to 16 inputs, one output.
static const char * transitions_map[NB_TRANSITIONS]
int ff_vk_shader_create(FFVulkanContext *s, FFVkSPIRVShader *shd, uint8_t *spirv, size_t spirv_size, const char *entrypoint)
static AVFrame * get_video_buffer(AVFilterLink *inlink, int w, int h)
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.
int ff_vk_pipeline_descriptor_set_add(FFVulkanContext *s, FFVulkanPipeline *pl, FFVkSPIRVShader *shd, FFVulkanDescriptorSetBinding *desc, int nb, int read_only, int print_to_shader_only)
Add descriptor to a pipeline.
void ff_vk_shader_set_compute_sizes(FFVkSPIRVShader *shd, int x, int y, int z)
A link between two filters.
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
const AVFilter ff_vf_xfade_vulkan
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.
int ff_vk_add_push_constant(FFVulkanPipeline *pl, int offset, int size, VkShaderStageFlagBits stage)
Add/update push constants for execution.
void * priv
private data for use by the filter
#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
int(* init)(AVBSFContext *ctx)
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0,...
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.
int(* compile_shader)(struct FFVkSPIRVCompiler *ctx, void *avctx, struct FFVkSPIRVShader *shd, uint8_t **data, size_t *size, const char *entrypoint, void **opaque)
void ff_vk_exec_pool_free(FFVulkanContext *s, FFVkExecPool *pool)
#define FILTER_INPUTS(array)
AVFrame * ff_inlink_peek_frame(AVFilterLink *link, size_t idx)
Access a frame in the link fifo without consuming it.
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[]
int ff_vk_init_compute_pipeline(FFVulkanContext *s, FFVulkanPipeline *pl, FFVkSPIRVShader *shd)
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.
int ff_vk_shader_init(FFVulkanPipeline *pl, FFVkSPIRVShader *shd, const char *name, VkShaderStageFlags stage, uint32_t required_subgroup_size)
Shader management.
int main(int argc, char **argv)
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
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
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
static const AVFilterPad xfade_vulkan_inputs[]
#define i(width, name, range_min, range_max)
int w
agreed upon image width
static const struct @363 planes[]
const char * ff_vk_shader_rep_fmt(enum AVPixelFormat pixfmt)
Returns the format to use for images in shaders.
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.
#define SHADER_SLIDE_COMMON
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
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.
#define FILTER_OUTPUTS(array)
int ff_vk_init_sampler(FFVulkanContext *s, VkSampler *sampler, int unnorm_coords, VkFilter filt)
Create a sampler.
int ff_vk_exec_pipeline_register(FFVulkanContext *s, FFVkExecPool *pool, FFVulkanPipeline *pl)
Register a pipeline with an exec pool.
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
AVFILTER_DEFINE_CLASS(xfade_vulkan)
static const char transition_slidedown[]
void ff_vk_shader_free(FFVulkanContext *s, FFVkSPIRVShader *shd)
static av_cold void uninit(AVFilterContext *avctx)
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