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

Motion estimation. More...

#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include "avcodec.h"
#include "h263.h"
#include "mathops.h"
#include "motion_est.h"
#include "mpegutils.h"
#include "mpegvideoenc.h"
#include "motion_est_template.c"

Go to the source code of this file.

Data Structures

struct  Minima
 

Macros

#define P_LEFT   P[1]
 
#define P_TOP   P[2]
 
#define P_TOPRIGHT   P[3]
 
#define P_MEDIAN   P[4]
 
#define P_MV1   P[9]
 
#define ME_MAP_SHIFT   3
 
#define ME_MAP_MV_BITS   11
 
#define FLAG_QPEL   1
 
#define FLAG_CHROMA   2
 
#define FLAG_DIRECT   4
 
#define CHECK_SAD_HALF_MV(suffix, x, y)
 
#define HASH(fx, fy, bx, by)
 
#define HASH8(fx, fy, bx, by)
 
#define CHECK_BIDIR(fx, fy, bx, by)
 
#define CHECK_BIDIR2(a, b, c, d)
 

Functions

static int sad_hpel_motion_search (MPVEncContext *const s, int *mx_ptr, int *my_ptr, int dmin, int src_index, int ref_index, int size, int h)
 
static unsigned update_map_generation (MotionEstContext *c)
 
static int minima_cmp (const void *a, const void *b)
 
static void init_ref (MotionEstContext *c, uint8_t *const src[3], uint8_t *const ref[3], uint8_t *const ref2[3], int x, int y, int ref_index)
 
static int get_flags (MotionEstContext *c, int direct, int chroma)
 
static av_always_inline int cmp_direct_inline (MPVEncContext *const s, const int x, const int y, const int subx, const int suby, const int size, const int h, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, int qpel)
 
static av_always_inline int cmp_inline (MPVEncContext *const s, const int x, const int y, const int subx, const int suby, const int size, const int h, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, int qpel, int chroma)
 
static int cmp_simple (MPVEncContext *const s, const int x, const int y, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func)
 
static int cmp_fpel_internal (MPVEncContext *const s, const int x, const int y, const int size, const int h, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags)
 
static int cmp_internal (MPVEncContext *const s, const int x, const int y, const int subx, const int suby, const int size, const int h, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags)
 
static av_always_inline int cmp (MPVEncContext *const s, const int x, const int y, const int subx, const int suby, const int size, const int h, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags)
 compares a block (either a full macroblock or a partition thereof) against a proposed motion-compensated prediction of that block
 
static int cmp_hpel (MPVEncContext *const s, const int x, const int y, const int subx, const int suby, const int size, const int h, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags)
 
static int cmp_qpel (MPVEncContext *const s, const int x, const int y, const int subx, const int suby, const int size, const int h, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags)
 
static int zero_cmp (MPVEncContext *const s, const uint8_t *a, const uint8_t *b, ptrdiff_t stride, int h)
 
static void zero_hpel (uint8_t *a, const uint8_t *b, ptrdiff_t stride, int h)
 
av_cold int ff_me_init (MotionEstContext *c, AVCodecContext *avctx, const MECmpContext *mecc, int mpvenc)
 
void ff_me_init_pic (MPVEncContext *const s)
 
static void set_p_mv_tables (MPVEncContext *const s, int mx, int my, int mv4)
 
static void get_limits (MPVEncContext *const s, int x, int y, int bframe)
 get fullpel ME search limits.
 
static void init_mv4_ref (MotionEstContext *c)
 
static int h263_mv4_search (MPVEncContext *const s, int mx, int my, int shift)
 
static void init_interlaced_ref (MPVEncContext *const s, int ref_index)
 
static int interlaced_search (MPVEncContext *const s, int ref_index, int16_t(*mv_tables[2][2])[2], uint8_t *field_select_tables[2], int mx, int my, int user_field_select)
 
static int get_penalty_factor (int lambda, int lambda2, int type)
 
void ff_estimate_p_frame_motion (MPVEncContext *const s, int mb_x, int mb_y)
 
int ff_pre_estimate_p_frame_motion (MPVEncContext *const s, int mb_x, int mb_y)
 
static int estimate_motion_b (MPVEncContext *const s, int mb_x, int mb_y, int16_t(*mv_table)[2], int ref_index, int f_code)
 
static int check_bidir_mv (MPVEncContext *const s, int motion_fx, int motion_fy, int motion_bx, int motion_by, int pred_fx, int pred_fy, int pred_bx, int pred_by, int size, int h)
 
static int bidir_refine (MPVEncContext *const s, int mb_x, int mb_y)
 
