Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * Copyright (C) 2012 Michael Niedermayer <michaelni@gmx.at> | ||
3 | * | ||
4 | * This file is part of FFmpeg. | ||
5 | * | ||
6 | * FFmpeg is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU Lesser General Public | ||
8 | * License as published by the Free Software Foundation; either | ||
9 | * version 2.1 of the License, or (at your option) any later version. | ||
10 | * | ||
11 | * FFmpeg is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * Lesser General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU Lesser General Public | ||
17 | * License along with FFmpeg; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
19 | */ | ||
20 | |||
21 | #include <float.h> /* FLT_MAX */ | ||
22 | |||
23 | #include "libavutil/common.h" | ||
24 | #include "libavutil/opt.h" | ||
25 | #include "filters.h" | ||
26 | #include "vf_idet.h" | ||
27 | |||
28 | #define OFFSET(x) offsetof(IDETContext, x) | ||
29 | #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM | ||
30 | |||
31 | static const AVOption idet_options[] = { | ||
32 | { "intl_thres", "set interlacing threshold", OFFSET(interlace_threshold), AV_OPT_TYPE_FLOAT, {.dbl = 1.04}, -1, FLT_MAX, FLAGS }, | ||
33 | { "prog_thres", "set progressive threshold", OFFSET(progressive_threshold), AV_OPT_TYPE_FLOAT, {.dbl = 1.5}, -1, FLT_MAX, FLAGS }, | ||
34 | { "rep_thres", "set repeat threshold", OFFSET(repeat_threshold), AV_OPT_TYPE_FLOAT, {.dbl = 3.0}, -1, FLT_MAX, FLAGS }, | ||
35 | { "half_life", "half life of cumulative statistics", OFFSET(half_life), AV_OPT_TYPE_FLOAT, {.dbl = 0.0}, -1, INT_MAX, FLAGS }, | ||
36 | { "analyze_interlaced_flag", "set number of frames to use to determine if the interlace flag is accurate", OFFSET(analyze_interlaced_flag), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, FLAGS }, | ||
37 | { NULL } | ||
38 | }; | ||
39 | |||
40 | AVFILTER_DEFINE_CLASS(idet); | ||
41 | |||
42 | 100 | static const char *type2str(Type type) | |
43 | { | ||
44 |
2/5✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 98 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
|
100 | switch(type) { |
45 | ✗ | case TFF : return "tff"; | |
46 | ✗ | case BFF : return "bff"; | |
47 | 98 | case PROGRESSIVE : return "progressive"; | |
48 | 2 | case UNDETERMINED : return "undetermined"; | |
49 | } | ||
50 | ✗ | return NULL; | |
51 | } | ||
52 | |||
53 | #define PRECISION 1048576 | ||
54 | |||
55 | 275 | static uint64_t uintpow(uint64_t b,unsigned int e) | |
56 | { | ||
57 | 275 | uint64_t r=1; | |
58 |
2/2✓ Branch 0 taken 550 times.
✓ Branch 1 taken 275 times.
|
825 | while(e--) r*=b; |
59 | 275 | return r; | |
60 | } | ||
61 | |||
62 | 275 | static int av_dict_set_fxp(AVDictionary **pm, const char *key, uint64_t value, unsigned int digits, | |
63 | int flags) | ||
64 | { | ||
65 | char valuestr[44]; | ||
66 | 275 | uint64_t print_precision = uintpow(10, digits); | |
67 | |||
68 | 275 | value = av_rescale(value, print_precision, PRECISION); | |
69 | |||
70 | 275 | snprintf(valuestr, sizeof(valuestr), "%"PRId64".%0*"PRId64, | |
71 | value / print_precision, digits, value % print_precision); | ||
72 | |||
73 | 275 | return av_dict_set(pm, key, valuestr, flags); | |
74 | } | ||
75 | |||
76 | 50 | static const char *rep2str(RepeatedField repeated_field) | |
77 | { | ||
78 |
1/4✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
50 | switch(repeated_field) { |
79 | 50 | case REPEAT_NONE : return "neither"; | |
80 | ✗ | case REPEAT_TOP : return "top"; | |
81 | ✗ | case REPEAT_BOTTOM : return "bottom"; | |
82 | } | ||
83 | ✗ | return NULL; | |
84 | } | ||
85 | |||
86 | 42800 | int ff_idet_filter_line_c(const uint8_t *a, const uint8_t *b, const uint8_t *c, int w) | |
87 | { | ||
88 | int x; | ||
89 | 42800 | int ret=0; | |
90 | |||
91 |
2/2✓ Branch 0 taken 15065600 times.
✓ Branch 1 taken 42800 times.
|
15108400 | for(x=0; x<w; x++){ |
92 | 15065600 | int v = (*a++ + *c++) - 2 * *b++; | |
93 | 15065600 | ret += FFABS(v); | |
94 | } | ||
95 | |||
96 | 42800 | return ret; | |
97 | } | ||
98 | |||
99 | ✗ | int ff_idet_filter_line_c_16bit(const uint16_t *a, const uint16_t *b, const uint16_t *c, int w) | |
100 | { | ||
101 | int x; | ||
102 | ✗ | int ret=0; | |
103 | |||
104 | ✗ | for(x=0; x<w; x++){ | |
105 | ✗ | int v = (*a++ + *c++) - 2 * *b++; | |
106 | ✗ | ret += FFABS(v); | |
107 | } | ||
108 | |||
109 | ✗ | return ret; | |
110 | } | ||
111 | |||
112 | 25 | static void filter(AVFilterContext *ctx) | |
113 | { | ||
114 | 25 | IDETContext *idet = ctx->priv; | |
115 | int y, i; | ||
116 | 25 | int64_t alpha[2]={0}; | |
117 | 25 | int64_t delta=0; | |
118 | 25 | int64_t gamma[2]={0}; | |
119 | Type type, best_type; | ||
120 | RepeatedField repeat; | ||
121 | 25 | int match = 0; | |
122 | 25 | AVDictionary **metadata = &idet->cur->metadata; | |
123 | |||
124 |
2/2✓ Branch 0 taken 25 times.
✓ Branch 1 taken 25 times.
|
50 | for (i = 0; i < idet->csp->nb_components; i++) { |
125 | 25 | int w = idet->cur->width; | |
126 | 25 | int h = idet->cur->height; | |
127 | 25 | int refs = idet->cur->linesize[i]; | |
128 | |||
129 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
25 | if (i && i<3) { |
130 | ✗ | w = AV_CEIL_RSHIFT(w, idet->csp->log2_chroma_w); | |
131 | ✗ | h = AV_CEIL_RSHIFT(h, idet->csp->log2_chroma_h); | |
132 | } | ||
133 | |||
134 |
2/2✓ Branch 0 taken 10700 times.
✓ Branch 1 taken 25 times.
|
10725 | for (y = 2; y < h - 2; y++) { |
135 | 10700 | uint8_t *prev = &idet->prev->data[i][y*refs]; | |
136 | 10700 | uint8_t *cur = &idet->cur ->data[i][y*refs]; | |
137 | 10700 | uint8_t *next = &idet->next->data[i][y*refs]; | |
138 | 10700 | alpha[ y &1] += idet->filter_line(cur-refs, prev, cur+refs, w); | |
139 | 10700 | alpha[(y^1)&1] += idet->filter_line(cur-refs, next, cur+refs, w); | |
140 | 10700 | delta += idet->filter_line(cur-refs, cur, cur+refs, w); | |
141 | 10700 | gamma[(y^1)&1] += idet->filter_line(cur , prev, cur , w); | |
142 | } | ||
143 | } | ||
144 | |||
145 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | if (alpha[0] > idet->interlace_threshold * alpha[1]){ |
146 | ✗ | type = TFF; | |
147 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | }else if(alpha[1] > idet->interlace_threshold * alpha[0]){ |
148 | ✗ | type = BFF; | |
149 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 1 times.
|
25 | }else if(alpha[1] > idet->progressive_threshold * delta){ |
150 | 24 | type = PROGRESSIVE; | |
151 | }else{ | ||
152 | 1 | type = UNDETERMINED; | |
153 | } | ||
154 | |||
155 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | if ( gamma[0] > idet->repeat_threshold * gamma[1] ){ |
156 | ✗ | repeat = REPEAT_TOP; | |
157 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | } else if ( gamma[1] > idet->repeat_threshold * gamma[0] ){ |
158 | ✗ | repeat = REPEAT_BOTTOM; | |
159 | } else { | ||
160 | 25 | repeat = REPEAT_NONE; | |
161 | } | ||
162 | |||
163 | 25 | memmove(idet->history+1, idet->history, HIST_SIZE-1); | |
164 | 25 | idet->history[0] = type; | |
165 | 25 | best_type = UNDETERMINED; | |
166 |
2/2✓ Branch 0 taken 100 times.
✓ Branch 1 taken 25 times.
|
125 | for(i=0; i<HIST_SIZE; i++){ |
167 |
2/2✓ Branch 0 taken 92 times.
✓ Branch 1 taken 8 times.
|
100 | if(idet->history[i] != UNDETERMINED){ |
168 |
2/2✓ Branch 0 taken 25 times.
✓ Branch 1 taken 67 times.
|
92 | if(best_type == UNDETERMINED) |
169 | 25 | best_type = idet->history[i]; | |
170 | |||
171 |
1/2✓ Branch 0 taken 92 times.
✗ Branch 1 not taken.
|
92 | if(idet->history[i] == best_type) { |
172 | 92 | match++; | |
173 | }else{ | ||
174 | ✗ | match=0; | |
175 | ✗ | break; | |
176 | } | ||
177 | } | ||
178 | } | ||
179 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 24 times.
|
25 | if(idet->last_type == UNDETERMINED){ |
180 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if(match ) idet->last_type = best_type; |
181 | }else{ | ||
182 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 1 times.
|
24 | if(match>2) idet->last_type = best_type; |
183 | } | ||
184 | |||
185 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | if (idet->last_type == TFF){ |
186 | #if FF_API_INTERLACED_FRAME | ||
187 | FF_DISABLE_DEPRECATION_WARNINGS | ||
188 | ✗ | idet->cur->top_field_first = 1; | |
189 | ✗ | idet->cur->interlaced_frame = 1; | |
190 | FF_ENABLE_DEPRECATION_WARNINGS | ||
191 | #endif | ||
192 | ✗ | idet->cur->flags |= (AV_FRAME_FLAG_INTERLACED | AV_FRAME_FLAG_TOP_FIELD_FIRST); | |
193 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | }else if(idet->last_type == BFF){ |
194 | #if FF_API_INTERLACED_FRAME | ||
195 | FF_DISABLE_DEPRECATION_WARNINGS | ||
196 | ✗ | idet->cur->top_field_first = 0; | |
197 | ✗ | idet->cur->interlaced_frame = 1; | |
198 | FF_ENABLE_DEPRECATION_WARNINGS | ||
199 | #endif | ||
200 | ✗ | idet->cur->flags &= ~AV_FRAME_FLAG_TOP_FIELD_FIRST; | |
201 | ✗ | idet->cur->flags |= AV_FRAME_FLAG_INTERLACED; | |
202 |
1/2✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
|
25 | }else if(idet->last_type == PROGRESSIVE){ |
203 | #if FF_API_INTERLACED_FRAME | ||
204 | FF_DISABLE_DEPRECATION_WARNINGS | ||
205 | 25 | idet->cur->interlaced_frame = 0; | |
206 | FF_ENABLE_DEPRECATION_WARNINGS | ||
207 | #endif | ||
208 | 25 | idet->cur->flags &= ~AV_FRAME_FLAG_INTERLACED; | |
209 | } | ||
210 | |||
211 |
2/2✓ Branch 0 taken 75 times.
✓ Branch 1 taken 25 times.
|
100 | for(i=0; i<3; i++) |
212 | 75 | idet->repeats[i] = av_rescale(idet->repeats [i], idet->decay_coefficient, PRECISION); | |
213 | |||
214 |
2/2✓ Branch 0 taken 100 times.
✓ Branch 1 taken 25 times.
|
125 | for(i=0; i<4; i++){ |
215 | 100 | idet->prestat [i] = av_rescale(idet->prestat [i], idet->decay_coefficient, PRECISION); | |
216 | 100 | idet->poststat[i] = av_rescale(idet->poststat[i], idet->decay_coefficient, PRECISION); | |
217 | } | ||
218 | |||
219 | 25 | idet->total_repeats [ repeat] ++; | |
220 | 25 | idet->repeats [ repeat] += PRECISION; | |
221 | |||
222 | 25 | idet->total_prestat [ type] ++; | |
223 | 25 | idet->prestat [ type] += PRECISION; | |
224 | |||
225 | 25 | idet->total_poststat[idet->last_type] ++; | |
226 | 25 | idet->poststat [idet->last_type] += PRECISION; | |
227 | |||
228 | 25 | av_log(ctx, AV_LOG_DEBUG, "Repeated Field:%12s, Single frame:%12s, Multi frame:%12s\n", | |
229 | rep2str(repeat), type2str(type), type2str(idet->last_type)); | ||
230 | |||
231 | 25 | av_dict_set (metadata, "lavfi.idet.repeated.current_frame", rep2str(repeat), 0); | |
232 | 25 | av_dict_set_fxp(metadata, "lavfi.idet.repeated.neither", idet->repeats[REPEAT_NONE], 2, 0); | |
233 | 25 | av_dict_set_fxp(metadata, "lavfi.idet.repeated.top", idet->repeats[REPEAT_TOP], 2, 0); | |
234 | 25 | av_dict_set_fxp(metadata, "lavfi.idet.repeated.bottom", idet->repeats[REPEAT_BOTTOM], 2, 0); | |
235 | |||
236 | 25 | av_dict_set (metadata, "lavfi.idet.single.current_frame", type2str(type), 0); | |
237 | 25 | av_dict_set_fxp(metadata, "lavfi.idet.single.tff", idet->prestat[TFF], 2 , 0); | |
238 | 25 | av_dict_set_fxp(metadata, "lavfi.idet.single.bff", idet->prestat[BFF], 2, 0); | |
239 | 25 | av_dict_set_fxp(metadata, "lavfi.idet.single.progressive", idet->prestat[PROGRESSIVE], 2, 0); | |
240 | 25 | av_dict_set_fxp(metadata, "lavfi.idet.single.undetermined", idet->prestat[UNDETERMINED], 2, 0); | |
241 | |||
242 | 25 | av_dict_set (metadata, "lavfi.idet.multiple.current_frame", type2str(idet->last_type), 0); | |
243 | 25 | av_dict_set_fxp(metadata, "lavfi.idet.multiple.tff", idet->poststat[TFF], 2, 0); | |
244 | 25 | av_dict_set_fxp(metadata, "lavfi.idet.multiple.bff", idet->poststat[BFF], 2, 0); | |
245 | 25 | av_dict_set_fxp(metadata, "lavfi.idet.multiple.progressive", idet->poststat[PROGRESSIVE], 2, 0); | |
246 | 25 | av_dict_set_fxp(metadata, "lavfi.idet.multiple.undetermined", idet->poststat[UNDETERMINED], 2, 0); | |
247 | 25 | } | |
248 | |||
249 | 26 | static int filter_frame(AVFilterLink *link, AVFrame *picref) | |
250 | { | ||
251 | 26 | AVFilterContext *ctx = link->dst; | |
252 | 26 | IDETContext *idet = ctx->priv; | |
253 | |||
254 | // initial frame(s) and not interlaced, just pass through for | ||
255 | // the analyze_interlaced_flag mode | ||
256 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
|
26 | if (idet->analyze_interlaced_flag && |
257 | ✗ | !(picref->flags & AV_FRAME_FLAG_INTERLACED) && | |
258 | ✗ | !idet->next) { | |
259 | ✗ | return ff_filter_frame(ctx->outputs[0], picref); | |
260 | } | ||
261 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
|
26 | if (idet->analyze_interlaced_flag_done) { |
262 | ✗ | if ((picref->flags & AV_FRAME_FLAG_INTERLACED) && idet->interlaced_flag_accuracy < 0) { | |
263 | #if FF_API_INTERLACED_FRAME | ||
264 | FF_DISABLE_DEPRECATION_WARNINGS | ||
265 | ✗ | picref->interlaced_frame = 0; | |
266 | FF_ENABLE_DEPRECATION_WARNINGS | ||
267 | #endif | ||
268 | ✗ | picref->flags &= ~AV_FRAME_FLAG_INTERLACED; | |
269 | } | ||
270 | ✗ | return ff_filter_frame(ctx->outputs[0], picref); | |
271 | } | ||
272 | |||
273 | 26 | av_frame_free(&idet->prev); | |
274 | |||
275 |
1/2✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
|
26 | if( picref->width != link->w |
276 |
1/2✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
|
26 | || picref->height != link->h |
277 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
|
26 | || picref->format != link->format) { |
278 | ✗ | link->dst->inputs[0]->format = picref->format; | |
279 | ✗ | link->dst->inputs[0]->w = picref->width; | |
280 | ✗ | link->dst->inputs[0]->h = picref->height; | |
281 | |||
282 | ✗ | av_frame_free(&idet->cur ); | |
283 | ✗ | av_frame_free(&idet->next); | |
284 | } | ||
285 | |||
286 | 26 | idet->prev = idet->cur; | |
287 | 26 | idet->cur = idet->next; | |
288 | 26 | idet->next = picref; | |
289 | |||
290 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 25 times.
|
26 | if (!idet->cur && |
291 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | !(idet->cur = av_frame_clone(idet->next))) |
292 | ✗ | return AVERROR(ENOMEM); | |
293 | |||
294 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 25 times.
|
26 | if (!idet->prev) |
295 | 1 | return 0; | |
296 | |||
297 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 24 times.
|
25 | if (!idet->csp) |
298 | 1 | idet->csp = av_pix_fmt_desc_get(link->format); | |
299 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | if (idet->csp->comp[0].depth > 8){ |
300 | ✗ | idet->filter_line = (ff_idet_filter_func)ff_idet_filter_line_c_16bit; | |
301 | #if ARCH_X86 | ||
302 | ✗ | ff_idet_init_x86(idet, 1); | |
303 | #endif | ||
304 | } | ||
305 | |||
306 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | if (idet->analyze_interlaced_flag) { |
307 | ✗ | if (idet->cur->flags & AV_FRAME_FLAG_INTERLACED) { | |
308 | #if FF_API_INTERLACED_FRAME | ||
309 | FF_DISABLE_DEPRECATION_WARNINGS | ||
310 | ✗ | idet->cur->interlaced_frame = 0; | |
311 | FF_ENABLE_DEPRECATION_WARNINGS | ||
312 | #endif | ||
313 | ✗ | idet->cur->flags &= ~AV_FRAME_FLAG_INTERLACED; | |
314 | ✗ | filter(ctx); | |
315 | ✗ | if (idet->last_type == PROGRESSIVE) { | |
316 | ✗ | idet->interlaced_flag_accuracy --; | |
317 | ✗ | idet->analyze_interlaced_flag --; | |
318 | ✗ | } else if (idet->last_type != UNDETERMINED) { | |
319 | ✗ | idet->interlaced_flag_accuracy ++; | |
320 | ✗ | idet->analyze_interlaced_flag --; | |
321 | } | ||
322 | ✗ | if (idet->analyze_interlaced_flag == 1) { | |
323 | ✗ | ff_filter_frame(ctx->outputs[0], av_frame_clone(idet->cur)); | |
324 | |||
325 | ✗ | if ((idet->next->flags & AV_FRAME_FLAG_INTERLACED) && idet->interlaced_flag_accuracy < 0) { | |
326 | #if FF_API_INTERLACED_FRAME | ||
327 | FF_DISABLE_DEPRECATION_WARNINGS | ||
328 | ✗ | idet->next->interlaced_frame = 0; | |
329 | FF_ENABLE_DEPRECATION_WARNINGS | ||
330 | #endif | ||
331 | ✗ | idet->next->flags &= ~AV_FRAME_FLAG_INTERLACED; | |
332 | } | ||
333 | ✗ | idet->analyze_interlaced_flag_done = 1; | |
334 | ✗ | av_log(ctx, AV_LOG_INFO, "Final flag accuracy %d\n", idet->interlaced_flag_accuracy); | |
335 | ✗ | return ff_filter_frame(ctx->outputs[0], av_frame_clone(idet->next)); | |
336 | } | ||
337 | } | ||
338 | } else { | ||
339 | 25 | filter(ctx); | |
340 | } | ||
341 | |||
342 | 25 | return ff_filter_frame(ctx->outputs[0], av_frame_clone(idet->cur)); | |
343 | } | ||
344 | |||
345 | 25 | static int request_frame(AVFilterLink *link) | |
346 | { | ||
347 | 25 | AVFilterContext *ctx = link->src; | |
348 | 25 | IDETContext *idet = ctx->priv; | |
349 | int ret; | ||
350 | |||
351 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | if (idet->eof) |
352 | ✗ | return AVERROR_EOF; | |
353 | |||
354 | 25 | ret = ff_request_frame(link->src->inputs[0]); | |
355 | |||
356 |
1/6✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
25 | if (ret == AVERROR_EOF && idet->cur && !idet->analyze_interlaced_flag_done) { |
357 | ✗ | AVFrame *next = av_frame_clone(idet->next); | |
358 | |||
359 | ✗ | if (!next) | |
360 | ✗ | return AVERROR(ENOMEM); | |
361 | |||
362 | ✗ | ret = filter_frame(link->src->inputs[0], next); | |
363 | ✗ | idet->eof = 1; | |
364 | } | ||
365 | |||
366 | 25 | return ret; | |
367 | } | ||
368 | |||
369 | 2 | static av_cold void uninit(AVFilterContext *ctx) | |
370 | { | ||
371 | 2 | IDETContext *idet = ctx->priv; | |
372 | |||
373 | 2 | av_log(ctx, AV_LOG_INFO, "Repeated Fields: Neither:%6"PRId64" Top:%6"PRId64" Bottom:%6"PRId64"\n", | |
374 | idet->total_repeats[REPEAT_NONE], | ||
375 | idet->total_repeats[REPEAT_TOP], | ||
376 | idet->total_repeats[REPEAT_BOTTOM] | ||
377 | ); | ||
378 | 2 | av_log(ctx, AV_LOG_INFO, "Single frame detection: TFF:%6"PRId64" BFF:%6"PRId64" Progressive:%6"PRId64" Undetermined:%6"PRId64"\n", | |
379 | idet->total_prestat[TFF], | ||
380 | idet->total_prestat[BFF], | ||
381 | idet->total_prestat[PROGRESSIVE], | ||
382 | idet->total_prestat[UNDETERMINED] | ||
383 | ); | ||
384 | 2 | av_log(ctx, AV_LOG_INFO, "Multi frame detection: TFF:%6"PRId64" BFF:%6"PRId64" Progressive:%6"PRId64" Undetermined:%6"PRId64"\n", | |
385 | idet->total_poststat[TFF], | ||
386 | idet->total_poststat[BFF], | ||
387 | idet->total_poststat[PROGRESSIVE], | ||
388 | idet->total_poststat[UNDETERMINED] | ||
389 | ); | ||
390 | |||
391 | 2 | av_frame_free(&idet->prev); | |
392 | 2 | av_frame_free(&idet->cur ); | |
393 | 2 | av_frame_free(&idet->next); | |
394 | 2 | } | |
395 | |||
396 | static const enum AVPixelFormat pix_fmts[] = { | ||
397 | AV_PIX_FMT_YUV420P, | ||
398 | AV_PIX_FMT_YUV422P, | ||
399 | AV_PIX_FMT_YUV444P, | ||
400 | AV_PIX_FMT_YUV410P, | ||
401 | AV_PIX_FMT_YUV411P, | ||
402 | AV_PIX_FMT_GRAY8, | ||
403 | AV_PIX_FMT_YUVJ420P, | ||
404 | AV_PIX_FMT_YUVJ422P, | ||
405 | AV_PIX_FMT_YUVJ444P, | ||
406 | AV_PIX_FMT_GRAY16, | ||
407 | AV_PIX_FMT_YUV440P, | ||
408 | AV_PIX_FMT_YUVJ440P, | ||
409 | AV_PIX_FMT_YUV420P9, | ||
410 | AV_PIX_FMT_YUV422P9, | ||
411 | AV_PIX_FMT_YUV444P9, | ||
412 | AV_PIX_FMT_YUV420P10, | ||
413 | AV_PIX_FMT_YUV422P10, | ||
414 | AV_PIX_FMT_YUV444P10, | ||
415 | AV_PIX_FMT_YUV420P12, | ||
416 | AV_PIX_FMT_YUV422P12, | ||
417 | AV_PIX_FMT_YUV444P12, | ||
418 | AV_PIX_FMT_YUV420P14, | ||
419 | AV_PIX_FMT_YUV422P14, | ||
420 | AV_PIX_FMT_YUV444P14, | ||
421 | AV_PIX_FMT_YUV420P16, | ||
422 | AV_PIX_FMT_YUV422P16, | ||
423 | AV_PIX_FMT_YUV444P16, | ||
424 | AV_PIX_FMT_YUVA420P, | ||
425 | AV_PIX_FMT_YUVA422P, | ||
426 | AV_PIX_FMT_YUVA444P, | ||
427 | AV_PIX_FMT_NONE | ||
428 | }; | ||
429 | |||
430 | 2 | static av_cold int init(AVFilterContext *ctx) | |
431 | { | ||
432 | 2 | IDETContext *idet = ctx->priv; | |
433 | |||
434 | 2 | idet->eof = 0; | |
435 | 2 | idet->last_type = UNDETERMINED; | |
436 | 2 | memset(idet->history, UNDETERMINED, HIST_SIZE); | |
437 | |||
438 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if( idet->half_life > 0 ) |
439 | ✗ | idet->decay_coefficient = lrint( PRECISION * exp2(-1.0 / idet->half_life) ); | |
440 | else | ||
441 | 2 | idet->decay_coefficient = PRECISION; | |
442 | |||
443 | 2 | idet->filter_line = ff_idet_filter_line_c; | |
444 | |||
445 | #if ARCH_X86 | ||
446 | 2 | ff_idet_init_x86(idet, 0); | |
447 | #endif | ||
448 | |||
449 | 2 | return 0; | |
450 | } | ||
451 | |||
452 | static const AVFilterPad idet_inputs[] = { | ||
453 | { | ||
454 | .name = "default", | ||
455 | .type = AVMEDIA_TYPE_VIDEO, | ||
456 | .filter_frame = filter_frame, | ||
457 | }, | ||
458 | }; | ||
459 | |||
460 | static const AVFilterPad idet_outputs[] = { | ||
461 | { | ||
462 | .name = "default", | ||
463 | .type = AVMEDIA_TYPE_VIDEO, | ||
464 | .request_frame = request_frame | ||
465 | }, | ||
466 | }; | ||
467 | |||
468 | const AVFilter ff_vf_idet = { | ||
469 | .name = "idet", | ||
470 | .description = NULL_IF_CONFIG_SMALL("Interlace detect Filter."), | ||
471 | .priv_size = sizeof(IDETContext), | ||
472 | .init = init, | ||
473 | .uninit = uninit, | ||
474 | .flags = AVFILTER_FLAG_METADATA_ONLY, | ||
475 | FILTER_INPUTS(idet_inputs), | ||
476 | FILTER_OUTPUTS(idet_outputs), | ||
477 | FILTER_PIXFMTS_ARRAY(pix_fmts), | ||
478 | .priv_class = &idet_class, | ||
479 | }; | ||
480 |