Signed-off-by: Paul B Mahol <onemda@gmail.com>
Paul B Mahol authored on 2017/11/19 02:18:39... | ... |
@@ -8610,6 +8610,48 @@ framework. |
8610 | 8610 |
|
8611 | 8611 |
It does not take parameters. |
8612 | 8612 |
|
8613 |
+@section fillborders |
|
8614 |
+ |
|
8615 |
+Fill borders of the input video, without changing video stream dimensions. |
|
8616 |
+Sometimes video can have garbage at the four edges and you may not want to |
|
8617 |
+crop video input to keep size multiple of some number. |
|
8618 |
+ |
|
8619 |
+This filter accepts the following options: |
|
8620 |
+ |
|
8621 |
+@table @option |
|
8622 |
+@item left |
|
8623 |
+Number of pixels to fill from left border. |
|
8624 |
+ |
|
8625 |
+@item right |
|
8626 |
+Number of pixels to fill from right border. |
|
8627 |
+ |
|
8628 |
+@item top |
|
8629 |
+Number of pixels to fill from top border. |
|
8630 |
+ |
|
8631 |
+@item bottom |
|
8632 |
+Number of pixels to fill from bottom border. |
|
8633 |
+ |
|
8634 |
+@item mode |
|
8635 |
+Set fill mode. |
|
8636 |
+ |
|
8637 |
+It accepts the following values: |
|
8638 |
+@table @samp |
|
8639 |
+@item smear |
|
8640 |
+fill pixels using outermost pixels |
|
8641 |
+ |
|
8642 |
+@item mirror |
|
8643 |
+fill pixels using mirroring |
|
8644 |
+ |
|
8645 |
+@item fixed |
|
8646 |
+fill pixels with constant value |
|
8647 |
+@end table |
|
8648 |
+ |
|
8649 |
+Default is @var{smear}. |
|
8650 |
+ |
|
8651 |
+@item color |
|
8652 |
+Set color for pixels in fixed mode. Default is @var{black}. |
|
8653 |
+@end table |
|
8654 |
+ |
|
8613 | 8655 |
@section find_rect |
8614 | 8656 |
|
8615 | 8657 |
Find a rectangular object |
... | ... |
@@ -192,6 +192,7 @@ OBJS-$(CONFIG_FIELD_FILTER) += vf_field.o |
192 | 192 |
OBJS-$(CONFIG_FIELDHINT_FILTER) += vf_fieldhint.o |
193 | 193 |
OBJS-$(CONFIG_FIELDMATCH_FILTER) += vf_fieldmatch.o |
194 | 194 |
OBJS-$(CONFIG_FIELDORDER_FILTER) += vf_fieldorder.o |
195 |
+OBJS-$(CONFIG_FILLBORDERS_FILTER) += vf_fillborders.o |
|
195 | 196 |
OBJS-$(CONFIG_FIND_RECT_FILTER) += vf_find_rect.o lavfutils.o |
196 | 197 |
OBJS-$(CONFIG_FLOODFILL_FILTER) += vf_floodfill.o |
197 | 198 |
OBJS-$(CONFIG_FORMAT_FILTER) += vf_format.o |
... | ... |
@@ -202,6 +202,7 @@ static void register_all(void) |
202 | 202 |
REGISTER_FILTER(FIELDHINT, fieldhint, vf); |
203 | 203 |
REGISTER_FILTER(FIELDMATCH, fieldmatch, vf); |
204 | 204 |
REGISTER_FILTER(FIELDORDER, fieldorder, vf); |
205 |
+ REGISTER_FILTER(FILLBORDERS, fillborders, vf); |
|
205 | 206 |
REGISTER_FILTER(FIND_RECT, find_rect, vf); |
206 | 207 |
REGISTER_FILTER(FLOODFILL, floodfill, vf); |
207 | 208 |
REGISTER_FILTER(FORMAT, format, vf); |
... | ... |
@@ -30,7 +30,7 @@ |
30 | 30 |
#include "libavutil/version.h" |
31 | 31 |
|
32 | 32 |
#define LIBAVFILTER_VERSION_MAJOR 7 |
33 |
-#define LIBAVFILTER_VERSION_MINOR 5 |
|
33 |
+#define LIBAVFILTER_VERSION_MINOR 6 |
|
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 100644 |
... | ... |
@@ -0,0 +1,394 @@ |
0 |
+/* |
|
1 |
+ * Copyright (c) 2017 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 |
+#include "libavutil/colorspace.h" |
|
21 |
+#include "libavutil/common.h" |
|
22 |
+#include "libavutil/opt.h" |
|
23 |
+#include "libavutil/pixdesc.h" |
|
24 |
+#include "avfilter.h" |
|
25 |
+#include "drawutils.h" |
|
26 |
+#include "formats.h" |
|
27 |
+#include "internal.h" |
|
28 |
+#include "video.h" |
|
29 |
+ |
|
30 |
+enum { Y, U, V, A }; |
|
31 |
+enum { R, G, B }; |
|
32 |
+ |
|
33 |
+enum FillMode { FM_SMEAR, FM_MIRROR, FM_FIXED, FM_NB_MODES }; |
|
34 |
+ |
|
35 |
+typedef struct Borders { |
|
36 |
+ int left, right, top, bottom; |
|
37 |
+} Borders; |
|
38 |
+ |
|
39 |
+typedef struct FillBordersContext { |
|
40 |
+ const AVClass *class; |
|
41 |
+ int left, right, top, bottom; |
|
42 |
+ int mode; |
|
43 |
+ |
|
44 |
+ int nb_planes; |
|
45 |
+ int depth; |
|
46 |
+ Borders borders[4]; |
|
47 |
+ int planewidth[4]; |
|
48 |
+ int planeheight[4]; |
|
49 |
+ uint8_t fill[4]; |
|
50 |
+ uint8_t yuv_color[4]; |
|
51 |
+ uint8_t rgba_color[4]; |
|
52 |
+ |
|
53 |
+ void (*fillborders)(struct FillBordersContext *s, AVFrame *frame); |
|
54 |
+} FillBordersContext; |
|
55 |
+ |
|
56 |
+static int query_formats(AVFilterContext *ctx) |
|
57 |
+{ |
|
58 |
+ static const enum AVPixelFormat pix_fmts[] = { |
|
59 |
+ AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV440P, |
|
60 |
+ AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ440P, |
|
61 |
+ AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUVA420P, AV_PIX_FMT_YUV420P, |
|
62 |
+ AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ420P, |
|
63 |
+ AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P, |
|
64 |
+ AV_PIX_FMT_YUV420P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV444P9, |
|
65 |
+ AV_PIX_FMT_YUV420P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV444P10, |
|
66 |
+ AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV440P12, |
|
67 |
+ AV_PIX_FMT_YUV420P14, AV_PIX_FMT_YUV422P14, AV_PIX_FMT_YUV444P14, |
|
68 |
+ AV_PIX_FMT_YUV420P16, AV_PIX_FMT_YUV422P16, AV_PIX_FMT_YUV444P16, |
|
69 |
+ AV_PIX_FMT_YUVA420P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA444P9, |
|
70 |
+ AV_PIX_FMT_YUVA420P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA444P10, |
|
71 |
+ AV_PIX_FMT_YUVA420P16, AV_PIX_FMT_YUVA422P16, AV_PIX_FMT_YUVA444P16, |
|
72 |
+ AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10, |
|
73 |
+ AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14, AV_PIX_FMT_GBRP16, |
|
74 |
+ AV_PIX_FMT_GBRAP, AV_PIX_FMT_GBRAP10, AV_PIX_FMT_GBRAP12, AV_PIX_FMT_GBRAP16, |
|
75 |
+ AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY9, AV_PIX_FMT_GRAY10, AV_PIX_FMT_GRAY12, AV_PIX_FMT_GRAY16, |
|
76 |
+ AV_PIX_FMT_NONE |
|
77 |
+ }; |
|
78 |
+ AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts); |
|
79 |
+ if (!fmts_list) |
|
80 |
+ return AVERROR(ENOMEM); |
|
81 |
+ return ff_set_common_formats(ctx, fmts_list); |
|
82 |
+} |
|
83 |
+ |
|
84 |
+static void smear_borders8(FillBordersContext *s, AVFrame *frame) |
|
85 |
+{ |
|
86 |
+ int p, y; |
|
87 |
+ |
|
88 |
+ for (p = 0; p < s->nb_planes; p++) { |
|
89 |
+ uint8_t *ptr = frame->data[p]; |
|
90 |
+ int linesize = frame->linesize[p]; |
|
91 |
+ |
|
92 |
+ for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) { |
|
93 |
+ memset(ptr + y * linesize, |
|
94 |
+ *(ptr + y * linesize + s->borders[p].left), |
|
95 |
+ s->borders[p].left); |
|
96 |
+ memset(ptr + y * linesize + s->planewidth[p] - s->borders[p].right, |
|
97 |
+ *(ptr + y * linesize + s->planewidth[p] - s->borders[p].right - 1), |
|
98 |
+ s->borders[p].right); |
|
99 |
+ } |
|
100 |
+ |
|
101 |
+ for (y = 0; y < s->borders[p].top; y++) { |
|
102 |
+ memcpy(ptr + y * linesize, |
|
103 |
+ ptr + s->borders[p].top * linesize, s->planewidth[p]); |
|
104 |
+ } |
|
105 |
+ |
|
106 |
+ for (y = s->planeheight[p] - s->borders[p].bottom; y < s->planeheight[p]; y++) { |
|
107 |
+ memcpy(ptr + y * linesize, |
|
108 |
+ ptr + (s->planeheight[p] - s->borders[p].bottom - 1) * linesize, |
|
109 |
+ s->planewidth[p]); |
|
110 |
+ } |
|
111 |
+ } |
|
112 |
+} |
|
113 |
+ |
|
114 |
+static void smear_borders16(FillBordersContext *s, AVFrame *frame) |
|
115 |
+{ |
|
116 |
+ int p, y, x; |
|
117 |
+ |
|
118 |
+ for (p = 0; p < s->nb_planes; p++) { |
|
119 |
+ uint16_t *ptr = (uint16_t *)frame->data[p]; |
|
120 |
+ int linesize = frame->linesize[p] / 2; |
|
121 |
+ |
|
122 |
+ for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) { |
|
123 |
+ for (x = 0; x < s->borders[p].left; x++) { |
|
124 |
+ ptr[y * linesize + x] = *(ptr + y * linesize + s->borders[p].left); |
|
125 |
+ } |
|
126 |
+ |
|
127 |
+ for (x = 0; x < s->borders[p].right; x++) { |
|
128 |
+ ptr[y * linesize + s->planewidth[p] - s->borders[p].right + x] = |
|
129 |
+ *(ptr + y * linesize + s->planewidth[p] - s->borders[p].right - 1); |
|
130 |
+ } |
|
131 |
+ } |
|
132 |
+ |
|
133 |
+ for (y = 0; y < s->borders[p].top; y++) { |
|
134 |
+ memcpy(ptr + y * linesize, |
|
135 |
+ ptr + s->borders[p].top * linesize, s->planewidth[p] * 2); |
|
136 |
+ } |
|
137 |
+ |
|
138 |
+ for (y = s->planeheight[p] - s->borders[p].bottom; y < s->planeheight[p]; y++) { |
|
139 |
+ memcpy(ptr + y * linesize, |
|
140 |
+ ptr + (s->planeheight[p] - s->borders[p].bottom - 1) * linesize, |
|
141 |
+ s->planewidth[p] * 2); |
|
142 |
+ } |
|
143 |
+ } |
|
144 |
+} |
|
145 |
+ |
|
146 |
+static void mirror_borders8(FillBordersContext *s, AVFrame *frame) |
|
147 |
+{ |
|
148 |
+ int p, y, x; |
|
149 |
+ |
|
150 |
+ for (p = 0; p < s->nb_planes; p++) { |
|
151 |
+ uint8_t *ptr = frame->data[p]; |
|
152 |
+ int linesize = frame->linesize[p]; |
|
153 |
+ |
|
154 |
+ for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) { |
|
155 |
+ for (x = 0; x < s->borders[p].left; x++) { |
|
156 |
+ ptr[y * linesize + x] = ptr[y * linesize + s->borders[p].left * 2 - 1 - x]; |
|
157 |
+ } |
|
158 |
+ |
|
159 |
+ for (x = 0; x < s->borders[p].right; x++) { |
|
160 |
+ ptr[y * linesize + s->planewidth[p] - s->borders[p].right + x] = |
|
161 |
+ ptr[y * linesize + s->planewidth[p] - s->borders[p].right - 1 - x]; |
|
162 |
+ } |
|
163 |
+ } |
|
164 |
+ |
|
165 |
+ for (y = 0; y < s->borders[p].top; y++) { |
|
166 |
+ memcpy(ptr + y * linesize, |
|
167 |
+ ptr + (s->borders[p].top * 2 - 1 - y) * linesize, |
|
168 |
+ s->planewidth[p]); |
|
169 |
+ } |
|
170 |
+ |
|
171 |
+ for (y = 0; y < s->borders[p].bottom; y++) { |
|
172 |
+ memcpy(ptr + (s->planeheight[p] - s->borders[p].bottom + y) * linesize, |
|
173 |
+ ptr + (s->planeheight[p] - s->borders[p].bottom - 1 - y) * linesize, |
|
174 |
+ s->planewidth[p]); |
|
175 |
+ } |
|
176 |
+ } |
|
177 |
+} |
|
178 |
+ |
|
179 |
+static void mirror_borders16(FillBordersContext *s, AVFrame *frame) |
|
180 |
+{ |
|
181 |
+ int p, y, x; |
|
182 |
+ |
|
183 |
+ for (p = 0; p < s->nb_planes; p++) { |
|
184 |
+ uint16_t *ptr = (uint16_t *)frame->data[p]; |
|
185 |
+ int linesize = frame->linesize[p] / 2; |
|
186 |
+ |
|
187 |
+ for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) { |
|
188 |
+ for (x = 0; x < s->borders[p].left; x++) { |
|
189 |
+ ptr[y * linesize + x] = ptr[y * linesize + s->borders[p].left * 2 - 1 - x]; |
|
190 |
+ } |
|
191 |
+ |
|
192 |
+ for (x = 0; x < s->borders[p].right; x++) { |
|
193 |
+ ptr[y * linesize + s->planewidth[p] - s->borders[p].right + x] = |
|
194 |
+ ptr[y * linesize + s->planewidth[p] - s->borders[p].right - 1 - x]; |
|
195 |
+ } |
|
196 |
+ } |
|
197 |
+ |
|
198 |
+ for (y = 0; y < s->borders[p].top; y++) { |
|
199 |
+ memcpy(ptr + y * linesize, |
|
200 |
+ ptr + (s->borders[p].top * 2 - 1 - y) * linesize, |
|
201 |
+ s->planewidth[p] * 2); |
|
202 |
+ } |
|
203 |
+ |
|
204 |
+ for (y = 0; y < s->borders[p].bottom; y++) { |
|
205 |
+ memcpy(ptr + (s->planeheight[p] - s->borders[p].bottom + y) * linesize, |
|
206 |
+ ptr + (s->planeheight[p] - s->borders[p].bottom - 1 - y) * linesize, |
|
207 |
+ s->planewidth[p] * 2); |
|
208 |
+ } |
|
209 |
+ } |
|
210 |
+} |
|
211 |
+ |
|
212 |
+static void fixed_borders8(FillBordersContext *s, AVFrame *frame) |
|
213 |
+{ |
|
214 |
+ int p, y; |
|
215 |
+ |
|
216 |
+ for (p = 0; p < s->nb_planes; p++) { |
|
217 |
+ uint8_t *ptr = frame->data[p]; |
|
218 |
+ uint8_t fill = s->fill[p]; |
|
219 |
+ int linesize = frame->linesize[p]; |
|
220 |
+ |
|
221 |
+ for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) { |
|
222 |
+ memset(ptr + y * linesize, fill, s->borders[p].left); |
|
223 |
+ memset(ptr + y * linesize + s->planewidth[p] - s->borders[p].right, fill, |
|
224 |
+ s->borders[p].right); |
|
225 |
+ } |
|
226 |
+ |
|
227 |
+ for (y = 0; y < s->borders[p].top; y++) { |
|
228 |
+ memset(ptr + y * linesize, fill, s->planewidth[p]); |
|
229 |
+ } |
|
230 |
+ |
|
231 |
+ for (y = s->planeheight[p] - s->borders[p].bottom; y < s->planeheight[p]; y++) { |
|
232 |
+ memset(ptr + y * linesize, fill, s->planewidth[p]); |
|
233 |
+ } |
|
234 |
+ } |
|
235 |
+} |
|
236 |
+ |
|
237 |
+static void fixed_borders16(FillBordersContext *s, AVFrame *frame) |
|
238 |
+{ |
|
239 |
+ int p, y, x; |
|
240 |
+ |
|
241 |
+ for (p = 0; p < s->nb_planes; p++) { |
|
242 |
+ uint16_t *ptr = (uint16_t *)frame->data[p]; |
|
243 |
+ uint16_t fill = s->fill[p] << (s->depth - 8); |
|
244 |
+ int linesize = frame->linesize[p] / 2; |
|
245 |
+ |
|
246 |
+ for (y = s->borders[p].top; y < s->planeheight[p] - s->borders[p].bottom; y++) { |
|
247 |
+ for (x = 0; x < s->borders[p].left; x++) { |
|
248 |
+ ptr[y * linesize + x] = fill; |
|
249 |
+ } |
|
250 |
+ |
|
251 |
+ for (x = 0; x < s->borders[p].right; x++) { |
|
252 |
+ ptr[y * linesize + s->planewidth[p] - s->borders[p].right + x] = fill; |
|
253 |
+ } |
|
254 |
+ } |
|
255 |
+ |
|
256 |
+ for (y = 0; y < s->borders[p].top; y++) { |
|
257 |
+ for (x = 0; x < s->planewidth[p]; x++) { |
|
258 |
+ ptr[y * linesize + x] = fill; |
|
259 |
+ } |
|
260 |
+ } |
|
261 |
+ |
|
262 |
+ for (y = s->planeheight[p] - s->borders[p].bottom; y < s->planeheight[p]; y++) { |
|
263 |
+ for (x = 0; x < s->planewidth[p]; x++) { |
|
264 |
+ ptr[y * linesize + x] = fill; |
|
265 |
+ } |
|
266 |
+ } |
|
267 |
+ } |
|
268 |
+} |
|
269 |
+ |
|
270 |
+static int filter_frame(AVFilterLink *inlink, AVFrame *frame) |
|
271 |
+{ |
|
272 |
+ FillBordersContext *s = inlink->dst->priv; |
|
273 |
+ |
|
274 |
+ s->fillborders(s, frame); |
|
275 |
+ |
|
276 |
+ return ff_filter_frame(inlink->dst->outputs[0], frame); |
|
277 |
+} |
|
278 |
+ |
|
279 |
+static int config_input(AVFilterLink *inlink) |
|
280 |
+{ |
|
281 |
+ AVFilterContext *ctx = inlink->dst; |
|
282 |
+ FillBordersContext *s = ctx->priv; |
|
283 |
+ const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); |
|
284 |
+ |
|
285 |
+ s->nb_planes = desc->nb_components; |
|
286 |
+ s->depth = desc->comp[0].depth; |
|
287 |
+ |
|
288 |
+ s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h); |
|
289 |
+ s->planeheight[0] = s->planeheight[3] = inlink->h; |
|
290 |
+ s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w); |
|
291 |
+ s->planewidth[0] = s->planewidth[3] = inlink->w; |
|
292 |
+ |
|
293 |
+ s->borders[0].left = s->borders[3].left = s->left; |
|
294 |
+ s->borders[0].right = s->borders[3].right = s->right; |
|
295 |
+ s->borders[0].top = s->borders[3].top = s->top; |
|
296 |
+ s->borders[0].bottom = s->borders[3].bottom = s->bottom; |
|
297 |
+ |
|
298 |
+ s->borders[1].left = s->left >> desc->log2_chroma_w; |
|
299 |
+ s->borders[1].right = s->right >> desc->log2_chroma_w; |
|
300 |
+ s->borders[1].top = s->top >> desc->log2_chroma_h; |
|
301 |
+ s->borders[1].bottom = s->bottom >> desc->log2_chroma_h; |
|
302 |
+ |
|
303 |
+ s->borders[2].left = s->left >> desc->log2_chroma_w; |
|
304 |
+ s->borders[2].right = s->right >> desc->log2_chroma_w; |
|
305 |
+ s->borders[2].top = s->top >> desc->log2_chroma_h; |
|
306 |
+ s->borders[2].bottom = s->bottom >> desc->log2_chroma_h; |
|
307 |
+ |
|
308 |
+ if (inlink->w < s->left + s->right || |
|
309 |
+ inlink->w <= s->left || |
|
310 |
+ inlink->w <= s->right || |
|
311 |
+ inlink->h < s->top + s->bottom || |
|
312 |
+ inlink->h <= s->top || |
|
313 |
+ inlink->h <= s->bottom || |
|
314 |
+ inlink->w < s->left * 2 || |
|
315 |
+ inlink->w < s->right * 2 || |
|
316 |
+ inlink->h < s->top * 2 || |
|
317 |
+ inlink->h < s->bottom * 2) { |
|
318 |
+ av_log(ctx, AV_LOG_ERROR, "Borders are bigger than input frame size.\n"); |
|
319 |
+ return AVERROR(EINVAL); |
|
320 |
+ } |
|
321 |
+ |
|
322 |
+ switch (s->mode) { |
|
323 |
+ case FM_SMEAR: s->fillborders = s->depth <= 8 ? smear_borders8 : smear_borders16; break; |
|
324 |
+ case FM_MIRROR: s->fillborders = s->depth <= 8 ? mirror_borders8 : mirror_borders16; break; |
|
325 |
+ case FM_FIXED: s->fillborders = s->depth <= 8 ? fixed_borders8 : fixed_borders16; break; |
|
326 |
+ } |
|
327 |
+ |
|
328 |
+ s->yuv_color[Y] = RGB_TO_Y_CCIR(s->rgba_color[R], s->rgba_color[G], s->rgba_color[B]); |
|
329 |
+ s->yuv_color[U] = RGB_TO_U_CCIR(s->rgba_color[R], s->rgba_color[G], s->rgba_color[B], 0); |
|
330 |
+ s->yuv_color[V] = RGB_TO_V_CCIR(s->rgba_color[R], s->rgba_color[G], s->rgba_color[B], 0); |
|
331 |
+ s->yuv_color[A] = s->rgba_color[A]; |
|
332 |
+ |
|
333 |
+ if (desc->flags & AV_PIX_FMT_FLAG_RGB) { |
|
334 |
+ uint8_t rgba_map[4]; |
|
335 |
+ int i; |
|
336 |
+ |
|
337 |
+ ff_fill_rgba_map(rgba_map, inlink->format); |
|
338 |
+ for (i = 0; i < 4; i++) |
|
339 |
+ s->fill[rgba_map[i]] = s->rgba_color[i]; |
|
340 |
+ } else { |
|
341 |
+ memcpy(s->fill, s->yuv_color, sizeof(s->yuv_color)); |
|
342 |
+ } |
|
343 |
+ |
|
344 |
+ return 0; |
|
345 |
+} |
|
346 |
+ |
|
347 |
+#define OFFSET(x) offsetof(FillBordersContext, x) |
|
348 |
+#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM |
|
349 |
+ |
|
350 |
+static const AVOption fillborders_options[] = { |
|
351 |
+ { "left", "set the left fill border", OFFSET(left), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX, FLAGS }, |
|
352 |
+ { "right", "set the right fill border", OFFSET(right), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX, FLAGS }, |
|
353 |
+ { "top", "set the top fill border", OFFSET(top), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX, FLAGS }, |
|
354 |
+ { "bottom", "set the bottom fill border", OFFSET(bottom), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX, FLAGS }, |
|
355 |
+ { "mode", "set the fill borders mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=FM_SMEAR}, 0, FM_NB_MODES-1, FLAGS, "mode" }, |
|
356 |
+ { "smear", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_SMEAR}, 0, 0, FLAGS, "mode" }, |
|
357 |
+ { "mirror", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_MIRROR}, 0, 0, FLAGS, "mode" }, |
|
358 |
+ { "fixed", NULL, 0, AV_OPT_TYPE_CONST, {.i64=FM_FIXED}, 0, 0, FLAGS, "mode" }, |
|
359 |
+ { "color", "set the color for the fixed mode", OFFSET(rgba_color), AV_OPT_TYPE_COLOR, {.str = "black"}, .flags = FLAGS }, |
|
360 |
+ { NULL } |
|
361 |
+}; |
|
362 |
+ |
|
363 |
+AVFILTER_DEFINE_CLASS(fillborders); |
|
364 |
+ |
|
365 |
+static const AVFilterPad fillborders_inputs[] = { |
|
366 |
+ { |
|
367 |
+ .name = "default", |
|
368 |
+ .type = AVMEDIA_TYPE_VIDEO, |
|
369 |
+ .config_props = config_input, |
|
370 |
+ .filter_frame = filter_frame, |
|
371 |
+ .needs_writable = 1, |
|
372 |
+ }, |
|
373 |
+ { NULL } |
|
374 |
+}; |
|
375 |
+ |
|
376 |
+static const AVFilterPad fillborders_outputs[] = { |
|
377 |
+ { |
|
378 |
+ .name = "default", |
|
379 |
+ .type = AVMEDIA_TYPE_VIDEO, |
|
380 |
+ }, |
|
381 |
+ { NULL } |
|
382 |
+}; |
|
383 |
+ |
|
384 |
+AVFilter ff_vf_fillborders = { |
|
385 |
+ .name = "fillborders", |
|
386 |
+ .description = NULL_IF_CONFIG_SMALL("Fill borders of the input video."), |
|
387 |
+ .priv_size = sizeof(FillBordersContext), |
|
388 |
+ .priv_class = &fillborders_class, |
|
389 |
+ .query_formats = query_formats, |
|
390 |
+ .inputs = fillborders_inputs, |
|
391 |
+ .outputs = fillborders_outputs, |
|
392 |
+ .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, |
|
393 |
+}; |