static int direct_search (MPVEncContext *const s, int mb_x, int mb_y)
 
void ff_estimate_b_frame_motion (MPVEncContext *const s, int mb_x, int mb_y)
 
int ff_get_best_fcode (MPVMainEncContext *const m, const int16_t(*mv_table)[2], int type)
 
void ff_fix_long_p_mvs (MPVEncContext *const s, int type)
 
void ff_fix_long_mvs (MPVEncContext *const s, uint8_t *field_select_table, int field_select, int16_t(*mv_table)[2], int f_code, int type, int truncate)
 

Detailed Description

Motion estimation.

Definition in file motion_est.c.

Macro Definition Documentation

◆ P_LEFT

◆ P_TOP

◆ P_TOPRIGHT

◆ P_MEDIAN

◆ P_MV1

#define P_MV1   P[9]

Definition at line 45 of file motion_est.c.

Referenced by epzs_motion_search2(), h263_mv4_search(), and interlaced_search().

◆ ME_MAP_SHIFT

#define ME_MAP_SHIFT   3

◆ ME_MAP_MV_BITS

#define ME_MAP_MV_BITS   11

◆ FLAG_QPEL

#define FLAG_QPEL   1

◆ FLAG_CHROMA

#define FLAG_CHROMA   2

◆ FLAG_DIRECT

#define FLAG_DIRECT   4

◆ CHECK_SAD_HALF_MV

#define CHECK_SAD_HALF_MV ( suffix,
x,
y )
Value:
{\
d = c->pix_abs[size][(x ? 1 : 0) + (y ? 2 : 0)](NULL, pix, ptr + ((x) >> 1), stride, h); \
d += (mv_penalty[pen_x + x] + mv_penalty[pen_y + y])*penalty_factor;\
COPY3_IF_LT(dminh, d, dx, x, dy, y)\
}
#define NULL
Definition coverity.c:32
static uint8_t mv_penalty[MAX_FCODE+1][MAX_DMV *2+1]
Definition h261enc.c:53
enum AVPixelFormat pix
Definition ohcodec.c:55
#define stride
int size
static double c[64]

Definition at line 406 of file motion_est.c.

Referenced by sad_hpel_motion_search().

◆ HASH

#define HASH ( fx,
fy,
bx,
by )
Value:
((fx)+17*(fy)+63*(bx)+117*(by))

Referenced by bidir_refine().

◆ HASH8

#define HASH8 ( fx,
fy,
bx,
by )
Value:
((uint8_t)HASH(fx,fy,bx,by))
#define HASH(fx, fy, bx, by)

Referenced by bidir_refine().

◆ CHECK_BIDIR

#define CHECK_BIDIR ( fx,
fy,
bx,
by )
Value:
if( !map[(hashidx+HASH(fx,fy,bx,by))&255]\
&&(fx<=0 || motion_fx+fx<=xmax) && (fy<=0 || motion_fy+fy<=ymax) && (bx<=0 || motion_bx+bx<=xmax) && (by<=0 || motion_by+by<=ymax)\
&&(fx>=0 || motion_fx+fx>=xmin) && (fy>=0 || motion_fy+fy>=ymin) && (bx>=0 || motion_bx+bx>=xmin) && (by>=0 || motion_by+by>=ymin)){\
int score;\
map[(hashidx+HASH(fx,fy,bx,by))&255] = 1;\
score= check_bidir_mv(s, motion_fx+fx, motion_fy+fy, motion_bx+bx, motion_by+by, pred_fx, pred_fy, pred_bx, pred_by, 0, 16);\
if(score < fbmin){\
hashidx += HASH(fx,fy,bx,by);\
fbmin= score;\
motion_fx+=fx;\
motion_fy+=fy;\
motion_bx+=bx;\
motion_by+=by;\
end=0;\
}\
}
#define s(width, name)
Definition cbs_vp9.c:198
const VDPAUPixFmtMap * map
static int check_bidir_mv(MPVEncContext *const s, int motion_fx, int motion_fy, int motion_bx, int motion_by, int pred_fx, int pred_fy, int pred_bx, int pred_by, int size, int h)

◆ CHECK_BIDIR2

#define CHECK_BIDIR2 ( a,
b,
c,
d )
Value:
CHECK_BIDIR(-(a),-(b),-(c),-(d))
int a
#define b
Definition input.c:43
#define CHECK_BIDIR(fx, fy, bx, by)

Referenced by bidir_refine().

Function Documentation

◆ sad_hpel_motion_search()

static int sad_hpel_motion_search ( MPVEncContext *const s,
int * mx_ptr,
int * my_ptr,
int dmin,
int src_index,
int ref_index,
int size,
int h )
static

