FFmpeg
Loading...
Searching...
No Matches
vf_cropdetect.c File Reference

border detection filter Ported from MPlayer libmpcodecs/vf_cropdetect.c. More...

#include "libavutil/imgutils.h"
#include "libavutil/internal.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/motion_vector.h"
#include "libavutil/qsort.h"
#include "avfilter.h"
#include "filters.h"
#include "video.h"
#include "edge_common.h"

Go to the source code of this file.

Data Structures

struct  CropDetectContext
 

Macros

#define SET_META(key, value)
 
#define FIND(DST, FROM, NOEND, INC, STEP0, STEP1, LEN)
 
#define FIND_EDGE(DST, FROM, NOEND, INC, STEP0, STEP1, LEN)
 
#define OFFSET(x)
 
#define FLAGS   AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
 
#define TFLAGS   AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_RUNTIME_PARAM
 

Enumerations

enum  CropMode { MODE_BLACK , MODE_MV_EDGES , MODE_NB }
 

Functions

static int comp (const int *a, const int *b)
 
static int checkline (void *ctx, const unsigned char *src, int stride, int len, int bpp)
 
static int checkline_edge (void *ctx, const unsigned char *src, int stride, int len, int bpp)
 
static av_cold int init (AVFilterContext *ctx)
 
static av_cold void uninit (AVFilterContext *ctx)
 
static int config_input (AVFilterLink *inlink)
 
static int filter_frame (AVFilterLink *inlink, AVFrame *frame)
 
static int process_command (AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
 
 AVFILTER_DEFINE_CLASS (cropdetect)
 

Variables

static enum AVPixelFormat pix_fmts []
 
static const AVOption cropdetect_options []
 
static const AVFilterPad avfilter_vf_cropdetect_inputs []
 
const FFFilter ff_vf_cropdetect
 

Detailed Description

border detection filter Ported from MPlayer libmpcodecs/vf_cropdetect.c.

Definition in file vf_cropdetect.c.

Macro Definition Documentation

◆ SET_META

#define SET_META ( key,
value )
Value:
static int FUNC metadata(CodedBitstreamContext *ctx, RWContext *rw, APVRawMetadata *current)
double value
Definition eval.c:102
const char * key
int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, int flags)
Convenience wrapper for av_dict_set() that converts the value to a string and stores it.
Definition dict.c:177

Definition at line 241 of file vf_cropdetect.c.

Referenced by filter_frame().

◆ FIND

#define FIND ( DST,
FROM,
NOEND,
INC,
STEP0,
STEP1,
LEN )
Value:
outliers = 0;\
for (last_y = y = FROM; NOEND; y = y INC) {\
if (checkline(ctx, frame->data[0] + STEP0 * y, STEP1, LEN, bpp) > limit_upscaled) {\
if (++outliers > s->max_outliers) { \
DST = last_y;\
break;\
}\
} else\
last_y = y INC;\
}
#define LEN
#define s(width, name)
Definition cbs_vp9.c:198
static AVFrame * frame
static AVFormatContext * ctx
Definition movenc.c:49
static int checkline(void *ctx, const unsigned char *src, int stride, int len, int bpp)
#define DST(x, y)

Referenced by filter_frame().

◆ FIND_EDGE

#define FIND_EDGE ( DST,
FROM,
NOEND,
INC,
STEP0,
STEP1,
LEN )
Value:
for (last_y = y = FROM; NOEND; y = y INC) { \
if (checkline_edge(ctx, tmpbuf + STEP0 * y, STEP1, LEN, bpp)) { \
if (last_y INC == y) { \
DST = y; \
break; \
} else \
last_y = y; \
} \
} \
if (!(NOEND)) { \
DST = y -(INC); \
}
static int checkline_edge(void *ctx, const unsigned char *src, int stride, int len, int bpp)

Referenced by filter_frame().

◆ OFFSET

#define OFFSET ( x)
Value:

Definition at line 467 of file vf_cropdetect.c.

◆ FLAGS

Definition at line 468 of file vf_cropdetect.c.

◆ TFLAGS

Enumeration Type Documentation

◆ CropMode

enum CropMode
Enumerator
MODE_BLACK 
MODE_MV_EDGES 
MODE_NB 

Definition at line 79 of file vf_cropdetect.c.

Function Documentation

◆ comp()

static int comp ( const int * a,
const int * b )
static

Definition at line 85 of file vf_cropdetect.c.

◆ checkline()

static int checkline ( void * ctx,
const unsigned char * src,
int stride,
int len,
int bpp )
static

Definition at line 90 of file vf_cropdetect.c.

◆ checkline_edge()

static int checkline_edge ( void * ctx,
const unsigned char * src,
int stride,
int len,
int bpp )
static

Definition at line 145 of file vf_cropdetect.c.

◆ init()

static av_cold int init ( AVFilterContext * ctx)
static

Definition at line 175 of file vf_cropdetect.c.

◆ uninit()

