... | ... |
@@ -2967,6 +2967,44 @@ Slower shaper using OpenType for substitutions and positioning |
2967 | 2967 |
The default is @code{auto}. |
2968 | 2968 |
@end table |
2969 | 2969 |
|
2970 |
+@section atadenoise |
|
2971 |
+Apply an Adaptive Temporal Averaging Denoiser to the video input. |
|
2972 |
+ |
|
2973 |
+The filter accepts the following options: |
|
2974 |
+ |
|
2975 |
+@table @option |
|
2976 |
+@item 0a |
|
2977 |
+Set threshold A for 1st plane. Default is 0.02. |
|
2978 |
+Valid range is 0 to 0.3. |
|
2979 |
+ |
|
2980 |
+@item 0b |
|
2981 |
+Set threshold B for 1st plane. Default is 0.04. |
|
2982 |
+Valid range is 0 to 5. |
|
2983 |
+ |
|
2984 |
+@item 1a |
|
2985 |
+Set threshold A for 2nd plane. Default is 0.02. |
|
2986 |
+Valid range is 0 to 0.3. |
|
2987 |
+ |
|
2988 |
+@item 1b |
|
2989 |
+Set threshold B for 2nd plane. Default is 0.04. |
|
2990 |
+Valid range is 0 to 5. |
|
2991 |
+ |
|
2992 |
+@item 2a |
|
2993 |
+Set threshold A for 3rd plane. Default is 0.02. |
|
2994 |
+Valid range is 0 to 0.3. |
|
2995 |
+ |
|
2996 |
+@item 2b |
|
2997 |
+Set threshold B for 3rd plane. Default is 0.04. |
|
2998 |
+Valid range is 0 to 5. |
|
2999 |
+ |
|
3000 |
+Threshold A is designed to react on abrupt changes in the input signal and |
|
3001 |
+threshold B is designed to react on continuous changes in the input signal. |
|
3002 |
+ |
|
3003 |
+@item s |
|
3004 |
+Set number of frames filter will use for averaging. Default is 33. Must be odd |
|
3005 |
+number in range [5, 129]. |
|
3006 |
+@end table |
|
3007 |
+ |
|
2970 | 3008 |
@section bbox |
2971 | 3009 |
|
2972 | 3010 |
Compute the bounding box for the non-black pixels in the input frame |
... | ... |
@@ -98,6 +98,7 @@ OBJS-$(CONFIG_ANULLSINK_FILTER) += asink_anullsink.o |
98 | 98 |
OBJS-$(CONFIG_ASS_FILTER) += vf_subtitles.o |
99 | 99 |
OBJS-$(CONFIG_ALPHAEXTRACT_FILTER) += vf_extractplanes.o |
100 | 100 |
OBJS-$(CONFIG_ALPHAMERGE_FILTER) += vf_alphamerge.o |
101 |
+OBJS-$(CONFIG_ATADENOISE_FILTER) += vf_atadenoise.o |
|
101 | 102 |
OBJS-$(CONFIG_BBOX_FILTER) += bbox.o vf_bbox.o |
102 | 103 |
OBJS-$(CONFIG_BLACKDETECT_FILTER) += vf_blackdetect.o |
103 | 104 |
OBJS-$(CONFIG_BLACKFRAME_FILTER) += vf_blackframe.o |
... | ... |
@@ -113,6 +113,7 @@ void avfilter_register_all(void) |
113 | 113 |
|
114 | 114 |
REGISTER_FILTER(ALPHAEXTRACT, alphaextract, vf); |
115 | 115 |
REGISTER_FILTER(ALPHAMERGE, alphamerge, vf); |
116 |
+ REGISTER_FILTER(ATADENOISE, atadenoise, vf); |
|
116 | 117 |
REGISTER_FILTER(ASS, ass, vf); |
117 | 118 |
REGISTER_FILTER(BBOX, bbox, vf); |
118 | 119 |
REGISTER_FILTER(BLACKDETECT, blackdetect, vf); |
... | ... |
@@ -30,7 +30,7 @@ |
30 | 30 |
#include "libavutil/version.h" |
31 | 31 |
|
32 | 32 |
#define LIBAVFILTER_VERSION_MAJOR 5 |
33 |
-#define LIBAVFILTER_VERSION_MINOR 31 |
|
33 |
+#define LIBAVFILTER_VERSION_MINOR 32 |
|
34 | 34 |
#define LIBAVFILTER_VERSION_MICRO 100 |
35 | 35 |
|
36 | 36 |
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ |
37 | 37 |
new file mode 100755 |
... | ... |
@@ -0,0 +1,417 @@ |
0 |
+/* |
|
1 |
+ * Copyright (c) 2015 Paul B Mahol |
|
2 |
+ * |
|
3 |
+ * This file is part of FFmpeg. |
|
4 |
+ * |
|
5 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
6 |
+ * modify it under the terms of the GNU Lesser General Public |
|
7 |
+ * License as published by the Free Software Foundation; either |
|
8 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
9 |
+ * |
|
10 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
11 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 |
+ * Lesser General Public License for more details. |
|
14 |
+ * |
|
15 |
+ * You should have received a copy of the GNU Lesser General Public |
|
16 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
17 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
18 |
+ */ |
|
19 |
+ |
|
20 |
+/** |
|
21 |
+ * @file |
|
22 |
+ * Adaptive Temporal Averaging Denoiser, |
|
23 |
+ * based on paper "Video Denoising Based on Adaptive Temporal Averaging" by |
|
24 |
+ * David Bartovčak and Miroslav Vrankić |
|
25 |
+ */ |
|
26 |
+ |
|
27 |
+#include "libavutil/opt.h" |
|
28 |
+#include "libavutil/pixdesc.h" |
|
29 |
+#include "avfilter.h" |
|
30 |
+ |
|
31 |
+#define FF_BUFQUEUE_SIZE 129 |
|
32 |
+#include "bufferqueue.h" |
|
33 |
+ |
|
34 |
+#include "formats.h" |
|
35 |
+#include "internal.h" |
|
36 |
+#include "video.h" |
|
37 |
+ |
|
38 |
+#define SIZE FF_BUFQUEUE_SIZE |
|
39 |
+ |
|
40 |
+typedef struct ATADenoiseContext { |
|
41 |
+ const AVClass *class; |
|
42 |
+ |
|
43 |
+ float fthra[4], fthrb[4]; |
|
44 |
+ int thra[4], thrb[4]; |
|
45 |
+ |
|
46 |
+ int nb_planes; |
|
47 |
+ int planewidth[4]; |
|
48 |
+ int planeheight[4]; |
|
49 |
+ |
|
50 |
+ struct FFBufQueue q; |
|
51 |
+ void *data[4][SIZE]; |
|
52 |
+ int linesize[4][SIZE]; |
|
53 |
+ int size, mid; |
|
54 |
+ int available; |
|
55 |
+ |
|
56 |
+ int (*filter_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs); |
|
57 |
+} ATADenoiseContext; |
|
58 |
+ |
|
59 |
+#define OFFSET(x) offsetof(ATADenoiseContext, x) |
|
60 |
+#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM |
|
61 |
+ |
|
62 |
+static const AVOption atadenoise_options[] = { |
|
63 |
+ { "0a", "set threshold A for 1st plane", OFFSET(fthra[0]), AV_OPT_TYPE_FLOAT, {.dbl=0.02}, 0, 0.3, FLAGS }, |
|
64 |
+ { "0b", "set threshold B for 1st plane", OFFSET(fthrb[0]), AV_OPT_TYPE_FLOAT, {.dbl=0.04}, 0, 5.0, FLAGS }, |
|
65 |
+ { "1a", "set threshold A for 2nd plane", OFFSET(fthra[1]), AV_OPT_TYPE_FLOAT, {.dbl=0.02}, 0, 0.3, FLAGS }, |
|
66 |
+ { "1b", "set threshold B for 2nd plane", OFFSET(fthrb[1]), AV_OPT_TYPE_FLOAT, {.dbl=0.04}, 0, 5.0, FLAGS }, |
|
67 |
+ { "2a", "set threshold A for 3rd plane", OFFSET(fthra[2]), AV_OPT_TYPE_FLOAT, {.dbl=0.02}, 0, 0.3, FLAGS }, |
|
68 |
+ { "2b", "set threshold B for 3rd plane", OFFSET(fthrb[2]), AV_OPT_TYPE_FLOAT, {.dbl=0.04}, 0, 5.0, FLAGS }, |
|
69 |
+ { "s", "set how many frames to use", OFFSET(size), AV_OPT_TYPE_INT, {.i64=33}, 5, SIZE, FLAGS }, |
|
70 |
+ { NULL } |
|
71 |
+}; |
|
72 |
+ |
|
73 |
+AVFILTER_DEFINE_CLASS(atadenoise); |
|
74 |
+ |
|
75 |
+static int query_formats(AVFilterContext *ctx) |
|
76 |
+{ |
|
77 |
+ static const enum AVPixelFormat pixel_fmts[] = { |
|
78 |
+ AV_PIX_FMT_GRAY8, |
|
79 |
+ AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P, |
|
80 |
+ AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, |
|
81 |
+ AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV444P, |
|
82 |
+ AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, |
|
83 |
+ AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ444P, |
|
84 |
+ AV_PIX_FMT_YUVJ411P, |
|
85 |
+ AV_PIX_FMT_YUV420P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV444P9, |
|
86 |
+ AV_PIX_FMT_YUV420P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV444P10, |
|
87 |
+ AV_PIX_FMT_YUV420P16, AV_PIX_FMT_YUV422P16, AV_PIX_FMT_YUV444P16, |
|
88 |
+ AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10, |
|
89 |
+ AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14, AV_PIX_FMT_GBRP16, |
|
90 |
+ AV_PIX_FMT_NONE |
|
91 |
+ }; |
|
92 |
+ AVFilterFormats *formats = ff_make_format_list(pixel_fmts); |
|
93 |
+ if (!formats) |
|
94 |
+ return AVERROR(ENOMEM); |
|
95 |
+ return ff_set_common_formats(ctx, formats); |
|
96 |
+} |
|
97 |
+ |
|
98 |
+static av_cold int init(AVFilterContext *ctx) |
|
99 |
+{ |
|
100 |
+ ATADenoiseContext *s = ctx->priv; |
|
101 |
+ |
|
102 |
+ if (!(s->size & 1)) { |
|
103 |
+ av_log(ctx, AV_LOG_ERROR, "size %d is invalid. Must be an odd value.\n", s->size); |
|
104 |
+ return AVERROR(EINVAL); |
|
105 |
+ } |
|
106 |
+ s->mid = s->size / 2 + 1; |
|
107 |
+ |
|
108 |
+ return 0; |
|
109 |
+} |
|
110 |
+ |
|
111 |
+typedef struct ThreadData { |
|
112 |
+ AVFrame *in, *out; |
|
113 |
+} ThreadData; |
|
114 |
+ |
|
115 |
+static int filter_slice8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) |
|
116 |
+{ |
|
117 |
+ ATADenoiseContext *s = ctx->priv; |
|
118 |
+ ThreadData *td = arg; |
|
119 |
+ AVFrame *in = td->in; |
|
120 |
+ AVFrame *out = td->out; |
|
121 |
+ const int size = s->size; |
|
122 |
+ const int mid = s->mid; |
|
123 |
+ int p, x, y, i, j; |
|
124 |
+ |
|
125 |
+ for (p = 0; p < s->nb_planes; p++) { |
|
126 |
+ const int h = s->planeheight[p]; |
|
127 |
+ const int w = s->planewidth[p]; |
|
128 |
+ const int slice_start = (h * jobnr) / nb_jobs; |
|
129 |
+ const int slice_end = (h * (jobnr+1)) / nb_jobs; |
|
130 |
+ const uint8_t *src = in->data[p] + slice_start * in->linesize[p]; |
|
131 |
+ uint8_t *dst = out->data[p] + slice_start * out->linesize[p]; |
|
132 |
+ const int thra = s->thra[p]; |
|
133 |
+ const int thrb = s->thrb[p]; |
|
134 |
+ const uint8_t **data = (const uint8_t **)s->data[p]; |
|
135 |
+ const int *linesize = (const int *)s->linesize[p]; |
|
136 |
+ const uint8_t *srcf[SIZE]; |
|
137 |
+ |
|
138 |
+ for (i = 0; i < size; i++) |
|
139 |
+ srcf[i] = data[i] + slice_start * linesize[i]; |
|
140 |
+ |
|
141 |
+ for (y = slice_start; y < slice_end; y++) { |
|
142 |
+ for (x = 0; x < w; x++) { |
|
143 |
+ const int srcx = src[x]; |
|
144 |
+ unsigned lsumdiff = 0, rsumdiff = 0; |
|
145 |
+ unsigned ldiff, rdiff; |
|
146 |
+ unsigned sum = srcx; |
|
147 |
+ int l = 0, r = 0; |
|
148 |
+ int srcjx, srcix; |
|
149 |
+ |
|
150 |
+ for (j = mid - 1, i = mid + 1; j >= 0 && i < size; j--, i++) { |
|
151 |
+ srcjx = srcf[j][x]; |
|
152 |
+ |
|
153 |
+ ldiff = FFABS(srcx - srcjx); |
|
154 |
+ lsumdiff += ldiff; |
|
155 |
+ if (ldiff > thra || |
|
156 |
+ lsumdiff > thrb) |
|
157 |
+ break; |
|
158 |
+ l++; |
|
159 |
+ sum += srcjx; |
|
160 |
+ |
|
161 |
+ srcix = srcf[i][x]; |
|
162 |
+ |
|
163 |
+ rdiff = FFABS(srcx - srcix); |
|
164 |
+ rsumdiff += rdiff; |
|
165 |
+ if (rdiff > thra || |
|
166 |
+ rsumdiff > thrb) |
|
167 |
+ break; |
|
168 |
+ r++; |
|
169 |
+ sum += srcix; |
|
170 |
+ } |
|
171 |
+ |
|
172 |
+ dst[x] = sum / (r + l + 1); |
|
173 |
+ } |
|
174 |
+ |
|
175 |
+ dst += out->linesize[p]; |
|
176 |
+ src += in->linesize[p]; |
|
177 |
+ |
|
178 |
+ for (i = 0; i < size; i++) |
|
179 |
+ srcf[i] += linesize[i]; |
|
180 |
+ } |
|
181 |
+ } |
|
182 |
+ |
|
183 |
+ return 0; |
|
184 |
+} |
|
185 |
+ |
|
186 |
+static int filter_slice16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) |
|
187 |
+{ |
|
188 |
+ ATADenoiseContext *s = ctx->priv; |
|
189 |
+ ThreadData *td = arg; |
|
190 |
+ AVFrame *in = td->in; |
|
191 |
+ AVFrame *out = td->out; |
|
192 |
+ const int size = s->size; |
|
193 |
+ const int mid = s->mid; |
|
194 |
+ int p, x, y, i, j; |
|
195 |
+ |
|
196 |
+ for (p = 0; p < s->nb_planes; p++) { |
|
197 |
+ const int h = s->planeheight[p]; |
|
198 |
+ const int w = s->planewidth[p]; |
|
199 |
+ const int slice_start = (h * jobnr) / nb_jobs; |
|
200 |
+ const int slice_end = (h * (jobnr+1)) / nb_jobs; |
|
201 |
+ const uint16_t *src = (uint16_t *)(in->data[p] + slice_start * in->linesize[p]); |
|
202 |
+ uint16_t *dst = (uint16_t *)(out->data[p] + slice_start * out->linesize[p]); |
|
203 |
+ const int thra = s->thra[p]; |
|
204 |
+ const int thrb = s->thrb[p]; |
|
205 |
+ const uint8_t **data = (const uint8_t **)s->data[p]; |
|
206 |
+ const int *linesize = (const int *)s->linesize[p]; |
|
207 |
+ const uint16_t *srcf[SIZE]; |
|
208 |
+ |
|
209 |
+ for (i = 0; i < s->size; i++) |
|
210 |
+ srcf[i] = (const uint16_t *)(data[i] + slice_start * linesize[i]); |
|
211 |
+ |
|
212 |
+ for (y = slice_start; y < slice_end; y++) { |
|
213 |
+ for (x = 0; x < w; x++) { |
|
214 |
+ const int srcx = src[x]; |
|
215 |
+ unsigned lsumdiff = 0, rsumdiff = 0; |
|
216 |
+ unsigned ldiff, rdiff; |
|
217 |
+ unsigned sum = srcx; |
|
218 |
+ int l = 0, r = 0; |
|
219 |
+ int srcjx, srcix; |
|
220 |
+ |
|
221 |
+ for (j = mid - 1, i = mid + 1; j >= 0 && i < size; j--, i++) { |
|
222 |
+ srcjx = srcf[j][x]; |
|
223 |
+ |
|
224 |
+ ldiff = FFABS(srcx - srcjx); |
|
225 |
+ lsumdiff += ldiff; |
|
226 |
+ if (ldiff > thra || |
|
227 |
+ lsumdiff > thrb) |
|
228 |
+ break; |
|
229 |
+ l++; |
|
230 |
+ sum += srcjx; |
|
231 |
+ |
|
232 |
+ srcix = srcf[i][x]; |
|
233 |
+ |
|
234 |
+ rdiff = FFABS(srcx - srcix); |
|
235 |
+ rsumdiff += rdiff; |
|
236 |
+ if (rdiff > thra || |
|
237 |
+ rsumdiff > thrb) |
|
238 |
+ break; |
|
239 |
+ r++; |
|
240 |
+ sum += srcix; |
|
241 |
+ } |
|
242 |
+ |
|
243 |
+ dst[x] = sum / (r + l + 1); |
|
244 |
+ } |
|
245 |
+ |
|
246 |
+ dst += out->linesize[p] / 2; |
|
247 |
+ src += in->linesize[p] / 2; |
|
248 |
+ |
|
249 |
+ for (i = 0; i < size; i++) |
|
250 |
+ srcf[i] += linesize[i] / 2; |
|
251 |
+ } |
|
252 |
+ } |
|
253 |
+ |
|
254 |
+ return 0; |
|
255 |
+} |
|
256 |
+ |
|
257 |
+static int config_input(AVFilterLink *inlink) |
|
258 |
+{ |
|
259 |
+ const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); |
|
260 |
+ AVFilterContext *ctx = inlink->dst; |
|
261 |
+ ATADenoiseContext *s = ctx->priv; |
|
262 |
+ int depth; |
|
263 |
+ |
|
264 |
+ s->nb_planes = desc->nb_components; |
|
265 |
+ |
|
266 |
+ s->planeheight[1] = s->planeheight[2] = FF_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h); |
|
267 |
+ s->planeheight[0] = s->planeheight[3] = inlink->h; |
|
268 |
+ s->planewidth[1] = s->planewidth[2] = FF_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w); |
|
269 |
+ s->planewidth[0] = s->planewidth[3] = inlink->w; |
|
270 |
+ |
|
271 |
+ depth = desc->comp[0].depth_minus1 + 1; |
|
272 |
+ if (depth == 8) |
|
273 |
+ s->filter_slice = filter_slice8; |
|
274 |
+ else |
|
275 |
+ s->filter_slice = filter_slice16; |
|
276 |
+ |
|
277 |
+ s->thra[0] = s->fthra[0] * (1 << depth) - 1; |
|
278 |
+ s->thra[1] = s->fthra[1] * (1 << depth) - 1; |
|
279 |
+ s->thra[2] = s->fthra[2] * (1 << depth) - 1; |
|
280 |
+ s->thrb[0] = s->fthrb[0] * (1 << depth) - 1; |
|
281 |
+ s->thrb[1] = s->fthrb[1] * (1 << depth) - 1; |
|
282 |
+ s->thrb[2] = s->fthrb[2] * (1 << depth) - 1; |
|
283 |
+ |
|
284 |
+ return 0; |
|
285 |
+} |
|
286 |
+ |
|
287 |
+static int config_output(AVFilterLink *outlink) |
|
288 |
+{ |
|
289 |
+ outlink->flags |= FF_LINK_FLAG_REQUEST_LOOP; |
|
290 |
+ return 0; |
|
291 |
+} |
|
292 |
+ |
|
293 |
+static int filter_frame(AVFilterLink *inlink, AVFrame *buf) |
|
294 |
+{ |
|
295 |
+ AVFilterContext *ctx = inlink->dst; |
|
296 |
+ AVFilterLink *outlink = ctx->outputs[0]; |
|
297 |
+ ATADenoiseContext *s = ctx->priv; |
|
298 |
+ AVFrame *out, *in; |
|
299 |
+ int i; |
|
300 |
+ |
|
301 |
+ if (s->q.available != s->size) { |
|
302 |
+ if (s->q.available < s->mid) { |
|
303 |
+ out = ff_get_video_buffer(outlink, outlink->w, outlink->h); |
|
304 |
+ for (i = 0; i < s->mid; i++) |
|
305 |
+ ff_bufqueue_add(ctx, &s->q, av_frame_clone(out)); |
|
306 |
+ av_frame_free(&out); |
|
307 |
+ } |
|
308 |
+ if (s->q.available < s->size) { |
|
309 |
+ ff_bufqueue_add(ctx, &s->q, buf); |
|
310 |
+ s->available++; |
|
311 |
+ } |
|
312 |
+ return 0; |
|
313 |
+ } |
|
314 |
+ |
|
315 |
+ in = ff_bufqueue_peek(&s->q, s->mid); |
|
316 |
+ |
|
317 |
+ if (!ctx->is_disabled) { |
|
318 |
+ ThreadData td; |
|
319 |
+ |
|
320 |
+ out = ff_get_video_buffer(outlink, outlink->w, outlink->h); |
|
321 |
+ if (!out) { |
|
322 |
+ av_frame_free(&buf); |
|
323 |
+ return AVERROR(ENOMEM); |
|
324 |
+ } |
|
325 |
+ |
|
326 |
+ for (i = 0; i < s->size; i++) { |
|
327 |
+ AVFrame *frame = ff_bufqueue_peek(&s->q, i); |
|
328 |
+ |
|
329 |
+ s->data[0][i] = frame->data[0]; |
|
330 |
+ s->data[1][i] = frame->data[1]; |
|
331 |
+ s->data[2][i] = frame->data[2]; |
|
332 |
+ s->linesize[0][i] = frame->linesize[0]; |
|
333 |
+ s->linesize[1][i] = frame->linesize[1]; |
|
334 |
+ s->linesize[2][i] = frame->linesize[2]; |
|
335 |
+ } |
|
336 |
+ |
|
337 |
+ td.in = in; td.out = out; |
|
338 |
+ ctx->internal->execute(ctx, s->filter_slice, &td, NULL, |
|
339 |
+ FFMIN3(s->planeheight[1], |
|
340 |
+ s->planeheight[2], |
|
341 |
+ ctx->graph->nb_threads)); |
|
342 |
+ av_frame_copy_props(out, in); |
|
343 |
+ } else { |
|
344 |
+ out = av_frame_clone(in); |
|
345 |
+ if (!out) { |
|
346 |
+ av_frame_free(&buf); |
|
347 |
+ return AVERROR(ENOMEM); |
|
348 |
+ } |
|
349 |
+ } |
|
350 |
+ |
|
351 |
+ in = ff_bufqueue_get(&s->q); |
|
352 |
+ av_frame_free(&in); |
|
353 |
+ ff_bufqueue_add(ctx, &s->q, buf); |
|
354 |
+ |
|
355 |
+ return ff_filter_frame(outlink, out); |
|
356 |
+} |
|
357 |
+ |
|
358 |
+static int request_frame(AVFilterLink *outlink) |
|
359 |
+{ |
|
360 |
+ AVFilterContext *ctx = outlink->src; |
|
361 |
+ ATADenoiseContext *s = ctx->priv; |
|
362 |
+ int ret = 0; |
|
363 |
+ |
|
364 |
+ ret = ff_request_frame(ctx->inputs[0]); |
|
365 |
+ |
|
366 |
+ if (ret == AVERROR_EOF && !ctx->is_disabled && s->available) { |
|
367 |
+ AVFrame *buf = ff_get_video_buffer(outlink, outlink->w, outlink->h); |
|
368 |
+ if (!buf) |
|
369 |
+ return AVERROR(ENOMEM); |
|
370 |
+ |
|
371 |
+ ret = filter_frame(ctx->inputs[0], buf); |
|
372 |
+ s->available--; |
|
373 |
+ } |
|
374 |
+ |
|
375 |
+ return ret; |
|
376 |
+} |
|
377 |
+ |
|
378 |
+static av_cold void uninit(AVFilterContext *ctx) |
|
379 |
+{ |
|
380 |
+ ATADenoiseContext *s = ctx->priv; |
|
381 |
+ |
|
382 |
+ ff_bufqueue_discard_all(&s->q); |
|
383 |
+} |
|
384 |
+ |
|
385 |
+static const AVFilterPad inputs[] = { |
|
386 |
+ { |
|
387 |
+ .name = "default", |
|
388 |
+ .type = AVMEDIA_TYPE_VIDEO, |
|
389 |
+ .filter_frame = filter_frame, |
|
390 |
+ .config_props = config_input, |
|
391 |
+ }, |
|
392 |
+ { NULL } |
|
393 |
+}; |
|
394 |
+ |
|
395 |
+static const AVFilterPad outputs[] = { |
|
396 |
+ { |
|
397 |
+ .name = "default", |
|
398 |
+ .type = AVMEDIA_TYPE_VIDEO, |
|
399 |
+ .request_frame = request_frame, |
|
400 |
+ .config_props = config_output, |
|
401 |
+ }, |
|
402 |
+ { NULL } |
|
403 |
+}; |
|
404 |
+ |
|
405 |
+AVFilter ff_vf_atadenoise = { |
|
406 |
+ .name = "atadenoise", |
|
407 |
+ .description = NULL_IF_CONFIG_SMALL("Apply an Adaptive Temporal Averaging Denoiser."), |
|
408 |
+ .priv_size = sizeof(ATADenoiseContext), |
|
409 |
+ .priv_class = &atadenoise_class, |
|
410 |
+ .init = init, |
|
411 |
+ .uninit = uninit, |
|
412 |
+ .query_formats = query_formats, |
|
413 |
+ .inputs = inputs, |
|
414 |
+ .outputs = outputs, |
|
415 |
+ .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL | AVFILTER_FLAG_SLICE_THREADS, |
|
416 |
+}; |