Definition at line 413 of file motion_est.c.

Referenced by ff_me_init().

◆ update_map_generation()

static unsigned update_map_generation ( MotionEstContext * c)
inlinestatic

Definition at line 55 of file motion_est.c.

Referenced by epzs_motion_search2(), and epzs_motion_search_internal().

◆ minima_cmp()

static int minima_cmp ( const void * a,
const void * b )
static

Definition at line 72 of file motion_est.c.

Referenced by sab_diamond_search().

◆ init_ref()

static void init_ref ( MotionEstContext * c,
uint8_t *const src[3],
uint8_t *const ref[3],
uint8_t *const ref2[3],
int x,
int y,
int ref_index )
inlinestatic

◆ get_flags()

static int get_flags ( MotionEstContext * c,
int direct,
int chroma )
static

Definition at line 104 of file motion_est.c.

Referenced by ff_me_init().

◆ cmp_direct_inline()

static av_always_inline int cmp_direct_inline ( MPVEncContext *const s,
const int x,
const int y,
const int subx,
const int suby,
const int size,
const int h,
int ref_index,
int src_index,
me_cmp_func cmp_func,
me_cmp_func chroma_cmp_func,
int qpel )
static

Definition at line 110 of file motion_est.c.

Referenced by cmp_fpel_internal(), cmp_hpel(), cmp_internal(), and cmp_qpel().

◆ cmp_inline()

static av_always_inline int cmp_inline ( MPVEncContext *const s,
const int x,
const int y,
const int subx,
const int suby,
const int size,
const int h,
int ref_index,
int src_index,
me_cmp_func cmp_func,
me_cmp_func chroma_cmp_func,
int qpel,
int chroma )
static

Definition at line 182 of file motion_est.c.

Referenced by cmp_fpel_internal(), cmp_hpel(), cmp_internal(), cmp_qpel(), and cmp_simple().

◆ cmp_simple()

static int cmp_simple ( MPVEncContext *const s,
const int x,
const int y,
int ref_index,
int src_index,
me_cmp_func cmp_func,
me_cmp_func chroma_cmp_func )
static

Definition at line 234 of file motion_est.c.

Referenced by cmp().

◆ cmp_fpel_internal()

static int cmp_fpel_internal ( MPVEncContext *const s,
const int x,
const int y,
const int size,
const int h,
int ref_index,
int src_index,
me_cmp_func cmp_func,
me_cmp_func chroma_cmp_func,
const int flags )
static

Definition at line 240 of file motion_est.c.

Referenced by cmp().

◆ cmp_internal()

static int cmp_internal ( MPVEncContext *const s,
const int x,
const int y,
const int subx,
const int suby,
const int size,
const int h,
int ref_index,
int src_index,
me_cmp_func cmp_func,
me_cmp_func chroma_cmp_func,
const int flags )
static

Definition at line 250 of file motion_est.c.

Referenced by cmp().

◆ cmp()

static av_always_inline int cmp ( MPVEncContext *const s,
const int x,
const int y,
const int subx,
const int suby,
const int size,
const int h,
int ref_index,
int src_index,
me_cmp_func cmp_func,
me_cmp_func chroma_cmp_func,
const int flags )
static

◆ cmp_hpel()

static int cmp_hpel ( MPVEncContext *const s,
const int x,
const int y,
const int subx,
const int suby,
const int size,
const int h,
int ref_index,
int src_index,
me_cmp_func cmp_func,
me_cmp_func chroma_cmp_func,
const int flags )
static

Definition at line 278 of file motion_est.c.

◆ cmp_qpel()

static int cmp_qpel ( MPVEncContext *const s,
const int x,
const int y,
const int subx,
const int suby,
const int size,
const int h,
int ref_index,
int src_index,
me_cmp_func cmp_func,
me_cmp_func chroma_cmp_func,
const int flags )
static

Definition at line 288 of file motion_est.c.

◆ zero_cmp()

static int zero_cmp ( MPVEncContext *const s,
const uint8_t * a,
const uint8_t * b,
ptrdiff_t stride,
int h )
static

Definition at line 300 of file motion_est.c.

◆ zero_hpel()

static void zero_hpel ( uint8_t * a,
const uint8_t * b,
ptrdiff_t stride,
int h )
static

Definition at line 306 of file motion_est.c.

Referenced by ff_me_init_pic().

◆ ff_me_init()

av_cold int ff_me_init ( MotionEstContext * c,
AVCodecContext * avctx,
const MECmpContext * mecc,
int mpvenc )

Definition at line 309 of file motion_est.c.

Referenced by encode_init(), me_cmp_init(), and svq1_encode_init().