static av_cold void uninit ( AVFilterContext * ctx)
static

Definition at line 189 of file vf_cropdetect.c.

◆ config_input()

static int config_input ( AVFilterLink * inlink)
static

Definition at line 203 of file vf_cropdetect.c.

◆ filter_frame()

static int filter_frame ( AVFilterLink * inlink,
AVFrame * frame )
static

Definition at line 244 of file vf_cropdetect.c.

◆ process_command()

static int process_command ( AVFilterContext * ctx,
const char * cmd,
const char * args,
char * res,
int res_len,
int flags )
static

Definition at line 446 of file vf_cropdetect.c.

◆ AVFILTER_DEFINE_CLASS()

AVFILTER_DEFINE_CLASS ( cropdetect )

Variable Documentation

◆ pix_fmts

enum AVPixelFormat pix_fmts[]
static
Initial value:
= {
}
#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
@ 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

Definition at line 62 of file vf_cropdetect.c.

◆ cropdetect_options

const AVOption cropdetect_options[]
static
Initial value:
= {
{ "limit", "Threshold below which the pixel is considered black", OFFSET(limit), AV_OPT_TYPE_FLOAT, { .dbl = 24.0/255 }, 0, 65535, TFLAGS },
{ "round", "Value by which the width/height should be divisible", OFFSET(round), AV_OPT_TYPE_INT, { .i64 = 16 }, 0, INT_MAX, FLAGS },
{ "reset", "Recalculate the crop area after this many frames", OFFSET(reset_count), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS },
{ "skip", "Number of initial frames to skip", OFFSET(skip), AV_OPT_TYPE_INT, { .i64 = 2 }, 0, INT_MAX, FLAGS },
{ "reset_count", "Recalculate the crop area after this many frames",OFFSET(reset_count),AV_OPT_TYPE_INT,{ .i64 = 0 }, 0, INT_MAX, FLAGS },
{ "max_outliers", "Threshold count of outliers", OFFSET(max_outliers),AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS },
{ "mode", "set mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=MODE_BLACK}, 0, MODE_NB-1, FLAGS, .unit = "mode" },
{ "black", "detect black pixels surrounding the video", 0, AV_OPT_TYPE_CONST, {.i64=MODE_BLACK}, INT_MIN, INT_MAX, FLAGS, .unit = "mode" },
{ "mvedges", "detect motion and edged surrounding the video", 0, AV_OPT_TYPE_CONST, {.i64=MODE_MV_EDGES}, INT_MIN, INT_MAX, FLAGS, .unit = "mode" },
{ "high", "Set high threshold for edge detection", OFFSET(high), AV_OPT_TYPE_FLOAT, {.dbl=25/255.}, 0, 1, FLAGS },
{ "low", "Set low threshold for edge detection", OFFSET(low), AV_OPT_TYPE_FLOAT, {.dbl=15/255.}, 0, 1, FLAGS },
{ "mv_threshold", "motion vector threshold when estimating video window size", OFFSET(mv_threshold), AV_OPT_TYPE_INT, {.i64=8}, 0, 100, FLAGS},
{ NULL }
}
#define TFLAGS
Definition af_afade.c:66
@ MODE_NB
static void BS_FUNC skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
#define FLAGS
Definition cmdutils.c:598
#define NULL
Definition coverity.c:32
int high
Definition dovi_rpuenc.c:39
mode
Use these values in ebur128_init (or'ed).
Definition ebur128.h:83
#define OFFSET(x)
@ 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
static av_always_inline av_const double round(double x)
Definition libm.h:446
@ MODE_BLACK
@ MODE_MV_EDGES
static double limit(double x)

Definition at line 471 of file vf_cropdetect.c.

◆ avfilter_vf_cropdetect_inputs

const AVFilterPad avfilter_vf_cropdetect_inputs[]
static
Initial value:
= {
{
.name = "default",
.config_props = config_input,
.filter_frame = filter_frame,
},
}
static int config_input(AVFilterLink *inlink)
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
Definition dolby_e.c:1067
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200

Definition at line 489 of file vf_cropdetect.c.

◆ ff_vf_cropdetect

const FFFilter ff_vf_cropdetect
Initial value:
= {
.p.name = "cropdetect",
.p.description = NULL_IF_CONFIG_SMALL("Auto-detect crop size."),
.p.priv_class = &cropdetect_class,
.priv_size = sizeof(CropDetectContext),
.init = init,
.process_command = process_command,
}
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
#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:196
#define AVFILTER_FLAG_METADATA_ONLY
The filter is a "metadata" filter - it does not modify the frame data in any way.
Definition avfilter.h:182
static av_cold void uninit(AVBitStreamFilterContext *ctx)
#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 NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
static enum AVPixelFormat pix_fmts[]
Definition libkvazaar.c:296
static const AVFilterPad avfilter_vf_cropdetect_inputs[]
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

Definition at line 498 of file vf_cropdetect.c.