FFmpeg
vf_yadif_videotoolbox.m
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Philip Langdale <philipl@overt.org>
3  * 2020 Aman Karmani <aman@tmm1.net>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "internal.h"
23 #include "metal/utils.h"
24 #include "yadif.h"
25 #include "libavutil/avassert.h"
26 #include "libavutil/hwcontext.h"
27 #include "libavutil/objc.h"
28 
29 #include <assert.h>
30 
32 extern unsigned int ff_vf_yadif_videotoolbox_metallib_len;
33 
34 typedef struct API_AVAILABLE(macos(10.11), ios(8.0)) YADIFVTContext {
35  YADIFContext yadif;
36 
37  AVBufferRef *device_ref;
38  AVBufferRef *input_frames_ref;
39  AVHWFramesContext *input_frames;
40 
41  id<MTLDevice> mtlDevice;
42  id<MTLLibrary> mtlLibrary;
43  id<MTLCommandQueue> mtlQueue;
44  id<MTLComputePipelineState> mtlPipeline;
45  id<MTLFunction> mtlFunction;
46  id<MTLBuffer> mtlParamsBuffer;
47 
48  CVMetalTextureCacheRef textureCache;
49 } YADIFVTContext API_AVAILABLE(macos(10.11), ios(8.0));
50 
51 // Using sizeof(YADIFVTContext) outside of an availability check will error
52 // if we're targeting an older OS version, so we need to calculate the size ourselves
53 // (we'll statically verify it's correct in yadif_videotoolbox_init behind a check)
54 #define YADIF_VT_CTX_SIZE (sizeof(YADIFContext) + sizeof(void*) * 10)
55 
56 struct mtlYadifParams {
57  uint channels;
58  uint parity;
59  uint tff;
60  bool is_second_field;
61  bool skip_spatial_check;
62  int field_mode;
63 };
64 
65 static void call_kernel(AVFilterContext *ctx,
66  id<MTLTexture> dst,
67  id<MTLTexture> prev,
68  id<MTLTexture> cur,
69  id<MTLTexture> next,
70  int channels,
71  int parity,
72  int tff) API_AVAILABLE(macos(10.11), ios(8.0))
73 {
74  YADIFVTContext *s = ctx->priv;
75  id<MTLCommandBuffer> buffer = s->mtlQueue.commandBuffer;
76  id<MTLComputeCommandEncoder> encoder = buffer.computeCommandEncoder;
77  struct mtlYadifParams *params = (struct mtlYadifParams *)s->mtlParamsBuffer.contents;
78  *params = (struct mtlYadifParams){
79  .channels = channels,
80  .parity = parity,
81  .tff = tff,
82  .is_second_field = !(parity ^ tff),
83  .skip_spatial_check = s->yadif.mode&2,
84  .field_mode = s->yadif.current_field
85  };
86 
87  [encoder setTexture:dst atIndex:0];
88  [encoder setTexture:prev atIndex:1];
89  [encoder setTexture:cur atIndex:2];
90  [encoder setTexture:next atIndex:3];
91  [encoder setBuffer:s->mtlParamsBuffer offset:0 atIndex:4];
92  ff_metal_compute_encoder_dispatch(s->mtlDevice, s->mtlPipeline, encoder, dst.width, dst.height);
93  [encoder endEncoding];
94 
95  [buffer commit];
96  [buffer waitUntilCompleted];
97 
98  ff_objc_release(&encoder);
100 }
101 
102 static void filter(AVFilterContext *ctx, AVFrame *dst,
103  int parity, int tff) API_AVAILABLE(macos(10.11), ios(8.0))
104 {
105  YADIFVTContext *s = ctx->priv;
106  YADIFContext *y = &s->yadif;
107  int i;
108 
109  for (i = 0; i < y->csp->nb_components; i++) {
110  int pixel_size, channels;
111  const AVComponentDescriptor *comp = &y->csp->comp[i];
112  CVMetalTextureRef prev, cur, next, dest;
113  id<MTLTexture> tex_prev, tex_cur, tex_next, tex_dest;
114  MTLPixelFormat format;
115 
116  if (comp->plane < i) {
117  // We process planes as a whole, so don't reprocess
118  // them for additional components
119  continue;
120  }
121 
122  pixel_size = (comp->depth + comp->shift) / 8;
123  channels = comp->step / pixel_size;
124  if (pixel_size > 2 || channels > 2) {
125  av_log(ctx, AV_LOG_ERROR, "Unsupported pixel format: %s\n", y->csp->name);
126  goto exit;
127  }
128  switch (pixel_size) {
129  case 1:
130  format = channels == 1 ? MTLPixelFormatR8Unorm : MTLPixelFormatRG8Unorm;
131  break;
132  case 2:
133  format = channels == 1 ? MTLPixelFormatR16Unorm : MTLPixelFormatRG16Unorm;
134  break;
135  default:
136  av_log(ctx, AV_LOG_ERROR, "Unsupported pixel format: %s\n", y->csp->name);
137  goto exit;
138  }
140  "Deinterlacing plane %d: pixel_size: %d channels: %d\n",
141  comp->plane, pixel_size, channels);
142 
143  prev = ff_metal_texture_from_pixbuf(ctx, s->textureCache, (CVPixelBufferRef)y->prev->data[3], i, format);
144  cur = ff_metal_texture_from_pixbuf(ctx, s->textureCache, (CVPixelBufferRef)y->cur->data[3], i, format);
145  next = ff_metal_texture_from_pixbuf(ctx, s->textureCache, (CVPixelBufferRef)y->next->data[3], i, format);
146  dest = ff_metal_texture_from_pixbuf(ctx, s->textureCache, (CVPixelBufferRef)dst->data[3], i, format);
147 
148  tex_prev = CVMetalTextureGetTexture(prev);
149  tex_cur = CVMetalTextureGetTexture(cur);
150  tex_next = CVMetalTextureGetTexture(next);
151  tex_dest = CVMetalTextureGetTexture(dest);
152 
153  call_kernel(ctx, tex_dest, tex_prev, tex_cur, tex_next,
154  channels, parity, tff);
155 
156  CFRelease(prev);
157  CFRelease(cur);
158  CFRelease(next);
159  CFRelease(dest);
160  }
161 
162  CVBufferPropagateAttachments((CVPixelBufferRef)y->cur->data[3], (CVPixelBufferRef)dst->data[3]);
163 
164  if (y->current_field == YADIF_FIELD_END) {
166  }
167 
168 exit:
169  return;
170 }
171 
172 static av_cold void do_uninit(AVFilterContext *ctx) API_AVAILABLE(macos(10.11), ios(8.0))
173 {
174  YADIFVTContext *s = ctx->priv;
175  YADIFContext *y = &s->yadif;
176 
177  av_frame_free(&y->prev);
178  av_frame_free(&y->cur);
179  av_frame_free(&y->next);
180 
181  av_buffer_unref(&s->device_ref);
182  av_buffer_unref(&s->input_frames_ref);
183  s->input_frames = NULL;
184 
185  ff_objc_release(&s->mtlParamsBuffer);
186  ff_objc_release(&s->mtlFunction);
187  ff_objc_release(&s->mtlPipeline);
188  ff_objc_release(&s->mtlQueue);
189  ff_objc_release(&s->mtlLibrary);
190  ff_objc_release(&s->mtlDevice);
191 
192  if (s->textureCache) {
193  CFRelease(s->textureCache);
194  s->textureCache = NULL;
195  }
196 }
197 
198 
199 static av_cold void yadif_videotoolbox_uninit(AVFilterContext *ctx)
200 {
201  if (@available(macOS 10.11, iOS 8.0, *)) {
202  do_uninit(ctx);
203  }
204 }
205 
206 static av_cold int do_init(AVFilterContext *ctx) API_AVAILABLE(macos(10.11), ios(8.0))
207 {
208  YADIFVTContext *s = ctx->priv;
209  NSError *err = nil;
210  CVReturn ret;
211 
212  s->mtlDevice = MTLCreateSystemDefaultDevice();
213  if (!s->mtlDevice) {
214  av_log(ctx, AV_LOG_ERROR, "Unable to find Metal device\n");
215  goto fail;
216  }
217 
218  av_log(ctx, AV_LOG_INFO, "Using Metal device: %s\n", s->mtlDevice.name.UTF8String);
219 
220  dispatch_data_t libData = dispatch_data_create(
223  nil,
224  nil);
225  s->mtlLibrary = [s->mtlDevice newLibraryWithData:libData error:&err];
226  dispatch_release(libData);
227  libData = nil;
228  if (err) {
229  av_log(ctx, AV_LOG_ERROR, "Failed to load Metal library: %s\n", err.description.UTF8String);
230  goto fail;
231  }
232 
233  s->mtlFunction = [s->mtlLibrary newFunctionWithName:@"deint"];
234  if (!s->mtlFunction) {
235  av_log(ctx, AV_LOG_ERROR, "Failed to create Metal function!\n");
236  goto fail;
237  }
238 
239  s->mtlQueue = s->mtlDevice.newCommandQueue;
240  if (!s->mtlQueue) {
241  av_log(ctx, AV_LOG_ERROR, "Failed to create Metal command queue!\n");
242  goto fail;
243  }
244 
245  s->mtlPipeline = [s->mtlDevice
246  newComputePipelineStateWithFunction:s->mtlFunction
247  error:&err];
248  if (err) {
249  av_log(ctx, AV_LOG_ERROR, "Failed to create Metal compute pipeline: %s\n", err.description.UTF8String);
250  goto fail;
251  }
252 
253  s->mtlParamsBuffer = [s->mtlDevice
254  newBufferWithLength:sizeof(struct mtlYadifParams)
255  options:MTLResourceStorageModeShared];
256  if (!s->mtlParamsBuffer) {
257  av_log(ctx, AV_LOG_ERROR, "Failed to create Metal buffer for parameters\n");
258  goto fail;
259  }
260 
261  ret = CVMetalTextureCacheCreate(
262  NULL,
263  NULL,
264  s->mtlDevice,
265  NULL,
266  &s->textureCache
267  );
268  if (ret != kCVReturnSuccess) {
269  av_log(ctx, AV_LOG_ERROR, "Failed to create CVMetalTextureCache: %d\n", ret);
270  goto fail;
271  }
272 
273  return 0;
274 fail:
275  yadif_videotoolbox_uninit(ctx);
276  return AVERROR_EXTERNAL;
277 }
278 
279 static av_cold int yadif_videotoolbox_init(AVFilterContext *ctx)
280 {
281  if (@available(macOS 10.11, iOS 8.0, *)) {
282  // Ensure we calculated YADIF_VT_CTX_SIZE correctly
283  static_assert(YADIF_VT_CTX_SIZE == sizeof(YADIFVTContext), "Incorrect YADIF_VT_CTX_SIZE value!");
284  return do_init(ctx);
285  } else {
286  av_log(ctx, AV_LOG_ERROR, "Metal is not available on this OS version\n");
287  return AVERROR(ENOSYS);
288  }
289 }
290 
291 static int do_config_input(AVFilterLink *inlink) API_AVAILABLE(macos(10.11), ios(8.0))
292 {
293  AVFilterContext *ctx = inlink->dst;
294  YADIFVTContext *s = ctx->priv;
295 
296  if (!inlink->hw_frames_ctx) {
297  av_log(ctx, AV_LOG_ERROR, "A hardware frames reference is "
298  "required to associate the processing device.\n");
299  return AVERROR(EINVAL);
300  }
301 
302  s->input_frames_ref = av_buffer_ref(inlink->hw_frames_ctx);
303  if (!s->input_frames_ref) {
304  av_log(ctx, AV_LOG_ERROR, "A input frames reference create "
305  "failed.\n");
306  return AVERROR(ENOMEM);
307  }
308  s->input_frames = (AVHWFramesContext*)s->input_frames_ref->data;
309 
310  return 0;
311 }
312 
313 static int config_input(AVFilterLink *inlink)
314 {
315  AVFilterContext *ctx = inlink->dst;
316  if (@available(macOS 10.11, iOS 8.0, *)) {
317  return do_config_input(inlink);
318  } else {
319  av_log(ctx, AV_LOG_ERROR, "Metal is not available on this OS version\n");
320  return AVERROR(ENOSYS);
321  }
322 }
323 
324 static int do_config_output(AVFilterLink *link) API_AVAILABLE(macos(10.11), ios(8.0))
325 {
326  AVHWFramesContext *output_frames;
327  AVFilterContext *ctx = link->src;
328  YADIFVTContext *s = ctx->priv;
329  YADIFContext *y = &s->yadif;
330  int ret = 0;
331 
332  av_assert0(s->input_frames);
333  s->device_ref = av_buffer_ref(s->input_frames->device_ref);
334  if (!s->device_ref) {
335  av_log(ctx, AV_LOG_ERROR, "A device reference create "
336  "failed.\n");
337  return AVERROR(ENOMEM);
338  }
339 
340  link->hw_frames_ctx = av_hwframe_ctx_alloc(s->device_ref);
341  if (!link->hw_frames_ctx) {
342  av_log(ctx, AV_LOG_ERROR, "Failed to create HW frame context "
343  "for output.\n");
344  ret = AVERROR(ENOMEM);
345  goto exit;
346  }
347 
348  output_frames = (AVHWFramesContext*)link->hw_frames_ctx->data;
349 
350  output_frames->format = AV_PIX_FMT_VIDEOTOOLBOX;
351  output_frames->sw_format = s->input_frames->sw_format;
352  output_frames->width = ctx->inputs[0]->w;
353  output_frames->height = ctx->inputs[0]->h;
354 
356  if (ret < 0)
357  goto exit;
358 
360  if (ret < 0) {
361  av_log(ctx, AV_LOG_ERROR, "Failed to initialise VideoToolbox frame "
362  "context for output: %d\n", ret);
363  goto exit;
364  }
365 
366  link->time_base.num = ctx->inputs[0]->time_base.num;
367  link->time_base.den = ctx->inputs[0]->time_base.den * 2;
368  link->w = ctx->inputs[0]->w;
369  link->h = ctx->inputs[0]->h;
370 
371  if(y->mode & 1)
372  link->frame_rate = av_mul_q(ctx->inputs[0]->frame_rate,
373  (AVRational){2, 1});
374 
375  if (link->w < 3 || link->h < 3) {
376  av_log(ctx, AV_LOG_ERROR, "Video of less than 3 columns or lines is not supported\n");
377  ret = AVERROR(EINVAL);
378  goto exit;
379  }
380 
381  y->csp = av_pix_fmt_desc_get(output_frames->sw_format);
382  y->filter = filter;
383 
384 exit:
385  return ret;
386 }
387 
388 static int config_output(AVFilterLink *link)
389 {
390  AVFilterContext *ctx = link->src;
391  if (@available(macOS 10.11, iOS 8.0, *)) {
392  return do_config_output(link);
393  } else {
394  av_log(ctx, AV_LOG_ERROR, "Metal is not available on this OS version\n");
395  return AVERROR(ENOSYS);
396  }
397 }
398 
399 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
400 #define CONST(name, help, val, unit) { name, help, 0, AV_OPT_TYPE_CONST, {.i64=val}, INT_MIN, INT_MAX, FLAGS, unit }
401 
402 static const AVOption yadif_videotoolbox_options[] = {
403  #define OFFSET(x) offsetof(YADIFContext, x)
404  { "mode", "specify the interlacing mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=YADIF_MODE_SEND_FRAME}, 0, 3, FLAGS, "mode"},
405  CONST("send_frame", "send one frame for each frame", YADIF_MODE_SEND_FRAME, "mode"),
406  CONST("send_field", "send one frame for each field", YADIF_MODE_SEND_FIELD, "mode"),
407  CONST("send_frame_nospatial", "send one frame for each frame, but skip spatial interlacing check", YADIF_MODE_SEND_FRAME_NOSPATIAL, "mode"),
408  CONST("send_field_nospatial", "send one frame for each field, but skip spatial interlacing check", YADIF_MODE_SEND_FIELD_NOSPATIAL, "mode"),
409 
410  { "parity", "specify the assumed picture field parity", OFFSET(parity), AV_OPT_TYPE_INT, {.i64=YADIF_PARITY_AUTO}, -1, 1, FLAGS, "parity" },
411  CONST("tff", "assume top field first", YADIF_PARITY_TFF, "parity"),
412  CONST("bff", "assume bottom field first", YADIF_PARITY_BFF, "parity"),
413  CONST("auto", "auto detect parity", YADIF_PARITY_AUTO, "parity"),
414 
415  { "deint", "specify which frames to deinterlace", OFFSET(deint), AV_OPT_TYPE_INT, {.i64=YADIF_DEINT_ALL}, 0, 1, FLAGS, "deint" },
416  CONST("all", "deinterlace all frames", YADIF_DEINT_ALL, "deint"),
417  CONST("interlaced", "only deinterlace frames marked as interlaced", YADIF_DEINT_INTERLACED, "deint"),
418  #undef OFFSET
419 
420  { NULL }
421 };
422 
423 AVFILTER_DEFINE_CLASS(yadif_videotoolbox);
424 
425 static const AVFilterPad yadif_videotoolbox_inputs[] = {
426  {
427  .name = "default",
428  .type = AVMEDIA_TYPE_VIDEO,
429  .filter_frame = ff_yadif_filter_frame,
430  .config_props = config_input,
431  },
432 };
433 
434 static const AVFilterPad yadif_videotoolbox_outputs[] = {
435  {
436  .name = "default",
437  .type = AVMEDIA_TYPE_VIDEO,
438  .request_frame = ff_yadif_request_frame,
439  .config_props = config_output,
440  },
441 };
442 
444  .name = "yadif_videotoolbox",
445  .description = NULL_IF_CONFIG_SMALL("YADIF for VideoToolbox frames using Metal compute"),
446  .priv_size = YADIF_VT_CTX_SIZE,
447  .priv_class = &yadif_videotoolbox_class,
448  .init = yadif_videotoolbox_init,
449  .uninit = yadif_videotoolbox_uninit,
451  FILTER_INPUTS(yadif_videotoolbox_inputs),
452  FILTER_OUTPUTS(yadif_videotoolbox_outputs),
454  .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
455 };
YADIF_MODE_SEND_FIELD
@ YADIF_MODE_SEND_FIELD
send 1 frame for each field
Definition: yadif.h:28
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
ios
void ios(8.0))
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: internal.h:370
comp
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
Definition: eamad.c:80
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2888
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
AVHWFramesContext::format
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition: hwcontext.h:209
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
YADIFContext::csp
const AVPixFmtDescriptor * csp
Definition: yadif.h:75
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:116
YADIFContext::mode
int mode
YADIFMode.
Definition: yadif.h:53
av_hwframe_ctx_init
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
Definition: hwcontext.c:334
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:330
ff_objc_release
static void ff_objc_release(NSObject **obj)
Definition: objc.h:24
av_hwframe_ctx_alloc
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
Definition: hwcontext.c:248
ff_vf_yadif_videotoolbox_metallib_len
unsigned int ff_vf_yadif_videotoolbox_metallib_len
AVPixFmtDescriptor::name
const char * name
Definition: pixdesc.h:70
AVOption
AVOption.
Definition: opt.h:251
filter
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 then the filter should push the output frames on the output link immediately As an exception to the previous rule if the input frame is enough to produce several output frames then the filter needs output only at least one per link The additional frames can be left buffered in the filter
Definition: filter_design.txt:228
av_buffer_ref
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:103
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:175
AVHWFramesContext::width
int width
The allocated dimensions of the frames in this pool.
Definition: hwcontext.h:229
objc.h
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:351
YADIF_MODE_SEND_FRAME
@ YADIF_MODE_SEND_FRAME
send 1 frame for each frame
Definition: yadif.h:27
YADIF_MODE_SEND_FIELD_NOSPATIAL
@ YADIF_MODE_SEND_FIELD_NOSPATIAL
send 1 frame for each field but skips spatial interlacing check
Definition: yadif.h:30
fail
#define fail()
Definition: checkasm.h:134
YADIF_PARITY_AUTO
@ YADIF_PARITY_AUTO
auto detection
Definition: yadif.h:36
YADIF_MODE_SEND_FRAME_NOSPATIAL
@ YADIF_MODE_SEND_FRAME_NOSPATIAL
send 1 frame for each frame but skips spatial interlacing check
Definition: yadif.h:29
ff_vf_yadif_videotoolbox
const AVFilter ff_vf_yadif_videotoolbox
AVRational::num
int num
Numerator.
Definition: rational.h:59
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:49
config_output
static int config_output(AVFilterLink *outlink)
Definition: af_adenorm.c:156
first
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But first
Definition: rate_distortion.txt:12
avassert.h
AV_LOG_TRACE
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:206
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_cold
#define av_cold
Definition: attributes.h:90
AVHWFramesContext::height
int height
Definition: hwcontext.h:229
s
#define s(width, name)
Definition: cbs_vp9.c:256
format
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 format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
ctx
AVFormatContext * ctx
Definition: movenc.c:48
channels
channels
Definition: aptx.h:31
field
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 field
Definition: writing_filters.txt:78
utils.h
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:190
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
if
if(ret)
Definition: filter_design.txt:179
NULL
#define NULL
Definition: coverity.c:32
AVHWFramesContext::sw_format
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition: hwcontext.h:222
YADIF_VT_CTX_SIZE
#define YADIF_VT_CTX_SIZE
config_input
static int config_input(AVFilterLink *inlink)
Definition: af_acontrast.c:121
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
AVComponentDescriptor
Definition: pixdesc.h:30
AVPixFmtDescriptor::nb_components
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:71
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
ff_metal_texture_from_pixbuf
CVMetalTextureRef ff_metal_texture_from_pixbuf(void *avclass, CVMetalTextureCacheRef textureCache, CVPixelBufferRef pixbuf, int plane, MTLPixelFormat format) API_AVAILABLE(macos(10.11)
OFFSET
#define OFFSET(x)
yadif.h
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:115
YADIFContext::filter
void(* filter)(AVFilterContext *ctx, AVFrame *dstpic, int parity, int tff)
Definition: yadif.h:64
parity
mcdeint parity
Definition: vf_mcdeint.c:266
AVFrame::time_base
AVRational time_base
Time base for the timestamps in this frame.
Definition: frame.h:452
ff_vf_yadif_videotoolbox_metallib_data
char ff_vf_yadif_videotoolbox_metallib_data[]
YADIFContext::prev
AVFrame * prev
Definition: yadif.h:61
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:59
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
internal.h
AVFILTER_DEFINE_CLASS
#define AVFILTER_DEFINE_CLASS(fname)
Definition: internal.h:325
FILTER_SINGLE_PIXFMT
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
Definition: internal.h:180
AV_PIX_FMT_VIDEOTOOLBOX
@ AV_PIX_FMT_VIDEOTOOLBOX
hardware decoding through Videotoolbox
Definition: pixfmt.h:302
call_kernel
static CUresult call_kernel(AVFilterContext *ctx, CUfunction func, CUdeviceptr prev, CUdeviceptr cur, CUdeviceptr next, CUarray_format format, int channels, int src_width, int src_height, int src_pitch, CUdeviceptr dst, int dst_width, int dst_height, int dst_pitch, int parity, int tff)
Definition: vf_yadif_cuda.c:57
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
available
if no frame is available
Definition: filter_design.txt:166
YADIFContext
Definition: yadif.h:50
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:55
AVFilter
Filter definition.
Definition: avfilter.h:171
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:124
ret
ret
Definition: filter_design.txt:187
YADIF_DEINT_ALL
@ YADIF_DEINT_ALL
deinterlace all frames
Definition: yadif.h:40
AVFrame::hw_frames_ctx
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame.
Definition: frame.h:674
YADIFContext::next
AVFrame * next
Definition: yadif.h:60
buffer
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
Definition: filter_design.txt:49
YADIF_FIELD_END
@ YADIF_FIELD_END
The first or last field in a sequence.
Definition: yadif.h:46
AVRational::den
int den
Denominator.
Definition: rational.h:60
mode
mode
Definition: ebur128.h:83
ff_yadif_request_frame
int ff_yadif_request_frame(AVFilterLink *link)
Definition: yadif_common.c:159
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
CONST
#define CONST(name, help, val, unit)
AVPixFmtDescriptor::comp
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:105
av_mul_q
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
AVFilterContext
An instance of a filter.
Definition: avfilter.h:402
YADIF_DEINT_INTERLACED
@ YADIF_DEINT_INTERLACED
only deinterlace frames marked as interlaced
Definition: yadif.h:41
YADIF_FIELD_NORMAL
@ YADIF_FIELD_NORMAL
A normal field in the middle of a sequence.
Definition: yadif.h:47
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
YADIF_PARITY_TFF
@ YADIF_PARITY_TFF
top field first
Definition: yadif.h:34
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
YADIFContext::current_field
int current_field
YADIFCurrentField.
Definition: yadif.h:86
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:191
AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
Definition: avfilter.h:160
hwcontext.h
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
YADIFContext::cur
AVFrame * cur
Definition: yadif.h:59
ff_metal_compute_encoder_dispatch
void ff_metal_compute_encoder_dispatch(id< MTLDevice > device, id< MTLComputePipelineState > pipeline, id< MTLComputeCommandEncoder > encoder, NSUInteger width, NSUInteger height) API_AVAILABLE(macos(10.11)
ff_yadif_filter_frame
int ff_yadif_filter_frame(AVFilterLink *link, AVFrame *frame)
Definition: yadif_common.c:92
FLAGS
#define FLAGS
YADIF_PARITY_BFF
@ YADIF_PARITY_BFF
bottom field first
Definition: yadif.h:35
ff_filter_init_hw_frames
int ff_filter_init_hw_frames(AVFilterContext *avctx, AVFilterLink *link, int default_pool_size)
Perform any additional setup required for hardware frames.
Definition: avfilter.c:1531