FFmpeg
Loading...
Searching...
No Matches
vf_mpdecimate.c File Reference
#include "config.h"
#include "libavutil/bprint.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "libavutil/pixelutils.h"
#include "libavutil/timestamp.h"
#include "avfilter.h"
#include "filters.h"
#include "mpdecimate.h"
#include "video.h"

Go to the source code of this file.

Data Structures

struct  DecimateContext
 

Macros

#define OFFSET(x)
 
#define FLAGS   AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
 

Enumerations

enum  DecimateResult { DECIMATE_DROP , DECIMATE_KEEP_UPDATE , DECIMATE_KEEP_NO_UPDATE }
 

Functions

 AVFILTER_DEFINE_CLASS (mpdecimate)
 
static int sad_8x8_16 (const uint8_t *src1, ptrdiff_t stride1, const uint8_t *src2, ptrdiff_t stride2)
 
av_pixelutils_sad_fn ff_mpdecimate_get_sad16_fn (void)
 Get the SAD function for 8x8 blocks of 16-bit samples.
 
static av_always_inline int diff_planes (AVFilterContext *ctx, AVBPrint *bp, uint8_t *cur, int cur_linesize, uint8_t *ref, int ref_linesize, int w, int h, int bpp)
 Return 1 if the two planes are different, 0 otherwise.
 
static int diff_planes_8 (AVFilterContext *ctx, AVBPrint *bp, uint8_t *cur, int cur_linesize, uint8_t *ref, int ref_linesize, int w, int h)
 
static int diff_planes_16 (AVFilterContext *ctx, AVBPrint *bp, uint8_t *cur, int cur_linesize, uint8_t *ref, int ref_linesize, int w, int h)
 
static int is_frame_different (AVFilterContext *ctx, AVBPrint *bp, AVFrame *cur, AVFrame *ref)
 Tell if the frame is different with respect to the reference frame ref.
 
static DecimateResult decimate_frame (AVFilterContext *ctx, AVBPrint *bp, AVFrame *cur, AVFrame *ref)
 Tell if the frame should be decimated, for example if it is no much different with respect to the reference frame ref.
 
static av_cold void uninit (AVFilterContext *ctx)
 
static int config_input (AVFilterLink *inlink)
 
static int filter_frame_mode_0 (AVFilterLink *inlink, AVFrame *cur)
 
static int filter_frame_mode_1 (AVFilterLink *inlink, AVFrame *cur)
 
static int filter_frame (AVFilterLink *inlink, AVFrame *cur)
 

Variables

static const AVOption mpdecimate_options []
 
static enum AVPixelFormat pix_fmts []
 
static const AVFilterPad mpdecimate_inputs []
 
const FFFilter ff_vf_mpdecimate
 

Macro Definition Documentation

◆ OFFSET

#define OFFSET ( x)
Value:

Definition at line 73 of file vf_mpdecimate.c.

◆ FLAGS

Definition at line 74 of file vf_mpdecimate.c.

Enumeration Type Documentation

◆ DecimateResult

Enumerator
DECIMATE_DROP 

similar frame, past keep threshold — drop it

DECIMATE_KEEP_UPDATE 

keep frame and update reference (frame is different, or first frame)

DECIMATE_KEEP_NO_UPDATE 

keep frame without updating reference (similar frame under keep threshold, or forced keep due to max_drop_count)

Definition at line 40 of file vf_mpdecimate.c.

Function Documentation

◆ AVFILTER_DEFINE_CLASS()

AVFILTER_DEFINE_CLASS ( mpdecimate )

◆ sad_8x8_16()

static int sad_8x8_16 ( const uint8_t * src1,
ptrdiff_t stride1,
const uint8_t * src2,
ptrdiff_t stride2 )
static

Definition at line 92 of file vf_mpdecimate.c.

Referenced by ff_mpdecimate_get_sad16_fn().

◆ ff_mpdecimate_get_sad16_fn()

av_pixelutils_sad_fn ff_mpdecimate_get_sad16_fn ( void )

Get the SAD function for 8x8 blocks of 16-bit samples.

Strides are in bytes.

Definition at line 107 of file vf_mpdecimate.c.

Referenced by check_sad16(), and config_input().

◆ diff_planes()

