Go to the documentation of this file.
45 #define OFFSET(x) offsetof(MEContext, x)
46 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
47 #define CONST(name, help, val, u) { name, help, 0, AV_OPT_TYPE_CONST, {.i64=val}, 0, 0, FLAGS, .unit = u }
85 s->mb_size = 1 <<
s->log2_mb_size;
87 s->b_width =
inlink->w >>
s->log2_mb_size;
88 s->b_height =
inlink->h >>
s->log2_mb_size;
89 s->b_count =
s->b_width *
s->b_height;
94 for (
i = 0;
i < 3;
i++) {
95 s->mv_table[
i] =
av_calloc(
s->b_count,
sizeof(*
s->mv_table[0]));
106 int x,
int y,
int x_mv,
int y_mv,
int dir)
110 mv->dst_x = x + (mb_size >> 1);
111 mv->dst_y = y + (mb_size >> 1);
112 mv->src_x = x_mv + (mb_size >> 1);
113 mv->src_y = y_mv + (mb_size >> 1);
114 mv->source = dir ? 1 : -1;
118 #define SEARCH_MV(method)\
120 for (mb_y = 0; mb_y < s->b_height; mb_y++)\
121 for (mb_x = 0; mb_x < s->b_width; mb_x++) {\
122 const int x_mb = mb_x << s->log2_mb_size;\
123 const int y_mb = mb_y << s->log2_mb_size;\
124 int mv[2] = {x_mb, y_mb};\
125 ff_me_search_##method(me_ctx, x_mb, y_mb, mv);\
126 add_mv_data(((AVMotionVector *) sd->data) + mv_count++, me_ctx->mb_size, x_mb, y_mb, mv[0], mv[1], dir);\
130 #define ADD_PRED(preds, px, py)\
132 preds.mvs[preds.nb][0] = px;\
133 preds.mvs[preds.nb][1] = py;\
158 s->mv_table[2] = memcpy(
s->mv_table[2],
s->mv_table[1],
sizeof(*
s->mv_table[1]) *
s->b_count);
159 s->mv_table[1] = memcpy(
s->mv_table[1],
s->mv_table[0],
sizeof(*
s->mv_table[0]) *
s->b_count);
183 for (dir = 0; dir < 2; dir++) {
201 for (mb_y = 0; mb_y <
s->b_height; mb_y++)
202 for (mb_x = 0; mb_x <
s->b_width; mb_x++) {
203 const int mb_i = mb_x + mb_y *
s->b_width;
204 const int x_mb = mb_x <<
s->log2_mb_size;
205 const int y_mb = mb_y <<
s->log2_mb_size;
206 int mv[2] = {x_mb, y_mb};
215 ADD_PRED(preds[0],
s->mv_table[0][mb_i - 1][dir][0],
s->mv_table[0][mb_i - 1][dir][1]);
219 ADD_PRED(preds[0],
s->mv_table[0][mb_i -
s->b_width][dir][0],
s->mv_table[0][mb_i -
s->b_width][dir][1]);
222 if (mb_x + 1 <
s->b_width)
223 ADD_PRED(preds[0],
s->mv_table[0][mb_i -
s->b_width + 1][dir][0],
s->mv_table[0][mb_i -
s->b_width + 1][dir][1]);
226 ADD_PRED(preds[0],
s->mv_table[0][mb_i -
s->b_width - 1][dir][0],
s->mv_table[0][mb_i -
s->b_width - 1][dir][1]);
230 if (preds[0].nb == 4) {
231 me_ctx->
pred_x =
mid_pred(preds[0].mvs[1][0], preds[0].mvs[2][0], preds[0].mvs[3][0]);
232 me_ctx->
pred_y =
mid_pred(preds[0].mvs[1][1], preds[0].mvs[2][1], preds[0].mvs[3][1]);
233 }
else if (preds[0].nb == 3) {
234 me_ctx->
pred_x =
mid_pred(0, preds[0].mvs[1][0], preds[0].mvs[2][0]);
235 me_ctx->
pred_y =
mid_pred(0, preds[0].mvs[1][1], preds[0].mvs[2][1]);
236 }
else if (preds[0].nb == 2) {
246 s->mv_table[0][mb_i][dir][0] =
mv[0] - x_mb;
247 s->mv_table[0][mb_i][dir][1] =
mv[1] - y_mb;
253 for (mb_y = 0; mb_y <
s->b_height; mb_y++)
254 for (mb_x = 0; mb_x <
s->b_width; mb_x++) {
255 const int mb_i = mb_x + mb_y *
s->b_width;
256 const int x_mb = mb_x <<
s->log2_mb_size;
257 const int y_mb = mb_y <<
s->log2_mb_size;
258 int mv[2] = {x_mb, y_mb};
268 ADD_PRED(preds[0],
s->mv_table[0][mb_i - 1][dir][0],
s->mv_table[0][mb_i - 1][dir][1]);
272 ADD_PRED(preds[0],
s->mv_table[0][mb_i -
s->b_width][dir][0],
s->mv_table[0][mb_i -
s->b_width][dir][1]);
275 if (mb_y > 0 && mb_x + 1 <
s->b_width)
276 ADD_PRED(preds[0],
s->mv_table[0][mb_i -
s->b_width + 1][dir][0],
s->mv_table[0][mb_i -
s->b_width + 1][dir][1]);
279 if (preds[0].nb == 4) {
280 me_ctx->
pred_x =
mid_pred(preds[0].mvs[1][0], preds[0].mvs[2][0], preds[0].mvs[3][0]);
281 me_ctx->
pred_y =
mid_pred(preds[0].mvs[1][1], preds[0].mvs[2][1], preds[0].mvs[3][1]);
282 }
else if (preds[0].nb == 3) {
283 me_ctx->
pred_x =
mid_pred(0, preds[0].mvs[1][0], preds[0].mvs[2][0]);
284 me_ctx->
pred_y =
mid_pred(0, preds[0].mvs[1][1], preds[0].mvs[2][1]);
285 }
else if (preds[0].nb == 2) {
294 ADD_PRED(preds[0],
s->mv_table[1][mb_i][dir][0],
s->mv_table[1][mb_i][dir][1]);
297 ADD_PRED(preds[1],
s->mv_table[1][mb_i][dir][0] + (
s->mv_table[1][mb_i][dir][0] -
s->mv_table[2][mb_i][dir][0]),
298 s->mv_table[1][mb_i][dir][1] + (
s->mv_table[1][mb_i][dir][1] -
s->mv_table[2][mb_i][dir][1]));
302 ADD_PRED(preds[1],
s->mv_table[1][mb_i - 1][dir][0],
s->mv_table[1][mb_i - 1][dir][1]);
306 ADD_PRED(preds[1],
s->mv_table[1][mb_i -
s->b_width][dir][0],
s->mv_table[1][mb_i -
s->b_width][dir][1]);
309 if (mb_x + 1 <
s->b_width)
310 ADD_PRED(preds[1],
s->mv_table[1][mb_i + 1][dir][0],
s->mv_table[1][mb_i + 1][dir][1]);
313 if (mb_y + 1 <
s->b_height)
314 ADD_PRED(preds[1],
s->mv_table[1][mb_i +
s->b_width][dir][0],
s->mv_table[1][mb_i +
s->b_width][dir][1]);
318 s->mv_table[0][mb_i][dir][0] =
mv[0] - x_mb;
319 s->mv_table[0][mb_i][dir][1] =
mv[1] - y_mb;
337 for (
i = 0;
i < 3;
i++)
354 .priv_class = &mestimate_class,
AVPixelFormat
Pixel format.
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
AVFrameSideData * av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, size_t size)
Add a new side data to a frame.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
#define FILTER_PIXFMTS_ARRAY(array)
int(*[3] mv_table)[2][2]
motion vectors of current & prev 2 frames
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
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
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).
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
const char * name
Filter name.
static void add_mv_data(AVMotionVector *mv, int mb_size, int x, int y, int x_mv, int y_mv, int dir)
AVMotionEstContext me_ctx
int method
motion estimation method
A link between two filters.
Copyright (c) 2016 Davinder Singh (DSM_) <ds.mudhar<@gmail.com>
int pred_x
median predictor x
#define SEARCH_MV(method)
static int config_input(AVFilterLink *inlink)
#define AV_ME_METHOD_ESA
Copyright (c) 2016 Davinder Singh (DSM_) <ds.mudhar<@gmail.com>
A filter pad used for either input or output.
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
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...
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
AVFILTER_DEFINE_CLASS(mestimate)
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
@ 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_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
static const AVFilterPad mestimate_inputs[]
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...
#define ADD_PRED(preds, px, py)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
const AVFilter ff_vf_mestimate
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
uint64_t ff_me_search_epzs(AVMotionEstContext *me_ctx, int x_mb, int y_mb, int *mv)
static const AVOption mestimate_options[]
#define AV_NOPTS_VALUE
Undefined timestamp value.
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
#define AV_ME_METHOD_EPZS
static enum AVPixelFormat pix_fmts[]
#define i(width, name, range_min, range_max)
#define AV_ME_METHOD_HEXBS
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
const char * name
Pad name.
void * av_calloc(size_t nmemb, size_t size)
void ff_me_init_context(AVMotionEstContext *me_ctx, int mb_size, int search_param, int width, int height, int x_min, int x_max, int y_min, int y_max)
static av_cold void uninit(AVFilterContext *ctx)
int search_param
search parameter
#define AVFILTER_FLAG_METADATA_ONLY
The filter is a "metadata" filter - it does not modify the frame data in any way.
int mb_size
macroblock size
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
int pred_y
median predictor y
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
#define AV_ME_METHOD_NTSS
Structure to hold side data for an AVFrame.
#define FILTER_OUTPUTS(array)
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
#define flags(name, subs,...)
@ 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...
uint64_t ff_me_search_umh(AVMotionEstContext *me_ctx, int x_mb, int y_mb, int *mv)
#define AV_ME_METHOD_TDLS
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
AVMotionEstPredictor preds[2]
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
static av_always_inline av_const int av_ceil_log2_c(int x)
Compute ceil(log2(x)).
#define CONST(name, help, val, u)