73#define OFFSET(x) offsetof(DecimateContext, x)
74#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
77 {
"max",
"for mode 0: set the maximum number of consecutive dropped frames (positive), or the minimum interval between dropped frames (negative)",
79 {
"keep",
"for mode 0: set the number of similar consecutive frames to be kept before starting to drop similar frames",
85 {
"min",
"for mode 1: set minimum number of previous frames that need to be duplicated to keep current frame",
93 const uint8_t *
src2, ptrdiff_t stride2)
97 for (
int y = 0; y < 8; y++) {
98 const uint16_t *s1 = (
const uint16_t *)(
src1 + y * stride1);
99 const uint16_t *s2 = (
const uint16_t *)(
src2 + y * stride2);
100 for (
int x = 0; x < 8; x++)
101 sum +=
FFABS(s1[x] - s2[x]);
111#if ARCH_X86 && HAVE_X86ASM
124 uint8_t *cur,
int cur_linesize,
125 uint8_t *
ref,
int ref_linesize,
126 int w,
int h,
int bpp)
132 int t = (
w/16)*(
h/16)*decimate->
frac;
133 int hi_thr = decimate->
hi_thr, lo_thr = decimate->
lo_thr;
136 for (y = 0; y <
h-7; y += 4) {
137 for (x = 8; x <
w-7; x += 4) {
138 d = decimate->
sad(cur + y*cur_linesize + x*bpp, cur_linesize,
139 ref + y*ref_linesize + x*bpp, ref_linesize);
159 uint8_t *cur,
int cur_linesize,
160 uint8_t *
ref,
int ref_linesize,
int w,
int h)
166 uint8_t *cur,
int cur_linesize,
167 uint8_t *
ref,
int ref_linesize,
int w,
int h)
180 uint8_t *cur,
int cur_linesize,
181 uint8_t *
ref,
int ref_linesize,
int w,
int h) =
185 for (plane = 0;
ref->data[plane] &&
ref->linesize[plane]; plane++) {
191 int vsub = plane == 1 || plane == 2 ? decimate->
vsub : 0;
192 int hsub = plane == 1 || plane == 2 ? decimate->
hsub : 0;
195 ref->data[plane],
ref->linesize[plane],
282 decimate->
bpp = depth > 8 ? 2 : 1;
295 decimate->
mode == 1 ?
"min_dup_count" :
"max_drop_count",
338 "%s%s pts:%s pts_time:%s drop_count:%d keep_count:%d\n",
381 "%s%s pts:%s pts_time:%s dup_count:%d\n",
421 .p.name =
"mpdecimate",
423 .p.priv_class = &mpdecimate_class,
static int config_input(AVFilterLink *inlink)
const FFFilter ff_vf_mpdecimate
static AVFormatContext * ctx
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Main libavfilter public API header.
void av_bprintf(AVBPrint *buf, const char *fmt,...)
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
#define AV_BPRINT_SIZE_AUTOMATIC
#define AV_CEIL_RSHIFT(a, b)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_VERBOSE
Detailed information.
static av_always_inline void scale(vec_s32 res[4], vec_s16 res_packed[2], const int shift)
static av_cold void uninit(AVBitStreamFilterContext *ctx)
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
#define FILTER_PIXFMTS_ARRAY(array)
#define AVFILTER_DEFINE_CLASS(fname)
static const AVOption mpdecimate_options[]
@ DECIMATE_KEEP_NO_UPDATE
keep frame without updating reference (similar frame under keep threshold, or forced keep due to max_...
@ DECIMATE_KEEP_UPDATE
keep frame and update reference (frame is different, or first frame)
@ DECIMATE_DROP
similar frame, past keep threshold — drop it
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 diff_planes_8(AVFilterContext *ctx, AVBPrint *bp, uint8_t *cur, int cur_linesize, uint8_t *ref, int ref_linesize, int w, int h)
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.
av_pixelutils_sad_fn ff_mpdecimate_get_sad16_fn(void)
Get the SAD function for 8x8 blocks of 16-bit samples.
static int filter_frame(AVFilterLink *inlink, AVFrame *cur)
static int config_input(AVFilterLink *inlink)
static int filter_frame_mode_1(AVFilterLink *inlink, AVFrame *cur)
static const AVFilterPad mpdecimate_inputs[]
static int filter_frame_mode_0(AVFilterLink *inlink, AVFrame *cur)
static av_cold void uninit(AVFilterContext *ctx)
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 ref...
static int sad_8x8_16(const uint8_t *src1, ptrdiff_t stride1, const uint8_t *src2, ptrdiff_t stride2)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
av_pixelutils_sad_fn av_pixelutils_get_sad_fn(int w_bits, int h_bits, int aligned, void *log_ctx)
Get a potentially optimized pointer to a Sum-of-absolute-differences function (see the av_pixelutils_...
static enum AVPixelFormat pix_fmts[]
av_pixelutils_sad_fn ff_mpdecimate_get_sad16_fn_x86(void)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
int(* av_pixelutils_sad_fn)(const uint8_t *src1, ptrdiff_t stride1, const uint8_t *src2, ptrdiff_t stride2)
Sum of abs(src1[x] - src2[x])
#define AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA422P9
#define AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUV420P14
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
#define AV_PIX_FMT_YUVA422P12
#define AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV440P10
#define AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_GBRP14
#define AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P10
int depth
Number of bits in the component.
void * priv
private data for use by the filter
AVFilterLink ** outputs
array of pointers to output links
A link between two filters.
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
AVFilterContext * dst
dest filter
int format
agreed upon media format
A filter pad used for either input or output.
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).
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
float frac
threshold of changed pixels over the total fraction
AVFrame * ref
reference picture
int max_drop_count
for mode 0: if positive: maximum number of sequential frames to drop for mode 0: if negative: minimum...
int dup_count
for mode 1: number of duplicated frames
int min_dup_count
for mode 1: minimum number of previous frames that need to be duplicated to keep frame
int drop_count
if positive: number of frames sequentially dropped if negative: number of sequential frames which wer...
int mode
0: drop similar frames, 1: drop similar and unique frames
av_pixelutils_sad_fn sad
sum of absolute difference function
int lo_thr
hi and lo scaled to the input bit depth
int max_keep_count
for mode 0: number of similar frames to ignore before to start dropping them
int hi
lower and higher threshold number of differences values for 8x8 blocks
int keep_count
for mode 0: number of similar frames already ignored
int vsub
chroma subsampling values
static int ref[MAX_W *MAX_W]
timestamp utils, mostly useful for debugging/logging purposes
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.