FFmpeg  4.3
Macros | Functions
motion_est_template.c File Reference
#include "libavutil/qsort.h"
#include "mpegvideo.h"

Go to the source code of this file.

Macros

#define LOAD_COMMON
 
#define CHECK_HALF_MV(dx, dy, x, y)
 
#define CHECK_QUARTER_MV(dx, dy, x, y)
 
#define CHECK_MV(x, y)
 
#define CHECK_CLIPPED_MV(ax, ay)
 
#define CHECK_MV_DIR(x, y, new_dir)
 
#define check(x, y, S, v)
 
#define LOAD_COMMON2
 
#define SAB_CHECK_MV(ax, ay)
 
#define MAX_SAB_SIZE   ME_MAP_SIZE
 

Functions

static int hpel_motion_search (MpegEncContext *s, int *mx_ptr, int *my_ptr, int dmin, int src_index, int ref_index, int size, int h)
 
static int no_sub_motion_search (MpegEncContext *s, int *mx_ptr, int *my_ptr, int dmin, int src_index, int ref_index, int size, int h)
 
static int get_mb_score (MpegEncContext *s, int mx, int my, int src_index, int ref_index, int size, int h, int add_rate)
 
int ff_get_mb_score (MpegEncContext *s, int mx, int my, int src_index, int ref_index, int size, int h, int add_rate)
 
static int qpel_motion_search (MpegEncContext *s, int *mx_ptr, int *my_ptr, int dmin, int src_index, int ref_index, int size, int h)
 
static av_always_inline int small_diamond_search (MpegEncContext *s, int *best, int dmin, int src_index, int ref_index, const int penalty_factor, int size, int h, int flags)
 
static int funny_diamond_search (MpegEncContext *s, int *best, int dmin, int src_index, int ref_index, const int penalty_factor, int size, int h, int flags)
 
static int hex_search (MpegEncContext *s, int *best, int dmin, int src_index, int ref_index, const int penalty_factor, int size, int h, int flags, int dia_size)
 
static int l2s_dia_search (MpegEncContext *s, int *best, int dmin, int src_index, int ref_index, const int penalty_factor, int size, int h, int flags)
 
static int umh_search (MpegEncContext *s, int *best, int dmin, int src_index, int ref_index, const int penalty_factor, int size, int h, int flags)
 
static int full_search (MpegEncContext *s, int *best, int dmin, int src_index, int ref_index, const int penalty_factor, int size, int h, int flags)
 
static int sab_diamond_search (MpegEncContext *s, int *best, int dmin, int src_index, int ref_index, const int penalty_factor, int size, int h, int flags)
 
static int var_diamond_search (MpegEncContext *s, int *best, int dmin, int src_index, int ref_index, const int penalty_factor, int size, int h, int flags)
 
static av_always_inline int diamond_search (MpegEncContext *s, int *best, int dmin, int src_index, int ref_index, const int penalty_factor, int size, int h, int flags)
 
static av_always_inline int epzs_motion_search_internal (MpegEncContext *s, int *mx_ptr, int *my_ptr, int P[10][2], int src_index, int ref_index, int16_t(*last_mv)[2], int ref_mv_scale, int flags, int size, int h)
 
int ff_epzs_motion_search (MpegEncContext *s, int *mx_ptr, int *my_ptr, int P[10][2], int src_index, int ref_index, int16_t(*last_mv)[2], int ref_mv_scale, int size, int h)
 
static int epzs_motion_search2 (MpegEncContext *s, int *mx_ptr, int *my_ptr, int P[10][2], int src_index, int ref_index, int16_t(*last_mv)[2], int ref_mv_scale, const int size)
 

Detailed Description

Motion estimation template.

Definition in file motion_est_template.c.

Macro Definition Documentation

◆ LOAD_COMMON

#define LOAD_COMMON
Value:
uint32_t av_unused * const score_map= c->score_map;\
const int av_unused xmin= c->xmin;\
const int av_unused ymin= c->ymin;\
const int av_unused xmax= c->xmax;\
const int av_unused ymax= c->ymax;\
uint8_t *mv_penalty= c->current_mv_penalty;\
const int pred_x= c->pred_x;\
const int pred_y= c->pred_y;\

