Go to the documentation of this file.
   84 static int comp(
const int *
a,
const int *
b)
 
   93     const uint16_t *src16 = (
const uint16_t *)
src;
 
  146     const uint16_t *src16 = (
const uint16_t *)
src;
 
  151             if (
src[0]) 
return 0;
 
  158             if (src16[0]) 
return 0;
 
  165             if (
src[0] || 
src[1] || 
src[2]) 
return 0;
 
  178     s->frame_nb = -1 * 
s->skip;
 
  179     s->low_u8   = 
s->low  * 255. + .5;
 
  180     s->high_u8  = 
s->high * 255. + .5;
 
  183            s->limit, 
s->round, 
s->skip, 
s->reset_count);
 
  211     s->bitdepth = 
desc->comp[0].depth;
 
  214         s->limit_upscaled = 
s->limit * ((1 << 
s->bitdepth) - 1);
 
  216         s->limit_upscaled = 
s->limit;
 
  223     s->window_size = 
FFMAX(
s->reset_count, 15);
 
  225     s->filterbuf   = 
av_malloc(bufsize * 
s->max_pixsteps[0]);
 
  226     s->gradients   = 
av_calloc(bufsize, 
sizeof(*
s->gradients));
 
  228     s->bboxes[0]   = 
av_malloc(
s->window_size * 
sizeof(*
s->bboxes[0]));
 
  229     s->bboxes[1]   = 
av_malloc(
s->window_size * 
sizeof(*
s->bboxes[1]));
 
  230     s->bboxes[2]   = 
av_malloc(
s->window_size * 
sizeof(*
s->bboxes[2]));
 
  231     s->bboxes[3]   = 
av_malloc(
s->window_size * 
sizeof(*
s->bboxes[3]));
 
  233     if (!
s->tmpbuf    || !
s->filterbuf || !
s->gradients || !
s->directions ||
 
  234         !
s->bboxes[0] || !
s->bboxes[1] || !
s->bboxes[2] || !
s->bboxes[3])
 
  240 #define SET_META(key, value) \ 
  241     av_dict_set_int(metadata, key, value, 0) 
  247     int bpp = 
s->max_pixsteps[0];
 
  248     int w, 
h, x, y, shrink_by, 
i;
 
  250     int outliers, last_y;
 
  251     int limit_upscaled = 
lrint(
s->limit_upscaled);
 
  254     const int inw = 
inlink->w;
 
  255     const int inh = 
inlink->h;
 
  256     uint8_t *tmpbuf     = 
s->tmpbuf;
 
  257     uint8_t *filterbuf  = 
s->filterbuf;
 
  258     uint16_t *gradients = 
s->gradients;
 
  259     int8_t *directions  = 
s->directions;
 
  261     int scan_w, scan_h, bboff;
 
  263     void (*
sobel)(
int w, 
int h, uint16_t *dst, 
int dst_linesize,
 
  264                   int8_t *dir, 
int dir_linesize,
 
  265                   const uint8_t *
src, 
int src_linesize, 
int src_stride) = (bpp == 2) ? &ff_sobel_16 : &ff_sobel_8;
 
  267                           uint8_t *dst, 
int dst_linesize,
 
  268                           const uint8_t *
