FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavfilter/vf_nnedi.c
Date: 2024-04-24 18:52:15
Exec Total Coverage
Lines: 0 547 0.0%
Functions: 0 37 0.0%
Branches: 0 252 0.0%

Line Branch Exec Source
1 /*
2 * Copyright (C) 2010-2011 Kevin Stone
3 * Copyright (C) 2016 Paul B Mahol
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (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
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22 #include <float.h>
23
24 #include "libavutil/common.h"
25 #include "libavutil/file_open.h"
26 #include "libavutil/float_dsp.h"
27 #include "libavutil/imgutils.h"
28 #include "libavutil/mem.h"
29 #include "libavutil/mem_internal.h"
30 #include "libavutil/opt.h"
31 #include "libavutil/pixdesc.h"
32 #include "avfilter.h"
33 #include "internal.h"
34 #include "video.h"
35
36 static const size_t NNEDI_WEIGHTS_SIZE = 13574928;
37 static const uint8_t NNEDI_XDIM[] = { 8, 16, 32, 48, 8, 16, 32 };
38 static const uint8_t NNEDI_YDIM[] = { 6, 6, 6, 6, 4, 4, 4 };
39 static const uint16_t NNEDI_NNS[] = { 16, 32, 64, 128, 256 };
40
41 typedef struct PrescreenerCoefficients {
42 DECLARE_ALIGNED(32, float, kernel_l0)[4][16 * 4];
43 DECLARE_ALIGNED(32, float, bias_l0)[4];
44
45 DECLARE_ALIGNED(32, float, kernel_l1)[4][4];
46 DECLARE_ALIGNED(32, float, bias_l1)[4];
47
48 DECLARE_ALIGNED(32, float, kernel_l2)[4][8];
49 DECLARE_ALIGNED(32, float, bias_l2)[4];
50 } PrescreenerCoefficients;
51
52 typedef struct PredictorCoefficients {
53 int xdim, ydim, nns, nsize;
54 float *data;
55 float *softmax_q1;
56 float *elliott_q1;
57 float *softmax_bias_q1;
58 float *elliott_bias_q1;
59 float *softmax_q2;
60 float *elliott_q2;
61 float *softmax_bias_q2;
62 float *elliott_bias_q2;
63 } PredictorCoefficients;
64
65 typedef struct NNEDIContext {
66 const AVClass *class;
67
68 char *weights_file;
69
70 AVFrame *prev;
71 int eof;
72 int64_t pts;
73
74 AVFloatDSPContext *fdsp;
75 int depth;
76 int nb_planes;
77 int nb_threads;
78 int linesize[4];
79 int planewidth[4];
80 int planeheight[4];
81 int field_n;
82
83 PrescreenerCoefficients prescreener[4];
84 PredictorCoefficients coeffs[2][5][7];
85
86 float half;
87 float in_scale;
88 float out_scale;
89
90 // Parameters
91 int deint;
92 int field;
93 int process_plane;
94 int nsize;
95 int nnsparam;
96 int qual;
97 int etype;
98 int pscrn;
99
100 int input_size;
101 uint8_t **prescreen_buf;
102 float **input_buf;
103 float **output_buf;
104
105 void (*read)(const uint8_t *src, float *dst,
106 int src_stride, int dst_stride,
107 int width, int height, float scale);
108 void (*write)(const float *src, uint8_t *dst,
109 int src_stride, int dst_stride,
110 int width, int height, int depth, float scale);
111 void (*prescreen[2])(AVFilterContext *ctx,
112 const void *src, ptrdiff_t src_stride,
113 uint8_t *prescreen, int N,
114 const PrescreenerCoefficients *const coeffs);
115 } NNEDIContext;
116
117 #define OFFSET(x) offsetof(NNEDIContext, x)
118 #define RFLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
119 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
120
121 static const AVOption nnedi_options[] = {
122 {"weights", "set weights file", OFFSET(weights_file), AV_OPT_TYPE_STRING, {.str="nnedi3_weights.bin"}, 0, 0, FLAGS },
123 {"deint", "set which frames to deinterlace", OFFSET(deint), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, RFLAGS, .unit = "deint" },
124 {"all", "deinterlace all frames", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, RFLAGS, .unit = "deint" },
125 {"interlaced", "only deinterlace frames marked as interlaced", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, RFLAGS, .unit = "deint" },
126 {"field", "set mode of operation", OFFSET(field), AV_OPT_TYPE_INT, {.i64=-1}, -2, 3, RFLAGS, .unit = "field" },
127 {"af", "use frame flags, both fields", 0, AV_OPT_TYPE_CONST, {.i64=-2}, 0, 0, RFLAGS, .unit = "field" },
128 {"a", "use frame flags, single field", 0, AV_OPT_TYPE_CONST, {.i64=-1}, 0, 0, RFLAGS, .unit = "field" },
129 {"t", "use top field only", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, RFLAGS, .unit = "field" },
130 {"b", "use bottom field only", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, RFLAGS, .unit = "field" },
131 {"tf", "use both fields, top first", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, RFLAGS, .unit = "field" },
132 {"bf", "use both fields, bottom first", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, RFLAGS, .unit = "field" },
133 {"planes", "set which planes to process", OFFSET(process_plane), AV_OPT_TYPE_INT, {.i64=7}, 0, 15, RFLAGS },
134 {"nsize", "set size of local neighborhood around each pixel, used by the predictor neural network", OFFSET(nsize), AV_OPT_TYPE_INT, {.i64=6}, 0, 6, RFLAGS, .unit = "nsize" },
135 {"s8x6", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, RFLAGS, .unit = "nsize" },
136 {"s16x6", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, RFLAGS, .unit = "nsize" },
137 {"s32x6", NULL, 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, RFLAGS, .unit = "nsize" },
138 {"s48x6", NULL, 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, RFLAGS, .unit = "nsize" },
139 {"s8x4", NULL, 0, AV_OPT_TYPE_CONST, {.i64=4}, 0, 0, RFLAGS, .unit = "nsize" },
140 {"s16x4", NULL, 0, AV_OPT_TYPE_CONST, {.i64=5}, 0, 0, RFLAGS, .unit = "nsize" },
141 {"s32x4", NULL, 0, AV_OPT_TYPE_CONST, {.i64=6}, 0, 0, RFLAGS, .unit = "nsize" },
142 {"nns", "set number of neurons in predictor neural network", OFFSET(nnsparam), AV_OPT_TYPE_INT, {.i64=1}, 0, 4, RFLAGS, .unit = "nns" },
143 {"n16", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, RFLAGS, .unit = "nns" },
144 {"n32", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, RFLAGS, .unit = "nns" },
145 {"n64", NULL, 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, RFLAGS, .unit = "nns" },
146 {"n128", NULL, 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, RFLAGS, .unit = "nns" },
147 {"n256", NULL, 0, AV_OPT_TYPE_CONST, {.i64=4}, 0, 0, RFLAGS, .unit = "nns" },
148 {"qual", "set quality", OFFSET(qual), AV_OPT_TYPE_INT, {.i64=1}, 1, 2, RFLAGS, .unit = "qual" },
149 {"fast", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, RFLAGS, .unit = "qual" },
150 {"slow", NULL, 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, RFLAGS, .unit = "qual" },
151 {"etype", "set which set of weights to use in the predictor", OFFSET(etype), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, RFLAGS, .unit = "etype" },
152 {"a", "weights trained to minimize absolute error", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, RFLAGS, .unit = "etype" },
153 {"abs","weights trained to minimize absolute error", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, RFLAGS, .unit = "etype" },
154 {"s", "weights trained to minimize squared error", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, RFLAGS, .unit = "etype" },
155 {"mse","weights trained to minimize squared error", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, RFLAGS, .unit = "etype" },
156 {"pscrn", "set prescreening", OFFSET(pscrn), AV_OPT_TYPE_INT, {.i64=2}, 0, 4, RFLAGS, .unit = "pscrn" },
157 {"none", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, RFLAGS, .unit = "pscrn" },
158 {"original", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, RFLAGS, .unit = "pscrn" },
159 {"new", NULL, 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, RFLAGS, .unit = "pscrn" },
160 {"new2", NULL, 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, RFLAGS, .unit = "pscrn" },
161 {"new3", NULL, 0, AV_OPT_TYPE_CONST, {.i64=4}, 0, 0, RFLAGS, .unit = "pscrn" },
162 { NULL }
163 };
164
165 AVFILTER_DEFINE_CLASS(nnedi);
166
167 static int config_output(AVFilterLink *outlink)
168 {
169 AVFilterContext *ctx = outlink->src;
170 const NNEDIContext *const s = ctx->priv;
171
172 outlink->time_base = av_mul_q(ctx->inputs[0]->time_base, (AVRational){1, 2});
173 outlink->w = ctx->inputs[0]->w;
174 outlink->h = ctx->inputs[0]->h;
175
176 if (s->field == -2 || s->field > 1)
177 outlink->frame_rate = av_mul_q(ctx->inputs[0]->frame_rate,
178 (AVRational){2, 1});
179
180 return 0;
181 }
182
183 static const enum AVPixelFormat pix_fmts[] = {
184 AV_PIX_FMT_GRAY8,
185 AV_PIX_FMT_GRAY9, AV_PIX_FMT_GRAY10, AV_PIX_FMT_GRAY12, AV_PIX_FMT_GRAY14, AV_PIX_FMT_GRAY16,
186 AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P,
187 AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P,
188 AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV444P,
189 AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ440P,
190 AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ420P,
191 AV_PIX_FMT_YUVJ411P,
192 AV_PIX_FMT_YUVA420P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA444P,
193 AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP,
194 AV_PIX_FMT_YUV420P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV444P9,
195 AV_PIX_FMT_YUV420P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV444P10,
196 AV_PIX_FMT_YUV440P10,
197 AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV444P12,
198 AV_PIX_FMT_YUV440P12,
199 AV_PIX_FMT_YUV420P14, AV_PIX_FMT_YUV422P14, AV_PIX_FMT_YUV444P14,
200 AV_PIX_FMT_YUV420P16, AV_PIX_FMT_YUV422P16, AV_PIX_FMT_YUV444P16,
201 AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14, AV_PIX_FMT_GBRP16,
202 AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA444P12, AV_PIX_FMT_YUVA444P16,
203 AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA422P12, AV_PIX_FMT_YUVA422P16,
204 AV_PIX_FMT_YUVA420P9, AV_PIX_FMT_YUVA420P10, AV_PIX_FMT_YUVA420P16,
205 AV_PIX_FMT_GBRAP10, AV_PIX_FMT_GBRAP12, AV_PIX_FMT_GBRAP16,
206 AV_PIX_FMT_NONE
207 };
208
209 static float dot_dsp(const NNEDIContext *const s, const float *kernel, const float *input,
210 int n, float scale, float bias)
211 {
212 float sum, y;
213
214 sum = s->fdsp->scalarproduct_float(kernel, input, n);
215
216 y = sum * scale + bias + 1e-20f;
217
218 return y;
219 }
220
221 static float elliott(float x)
222 {
223 return x / (1.0f + fabsf(x));
224 }
225
226 static void transform_elliott(float *input, int size)
227 {
228 for (int i = 0; i < size; i++)
229 input[i] = elliott(input[i]);
230 }
231
232 static void process_old(AVFilterContext *ctx,
233 const void *src, ptrdiff_t src_stride,
234 uint8_t *prescreen, int N,
235 const PrescreenerCoefficients *const m_data)
236 {
237 NNEDIContext *s = ctx->priv;
238 const float *src_p = src;
239
240 // Adjust source pointer to point to top-left of filter window.
241 const float *window = src_p - 2 * src_stride - 5;
242
243 for (int j = 0; j < N; j++) {
244 LOCAL_ALIGNED_32(float, input, [48]);
245 float state[12];
246
247 for (int i = 0; i < 4; i++)
248 memcpy(input + i * 12, window + i * src_stride + j, 12 * sizeof(float));
249
250 // Layer 0.
251 for (int n = 0; n < 4; n++)
252 state[n] = dot_dsp(s, m_data->kernel_l0[n], input, 48, 1.0f, m_data->bias_l0[n]);
253 transform_elliott(state + 1, 3);
254
255 // Layer 1.
256 for (int n = 0; n < 4; n++)
257 state[n + 4] = dot_dsp(s, m_data->kernel_l1[n], state, 4, 1.0f, m_data->bias_l1[n]);
258 transform_elliott(state + 4, 3);
259
260 // Layer 2.
261 for (int n = 0; n < 4; n++)
262 state[n + 8] = dot_dsp(s, m_data->kernel_l2[n], state, 8, 1.0f, m_data->bias_l2[n]);
263
264 prescreen[j] = FFMAX(state[10], state[11]) <= FFMAX(state[8], state[9]) ? 255 : 0;
265 }
266 }
267
268 static void process_new(AVFilterContext *ctx,
269 const void *src, ptrdiff_t src_stride,
270 uint8_t *prescreen, int N,
271 const PrescreenerCoefficients *const m_data)
272 {
273 NNEDIContext *s = ctx->priv;
274 const float *src_p = src;
275
276 // Adjust source pointer to point to top-left of filter window.
277 const float *window = src_p - 2 * src_stride - 6;
278
279 for (int j = 0; j < N; j += 4) {
280 LOCAL_ALIGNED_32(float, input, [64]);
281 float state[8];
282
283 for (int i = 0; i < 4; i++)
284 memcpy(input + i * 16, window + i * src_stride + j, 16 * sizeof(float));
285
286 for (int n = 0; n < 4; n++)
287 state[n] = dot_dsp(s, m_data->kernel_l0[n], input, 64, 1.0f, m_data->bias_l0[n]);
288 transform_elliott(state, 4);
289
290 for (int n = 0; n < 4; n++)
291 state[n + 4] = dot_dsp(s, m_data->kernel_l1[n], state, 4, 1.0f, m_data->bias_l1[n]);
292
293 for (int n = 0; n < 4; n++)
294 prescreen[j + n] = state[n + 4] > 0.f;
295 }
296 }
297
298 static int filter_offset(int nn, const PredictorCoefficients *const model)
299 {
300 return nn * model->nsize;
301 }
302
303 static const float *softmax_q1_filter(int nn,
304 const PredictorCoefficients *const model)
305 {
306 return model->softmax_q1 + filter_offset(nn, model);
307 }
308
309 static const float *elliott_q1_filter(int nn,
310 const PredictorCoefficients *const model)
311 {
312 return model->elliott_q1 + filter_offset(nn, model);
313 }
314
315 static const float *softmax_q2_filter(int nn,
316 const PredictorCoefficients *const model)
317 {
318 return model->softmax_q2 + filter_offset(nn, model);
319 }
320
321 static const float *elliott_q2_filter(int nn,
322 const PredictorCoefficients *const model)
323 {
324 return model->elliott_q2 + filter_offset(nn, model);
325 }
326
327 static void gather_input(const float *src, ptrdiff_t src_stride,
328 float *buf, float mstd[4],
329 const PredictorCoefficients *const model)
330 {
331 const float scale = 1.f / model->nsize;
332 float sum = 0.f;
333 float sum_sq = 0.f;
334 float tmp;
335
336 for (int i = 0; i < model->ydim; i++) {
337 memcpy(buf, src, model->xdim * sizeof(float));
338
339 for (int j = 0; j < model->xdim; j++) {
340 const float val = src[j];
341
342 sum += val;
343 sum_sq += val * val;
344 }
345
346 src += src_stride;
347 buf += model->xdim;
348 }
349
350 mstd[0] = sum * scale;
351 mstd[3] = 0.f;
352
353 tmp = sum_sq * scale - mstd[0] * mstd[0];
354 if (tmp < FLT_EPSILON) {
355 mstd[1] = 0.0f;
356 mstd[2] = 0.0f;
357 } else {
358 mstd[1] = sqrtf(tmp);
359 mstd[2] = 1.0f / mstd[1];
360 }
361 }
362
363 static float softmax_exp(float x)
364 {
365 return expf(av_clipf(x, -80.f, 80.f));
366 }
367
368 static void transform_softmax_exp(float *input, int size)
369 {
370 for (int i = 0; i < size; i++)
371 input[i] = softmax_exp(input[i]);
372 }
373
374 static void wae5(const float *softmax, const float *el,
375 int n, float mstd[4])
376 {
377 float vsum = 0.0f, wsum = 0.0f;
378
379 for (int i = 0; i < n; i++) {
380 vsum += softmax[i] * elliott(el[i]);
381 wsum += softmax[i];
382 }
383
384 if (wsum > 1e-10f)
385 mstd[3] += (5.0f * vsum) / wsum * mstd[1] + mstd[0];
386 else
387 mstd[3] += mstd[0];
388 }
389
390 static void predictor(AVFilterContext *ctx,
391 const void *src, ptrdiff_t src_stride, void *dst,
392 const uint8_t *prescreen, int N,
393 const PredictorCoefficients *const model, int use_q2)
394 {
395 const NNEDIContext *const s = ctx->priv;
396 const float *src_p = src;
397 float *dst_p = dst;
398
399 // Adjust source pointer to point to top-left of filter window.
400 const float *window = src_p - (model->ydim / 2) * src_stride - (model->xdim / 2 - 1);
401 const int filter_size = model->nsize;
402 const int nns = model->nns;
403
404 for (int i = 0; i < N; i++) {
405 LOCAL_ALIGNED_32(float, input, [48 * 6]);
406 float activation[256 * 2];
407 float mstd[4];
408 float scale;
409
410 if (prescreen[i])
411 continue;
412
413 gather_input(window + i, src_stride, input, mstd, model);
414 scale = mstd[2];
415
416 for (int nn = 0; nn < nns; nn++)
417 activation[nn] = dot_dsp(s, softmax_q1_filter(nn, model), input, filter_size, scale, model->softmax_bias_q1[nn]);
418
419 for (int nn = 0; nn < nns; nn++)
420 activation[nns + nn] = dot_dsp(s, elliott_q1_filter(nn, model), input, filter_size, scale, model->elliott_bias_q1[nn]);
421
422 transform_softmax_exp(activation, nns);
423 wae5(activation, activation + nns, nns, mstd);
424
425 if (use_q2) {
426 for (int nn = 0; nn < nns; nn++)
427 activation[nn] = dot_dsp(s, softmax_q2_filter(nn, model), input, filter_size, scale, model->softmax_bias_q2[nn]);
428
429 for (int nn = 0; nn < nns; nn++)
430 activation[nns + nn] = dot_dsp(s, elliott_q2_filter(nn, model), input, filter_size, scale, model->elliott_bias_q2[nn]);
431
432 transform_softmax_exp(activation, nns);
433 wae5(activation, activation + nns, nns, mstd);
434 }
435
436 dst_p[i] = mstd[3] * (use_q2 ? 0.5f : 1.f);
437 }
438 }
439
440 static void read_bytes(const uint8_t *src, float *dst,
441 int src_stride, int dst_stride,
442 int width, int height, float scale)
443 {
444 for (int y = 0; y < height; y++) {
445 for (int x = 0; x < 32; x++)
446 dst[-x - 1] = src[x];
447
448 for (int x = 0; x < width; x++)
449 dst[x] = src[x];
450
451 for (int x = 0; x < 32; x++)
452 dst[width + x] = src[width - x - 1];
453
454 dst += dst_stride;
455 src += src_stride;
456 }
457 }
458
459 static void read_words(const uint8_t *srcp, float *dst,
460 int src_stride, int dst_stride,
461 int width, int height, float scale)
462 {
463 const uint16_t *src = (const uint16_t *)srcp;
464
465 src_stride /= 2;
466
467 for (int y = 0; y < height; y++) {
468 for (int x = 0; x < 32; x++)
469 dst[-x - 1] = src[x] * scale;
470
471 for (int x = 0; x < width; x++)
472 dst[x] = src[x] * scale;
473
474 for (int x = 0; x < 32; x++)
475 dst[width + x] = src[width - x - 1] * scale;
476
477 dst += dst_stride;
478 src += src_stride;
479 }
480 }
481
482 static void write_bytes(const float *src, uint8_t *dst,
483 int src_stride, int dst_stride,
484 int width, int height, int depth,
485 float scale)
486 {
487 for (int y = 0; y < height; y++) {
488 for (int x = 0; x < width; x++)
489 dst[x] = av_clip_uint8(src[x]);
490
491 dst += dst_stride;
492 src += src_stride;
493 }
494 }
495
496 static void write_words(const float *src, uint8_t *dstp,
497 int src_stride, int dst_stride,
498 int width, int height, int depth,
499 float scale)
500 {
501 uint16_t *dst = (uint16_t *)dstp;
502
503 dst_stride /= 2;
504
505 for (int y = 0; y < height; y++) {
506 for (int x = 0; x < width; x++)
507 dst[x] = av_clip_uintp2_c(src[x] * scale, depth);
508
509 dst += dst_stride;
510 src += src_stride;
511 }
512 }
513
514 static void interpolation(const void *src, ptrdiff_t src_stride,
515 void *dst, const uint8_t *prescreen, int n)
516 {
517 const float *src_p = src;
518 float *dst_p = dst;
519 const float *window = src_p - 2 * src_stride;
520
521 for (int i = 0; i < n; i++) {
522 float accum = 0.0f;
523
524 if (!prescreen[i])
525 continue;
526
527 accum += (-3.0f / 32.0f) * window[0 * src_stride + i];
528 accum += (19.0f / 32.0f) * window[1 * src_stride + i];
529 accum += (19.0f / 32.0f) * window[2 * src_stride + i];
530 accum += (-3.0f / 32.0f) * window[3 * src_stride + i];
531
532 dst_p[i] = accum;
533 }
534 }
535
536 static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
537 {
538 const NNEDIContext *const s = ctx->priv;
539 AVFrame *out = arg;
540 AVFrame *in = s->prev;
541 const float in_scale = s->in_scale;
542 const float out_scale = s->out_scale;
543 const int depth = s->depth;
544 const int interlaced = !!(in->flags & AV_FRAME_FLAG_INTERLACED);
545 const int tff = s->field_n == (s->field < 0 ? interlaced ? (in->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST) : 1 :
546 (s->field & 1) ^ 1);
547
548
549 for (int p = 0; p < s->nb_planes; p++) {
550 const int height = s->planeheight[p];
551 const int width = s->planewidth[p];
552 const int slice_start = 2 * ((height / 2 * jobnr) / nb_jobs);
553 const int slice_end = 2 * ((height / 2 * (jobnr+1)) / nb_jobs);
554 const uint8_t *src_data = in->data[p];
555 uint8_t *dst_data = out->data[p];
556 uint8_t *dst = out->data[p] + slice_start * out->linesize[p];
557 const int src_linesize = in->linesize[p];
558 const int dst_linesize = out->linesize[p];
559 uint8_t *prescreen_buf = s->prescreen_buf[jobnr];
560 float *srcbuf = s->input_buf[jobnr];
561 const int srcbuf_stride = width + 64;
562 float *dstbuf = s->output_buf[jobnr];
563 const int dstbuf_stride = width;
564 const int slice_height = (slice_end - slice_start) / 2;
565 const int last_slice = slice_end == height;
566 const uint8_t *in_line;
567 uint8_t *out_line;
568 int y_out;
569
570 if (!(s->process_plane & (1 << p))) {
571 av_image_copy_plane(dst, out->linesize[p],
572 in->data[p] + slice_start * in->linesize[p],
573 in->linesize[p],
574 s->linesize[p], slice_end - slice_start);
575 continue;
576 }
577
578 y_out = slice_start + (tff ^ (slice_start & 1));
579 in_line = src_data + (y_out * src_linesize);
580 out_line = dst_data + (y_out * dst_linesize);
581
582 while (y_out < slice_end) {
583 memcpy(out_line, in_line, s->linesize[p]);
584 y_out += 2;
585 in_line += src_linesize * 2;
586 out_line += dst_linesize * 2;
587 }
588
589 y_out = slice_start + ((!tff) ^ (slice_start & 1));
590
591 s->read(src_data + FFMAX(y_out - 5, tff) * src_linesize,
592 srcbuf + 32,
593 src_linesize * 2, srcbuf_stride,
594 width, 1, in_scale);
595 srcbuf += srcbuf_stride;
596
597 s->read(src_data + FFMAX(y_out - 3, tff) * src_linesize,
598 srcbuf + 32,
599 src_linesize * 2, srcbuf_stride,
600 width, 1, in_scale);
601 srcbuf += srcbuf_stride;
602
603 s->read(src_data + FFMAX(y_out - 1, tff) * src_linesize,
604 srcbuf + 32,
605 src_linesize * 2, srcbuf_stride,
606 width, 1, in_scale);
607 srcbuf += srcbuf_stride;
608
609 in_line = src_data + FFMIN(y_out + 1, height - 1 - !tff) * src_linesize;
610 out_line = dst_data + (y_out * dst_linesize);
611
612 s->read(in_line, srcbuf + 32, src_linesize * 2, srcbuf_stride,
613 width, slice_height - last_slice, in_scale);
614
615 y_out += (slice_height - last_slice) * 2;
616
617 s->read(src_data + FFMIN(y_out + 1, height - 1 - !tff) * src_linesize,
618 srcbuf + 32 + srcbuf_stride * (slice_height - last_slice),
619 src_linesize * 2, srcbuf_stride,
620 width, 1, in_scale);
621
622 s->read(src_data + FFMIN(y_out + 3, height - 1 - !tff) * src_linesize,
623 srcbuf + 32 + srcbuf_stride * (slice_height + 1 - last_slice),
624 src_linesize * 2, srcbuf_stride,
625 width, 1, in_scale);
626
627 s->read(src_data + FFMIN(y_out + 5, height - 1 - !tff) * src_linesize,
628 srcbuf + 32 + srcbuf_stride * (slice_height + 2 - last_slice),
629 src_linesize * 2, srcbuf_stride,
630 width, 1, in_scale);
631
632 for (int y = 0; y < slice_end - slice_start; y += 2) {
633 if (s->pscrn > 0)
634 s->prescreen[s->pscrn > 1](ctx, srcbuf + (y / 2) * srcbuf_stride + 32,
635 srcbuf_stride, prescreen_buf, width,
636 &s->prescreener[s->pscrn - 1]);
637
638 predictor(ctx,
639 srcbuf + (y / 2) * srcbuf_stride + 32,
640 srcbuf_stride,
641 dstbuf + (y / 2) * dstbuf_stride,
642 prescreen_buf, width,
643 &s->coeffs[s->etype][s->nnsparam][s->nsize], s->qual == 2);
644
645 if (s->pscrn > 0)
646 interpolation(srcbuf + (y / 2) * srcbuf_stride + 32,
647 srcbuf_stride,
648 dstbuf + (y / 2) * dstbuf_stride,
649 prescreen_buf, width);
650 }
651
652 s->write(dstbuf, out_line, dstbuf_stride, dst_linesize * 2,
653 width, slice_height, depth, out_scale);
654 }
655
656 return 0;
657 }
658
659 static int get_frame(AVFilterContext *ctx, int is_second)
660 {
661 NNEDIContext *s = ctx->priv;
662 AVFilterLink *outlink = ctx->outputs[0];
663 AVFrame *dst;
664
665 dst = ff_get_video_buffer(outlink, outlink->w, outlink->h);
666 if (!dst)
667 return AVERROR(ENOMEM);
668 av_frame_copy_props(dst, s->prev);
669 #if FF_API_INTERLACED_FRAME
670 FF_DISABLE_DEPRECATION_WARNINGS
671 dst->interlaced_frame = 0;
672 FF_ENABLE_DEPRECATION_WARNINGS
673 #endif
674 dst->flags &= ~AV_FRAME_FLAG_INTERLACED;
675 dst->pts = s->pts;
676
677 ff_filter_execute(ctx, filter_slice, dst, NULL,
678 FFMIN(s->planeheight[1] / 2, s->nb_threads));
679
680 if (s->field == -2 || s->field > 1)
681 s->field_n = !s->field_n;
682
683 return ff_filter_frame(outlink, dst);
684 }
685
686 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
687 {
688 AVFilterContext *ctx = inlink->dst;
689 NNEDIContext *s = ctx->priv;
690 int ret;
691
692 if (!s->prev) {
693 s->prev = in;
694 return 0;
695 }
696
697 if ((s->deint && !(s->prev->flags & AV_FRAME_FLAG_INTERLACED)) || ctx->is_disabled) {
698 s->prev->pts *= 2;
699 ret = ff_filter_frame(ctx->outputs[0], s->prev);
700 s->prev = in;
701 return ret;
702 }
703
704 s->pts = s->prev->pts * 2;
705 ret = get_frame(ctx, 0);
706 if (ret < 0 || (s->field > -2 && s->field < 2)) {
707 av_frame_free(&s->prev);
708 s->prev = in;
709 return ret;
710 }
711
712 s->pts = s->prev->pts + in->pts;
713 ret = get_frame(ctx, 1);
714 av_frame_free(&s->prev);
715 s->prev = in;
716 return ret;
717 }
718
719 static int request_frame(AVFilterLink *link)
720 {
721 AVFilterContext *ctx = link->src;
722 NNEDIContext *s = ctx->priv;
723 int ret;
724
725 if (s->eof)
726 return AVERROR_EOF;
727
728 ret = ff_request_frame(ctx->inputs[0]);
729
730 if (ret == AVERROR_EOF && s->prev) {
731 AVFrame *next = av_frame_clone(s->prev);
732
733 if (!next)
734 return AVERROR(ENOMEM);
735
736 next->pts = s->prev->pts + av_rescale_q(1, av_inv_q(ctx->outputs[0]->frame_rate),
737 ctx->outputs[0]->time_base);
738 s->eof = 1;
739
740 ret = filter_frame(ctx->inputs[0], next);
741 } else if (ret < 0) {
742 return ret;
743 }
744
745 return ret;
746 }
747
748 static void copy_weights(float *dst, int n, const float **data)
749 {
750 memcpy(dst, *data, n * sizeof(float));
751 *data += n;
752 }
753
754 static float *allocate(float **ptr, int size)
755 {
756 float *ret = *ptr;
757
758 *ptr += size;
759
760 return ret;
761 }
762
763 static int allocate_model(PredictorCoefficients *coeffs, int xdim, int ydim, int nns)
764 {
765 int filter_size = nns * xdim * ydim;
766 int bias_size = nns;
767 float *data;
768
769 data = av_calloc(filter_size + bias_size, 4 * sizeof(float));
770 if (!data)
771 return AVERROR(ENOMEM);
772
773 coeffs->data = data;
774 coeffs->xdim = xdim;
775 coeffs->ydim = ydim;
776 coeffs->nsize = xdim * ydim;
777 coeffs->nns = nns;
778
779 coeffs->softmax_q1 = allocate(&data, filter_size);
780 coeffs->elliott_q1 = allocate(&data, filter_size);
781 coeffs->softmax_bias_q1 = allocate(&data, bias_size);
782 coeffs->elliott_bias_q1 = allocate(&data, bias_size);
783
784 coeffs->softmax_q2 = allocate(&data, filter_size);
785 coeffs->elliott_q2 = allocate(&data, filter_size);
786 coeffs->softmax_bias_q2 = allocate(&data, bias_size);
787 coeffs->elliott_bias_q2 = allocate(&data, bias_size);
788
789 return 0;
790 }
791
792 static int read_weights(AVFilterContext *ctx, const float *bdata)
793 {
794 NNEDIContext *s = ctx->priv;
795 int ret;
796
797 copy_weights(&s->prescreener[0].kernel_l0[0][0], 4 * 48, &bdata);
798 copy_weights(s->prescreener[0].bias_l0, 4, &bdata);
799
800 copy_weights(&s->prescreener[0].kernel_l1[0][0], 4 * 4, &bdata);
801 copy_weights(s->prescreener[0].bias_l1, 4, &bdata);
802
803 copy_weights(&s->prescreener[0].kernel_l2[0][0], 4 * 8, &bdata);
804 copy_weights(s->prescreener[0].bias_l2, 4, &bdata);
805
806 for (int i = 0; i < 3; i++) {
807 PrescreenerCoefficients *data = &s->prescreener[i + 1];
808 float kernel_l0_shuffled[4 * 64];
809 float kernel_l1_shuffled[4 * 4];
810
811 copy_weights(kernel_l0_shuffled, 4 * 64, &bdata);
812 copy_weights(data->bias_l0, 4, &bdata);
813
814 copy_weights(kernel_l1_shuffled, 4 * 4, &bdata);
815 copy_weights(data->bias_l1, 4, &bdata);
816
817 for (int n = 0; n < 4; n++) {
818 for (int k = 0; k < 64; k++)
819 data->kernel_l0[n][k] = kernel_l0_shuffled[(k / 8) * 32 + n * 8 + k % 8];
820 for (int k = 0; k < 4; k++)
821 data->kernel_l1[n][k] = kernel_l1_shuffled[k * 4 + n];
822 }
823 }
824
825 for (int m = 0; m < 2; m++) {
826 // Grouping by neuron count.
827 for (int i = 0; i < 5; i++) {
828 const int nns = NNEDI_NNS[i];
829
830 // Grouping by window size.
831 for (int j = 0; j < 7; j++) {
832 PredictorCoefficients *model = &s->coeffs[m][i][j];
833 const int xdim = NNEDI_XDIM[j];
834 const int ydim = NNEDI_YDIM[j];
835 const int filter_size = xdim * ydim;
836
837 ret = allocate_model(model, xdim, ydim, nns);
838 if (ret < 0)
839 return ret;
840
841 // Quality 1 model. NNS[i] * (XDIM[j] * YDIM[j]) * 2 coefficients.
842 copy_weights(model->softmax_q1, nns * filter_size, &bdata);
843 copy_weights(model->elliott_q1, nns * filter_size, &bdata);
844
845 // Quality 1 model bias. NNS[i] * 2 coefficients.
846 copy_weights(model->softmax_bias_q1, nns, &bdata);
847 copy_weights(model->elliott_bias_q1, nns, &bdata);
848
849 // Quality 2 model. NNS[i] * (XDIM[j] * YDIM[j]) * 2 coefficients.
850 copy_weights(model->softmax_q2, nns * filter_size, &bdata);
851 copy_weights(model->elliott_q2, nns * filter_size, &bdata);
852
853 // Quality 2 model bias. NNS[i] * 2 coefficients.
854 copy_weights(model->softmax_bias_q2, nns, &bdata);
855 copy_weights(model->elliott_bias_q2, nns, &bdata);
856 }
857 }
858 }
859
860 return 0;
861 }
862
863 static float mean(const float *input, int size)
864 {
865 float sum = 0.f;
866
867 for (int i = 0; i < size; i++)
868 sum += input[i];
869
870 return sum / size;
871 }
872
873 static void transform(float *input, int size, float mean, float half)
874 {
875 for (int i = 0; i < size; i++)
876 input[i] = (input[i] - mean) / half;
877 }
878
879 static void subtract_mean_old(PrescreenerCoefficients *coeffs, float half)
880 {
881 for (int n = 0; n < 4; n++) {
882 float m = mean(coeffs->kernel_l0[n], 48);
883
884 transform(coeffs->kernel_l0[n], 48, m, half);
885 }
886 }
887
888 static void subtract_mean_new(PrescreenerCoefficients *coeffs, float half)
889 {
890 for (int n = 0; n < 4; n++) {
891 float m = mean(coeffs->kernel_l0[n], 64);
892
893 transform(coeffs->kernel_l0[n], 64, m, half);
894 }
895 }
896
897 static void subtract_mean_predictor(PredictorCoefficients *model)
898 {
899 const int filter_size = model->nsize;
900 const int nns = model->nns;
901 const float scale = 1.f / nns;
902
903 double softmax_means[256]; // Average of individual softmax filters.
904 double elliott_means[256]; // Average of individual elliott filters.
905 double mean_filter[48 * 6] = { 0 }; // Pointwise average of all softmax filters.
906 double mean_bias;
907
908 // Quality 1.
909 for (int nn = 0; nn < nns; nn++) {
910 softmax_means[nn] = mean(model->softmax_q1 + nn * filter_size, filter_size);
911 elliott_means[nn] = mean(model->elliott_q1 + nn * filter_size, filter_size);
912
913 for (int k = 0; k < filter_size; k++)
914 mean_filter[k] += model->softmax_q1[nn * filter_size + k] - softmax_means[nn];
915 }
916
917 for (int k = 0; k < filter_size; k++)
918 mean_filter[k] *= scale;
919
920 mean_bias = mean(model->softmax_bias_q1, nns);
921
922 for (int nn = 0; nn < nns; nn++) {
923 for (int k = 0; k < filter_size; k++) {
924 model->softmax_q1[nn * filter_size + k] -= softmax_means[nn] + mean_filter[k];
925 model->elliott_q1[nn * filter_size + k] -= elliott_means[nn];
926 }
927 model->softmax_bias_q1[nn] -= mean_bias;
928 }
929
930 // Quality 2.
931 memset(mean_filter, 0, sizeof(mean_filter));
932
933 for (int nn = 0; nn < nns; nn++) {
934 softmax_means[nn] = mean(model->softmax_q2 + nn * filter_size, filter_size);
935 elliott_means[nn] = mean(model->elliott_q2 + nn * filter_size, filter_size);
936
937 for (int k = 0; k < filter_size; k++) {
938 mean_filter[k] += model->softmax_q2[nn * filter_size + k] - softmax_means[nn];
939 }
940 }
941
942 for (int k = 0; k < filter_size; k++)
943 mean_filter[k] *= scale;
944
945 mean_bias = mean(model->softmax_bias_q2, nns);
946
947 for (int nn = 0; nn < nns; nn++) {
948 for (int k = 0; k < filter_size; k++) {
949 model->softmax_q2[nn * filter_size + k] -= softmax_means[nn] + mean_filter[k];
950 model->elliott_q2[nn * filter_size + k] -= elliott_means[nn];
951 }
952
953 model->softmax_bias_q2[nn] -= mean_bias;
954 }
955 }
956
957 static av_cold int init(AVFilterContext *ctx)
958 {
959 NNEDIContext *s = ctx->priv;
960 FILE *weights_file = NULL;
961 int64_t weights_size;
962 float *bdata;
963 size_t bytes_read;
964 int ret = 0;
965
966 weights_file = avpriv_fopen_utf8(s->weights_file, "rb");
967 if (!weights_file) {
968 av_log(ctx, AV_LOG_ERROR, "No weights file provided, aborting!\n");
969 return AVERROR(EINVAL);
970 }
971
972 if (fseek(weights_file, 0, SEEK_END)) {
973 av_log(ctx, AV_LOG_ERROR, "Couldn't seek to the end of weights file.\n");
974 fclose(weights_file);
975 return AVERROR(EINVAL);
976 }
977
978 weights_size = ftell(weights_file);
979
980 if (weights_size == -1) {
981 fclose(weights_file);
982 av_log(ctx, AV_LOG_ERROR, "Couldn't get size of weights file.\n");
983 return AVERROR(EINVAL);
984 } else if (weights_size != NNEDI_WEIGHTS_SIZE) {
985 fclose(weights_file);
986 av_log(ctx, AV_LOG_ERROR, "Unexpected weights file size.\n");
987 return AVERROR(EINVAL);
988 }
989
990 if (fseek(weights_file, 0, SEEK_SET)) {
991 fclose(weights_file);
992 av_log(ctx, AV_LOG_ERROR, "Couldn't seek to the start of weights file.\n");
993 return AVERROR(EINVAL);
994 }
995
996 bdata = av_malloc(NNEDI_WEIGHTS_SIZE);
997 if (!bdata) {
998 fclose(weights_file);
999 return AVERROR(ENOMEM);
1000 }
1001
1002 bytes_read = fread(bdata, 1, NNEDI_WEIGHTS_SIZE, weights_file);
1003 if (bytes_read != NNEDI_WEIGHTS_SIZE) {
1004 fclose(weights_file);
1005 ret = AVERROR_INVALIDDATA;
1006 av_log(ctx, AV_LOG_ERROR, "Couldn't read weights file.\n");
1007 goto fail;
1008 }
1009
1010 fclose(weights_file);
1011
1012 s->fdsp = avpriv_float_dsp_alloc(0);
1013 if (!s->fdsp) {
1014 ret = AVERROR(ENOMEM);
1015 goto fail;
1016 }
1017
1018 ret = read_weights(ctx, bdata);
1019 if (ret < 0)
1020 goto fail;
1021
1022 fail:
1023 av_free(bdata);
1024 return ret;
1025 }
1026
1027 static int config_input(AVFilterLink *inlink)
1028 {
1029 AVFilterContext *ctx = inlink->dst;
1030 NNEDIContext *s = ctx->priv;
1031 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
1032 int ret;
1033
1034 s->depth = desc->comp[0].depth;
1035 s->nb_threads = ff_filter_get_nb_threads(ctx);
1036 s->nb_planes = av_pix_fmt_count_planes(inlink->format);
1037 if ((ret = av_image_fill_linesizes(s->linesize, inlink->format, inlink->w)) < 0)
1038 return ret;
1039
1040 s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
1041 s->planewidth[0] = s->planewidth[3] = inlink->w;
1042 s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
1043 s->planeheight[0] = s->planeheight[3] = inlink->h;
1044
1045 s->half = ((1 << 8) - 1) / 2.f;
1046 s->out_scale = 1 << (s->depth - 8);
1047 s->in_scale = 1.f / s->out_scale;
1048
1049 switch (s->depth) {
1050 case 8:
1051 s->read = read_bytes;
1052 s->write = write_bytes;
1053 break;
1054 default:
1055 s->read = read_words;
1056 s->write = write_words;
1057 break;
1058 }
1059
1060 subtract_mean_old(&s->prescreener[0], s->half);
1061 subtract_mean_new(&s->prescreener[1], s->half);
1062 subtract_mean_new(&s->prescreener[2], s->half);
1063 subtract_mean_new(&s->prescreener[3], s->half);
1064
1065 s->prescreen[0] = process_old;
1066 s->prescreen[1] = process_new;
1067
1068 for (int i = 0; i < 2; i++) {
1069 for (int j = 0; j < 5; j++) {
1070 for (int k = 0; k < 7; k++)
1071 subtract_mean_predictor(&s->coeffs[i][j][k]);
1072 }
1073 }
1074
1075 s->input_size = (s->planewidth[0] + 64) * (s->planeheight[0] + 6);
1076 s->input_buf = av_calloc(s->nb_threads, sizeof(*s->input_buf));
1077 if (!s->input_buf)
1078 return AVERROR(ENOMEM);
1079
1080 for (int i = 0; i < s->nb_threads; i++) {
1081 s->input_buf[i] = av_calloc(s->input_size, sizeof(**s->input_buf));
1082 if (!s->input_buf[i])
1083 return AVERROR(ENOMEM);
1084 }
1085
1086 s->output_buf = av_calloc(s->nb_threads, sizeof(*s->output_buf));
1087 if (!s->output_buf)
1088 return AVERROR(ENOMEM);
1089
1090 for (int i = 0; i < s->nb_threads; i++) {
1091 s->output_buf[i] = av_calloc(s->input_size, sizeof(**s->output_buf));
1092 if (!s->output_buf[i])
1093 return AVERROR(ENOMEM);
1094 }
1095
1096 s->prescreen_buf = av_calloc(s->nb_threads, sizeof(*s->prescreen_buf));
1097 if (!s->prescreen_buf)
1098 return AVERROR(ENOMEM);
1099
1100 for (int i = 0; i < s->nb_threads; i++) {
1101 s->prescreen_buf[i] = av_calloc(s->planewidth[0], sizeof(**s->prescreen_buf));
1102 if (!s->prescreen_buf[i])
1103 return AVERROR(ENOMEM);
1104 }
1105
1106 return 0;
1107 }
1108
1109 static av_cold void uninit(AVFilterContext *ctx)
1110 {
1111 NNEDIContext *s = ctx->priv;
1112
1113 for (int i = 0; i < s->nb_threads && s->prescreen_buf; i++)
1114 av_freep(&s->prescreen_buf[i]);
1115
1116 av_freep(&s->prescreen_buf);
1117
1118 for (int i = 0; i < s->nb_threads && s->input_buf; i++)
1119 av_freep(&s->input_buf[i]);
1120
1121 av_freep(&s->input_buf);
1122
1123 for (int i = 0; i < s->nb_threads && s->output_buf; i++)
1124 av_freep(&s->output_buf[i]);
1125
1126 av_freep(&s->output_buf);
1127 av_freep(&s->fdsp);
1128
1129 for (int i = 0; i < 2; i++) {
1130 for (int j = 0; j < 5; j++) {
1131 for (int k = 0; k < 7; k++) {
1132 av_freep(&s->coeffs[i][j][k].data);
1133 }
1134 }
1135 }
1136
1137 av_frame_free(&s->prev);
1138 }
1139
1140 static const AVFilterPad inputs[] = {
1141 {
1142 .name = "default",
1143 .type = AVMEDIA_TYPE_VIDEO,
1144 .filter_frame = filter_frame,
1145 .config_props = config_input,
1146 },
1147 };
1148
1149 static const AVFilterPad outputs[] = {
1150 {
1151 .name = "default",
1152 .type = AVMEDIA_TYPE_VIDEO,
1153 .config_props = config_output,
1154 .request_frame = request_frame,
1155 },
1156 };
1157
1158 const AVFilter ff_vf_nnedi = {
1159 .name = "nnedi",
1160 .description = NULL_IF_CONFIG_SMALL("Apply neural network edge directed interpolation intra-only deinterlacer."),
1161 .priv_size = sizeof(NNEDIContext),
1162 .priv_class = &nnedi_class,
1163 .init = init,
1164 .uninit = uninit,
1165 FILTER_INPUTS(inputs),
1166 FILTER_OUTPUTS(outputs),
1167 FILTER_PIXFMTS_ARRAY(pix_fmts),
1168 .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL | AVFILTER_FLAG_SLICE_THREADS,
1169 .process_command = ff_filter_process_command,
1170 };
1171