◆ ff_me_init_pic()

void ff_me_init_pic ( MPVEncContext *const s)

Definition at line 371 of file motion_est.c.

Referenced by encode_frame(), encode_picture(), and svq1_encode_plane().

◆ set_p_mv_tables()

static void set_p_mv_tables ( MPVEncContext *const s,
int mx,
int my,
int mv4 )
inlinestatic

Definition at line 518 of file motion_est.c.

Referenced by ff_estimate_p_frame_motion().

◆ get_limits()

static void get_limits ( MPVEncContext *const s,
int x,
int y,
int bframe )
inlinestatic

◆ init_mv4_ref()

static void init_mv4_ref ( MotionEstContext * c)
inlinestatic

Definition at line 581 of file motion_est.c.

Referenced by h263_mv4_search().

◆ h263_mv4_search()

static int h263_mv4_search ( MPVEncContext *const s,
int mx,
int my,
int shift )
inlinestatic

Definition at line 592 of file motion_est.c.

Referenced by ff_estimate_p_frame_motion().

◆ init_interlaced_ref()

static void init_interlaced_ref ( MPVEncContext *const s,
int ref_index )
inlinestatic

Definition at line 731 of file motion_est.c.

Referenced by interlaced_search().

◆ interlaced_search()

static int interlaced_search ( MPVEncContext *const s,
int ref_index,
int16_t(*[2][2]) mv_tables[2],
uint8_t * field_select_tables[2],
int mx,
int my,
int user_field_select )
static

Definition at line 745 of file motion_est.c.

Referenced by ff_estimate_b_frame_motion(), and ff_estimate_p_frame_motion().

◆ get_penalty_factor()

static int get_penalty_factor ( int lambda,
int lambda2,
int type )
inlinestatic

◆ ff_estimate_p_frame_motion()

void ff_estimate_p_frame_motion ( MPVEncContext *const s,
int mb_x,
int mb_y )

< the variance of the block (sum of squared (p[y][x]-average))

< sum of squared differences with the estimated motion vector

Definition at line 888 of file motion_est.c.

Referenced by estimate_motion_thread(), and svq1_encode_plane().

◆ ff_pre_estimate_p_frame_motion()

int ff_pre_estimate_p_frame_motion ( MPVEncContext *const s,
int mb_x,
int mb_y )

Definition at line 1063 of file motion_est.c.

Referenced by pre_estimate_motion_thread().

◆ estimate_motion_b()

static int estimate_motion_b ( MPVEncContext *const s,
int mb_x,
int mb_y,
int16_t(*) mv_table[2],
int ref_index,
int f_code )
static

Definition at line 1114 of file motion_est.c.

Referenced by ff_estimate_b_frame_motion().

◆ check_bidir_mv()

static int check_bidir_mv ( MPVEncContext *const s,
int motion_fx,
int motion_fy,
int motion_bx,
int motion_by,
int pred_fx,
int pred_fy,
int pred_bx,
int pred_by,
int size,
int h )
inlinestatic

Definition at line 1173 of file motion_est.c.

Referenced by bidir_refine().

◆ bidir_refine()

static int bidir_refine ( MPVEncContext *const s,
int mb_x,
int mb_y )
inlinestatic

Definition at line 1238 of file motion_est.c.

Referenced by ff_estimate_b_frame_motion().

◆ direct_search()

static int direct_search ( MPVEncContext *const s,
int mb_x,
int mb_y )
inlinestatic

Definition at line 1385 of file motion_est.c.

Referenced by ff_estimate_b_frame_motion().

◆ ff_estimate_b_frame_motion()

void ff_estimate_b_frame_motion ( MPVEncContext *const s,
int mb_x,
int mb_y )

Definition at line 1487 of file motion_est.c.

Referenced by estimate_motion_thread().

◆ ff_get_best_fcode()

int ff_get_best_fcode ( MPVMainEncContext *const m,
const int16_t(*) mv_table[2],
int type )

Definition at line 1599 of file motion_est.c.

Referenced by encode_picture().

◆ ff_fix_long_p_mvs()

void ff_fix_long_p_mvs ( MPVEncContext *const s,
int type )

Definition at line 1655 of file motion_est.c.

Referenced by encode_picture(), and svq1_encode_plane().

◆ ff_fix_long_mvs()

void ff_fix_long_mvs ( MPVEncContext *const s,
uint8_t * field_select_table,
int field_select,
int16_t(*) mv_table[2],
int f_code,
int type,
int truncate )
Parameters
truncate1 for truncation, 0 for using intra

Definition at line 1704 of file motion_est.c.

Referenced by encode_picture(), and svq1_encode_plane().