src, 
int src_linesize, 
int src_stride) = (bpp == 2) ? &ff_gaussian_blur_16 : &ff_gaussian_blur_8;
 
  272     if (++
s->frame_nb > 0) {
 
  276         if (
s->reset_count > 0 && 
s->frame_nb > 
s->reset_count) {
 
  284 #define FIND(DST, FROM, NOEND, INC, STEP0, STEP1, LEN) \ 
  286         for (last_y = y = FROM; NOEND; y = y INC) {\ 
  287             if (checkline(ctx, frame->data[0] + STEP0 * y, STEP1, LEN, bpp) > limit_upscaled) {\ 
  288                 if (++outliers > s->max_outliers) { \ 
  317                 sobel(inw, inh, gradients, inw, directions, inw, filterbuf, inw*bpp, bpp);
 
  321                 memset(tmpbuf, 0, inw * inh);
 
  327                                     tmpbuf, inw, tmpbuf, inw);
 
  336                     const int mx = 
mv->dst_x - 
mv->src_x;
 
  337                     const int my = 
mv->dst_y - 
mv->src_y;
 
  339                     if (
mv->dst_x >= 0 && 
mv->dst_x < inw &&
 
  340                         mv->dst_y >= 0 && 
mv->dst_y < inh &&
 
  341                         mv->src_x >= 0 && 
mv->src_x < inw &&
 
  342                         mv->src_y >= 0 && 
mv->src_y < inh &&
 
  343                         mx * mx + my * my >= 
s->mv_threshold * 
s->mv_threshold) {
 
  344                         s->x1 = 
mv->dst_x < 
s->x1 ? 
mv->dst_x : 
s->x1;
 
  345                         s->y1 = 
mv->dst_y < 
s->y1 ? 
mv->dst_y : 
s->y1;
 
  346                         s->x2 = 
mv->dst_x > 
s->x2 ? 
mv->dst_x : 
s->x2;
 
  347                         s->y2 = 
mv->dst_y > 
s->y2 ? 
mv->dst_y : 
s->y2;
 
  356                 scan_w = 
s->x2 - 
s->x1;
 
  357                 scan_h = 
s->y2 - 
s->y1;
 
  359 #define FIND_EDGE(DST, FROM, NOEND, INC, STEP0, STEP1, LEN)             \ 
  360     for (last_y = y = FROM; NOEND; y = y INC) {                         \ 
  361         if (checkline_edge(ctx, tmpbuf + STEP0 * y, STEP1, LEN, bpp)) { \ 
  362             if (last_y INC == y) {                                      \ 
  373                 FIND_EDGE(
s->y1, 
s->y1, y >=  0, -1, inw, bpp, scan_w);
 
  374                 FIND_EDGE(
s->y2, 
s->y2, y < inh, +1, inw, bpp, scan_w);
 
  375                 FIND_EDGE(
s->x1, 
s->x1, y >=  0, -1, bpp, inw, scan_h);
 
  376                 FIND_EDGE(
s->x2, 
s->x2, y < inw, +1, bpp, inw, scan_h);
 
  379                 bboff = (
s->frame_nb - 1) % 
s->window_size;
 
  380                 s->bboxes[0][bboff] = 
s->x1;
 
  381                 s->bboxes[1][bboff] = 
s->x2;
 
  382                 s->bboxes[2][bboff] = 
s->y1;
 
  383                 s->bboxes[3][bboff] = 
s->y2;
 
  386                 bboff = 
FFMIN(
s->frame_nb, 
s->window_size);
 
  393                 s->x1 = 
s->bboxes[0][bboff/2];
 
  394                 s->x2 = 
s->bboxes[1][bboff/2];
 
  395                 s->y1 = 
s->bboxes[2][bboff/2];
 
  396                 s->y2 = 
s->bboxes[3][bboff/2];
 
  415         shrink_by = 
w % 
s->round;
 
  417         x += (shrink_by/2 + 1) & ~1;
 
  419         shrink_by = 
h % 
s->round;
 
  421         y += (shrink_by/2 + 1) & ~1;
 
  432         snprintf(limit_str, 
sizeof(limit_str), 
"%f", 
s->limit);
 
  433         av_dict_set(metadata, 
"lavfi.cropdetect.limit", limit_str, 0);
 
  436                "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",
 
  439                s->limit, 
w, 
h, x, y);
 
  446                            char *res, 
int res_len, 
int flags)
 
  449     float old_limit = 
s->limit;
 
  455     if (old_limit != 
s->limit) {
 
  457             s->limit_upscaled = 
s->limit * ((1 << 
s->bitdepth) - 1);
 
  459             s->limit_upscaled = 
s->limit;
 
  460         s->frame_nb = 
s->reset_count;
 
  466 #define OFFSET(x) offsetof(CropDetectContext, x) 
  467 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM 
  468 #define TFLAGS AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_RUNTIME_PARAM 
  473     { 
"reset", 
"Recalculate the crop area after this many frames",    
OFFSET(reset_count), 
AV_OPT_TYPE_INT, { .i64 = 0 },  0, INT_MAX, 
FLAGS },
 
  475     { 
"reset_count", 
"Recalculate the crop area after this many frames",
OFFSET(reset_count),
AV_OPT_TYPE_INT,{ .i64 = 0 },  0, INT_MAX, 
FLAGS },
 
  482     { 
"mv_threshold", 
"motion vector threshold when estimating video window size", 
OFFSET(mv_threshold), 
AV_OPT_TYPE_INT, {.i64=8}, 0, 100, 
FLAGS},
 
  498     .
name          = 
"cropdetect",
 
  501     .priv_class    = &cropdetect_class,
 
  
#define AV_LOG_WARNING
Something somehow does not look correct.
 
AVPixelFormat
Pixel format.
 
static av_cold int init(AVFilterContext *ctx)
 
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
 
void fn() gaussian_blur(int w, int h, uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int src_stride)
 
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
 
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
 
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
 
#define FILTER_PIXFMTS_ARRAY(array)
 
static const int8_t mv[256][2]
 
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
 
#define SET_META(key, value)
 
This structure describes decoded (raw) audio or video data.
 
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
 
#define AV_PIX_FMT_YUV420P10
 
#define AV_LOG_VERBOSE
Detailed information.
 
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
 
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
 
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
 
static int comp(const int *a, const int *b)
 
const char * name
Filter name.
 
A link between two filters.
 
static int checkline(void *ctx, const unsigned char *src, int stride, int len, int bpp)
 
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
 
#define AV_PIX_FMT_YUV422P9
 
A filter pad used for either input or output.
 
#define FFDIFFSIGN(x, y)
Comparator.
 
#define AV_PIX_FMT_YUV444P10
 
#define AV_PIX_FMT_YUV422P16
 
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
 
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
 
#define AV_PIX_FMT_YUV444P16
 
static double av_q2d(AVRational a)
Convert an AVRational to a double.
 
#define AV_PIX_FMT_YUV420P9
 
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
 
#define AV_PIX_FMT_YUV420P16
 
AVFILTER_DEFINE_CLASS(cropdetect)
 
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
 
#define FILTER_INPUTS(array)
 
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
 
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
 
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
 
Describe the class of an AVClass context structure.
 
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
 
static const AVOption cropdetect_options[]
 
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...
 
#define AV_PIX_FMT_YUV422P10
 
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
 
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
 
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
 
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 ...
 
static enum AVPixelFormat pix_fmts[]
 
#define FIND(DST, FROM, NOEND, INC, STEP0, STEP1, LEN)
 
#define AV_PIX_FMT_YUV422P12
 
#define AV_NOPTS_VALUE
Undefined timestamp value.
 
#define AV_PIX_FMT_YUV444P12
 
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.
 
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
 
static int config_input(AVFilterLink *inlink)
 
#define AV_LOG_INFO
Standard information.
 
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
 
#define FIND_EDGE(DST, FROM, NOEND, INC, STEP0, STEP1, LEN)
 
#define i(width, name, range_min, range_max)
 
#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...
 
static av_always_inline av_const double round(double x)
 
@ AV_PIX_FMT_NV21
as above, but U and V bytes are swapped
 
const char * name
Pad name.
 
void * av_calloc(size_t nmemb, size_t size)
 
#define AV_PIX_FMT_YUV444P9
 
static double limit(double x)
 
@ 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...
 
#define FFSWAP(type, a, b)
 
#define AV_PIX_FMT_YUV420P12
 
#define AV_PIX_FMT_YUV422P14
 
AVDictionary * metadata
metadata.
 
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
 
#define AVFILTER_FLAG_METADATA_ONLY
The filter is a "metadata" filter - it does not modify the frame data in any way.
 
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 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.
 
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
 
static int checkline_edge(void *ctx, const unsigned char *src, int stride, int len, int bpp)
 
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
 
static const AVFilterPad avfilter_vf_cropdetect_inputs[]
 
Structure to hold side data for an AVFrame.
 
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
 
#define FILTER_OUTPUTS(array)
 
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
 
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
 
#define flags(name, subs,...)
 
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
 
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
 
@ AV_FRAME_DATA_MOTION_VECTORS
Motion vectors exported by some codecs (on demand through the export_mvs flag set in the libavcodec A...
 
#define AV_PIX_FMT_YUV444P14
 
static av_cold void uninit(AVFilterContext *ctx)
 
static void BS_FUNC() skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
 
#define AV_PIX_FMT_YUV420P14
 
const AVFilter ff_vf_cropdetect