FFmpeg
Loading...
Searching...
No Matches
vf_cropdetect.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2002 A'rpi
3 * This file is part of FFmpeg.
4 *
5 * FFmpeg is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (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
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20/**
21 * @file
22 * border detection filter
23 * Ported from MPlayer libmpcodecs/vf_cropdetect.c.
24 */
25
26#include "libavutil/imgutils.h"
27#include "libavutil/internal.h"
28#include "libavutil/mem.h"
29#include "libavutil/opt.h"
31#include "libavutil/qsort.h"
32
33#include "avfilter.h"
34#include "filters.h"
35#include "video.h"
36#include "edge_common.h"
37
38typedef struct CropDetectContext {
39 const AVClass *class;
40 int x1, y1, x2, y2;
41 float limit;
43 int round;
44 int skip;
49 int mode;
53 float low, high;
54 uint8_t low_u8, high_u8;
55 uint8_t *filterbuf;
56 uint8_t *tmpbuf;
57 uint16_t *gradients;
59 int *bboxes[4];
61
78
84
85static int comp(const int *a,const int *b)
86{
87 return FFDIFFSIGN(*a, *b);
88}
89
90static int checkline(void *ctx, const unsigned char *src, int stride, int len, int bpp)
91{
92 int total = 0;
93 int div = len;
94 const uint16_t *src16 = (const uint16_t *)src;
95
96 switch (bpp) {
97 case 1:
98 while (len >= 8) {
99 total += src[ 0] + src[ stride] + src[2*stride] + src[3*stride]
100 + src[4*stride] + src[5*stride] + src[6*stride] + src[7*stride];
101 src += 8*stride;
102 len -= 8;
103 }
104 while (--len >= 0) {
105 total += src[0];
106 src += stride;
107 }
108 break;
109 case 2:
110 stride >>= 1;
111 while (len >= 8) {
112 total += src16[ 0] + src16[ stride] + src16[2*stride] + src16[3*stride]
113 + src16[4*stride] + src16[5*stride] + src16[6*stride] + src16[7*stride];
114 src16 += 8*stride;
115 len -= 8;
116 }
117 while (--len >= 0) {
118 total += src16[0];
119 src16 += stride;
120 }
121 break;
122 case 3:
123 case 4:
124 while (len >= 4) {
125 total += src[0] + src[1 ] + src[2 ]
126 + src[ stride] + src[1+ stride] + src[2+ stride]
127 + src[2*stride] + src[1+2*stride] + src[2+2*stride]
128 + src[3*stride] + src[1+3*stride] + src[2+3*stride];
129 src += 4*stride;
130 len -= 4;
131 }
132 while (--len >= 0) {
133 total += src[0] + src[1] + src[2];
134 src += stride;
135 }
136 div *= 3;
137 break;
138 }
139 total /= div;
140
141 av_log(ctx, AV_LOG_DEBUG, "total:%d\n", total);
142 return total;
143}
144
145static int checkline_edge(void *ctx, const unsigned char *src, int stride, int len)
146{
147 while (--len >= 0) {
148 if (src[0]) return 0;
149 src += stride;
150 }
151
152 return 1;
153}
154
156{
157 CropDetectContext *s = ctx->priv;
158
159 s->frame_nb = -1 * s->skip;
160 s->low_u8 = s->low * 255. + .5;
161 s->high_u8 = s->high * 255. + .5;
162
163 av_log(ctx, AV_LOG_VERBOSE, "limit:%f round:%d skip:%d reset_count:%d\n",
164 s->limit, s->round, s->skip, s->reset_count);
165
166 return 0;
167}
168
170{
171 CropDetectContext *s = ctx->priv;
172
173 av_freep(&s->tmpbuf);
174 av_freep(&s->filterbuf);
175 av_freep(&s->gradients);
176 av_freep(&s->directions);
177 av_freep(&s->bboxes[0]);
178 av_freep(&s->bboxes[1]);
179 av_freep(&s->bboxes[2]);
180 av_freep(&s->bboxes[3]);
181}
182
183static int config_input(AVFilterLink *inlink)
184{
185 AVFilterContext *ctx = inlink->dst;
186 CropDetectContext *s = ctx->priv;
188 const int bufsize = inlink->w * inlink->h;
189
190 av_image_fill_max_pixsteps(s->max_pixsteps, NULL, desc);
191
192 s->bitdepth = desc->comp[0].depth;
193
194 if (s->limit < 1.0)
195 s->limit_upscaled = s->limit * ((1 << s->bitdepth) - 1);
196 else
197 s->limit_upscaled = s->limit;
198
199 s->x1 = inlink->w - 1;
200 s->y1 = inlink->h - 1;
201 s->x2 = 0;
202 s->y2 = 0;
203
204 s->window_size = FFMAX(s->reset_count, 15);
205 s->tmpbuf = av_malloc(bufsize);
206 s->filterbuf = av_malloc(bufsize * s->max_pixsteps[0]);
207 s->gradients = av_calloc(bufsize, sizeof(*s->gradients));
208 s->directions = av_malloc(bufsize);
209 s->bboxes[0] = av_malloc(s->window_size * sizeof(*s->bboxes[0]));
210 s->bboxes[1] = av_malloc(s->window_size * sizeof(*s->bboxes[1]));
211 s->bboxes[2] = av_malloc(s->window_size * sizeof(*s->bboxes[2]));
212 s->bboxes[3] = av_malloc(s->window_size * sizeof(*s->bboxes[3]));
213
214 if (!s->tmpbuf || !s->filterbuf || !s->gradients || !s->directions ||
215 !s->bboxes[0] || !s->bboxes[1] || !s->bboxes[2] || !s->bboxes[3])
216 return AVERROR(ENOMEM);
217
218 return 0;
219}
220
221#define SET_META(key, value) \
222 av_dict_set_int(metadata, key, value, 0)
223
225{
226 AVFilterContext *ctx = inlink->dst;
227 CropDetectContext *s = ctx->priv;
228 int bpp = s->max_pixsteps[0];
229 int w, h, x, y, shrink_by, i;
231 int outliers, last_y;
232 int limit_upscaled = lrint(s->limit_upscaled);
233 char limit_str[22];
234
235 const int inw = inlink->w;
236 const int inh = inlink->h;
237 uint8_t *tmpbuf = s->tmpbuf;
238 uint8_t *filterbuf = s->filterbuf;
239 uint16_t *gradients = s->gradients;
240 int8_t *directions = s->directions;
241 const AVFrameSideData *sd = NULL;
242 int scan_w, scan_h, bboff;
243
244 void (*sobel)(int w, int h, uint16_t *dst, int dst_linesize,
245 int8_t *dir, int dir_linesize,
246 const uint8_t *src, int src_linesize, int src_stride) = (bpp == 2) ? &ff_sobel_16 : &ff_sobel_8;
247 void (*gaussian_blur)(int w, int h,
248 uint8_t *dst, int dst_linesize,
249 const uint8_t *src, int src_linesize, int src_stride) = (bpp == 2) ? &ff_gaussian_blur_16 : &ff_gaussian_blur_8;
250
251
252 // ignore first s->skip frames
253 if (++s->frame_nb > 0) {
254 metadata = &frame->metadata;
255
256 // Reset the crop area every reset_count frames, if reset_count is > 0
257 if (s->reset_count > 0 && s->frame_nb > s->reset_count) {
258 s->x1 = frame->width - 1;
259 s->y1 = frame->height - 1;
260 s->x2 = 0;
261 s->y2 = 0;
262 s->frame_nb = 1;
263 }
264
265#define FIND(DST, FROM, NOEND, INC, STEP0, STEP1, LEN) \
266 outliers = 0;\
267 for (last_y = y = FROM; NOEND; y = y INC) {\
268 if (checkline(ctx, frame->data[0] + STEP0 * y, STEP1, LEN, bpp) > limit_upscaled) {\
269 if (++outliers > s->max_outliers) { \
270 DST = last_y;\
271 break;\
272 }\
273 } else\
274 last_y = y INC;\
275 }
276
277 if (s->mode == MODE_BLACK) {
278 FIND(s->y1, 0, y < s->y1, +1, frame->linesize[0], bpp, frame->width);
279 FIND(s->y2, frame->height - 1, y > FFMAX(s->y2, s->y1), -1, frame->linesize[0], bpp, frame->width);
280 FIND(s->x1, 0, y < s->x1, +1, bpp, frame->linesize[0], frame->height);
281 FIND(s->x2, frame->width - 1, y > FFMAX(s->x2, s->x1), -1, bpp, frame->linesize[0], frame->height);
282 } else { // MODE_MV_EDGES
284 s->x1 = 0;
285 s->y1 = 0;
286 s->x2 = inw - 1;
287 s->y2 = inh - 1;
288
289 if (!sd) {
290 av_log(ctx, AV_LOG_WARNING, "Cannot detect: no motion vectors available");
291 } else {
292 // gaussian filter to reduce noise
293 gaussian_blur(inw, inh,
294 filterbuf, inw*bpp,
295 frame->data[0], frame->linesize[0], bpp);
296
297 // compute the 16-bits gradients and directions for the next step
298 sobel(inw, inh, gradients, inw, directions, inw, filterbuf, inw*bpp, bpp);
299
300 // non_maximum_suppression() will actually keep & clip what's necessary and
301 // ignore the rest, so we need a clean output buffer
302 memset(tmpbuf, 0, inw * inh);
303 ff_non_maximum_suppression(inw, inh, tmpbuf, inw, directions, inw, gradients, inw);
304
305
306 // keep high values, or low values surrounded by high values
307 ff_double_threshold(s->low_u8, s->high_u8, inw, inh,
308 tmpbuf, inw, tmpbuf, inw);
309
310 // scan all MVs and store bounding box
311 s->x1 = inw - 1;
312 s->y1 = inh - 1;
313 s->x2 = 0;
314 s->y2 = 0;
315 for (i = 0; i < sd->size / sizeof(AVMotionVector); i++) {
316 const AVMotionVector *mv = (const AVMotionVector*)sd->data + i;
317 const int mx = mv->dst_x - mv->src_x;
318 const int my = mv->dst_y - mv->src_y;
319
320 if (mv->dst_x >= 0 && mv->dst_x < inw &&
321 mv->dst_y >= 0 && mv->dst_y < inh &&
322 mv->src_x >= 0 && mv->src_x < inw &&
323 mv->src_y >= 0 && mv->src_y < inh &&
324 mx * mx + my * my >= s->mv_threshold * s->mv_threshold) {
325 s->x1 = mv->dst_x < s->x1 ? mv->dst_x : s->x1;
326 s->y1 = mv->dst_y < s->y1 ? mv->dst_y : s->y1;
327 s->x2 = mv->dst_x > s->x2 ? mv->dst_x : s->x2;
328 s->y2 = mv->dst_y > s->y2 ? mv->dst_y : s->y2;
329 }
330 }
331
332 // assert x1<x2, y1<y2
333 if (s->x1 > s->x2) FFSWAP(int, s->x1, s->x2);
334 if (s->y1 > s->y2) FFSWAP(int, s->y1, s->y2);
335
336 // scan outward looking for 0-edge-lines in edge image
337 scan_w = s->x2 - s->x1;
338 scan_h = s->y2 - s->y1;
339
340#define FIND_EDGE(DST, FROM, NOEND, INC, STEP0, STEP1, LEN) \
341 for (last_y = y = FROM; NOEND; y = y INC) { \
342 if (checkline_edge(ctx, tmpbuf + STEP0 * y, STEP1, LEN)) { \
343 if (last_y INC == y) { \
344 DST = y; \
345 break; \
346 } else \
347 last_y = y; \
348 } \
349 } \
350 if (!(NOEND)) { \
351 DST = y -(INC); \
352 }
353
354 FIND_EDGE(s->y1, s->y1, y >= 0, -1, inw, 1, scan_w);
355 FIND_EDGE(s->y2, s->y2, y < inh, +1, inw, 1, scan_w);
356 FIND_EDGE(s->x1, s->x1, y >= 0, -1, 1, inw, scan_h);
357 FIND_EDGE(s->x2, s->x2, y < inw, +1, 1, inw, scan_h);
358
359 // queue bboxes
360 bboff = (s->frame_nb - 1) % s->window_size;
361 s->bboxes[0][bboff] = s->x1;
362 s->bboxes[1][bboff] = s->x2;
363 s->bboxes[2][bboff] = s->y1;
364 s->bboxes[3][bboff] = s->y2;
365
366 // sort queue
367 bboff = FFMIN(s->frame_nb, s->window_size);
368 AV_QSORT(s->bboxes[0], bboff, int, comp);
369 AV_QSORT(s->bboxes[1], bboff, int, comp);
370 AV_QSORT(s->bboxes[2], bboff, int, comp);
371 AV_QSORT(s->bboxes[3], bboff, int, comp);
372
373 // return median of window_size elems
374 s->x1 = s->bboxes[0][bboff/2];
375 s->x2 = s->bboxes[1][bboff/2];
376 s->y1 = s->bboxes[2][bboff/2];
377 s->y2 = s->bboxes[3][bboff/2];
378 }
379 }
380
381 // round x and y (up), important for yuv colorspaces
382 // make sure they stay rounded!
383 x = (s->x1+1) & ~1;
384 y = (s->y1+1) & ~1;
385
386 w = s->x2 - x + 1;
387 h = s->y2 - y + 1;
388
389 // w and h must be divisible by 2 as well because of yuv
390 // colorspace problems.
391 if (s->round <= 1)
392 s->round = 16;
393 if (s->round % 2)
394 s->round *= 2;
395
396 shrink_by = w % s->round;
397 w -= shrink_by;
398 x += (shrink_by/2 + 1) & ~1;
399
400 shrink_by = h % s->round;
401 h -= shrink_by;
402 y += (shrink_by/2 + 1) & ~1;
403
404 SET_META("lavfi.cropdetect.x1", s->x1);
405 SET_META("lavfi.cropdetect.x2", s->x2);
406 SET_META("lavfi.cropdetect.y1", s->y1);
407 SET_META("lavfi.cropdetect.y2", s->y2);
408 SET_META("lavfi.cropdetect.w", w);
409 SET_META("lavfi.cropdetect.h", h);
410 SET_META("lavfi.cropdetect.x", x);
411 SET_META("lavfi.cropdetect.y", y);
412
413 snprintf(limit_str, sizeof(limit_str), "%f", s->limit);
414 av_dict_set(metadata, "lavfi.cropdetect.limit", limit_str, 0);
415
417 "x1:%d x2:%d y1:%d y2:%d w:%d h:%d x:%d y:%d pts:%"PRId64" t:%f limit:%f crop=%d:%d:%d:%d\n",
418 s->x1, s->x2, s->y1, s->y2, w, h, x, y, frame->pts,
419 frame->pts == AV_NOPTS_VALUE ? -1 : frame->pts * av_q2d(inlink->time_base),
420 s->limit, w, h, x, y);
421 }
422
423 return ff_filter_frame(inlink->dst->outputs[0], frame);
424}
425
426static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
427 char *res, int res_len, int flags)
428{
429 CropDetectContext *s = ctx->priv;
430 float old_limit = s->limit;
431 int ret;
432
433 if ((ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags)) < 0)
434 return ret;
435
436 if (old_limit != s->limit) {
437 if (s->limit < 1.0)
438 s->limit_upscaled = s->limit * ((1 << s->bitdepth) - 1);
439 else
440 s->limit_upscaled = s->limit;
441 s->frame_nb = s->reset_count;
442 }
443
444 return 0;
445}
446
447#define OFFSET(x) offsetof(CropDetectContext, x)
448#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
449#define TFLAGS AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_RUNTIME_PARAM
450
451static const AVOption cropdetect_options[] = {
452 { "limit", "Threshold below which the pixel is considered black", OFFSET(limit), AV_OPT_TYPE_FLOAT, { .dbl = 24.0/255 }, 0, 65535, TFLAGS },
453 { "round", "Value by which the width/height should be divisible", OFFSET(round), AV_OPT_TYPE_INT, { .i64 = 16 }, 0, INT_MAX, FLAGS },
454 { "reset", "Recalculate the crop area after this many frames", OFFSET(reset_count), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS },
455 { "skip", "Number of initial frames to skip", OFFSET(skip), AV_OPT_TYPE_INT, { .i64 = 2 }, 0, INT_MAX, FLAGS },
456 { "reset_count", "Recalculate the crop area after this many frames",OFFSET(reset_count),AV_OPT_TYPE_INT,{ .i64 = 0 }, 0, INT_MAX, FLAGS },
457 { "max_outliers", "Threshold count of outliers", OFFSET(max_outliers),AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS },
458 { "mode", "set mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=MODE_BLACK}, 0, MODE_NB-1, FLAGS, .unit = "mode" },
459 { "black", "detect black pixels surrounding the video", 0, AV_OPT_TYPE_CONST, {.i64=MODE_BLACK}, INT_MIN, INT_MAX, FLAGS, .unit = "mode" },
460 { "mvedges", "detect motion and edged surrounding the video", 0, AV_OPT_TYPE_CONST, {.i64=MODE_MV_EDGES}, INT_MIN, INT_MAX, FLAGS, .unit = "mode" },
461 { "high", "Set high threshold for edge detection", OFFSET(high), AV_OPT_TYPE_FLOAT, {.dbl=25/255.}, 0, 1, FLAGS },
462 { "low", "Set low threshold for edge detection", OFFSET(low), AV_OPT_TYPE_FLOAT, {.dbl=15/255.}, 0, 1, FLAGS },
463 { "mv_threshold", "motion vector threshold when estimating video window size", OFFSET(mv_threshold), AV_OPT_TYPE_INT, {.i64=8}, 0, 100, FLAGS},
464 { NULL }
465};
466
468
470 {
471 .name = "default",
472 .type = AVMEDIA_TYPE_VIDEO,
473 .config_props = config_input,
474 .filter_frame = filter_frame,
475 },
476};
477
479 .p.name = "cropdetect",
480 .p.description = NULL_IF_CONFIG_SMALL("Auto-detect crop size."),
481 .p.priv_class = &cropdetect_class,
483 .priv_size = sizeof(CropDetectContext),
484 .init = init,
485 .uninit = uninit,
489 .process_command = process_command,
490};
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t my
Definition dsp.h:57
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t mx
Definition dsp.h:57
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
static int config_input(AVFilterLink *inlink)
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
#define TFLAGS
Definition af_afade.c:66
const FFFilter ff_vf_cropdetect
static AVFormatContext * ctx
@ MODE_NB
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition avfilter.c:1073
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
Definition avfilter.c:911
Main libavfilter public API header.
static void BS_FUNC skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
static int FUNC metadata(CodedBitstreamContext *ctx, RWContext *rw, APVRawMetadata *current)
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
#define FLAGS
Definition cmdutils.c:596
#define NULL
Definition coverity.c:32
static AVFrame * frame
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
Definition dolby_e.c:1067
int high
Definition dovi_rpuenc.c:39
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
Definition eamad.c:79
void ff_non_maximum_suppression(int w, int h, uint8_t *dst, int dst_linesize, const int8_t *dir, int dir_linesize, const uint16_t *src, int src_linesize)
Filters rounded gradients to drop all non-maxima pixels in the magnitude image Expects gradients gene...
Definition edge_common.c:60
void ff_double_threshold(int low, int high, int w, int h, uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize)
Filters all pixels in src to keep all pixels > high, and keep all pixels > low where all surrounding ...
Definition edge_common.c:89
common functions for edge detection
void fn sobel(int w, int h, uint16_t *dst, int dst_linesize, int8_t *dir, int dir_linesize, const uint8_t *src, int src_linesize, int src_stride)
void fn gaussian_blur(int w, int h, uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int src_stride)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition opt.h:298
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
Definition opt.h:270
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
Definition avfilter.h:202
#define AVFILTER_FLAG_METADATA_ONLY
The filter is a "metadata" filter - it does not modify the frame data in any way.
Definition avfilter.h:188
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition dict.c:86
#define AVERROR(e)
Definition error.h:45
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition frame.c:659
@ AV_FRAME_DATA_MOTION_VECTORS
Motion vectors exported by some codecs (on demand through the export_mvs flag set in the libavcodec A...
Definition frame.h:97
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_VERBOSE
Detailed information.
Definition log.h:226
#define AV_LOG_INFO
Standard information.
Definition log.h:221
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition rational.h:104
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
void av_image_fill_max_pixsteps(int max_pixsteps[4], int max_pixstep_comps[4], const AVPixFmtDescriptor *pixdesc)
Compute the max pixel step for each plane of an image with a format described by pixdesc.
Definition imgutils.c:35
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition avutil.h:247
int a
misc image utilities
#define b
Definition input.c:43
static av_cold void uninit(AVBitStreamFilterContext *ctx)
static const int8_t mv[256][2]
Definition 4xm.c:81
#define FILTER_INPUTS(array)
Definition filters.h:264
#define FILTER_OUTPUTS(array)
Definition filters.h:265
#define FILTER_PIXFMTS_ARRAY(array)
Definition filters.h:244
#define AVFILTER_DEFINE_CLASS(fname)
Definition filters.h:478
#define av_cold
Definition attributes.h:117
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:97
static enum AVPixelFormat pix_fmts[]
Definition libkvazaar.c:296
const char * desc
Definition libsvtav1.c:83
uint8_t w
Definition llvidencdsp.c:39
#define FFSWAP(type, a, b)
Definition macros.h:52
#define FFMIN(a, b)
Definition macros.h:49
#define FFMAX(a, b)
Definition macros.h:47
#define FFDIFFSIGN(x, y)
Comparator.
Definition macros.h:45
void * av_calloc(size_t nmemb, size_t size)
Definition mem.c:370
Memory handling functions.
#define av_malloc(s)
Definition ops_static.c:52
AVOptions.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3460
#define AV_PIX_FMT_YUV420P16
Definition pixfmt.h:556
#define AV_PIX_FMT_YUV444P12
Definition pixfmt.h:552
#define AV_PIX_FMT_YUV444P9
Definition pixfmt.h:544
#define AV_PIX_FMT_YUV420P10
Definition pixfmt.h:545
#define AV_PIX_FMT_YUV422P9
Definition pixfmt.h:543
#define AV_PIX_FMT_YUV420P12
Definition pixfmt.h:549
#define AV_PIX_FMT_YUV422P12
Definition pixfmt.h:550
#define AV_PIX_FMT_YUV422P10
Definition pixfmt.h:546
#define AV_PIX_FMT_YUV420P9
Definition pixfmt.h:542
#define AV_PIX_FMT_YUV420P14
Definition pixfmt.h:553
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition pixfmt.h:96
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition pixfmt.h:75
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition pixfmt.h:73
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition pixfmt.h:106
@ AV_PIX_FMT_NV21
as above, but U and V bytes are swapped
Definition pixfmt.h:97
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition pixfmt.h:77
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition pixfmt.h:102
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition pixfmt.h:81
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition pixfmt.h:79
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition pixfmt.h:80
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition pixfmt.h:100
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition pixfmt.h:78
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition pixfmt.h:86
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition pixfmt.h:76
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition pixfmt.h:87
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition pixfmt.h:85
#define AV_PIX_FMT_YUV422P14
Definition pixfmt.h:554
#define AV_PIX_FMT_YUV422P16
Definition pixfmt.h:557
#define AV_PIX_FMT_YUV444P14
Definition pixfmt.h:555
#define AV_PIX_FMT_YUV444P16
Definition pixfmt.h:558
#define AV_PIX_FMT_YUV444P10
Definition pixfmt.h:548
#define AV_QSORT(p, num, type, cmp)
Quicksort This sort is fast, and fully inplace but not stable and it is possible to construct input t...
Definition qsort.h:33
Describe the class of an AVClass context structure.
Definition log.h:76
An instance of a filter.
Definition avfilter.h:279
AVFilterLink ** outputs
array of pointers to output links
Definition avfilter.h:291
A filter pad used for either input or output.
Definition filters.h:40
Structure to hold side data for an AVFrame.
Definition frame.h:334
size_t size
Definition frame.h:337
uint8_t * data
Definition frame.h:336
This structure describes decoded (raw) audio or video data.
Definition frame.h:479
AVOption.
Definition opt.h:428
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
uint16_t * gradients
Definition swscale.c:71
#define stride
#define lrint
Definition tablegen.h:53
#define av_freep(p)
#define av_log(a,...)
#define src
Definition vp8dsp.c:248
static int checkline(void *ctx, const unsigned char *src, int stride, int len, int bpp)
#define FIND(DST, FROM, NOEND, INC, STEP0, STEP1, LEN)
static const AVOption cropdetect_options[]
#define FIND_EDGE(DST, FROM, NOEND, INC, STEP0, STEP1, LEN)
static int config_input(AVFilterLink *inlink)
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
CropMode
@ MODE_BLACK
@ MODE_MV_EDGES
static int comp(const int *a, const int *b)
static const AVFilterPad avfilter_vf_cropdetect_inputs[]
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
static av_cold void uninit(AVFilterContext *ctx)
#define SET_META(key, value)
static int checkline_edge(void *ctx, const unsigned char *src, int stride, int len)
#define OFFSET(x)
static double limit(double x)
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
Definition video.c:37
int len