static av_always_inline int diff_planes ( AVFilterContext * ctx,
AVBPrint * bp,
uint8_t * cur,
int cur_linesize,
uint8_t * ref,
int ref_linesize,
int w,
int h,
int bpp )
static

Return 1 if the two planes are different, 0 otherwise.

The reason is appended to bp, which the caller prints with the frame's keep/drop decision in a single av_log() call.

Definition at line 123 of file vf_mpdecimate.c.

Referenced by diff_planes_16(), and diff_planes_8().

◆ diff_planes_8()

static int diff_planes_8 ( AVFilterContext * ctx,
AVBPrint * bp,
uint8_t * cur,
int cur_linesize,
uint8_t * ref,
int ref_linesize,
int w,
int h )
static

Definition at line 158 of file vf_mpdecimate.c.

Referenced by is_frame_different().

◆ diff_planes_16()

static int diff_planes_16 ( AVFilterContext * ctx,
AVBPrint * bp,
uint8_t * cur,
int cur_linesize,
uint8_t * ref,
int ref_linesize,
int w,
int h )
static

Definition at line 165 of file vf_mpdecimate.c.

Referenced by is_frame_different().

◆ is_frame_different()

static int is_frame_different ( AVFilterContext * ctx,
AVBPrint * bp,
AVFrame * cur,
AVFrame * ref )
static

Tell if the frame is different with respect to the reference frame ref.

Definition at line 175 of file vf_mpdecimate.c.

Referenced by decimate_frame(), and filter_frame_mode_1().

◆ decimate_frame()

static DecimateResult decimate_frame ( AVFilterContext * ctx,
AVBPrint * bp,
AVFrame * cur,
AVFrame * ref )
static

Tell if the frame should be decimated, for example if it is no much different with respect to the reference frame ref.

Definition at line 208 of file vf_mpdecimate.c.

Referenced by filter_frame_mode_0().

◆ uninit()

static av_cold void uninit ( AVFilterContext * ctx)
static

Definition at line 234 of file vf_mpdecimate.c.

◆ config_input()

static int config_input ( AVFilterLink * inlink)
static

Definition at line 271 of file vf_mpdecimate.c.

◆ filter_frame_mode_0()

static int filter_frame_mode_0 ( AVFilterLink * inlink,
AVFrame * cur )
static

Definition at line 302 of file vf_mpdecimate.c.

Referenced by filter_frame().

◆ filter_frame_mode_1()

static int filter_frame_mode_1 ( AVFilterLink * inlink,
AVFrame * cur )
static

Definition at line 357 of file vf_mpdecimate.c.

Referenced by filter_frame().

◆ filter_frame()

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

Definition at line 405 of file vf_mpdecimate.c.

Variable Documentation

◆ mpdecimate_options

