1 /*
2 * Copyright (c) 2003 Rich Felker
3 * Copyright (c) 2012 Stefano Sabatini
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 /**
23 * @file decimate filter, ported from libmpcodecs/vf_decimate.c by
24 * Rich Felker.
25 */
26
34
36 int lo, hi;
///< lower and higher threshold number of differences
37 ///< values for 8x8 blocks
38
39 float frac;
///< threshold of changed pixels over the total fraction
40
41 int max_drop_count;
///< if positive: maximum number of sequential frames to drop
42 ///< if negative: minimum number of frames between two drops
43
44 int drop_count;
///< if positive: number of frames sequentially dropped
45 ///< if negative: number of sequential frames which were not dropped
46
47 int hsub,
vsub;
///< chroma subsampling values
52
53 /**
54 * Return 1 if the two planes are different, 0 otherwise.
55 */
58 int w, int h)
59 {
62
63 int x, y;
65 int t = (w/16)*(h/16)*decimate->
frac;
67
68 /* compute difference for blocks of 8x8 bytes */
69 for (y = 0; y < h-7; y += 4) {
70 for (x = 8; x < w-7; x += 4) {
72 cur+x+y*linesize,
73 ref+x+y*linesize, linesize);
76 return 1;
77 if (d > decimate->
lo) {
78 c++;
79 if (c > t)
80 return 1;
81 }
82 }
83 }
84 return 0;
85 }
86
87 /**
88 * Tell if the frame should be decimated, for example if it is no much
89 * different with respect to the reference frame ref.
90 */
93 {
95 int plane;
96
99 return 0;
102 return 0;
103
104 for (plane = 0; ref->
data[plane] && ref->
linesize[plane]; plane++) {
105 int vsub = plane == 1 || plane == 2 ? decimate->
vsub : 0;
106 int hsub = plane == 1 || plane == 2 ? decimate->
hsub : 0;
110 return 0;
111 }
112
113 return 1;
114 }
115
117 {
119
120 /* set default values */
123 decimate->
hi = 64*12;
124 decimate->
frac = 0.33;
125
126 if (args) {
128 int n = sscanf(args, "%d%c%d%c%d%c%f%c",
130 &decimate->
hi, &c2, &decimate->
lo, &c3,
131 &decimate->
frac, &c4);
132 if (n != 1 &&
133 (n != 3 || c1 != ':') &&
134 (n != 5 || c1 != ':' || c2 != ':') &&
135 (n != 7 || c1 != ':' || c2 != ':' || c3 != ':')) {
137 "Invalid syntax for argument '%s': "
138 "must be in the form 'max:hi:lo:frac'\n", args);
140 }
141 }
142
145
147 if (!decimate->
avctx)
150
151 return 0;
152 }
153
155 {
160 }
161
163 {
172 };
173
175
176 return 0;
177 }
178
180 {
186
187 return 0;
188 }
189
191 {
194 int ret;
195
198 } else {
202
204 return ret;
205 }
206
208 "%s pts:%s pts_time:%s drop_count:%d\n",
212
215
216 return 0;
217 }
218
220 {
223 int ret;
224
225 do {
227 }
while (decimate->
drop_count > 0 && ret >= 0);
228
229 return ret;
230 }
231
233 {
240 },
242 };
243
245 {
249 },
251 };
252
258
261 .
inputs = decimate_inputs,
263 };