22 #include "libavutil/opt.h"
23 #include "libavutil/pixdesc.h"
24 #include "libavutil/timestamp.h"
29 #define INPUT_CLEANSRC 1
64 #define OFFSET(x) offsetof(DecimateContext, x)
65 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
68 {
"cycle",
"set the number of frame from which one will be dropped",
OFFSET(cycle),
AV_OPT_TYPE_INT, {.i64 = 5}, 2, 25,
FLAGS },
71 {
"blockx",
"set the size of the x-axis blocks used during metric calculations",
OFFSET(blockx),
AV_OPT_TYPE_INT, {.i64 = 32}, 4, 1<<9,
FLAGS },
72 {
"blocky",
"set the size of the y-axis blocks used during metric calculations",
OFFSET(blocky),
AV_OPT_TYPE_INT, {.i64 = 32}, 4, 1<<9,
FLAGS },
73 {
"ppsrc",
"mark main input as a pre-processed input and activate clean source input stream",
OFFSET(ppsrc),
AV_OPT_TYPE_INT, {.i64=0}, 0, 1,
FLAGS },
74 {
"chroma",
"set whether or not chroma is considered in the metric calculations",
OFFSET(chroma),
AV_OPT_TYPE_INT, {.i64=1}, 0, 1,
FLAGS },
84 int64_t *bdiffs = dm->
bdiffs;
87 memset(bdiffs, 0, dm->
bdiffsize *
sizeof(*bdiffs));
89 for (plane = 0; plane < (dm->
chroma && f1->
data[2] ? 3 : 1); plane++) {
91 const int linesize1 = f1->
linesize[plane];
92 const int linesize2 = f2->
linesize[plane];
97 int hblockx = dm->
blockx / 2;
98 int hblocky = dm->
blocky / 2;
101 hblockx >>= dm->
hsub;
102 hblocky >>= dm->
vsub;
105 for (y = 0; y <
height; y++) {
106 int ydest = y / hblocky;
109 #define CALC_DIFF(nbits) do { \
110 for (x = 0; x < width; x += hblockx) { \
112 int m = FFMIN(width, x + hblockx); \
113 for (xl = x; xl < m; xl++) \
114 acc += abs(((const uint##nbits##_t *)f1p)[xl] - \
115 ((const uint##nbits##_t *)f2p)[xl]); \
116 bdiffs[ydest * dm->nxblocks + xdest] += acc; \
128 for (i = 0; i < dm->
nyblocks - 1; i++) {
129 for (j = 0; j < dm->
nxblocks - 1; j++) {
130 int64_t tmp = bdiffs[ i * dm->
nxblocks + j ]
132 + bdiffs[(i + 1) * dm->
nxblocks + j ]
133 + bdiffs[(i + 1) * dm->
nxblocks + j + 1];
147 int scpos = -1, duppos = -1;
148 int drop = INT_MIN, i, lowest = 0,
ret;
180 for (i = 0; i < dm->
cycle; i++) {
188 drop = scpos >= 0 && duppos < 0 ? scpos : lowest;
197 i == scpos ?
" sc" :
"",
198 i == duppos ?
" dup" :
"",
199 i == lowest ?
" lowest" :
"",
200 i == drop ?
" [DROP]" :
"");
233 const int w = inlink->
w;
234 const int h = inlink->
h;
239 max_value = (1 << dm->
depth) - 1;
327 if ((dm->
eof & eof_mask) == eof_mask)
339 #define PF_NOALPHA(suf) AV_PIX_FMT_YUV420##suf, AV_PIX_FMT_YUV422##suf, AV_PIX_FMT_YUV444##suf
340 #define PF_ALPHA(suf) AV_PIX_FMT_YUVA420##suf, AV_PIX_FMT_YUVA422##suf, AV_PIX_FMT_YUVA444##suf
341 #define PF(suf) PF_NOALPHA(suf), PF_ALPHA(suf)
359 if (!fps.
num || !fps.
den) {
361 "current rate of %d/%d is invalid\n", fps.
num, fps.
den);
371 outlink->
w = inlink->
w;
372 outlink->
h = inlink->
h;
395 .priv_class = &decimate_class,
static const AVFilterPad decimate_outputs[]
void * av_calloc(size_t nmemb, size_t size) av_malloc_attrib
Allocate a block of nmemb * size bytes with alignment suitable for all memory accesses (including vec...
uint32_t eof
bitmask for end of stream
This structure describes decoded (raw) audio or video data.
const char * name
Filter name.
void * priv
private data for use by the filter
static const AVFilterPad outputs[]
char * av_strdup(const char *s) av_malloc_attrib
Duplicate the string s.
int h
agreed upon image height
#define AVFILTER_FLAG_DYNAMIC_INPUTS
The number of the filter inputs is not determined just by AVFilter.inputs.
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
AVFrame ** clean_src
frame queue for the clean source
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
const char * name
Pad name.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
int fid
current frame id in the queue
#define FF_CEIL_RSHIFT(a, b)
static double av_q2d(AVRational a)
Convert rational to double.
AVRational av_mul_q(AVRational b, AVRational c) av_const
Multiply two rationals.
#define AV_LOG_VERBOSE
Detailed information.
A filter pad used for either input or output.
A link between two filters.
AVFilter avfilter_vf_decimate
#define AV_PIX_FMT_GRAY16
uint16_t depth_minus1
number of bits in the component minus 1
int width
width and height of the video frame
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);ff_audio_convert_init_arm(ac);ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
unsigned flags
Link processing flags.
Frame requests may need to loop in order to be fulfilled.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown; if left to 0/0, will be automatically be cop...
AVFrame * last
last frame from the previous queue
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
AVFilterContext * src
source filter
int av_log_get_level(void)
Get the current log level.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
double ts_unit
timestamp units for the output frames
AVPixelFormat
Pixel format.
int w
agreed upon image width
int filled
1 if the queue is filled, 0 otherwise
static av_cold void decimate_uninit(AVFilterContext *ctx)
unsigned nb_inputs
number of input pads
static int config_input(AVFilterLink *inlink)
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static int request_inlink(AVFilterContext *ctx, int lid)
int format
agreed upon media format
Main libavfilter public API header.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
AVFilterLink ** outputs
array of pointers to output links
struct qitem * queue
window of cycle frames and the associated data diff
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
static const AVOption decimate_options[]
AVFilterPad * input_pads
array of input pads
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
BYTE int const BYTE int int int height
Describe the class of an AVClass context structure.
static av_cold int decimate_init(AVFilterContext *ctx)
AVFilterLink ** inputs
array of pointers to input links
int vsub
chroma subsampling values
rational number numerator/denominator
static int request_frame(AVFilterLink *outlink)
int got_frame[2]
frame request flag for each input stream
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
AVFilterContext * dst
dest filter
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
#define FF_INLINK_IDX(link)
Find the index of a link.
AVFrame * av_frame_clone(AVFrame *src)
Create a new frame that references the same data as src.
static void calc_diffs(const DecimateContext *dm, struct qitem *q, const AVFrame *f1, const AVFrame *f2)
#define AVFILTER_DEFINE_CLASS(fname)
static int config_output(AVFilterLink *outlink)
int(* config_props)(AVFilterLink *link)
Link configuration callback.
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
static int query_formats(AVFilterContext *ctx)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
int64_t frame_count
Number of past frames sent through the link.
static int ff_insert_inpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new input pad for the filter.