const AVOption mpdecimate_options[]
static
Initial value:
= {
{ "max", "for mode 0: set the maximum number of consecutive dropped frames (positive), or the minimum interval between dropped frames (negative)",
OFFSET(max_drop_count), AV_OPT_TYPE_INT, {.i64=0}, INT_MIN, INT_MAX, FLAGS },
{ "keep", "for mode 0: set the number of similar consecutive frames to be kept before starting to drop similar frames",
OFFSET(max_keep_count), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX, FLAGS },
{ "hi", "set high dropping threshold", OFFSET(hi), AV_OPT_TYPE_INT, {.i64=64*12}, INT_MIN, INT_MAX, FLAGS },
{ "lo", "set low dropping threshold", OFFSET(lo), AV_OPT_TYPE_INT, {.i64=64*5}, INT_MIN, INT_MAX, FLAGS },
{ "frac", "set fraction dropping threshold", OFFSET(frac), AV_OPT_TYPE_FLOAT, {.dbl=0.33}, 0, 1, FLAGS },
{ "mode", "0: drop similar frames, 1: drop similar and unique frames", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS },
{ "min", "for mode 1: set minimum number of previous frames that need to be duplicated to keep current frame",
OFFSET(min_dup_count), AV_OPT_TYPE_INT, {.i64=1}, 1, INT_MAX, FLAGS },
{ NULL }
}
#define FLAGS
Definition cmdutils.c:596
#define NULL
Definition coverity.c:32
mode
Use these values in ebur128_init (or'ed).
Definition ebur128.h:83
#define OFFSET(x)
@ 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

Definition at line 76 of file vf_mpdecimate.c.

◆ pix_fmts

enum AVPixelFormat pix_fmts[]
static
Initial value:
= {
}
#define AV_PIX_FMT_YUV420P16
Definition pixfmt.h:559
#define AV_PIX_FMT_YUV444P12
Definition pixfmt.h:555
#define AV_PIX_FMT_YUV444P9
Definition pixfmt.h:547
#define AV_PIX_FMT_YUV420P10
Definition pixfmt.h:548
#define AV_PIX_FMT_YUV440P12
Definition pixfmt.h:554
#define AV_PIX_FMT_GBRP9
Definition pixfmt.h:566
#define AV_PIX_FMT_YUV422P9
Definition pixfmt.h:546
#define AV_PIX_FMT_YUVA444P10
Definition pixfmt.h:601
#define AV_PIX_FMT_YUVA420P16
Definition pixfmt.h:604
#define AV_PIX_FMT_YUV420P12
Definition pixfmt.h:552
#define AV_PIX_FMT_YUVA420P10
Definition pixfmt.h:599
#define AV_PIX_FMT_YUVA422P9
Definition pixfmt.h:597
#define AV_PIX_FMT_YUV422P12
Definition pixfmt.h:553
#define AV_PIX_FMT_GBRP10
Definition pixfmt.h:567
#define AV_PIX_FMT_YUV422P10
Definition pixfmt.h:549
#define AV_PIX_FMT_GBRP12
Definition pixfmt.h:568
#define AV_PIX_FMT_YUV420P9
Definition pixfmt.h:545
#define AV_PIX_FMT_YUVA420P9
Definition pixfmt.h:596
#define AV_PIX_FMT_YUVA422P10
Definition pixfmt.h:600
#define AV_PIX_FMT_YUV420P14
Definition pixfmt.h:556
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
@ 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_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition pixfmt.h:77
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition pixfmt.h:108
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
Definition pixfmt.h:107
@ 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_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition pixfmt.h:78
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition pixfmt.h:174
@ 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_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition pixfmt.h:173
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition pixfmt.h:165
@ 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_YUVA422P12
Definition pixfmt.h:602
#define AV_PIX_FMT_YUV422P14
Definition pixfmt.h:557
#define AV_PIX_FMT_YUV422P16
Definition pixfmt.h:560
#define AV_PIX_FMT_YUV440P10
Definition pixfmt.h:550
#define AV_PIX_FMT_YUVA444P16
Definition pixfmt.h:606
#define AV_PIX_FMT_YUVA422P16
Definition pixfmt.h:605
#define AV_PIX_FMT_GBRP16
Definition pixfmt.h:570
#define AV_PIX_FMT_YUV444P14
Definition pixfmt.h:558
#define AV_PIX_FMT_YUVA444P9
Definition pixfmt.h:598
#define AV_PIX_FMT_GBRP14
Definition pixfmt.h:569
#define AV_PIX_FMT_YUVA444P12
Definition pixfmt.h:603
#define AV_PIX_FMT_YUV444P16
Definition pixfmt.h:561
#define AV_PIX_FMT_YUV444P10
Definition pixfmt.h:551

Definition at line 240 of file vf_mpdecimate.c.

◆ mpdecimate_inputs

const AVFilterPad mpdecimate_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 411 of file vf_mpdecimate.c.

◆ ff_vf_mpdecimate

const FFFilter ff_vf_mpdecimate
Initial value:
= {
.p.name = "mpdecimate",
.p.description = NULL_IF_CONFIG_SMALL("Remove near-duplicate frames."),
.p.priv_class = &mpdecimate_class,
.uninit = uninit,
.priv_size = sizeof(DecimateContext),
}
static av_cold void uninit(AVBitStreamFilterContext *ctx)
#define FILTER_INPUTS(array)
Definition filters.h:279
#define FILTER_OUTPUTS(array)
Definition filters.h:280
#define FILTER_PIXFMTS_ARRAY(array)
Definition filters.h:259
static const AVFilterPad mpdecimate_inputs[]
#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 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 420 of file vf_mpdecimate.c.