Definition at line 31 of file motion_est_template.c.

◆ CHECK_HALF_MV

#define CHECK_HALF_MV (   dx,
  dy,
  x,
 
)
Value:
{\
const int hx= 2*(x)+(dx);\
const int hy= 2*(y)+(dy);\
d= cmp_hpel(s, x, y, dx, dy, size, h, ref_index, src_index, cmp_sub, chroma_cmp_sub, flags);\
d += (mv_penalty[hx - pred_x] + mv_penalty[hy - pred_y])*penalty_factor;\
COPY3_IF_LT(dmin, d, bx, hx, by, hy)\
}

Definition at line 41 of file motion_est_template.c.

◆ CHECK_QUARTER_MV

#define CHECK_QUARTER_MV (   dx,
  dy,
  x,
 
)
Value:
{\
const int hx= 4*(x)+(dx);\
const int hy= 4*(y)+(dy);\
d= cmp_qpel(s, x, y, dx, dy, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\
d += (mv_penalty[hx - pred_x] + mv_penalty[hy - pred_y])*penalty_factor;\
COPY3_IF_LT(dmin, d, bx, hx, by, hy)\
}

Definition at line 198 of file motion_est_template.c.

◆ CHECK_MV

#define CHECK_MV (   x,
 
)
Value:
{\
const unsigned key = ((unsigned)(y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
const int index= (((unsigned)(y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);\
av_assert2((x) >= xmin);\
av_assert2((x) <= xmax);\
av_assert2((y) >= ymin);\
av_assert2((y) <= ymax);\
if(map[index]!=key){\
d= cmp(s, x, y, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\
map[index]= key;\
score_map[index]= d;\
d += (mv_penalty[((x)*(1<<shift))-pred_x] + mv_penalty[((y)*(1<<shift))-pred_y])*penalty_factor;\
COPY3_IF_LT(dmin, d, best[0], x, best[1], y)\
}\
}

Definition at line 360 of file motion_est_template.c.

◆ CHECK_CLIPPED_MV

#define CHECK_CLIPPED_MV (   ax,
  ay 
)
Value:
{\
const int Lx= ax;\
const int Ly= ay;\
const int Lx2= FFMAX(xmin, FFMIN(Lx, xmax));\
const int Ly2= FFMAX(ymin, FFMIN(Ly, ymax));\
CHECK_MV(Lx2, Ly2)\
}

Definition at line 377 of file motion_est_template.c.

◆ CHECK_MV_DIR

#define CHECK_MV_DIR (   x,
  y,
  new_dir 
)
Value:
{\
const unsigned key = ((unsigned)(y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
const int index= (((unsigned)(y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);\
if(map[index]!=key){\
d= cmp(s, x, y, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\
map[index]= key;\
score_map[index]= d;\
d += (mv_penalty[(int)((unsigned)(x)<<shift)-pred_x] + mv_penalty[(int)((unsigned)(y)<<shift)-pred_y])*penalty_factor;\
if(d<dmin){\
best[0]=x;\
best[1]=y;\
dmin=d;\
next_dir= new_dir;\
}\
}\
}

Definition at line 386 of file motion_est_template.c.

◆ check

#define check (   x,
  y,
  S,
 
)
Value:
if( (x)<(xmin<<(S)) ) av_log(NULL, AV_LOG_ERROR, "%d %d %d %d %d xmin" #v, xmin, (x), (y), s->mb_x, s->mb_y);\
if( (x)>(xmax<<(S)) ) av_log(NULL, AV_LOG_ERROR, "%d %d %d %d %d xmax" #v, xmax, (x), (y), s->mb_x, s->mb_y);\
if( (y)<(ymin<<(S)) ) av_log(NULL, AV_LOG_ERROR, "%d %d %d %d %d ymin" #v, ymin, (x), (y), s->mb_x, s->mb_y);\
if( (y)>(ymax<<(S)) ) av_log(NULL, AV_LOG_ERROR, "%d %d %d %d %d ymax" #v, ymax, (x), (y), s->mb_x, s->mb_y);\

Definition at line 404 of file motion_est_template.c.

◆ LOAD_COMMON2

#define LOAD_COMMON2
Value:
uint32_t *map= c->map;\
const int qpel= flags&FLAG_QPEL;\
const int shift= 1+qpel;\

Definition at line 410 of file motion_est_template.c.

◆ SAB_CHECK_MV

#define SAB_CHECK_MV (   ax,
  ay 
)
Value:
{\
const unsigned key = ((ay)<<ME_MAP_MV_BITS) + (ax) + map_generation;\
const int index= (((ay)<<ME_MAP_SHIFT) + (ax))&(ME_MAP_SIZE-1);\
if(map[index]!=key){\
d= cmp(s, ax, ay, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\
map[index]= key;\
score_map[index]= d;\
d += (mv_penalty[((ax)<<shift)-pred_x] + mv_penalty[((ay)<<shift)-pred_y])*penalty_factor;\
if(d < minima[minima_count-1].height){\
int j=0;\
\
while(d >= minima[j].height) j++;\
\
memmove(&minima [j+1], &minima [j], (minima_count - j - 1)*sizeof(Minima));\
\
minima[j].checked= 0;\
minima[j].height= d;\
minima[j].x= ax;\
minima[j].y= ay;\
\
i=-1;\
continue;\
}\
}\
}

Definition at line 652 of file motion_est_template.c.

◆ MAX_SAB_SIZE

#define MAX_SAB_SIZE   ME_MAP_SIZE

Definition at line 679 of file motion_est_template.c.

Function Documentation

◆ hpel_motion_search()

static int hpel_motion_search ( MpegEncContext s,
int mx_ptr,
int my_ptr,
int  dmin,
int  src_index,
int  ref_index,
int  size,
int  h 
)
static

Definition at line 50 of file motion_est_template.c.

Referenced by direct_search(), and ff_init_me().

◆ no_sub_motion_search()

static int no_sub_motion_search ( MpegEncContext s,
int mx_ptr,
int my_ptr,
int  dmin,
int  src_index,
int  ref_index,
int  size,
int  h 
)
static

Definition at line 155 of file motion_est_template.c.

Referenced by ff_init_me().

◆ get_mb_score()

static int get_mb_score ( MpegEncContext s,
int  mx,
int  my,
int  src_index,
int  ref_index,
int  size,
int  h,
int  add_rate 
)
inlinestatic

◆ ff_get_mb_score()

int ff_get_mb_score ( MpegEncContext s,
int  mx,
int  my,
int  src_index,
int  ref_index,
int  size,
int  h,
int  add_rate 
)

Definition at line 192 of file motion_est_template.c.

Referenced by encode_q_branch().

◆ qpel_motion_search()

static int qpel_motion_search ( MpegEncContext s,
int mx_ptr,
int my_ptr,
int  dmin,
int  src_index,
int  ref_index,
int  size,
int  h 
)
static

Definition at line 207 of file motion_est_template.c.

Referenced by direct_search(), and ff_init_me().

◆ small_diamond_search()

static av_always_inline int small_diamond_search ( MpegEncContext s,
int best,
int  dmin,
int  src_index,
int  ref_index,
const int  penalty_factor,
int  size,
int  h,
int  flags 
)
static

Definition at line 415 of file motion_est_template.c.

Referenced by diamond_search().

◆ funny_diamond_search()

static int funny_diamond_search ( MpegEncContext s,
int best,
int  dmin,
int  src_index,
int  ref_index,
const int  penalty_factor,
int  size,
int  h,
int  flags 
)
static

Definition at line 456 of file motion_est_template.c.

Referenced by diamond_search().

◆ hex_search()

static int hex_search ( MpegEncContext s,
int best,
int  dmin,
int  src_index,
int  ref_index,
const int  penalty_factor,
int  size,
int  h,
int  flags,
int  dia_size 
)
static

Definition at line 498 of file motion_est_template.c.

Referenced by diamond_search(), and umh_search().

◆ l2s_dia_search()

static int l2s_dia_search ( MpegEncContext s,
int best,
int  dmin,
int  src_index,
int  ref_index,
const int  penalty_factor,
int  size,
int  h,
int  flags 
)
static

Definition at line 532 of file motion_est_template.c.

Referenced by diamond_search().

◆ umh_search()

static int umh_search ( MpegEncContext s,
int best,
int  dmin,
int  src_index,
int  ref_index,
const int  penalty_factor,
int  size,
int  h,
int  flags 
)
static

Definition at line 570 of file motion_est_template.c.

Referenced by diamond_search().

◆ full_search()

static int full_search ( MpegEncContext s,
int best,
int  dmin,
int  src_index,
int  ref_index,
const int  penalty_factor,
int  size,
int  h,
int  flags 
)
static

Definition at line 617 of file motion_est_template.c.

Referenced by diamond_search().

◆ sab_diamond_search()

static int sab_diamond_search ( MpegEncContext s,
int best,
int  dmin,
int  src_index,
int  ref_index,
const int  penalty_factor,
int  size,
int  h,
int  flags 
)
static

Definition at line 680 of file motion_est_template.c.

Referenced by diamond_search().

◆ var_diamond_search()

static int var_diamond_search ( MpegEncContext s,
int best,
int  dmin,
int  src_index,
int  ref_index,
const int  penalty_factor,
int  size,
int  h,
int  flags 
)
static

Definition at line 770 of file motion_est_template.c.

Referenced by diamond_search().

◆ diamond_search()

static av_always_inline int diamond_search ( MpegEncContext s,
int best,
int  dmin,
int  src_index,
int  ref_index,
const int  penalty_factor,
int  size,
int  h,
int  flags 
)
static

Definition at line 831 of file motion_est_template.c.

Referenced by epzs_motion_search2(), and epzs_motion_search_internal().

◆ epzs_motion_search_internal()

static av_always_inline int epzs_motion_search_internal ( MpegEncContext s,
int mx_ptr,
int my_ptr,
int  P[10][2],
int  src_index,
int  ref_index,
int16_t(*)  last_mv[2],
int  ref_mv_scale,
int  flags,
int  size,
int  h 
)
static
Parameters
Pa list of candidate mvs to check before starting the iterative search. If one of the candidates is close to the optimal mv, then it takes fewer iterations. And it increases the chance that we find the optimal mv.

< x and y coordinates of the best motion vector. i.e. the difference between the position of the block currently being encoded and the position of the block chosen to predict it from.

< the score (cmp + penalty) of any given mv

< the best value of d, i.e. the score corresponding to the mv stored in best[].

Definition at line 859 of file motion_est_template.c.

Referenced by ff_epzs_motion_search().

◆ ff_epzs_motion_search()

int ff_epzs_motion_search ( MpegEncContext s,
int mx_ptr,
int my_ptr,
int  P[10][2],
int  src_index,
int  ref_index,
int16_t(*)  last_mv[2],
int  ref_mv_scale,
int  size,
int  h 
)

◆ epzs_motion_search2()

static int epzs_motion_search2 ( MpegEncContext s,
int mx_ptr,
int my_ptr,
int  P[10][2],
int  src_index,
int  ref_index,
int16_t(*)  last_mv[2],
int  ref_mv_scale,
const int  size 
)
static

Definition at line 992 of file motion_est_template.c.

Referenced by h263_mv4_search(), and interlaced_search().

av_unused
#define av_unused
Definition: attributes.h:131
cmp_qpel
static int cmp_qpel(MpegEncContext *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)
Definition: motion_est.c:285
S
#define S(s, c, i)
Definition: flacdsp_template.c:46
mv_penalty
static uint8_t mv_penalty[MAX_FCODE+1][MAX_DMV *2+1]
Table of number of bits a motion vector component needs.
Definition: ituh263enc.c:47
x
FFmpeg Automated Testing Environment ************************************Introduction Using FATE from your FFmpeg source directory Submitting the results to the FFmpeg result aggregation server Uploading new samples to the fate suite FATE makefile targets and variables Makefile targets Makefile variables Examples Introduction **************FATE is an extended regression suite on the client side and a means for results aggregation and presentation on the server side The first part of this document explains how you can use FATE from your FFmpeg source directory to test your ffmpeg binary The second part describes how you can run FATE to submit the results to FFmpeg’s FATE server In any way you can have a look at the publicly viewable FATE results by visiting this as it can be seen if some test on some platform broke with their recent contribution This usually happens on the platforms the developers could not test on The second part of this document describes how you can run FATE to submit your results to FFmpeg’s FATE server If you want to submit your results be sure to check that your combination of OS and compiler is not already listed on the above mentioned website In the third part you can find a comprehensive listing of FATE makefile targets and variables Using FATE from your FFmpeg source directory **********************************************If you want to run FATE on your machine you need to have the samples in place You can get the samples via the build target fate rsync Use this command from the top level source this will cause FATE to fail NOTE To use a custom wrapper to run the pass ‘ target exec’ to ‘configure’ or set the TARGET_EXEC Make variable Submitting the results to the FFmpeg result aggregation server ****************************************************************To submit your results to the server you should run fate through the shell script ‘tests fate sh’ from the FFmpeg sources This script needs to be invoked with a configuration file as its first argument tests fate sh path to fate_config A configuration file template with comments describing the individual configuration variables can be found at ‘doc fate_config sh template’ Create a configuration that suits your based on the configuration template The ‘slot’ configuration variable can be any string that is not yet but it is suggested that you name it adhering to the following pattern ‘ARCH OS COMPILER COMPILER VERSION’ The configuration file itself will be sourced in a shell therefore all shell features may be used This enables you to setup the environment as you need it for your build For your first test runs the ‘fate_recv’ variable should be empty or commented out This will run everything as normal except that it will omit the submission of the results to the server The following files should be present in $workdir as specified in the configuration it may help to try out the ‘ssh’ command with one or more ‘ v’ options You should get detailed output concerning your SSH configuration and the authentication process The only thing left is to automate the execution of the fate sh script and the synchronisation of the samples directory Uploading new samples to the fate suite *****************************************If you need a sample uploaded send a mail to samples request This is for developers who have an account on the fate suite server If you upload new please make sure they are as small as space on each network bandwidth and so on benefit from smaller test cases Also keep in mind older checkouts use existing sample that means in practice generally do not remove or overwrite files as it likely would break older checkouts or releases Also all needed samples for a commit should be ideally before the push If you need an account for frequently uploading samples or you wish to help others by doing that send a mail to ffmpeg devel rsync vauL Duo x
Definition: fate.txt:150
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
cmp_hpel
static int cmp_hpel(MpegEncContext *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)
Definition: motion_est.c:275
s
#define s(width, name)
Definition: cbs_vp9.c:257
Minima
Definition: motion_est.c:66
key
const char * key
Definition: hwcontext_opencl.c:168
cmp
static av_always_inline int cmp(MpegEncContext *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-compensa...
Definition: motion_est.c:260
NULL
#define NULL
Definition: coverity.c:32
ME_MAP_MV_BITS
#define ME_MAP_MV_BITS
Definition: motion_est.c:48
ME_MAP_SIZE
#define ME_MAP_SIZE
Definition: motion_est.h:38
index
int index
Definition: gxfenc.c:89
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
FFMAX
#define FFMAX(a, b)
Definition: common.h:94
size
int size
Definition: twinvq_data.h:11134
height
#define height
FFMIN
#define FFMIN(a, b)
Definition: common.h:96
ME_MAP_SHIFT
#define ME_MAP_SHIFT
Definition: motion_est.c:47
FLAG_QPEL
#define FLAG_QPEL
Definition: motion_est.c:79
shift
static int shift(int a, int b)
Definition: sonic.c:82
map
const VDPAUPixFmtMap * map
Definition: hwcontext_vdpau.c:85
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:564
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
h
h
Definition: vp9dsp_template.c:2038
int
int
Definition: ffmpeg_filter.c:192