FFmpeg
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
motion_est.h
Go to the documentation of this file.
1 /*
2  * Motion estimation
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef AVCODEC_MOTION_EST_H
22 #define AVCODEC_MOTION_EST_H
23 
24 #include <stdint.h>
25 
26 #include "avcodec.h"
27 #include "hpeldsp.h"
28 #include "me_cmp.h"
29 #include "qpeldsp.h"
30 
31 typedef struct MPVEncContext MPVEncContext;
33 
34 #if ARCH_IA64 // Limit static arrays to avoid gcc failing "short data segment overflowed"
35 #define MAX_MV 1024
36 #else
37 #define MAX_MV 4096
38 #endif
39 #define MAX_DMV (2*MAX_MV)
40 #define ME_MAP_SIZE 64
41 
42 #define FF_ME_ZERO 0
43 #define FF_ME_EPZS 1
44 #define FF_ME_XONE 2
45 
46 /**
47  * Motion estimation context.
48  */
49 typedef struct MotionEstContext {
51  int motion_est; ///< ME algorithm
52  int skip; ///< set if ME is skipped for the current MB
53  int co_located_mv[4][2]; ///< mv from last P-frame for direct mode ME
54  int direct_basis_mv[4][2];
55  uint8_t *scratchpad; /**< data area for the ME algo, so that
56  * the ME does not need to malloc/free. */
57  uint8_t *temp;
58  unsigned map_generation;
60  int penalty_factor; /**< an estimate of the bits required to
61  * code a given mv value, e.g. (1,0) takes
62  * more bits than (0,0). We have to
63  * estimate whether any reduction in
64  * residual is worth the extra bits. */
67  int flags;
68  int sub_flags;
69  int mb_flags;
70  int pre_pass; ///< = 1 for the pre pass
71  int dia_size;
72  int xmin;
73  int xmax;
74  int ymin;
75  int ymax;
76  int pred_x;
77  int pred_y;
78  const uint8_t *src[4][4];
79  const uint8_t *ref[4][4];
80  int stride;
81  int uvstride;
82  /* temp variables for picture complexity calculation */
86 
91 
94 
99  const uint8_t (*mv_penalty)[MAX_DMV * 2 + 1]; ///< bit amount needed to encode a MV
100  const uint8_t *current_mv_penalty;
102  int *mx_ptr, int *my_ptr, int dmin,
103  int src_index, int ref_index,
104  int size, int h);
105 
106  uint32_t map[ME_MAP_SIZE]; ///< map to avoid duplicate evaluations
107  uint32_t score_map[ME_MAP_SIZE];///< map to store the scores
109 
110 /**
111  * Performs one-time initialization of the MotionEstContext.
112  */
113 int ff_me_init(MotionEstContext *c, struct AVCodecContext *avctx,
114  const struct MECmpContext *mecc, int mpvenc);
115 
117 
118 void ff_estimate_p_frame_motion(MPVEncContext *s, int mb_x, int mb_y);
119 void ff_estimate_b_frame_motion(MPVEncContext *s, int mb_x, int mb_y);
120 
122  int mb_x, int mb_y);
123 
124 int ff_epzs_motion_search(MPVEncContext *s, int *mx_ptr, int *my_ptr,
125  int P[10][2], int src_index, int ref_index,
126  const int16_t (*last_mv)[2], int ref_mv_scale,
127  int size, int h);
128 
129 int ff_get_mb_score(MPVEncContext *s, int mx, int my, int src_index,
130  int ref_index, int size, int h, int add_rate);
131 
133  const int16_t (*mv_table)[2], int type);
134 
136 void ff_fix_long_mvs(MPVEncContext *s, uint8_t *field_select_table,
137  int field_select, int16_t (*mv_table)[2], int f_code,
138  int type, int truncate);
139 
140 #endif /* AVCODEC_MOTION_EST_H */
MPVEncContext
Definition: mpegvideoenc.h:45
MotionEstContext::pred_y
int pred_y
Definition: motion_est.h:77
MotionEstContext::sub_penalty_factor
int sub_penalty_factor
Definition: motion_est.h:65
MotionEstContext::mb_penalty_factor
int mb_penalty_factor
Definition: motion_est.h:66
MotionEstContext
Motion estimation context.
Definition: motion_est.h:49
int64_t
long long int64_t
Definition: coverity.c:34
MAX_DMV
#define MAX_DMV
Definition: motion_est.h:39
MotionEstContext::current_mv_penalty
const uint8_t * current_mv_penalty
Definition: motion_est.h:100
MotionEstContext::map
uint32_t map[ME_MAP_SIZE]
map to avoid duplicate evaluations
Definition: motion_est.h:106
MotionEstContext::co_located_mv
int co_located_mv[4][2]
mv from last P-frame for direct mode ME
Definition: motion_est.h:53
ff_fix_long_p_mvs
void ff_fix_long_p_mvs(MPVEncContext *s, int type)
Definition: motion_est.c:1661
mx
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t mx
Definition: dsp.h:53
MotionEstContext::sub_motion_search
int(* sub_motion_search)(MPVEncContext *s, int *mx_ptr, int *my_ptr, int dmin, int src_index, int ref_index, int size, int h)
Definition: motion_est.h:101
ff_me_init
int ff_me_init(MotionEstContext *c, struct AVCodecContext *avctx, const struct MECmpContext *mecc, int mpvenc)
Performs one-time initialization of the MotionEstContext.
ff_pre_estimate_p_frame_motion
int ff_pre_estimate_p_frame_motion(MPVEncContext *s, int mb_x, int mb_y)
Definition: motion_est.c:1067
MotionEstContext::qpel_avg
qpel_mc_func(* qpel_avg)[16]
Definition: motion_est.h:98
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
ff_fix_long_mvs
void ff_fix_long_mvs(MPVEncContext *s, uint8_t *field_select_table, int field_select, int16_t(*mv_table)[2], int f_code, int type, int truncate)
Definition: motion_est.c:1710
MotionEstContext::mb_var_sum_temp
int64_t mb_var_sum_temp
Definition: motion_est.h:84
MotionEstContext::hpel_avg
op_pixels_func(* hpel_avg)[4]
Definition: motion_est.h:96
me_cmp_func
int(* me_cmp_func)(MPVEncContext *c, const uint8_t *blk1, const uint8_t *blk2, ptrdiff_t stride, int h)
Definition: me_cmp.h:50
s
#define s(width, name)
Definition: cbs_vp9.c:198
MotionEstContext::me_pre_cmp
me_cmp_func me_pre_cmp[6]
Definition: motion_est.h:87
MotionEstContext::hpel_put
op_pixels_func(* hpel_put)[4]
Definition: motion_est.h:95
MotionEstContext::ymax
int ymax
Definition: motion_est.h:75
ff_estimate_p_frame_motion
void ff_estimate_p_frame_motion(MPVEncContext *s, int mb_x, int mb_y)
Definition: motion_est.c:892
my
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t my
Definition: dsp.h:53
MotionEstContext::mb_cmp
me_cmp_func mb_cmp[6]
Definition: motion_est.h:90
MotionEstContext::dia_size
int dia_size
Definition: motion_est.h:71
MECmpContext
Definition: me_cmp.h:55
MotionEstContext::score_map
uint32_t score_map[ME_MAP_SIZE]
map to store the scores
Definition: motion_est.h:107
MotionEstContext::flags
int flags
Definition: motion_est.h:67
qpeldsp.h
MotionEstContext::skip
int skip
set if ME is skipped for the current MB
Definition: motion_est.h:52
ME_MAP_SIZE
#define ME_MAP_SIZE
Definition: motion_est.h:40
op_pixels_func
void(* op_pixels_func)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
Definition: hpeldsp.h:38
MPVMainEncContext
Definition: mpegvideoenc.h:172
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
qpel_mc_func
void(* qpel_mc_func)(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)
Definition: qpeldsp.h:65
MotionEstContext::xmax
int xmax
Definition: motion_est.h:73
MotionEstContext::qpel_put
qpel_mc_func(* qpel_put)[16]
Definition: motion_est.h:97
MotionEstContext::temp
uint8_t * temp
Definition: motion_est.h:57
MotionEstContext::avctx
AVCodecContext * avctx
Definition: motion_est.h:50
P
#define P
MotionEstContext::stride
int stride
Definition: motion_est.h:80
MotionEstContext::ymin
int ymin
Definition: motion_est.h:74
size
int size
Definition: twinvq_data.h:10344
MotionEstContext::mv_penalty
const uint8_t(* mv_penalty)[MAX_DMV *2+1]
bit amount needed to encode a MV
Definition: motion_est.h:99
MotionEstContext::me_sub_cmp
me_cmp_func me_sub_cmp[6]
Definition: motion_est.h:89
ff_estimate_b_frame_motion
void ff_estimate_b_frame_motion(MPVEncContext *s, int mb_x, int mb_y)
Definition: motion_est.c:1493
MotionEstContext::ref
const uint8_t * ref[4][4]
Definition: motion_est.h:79
ff_get_mb_score
int ff_get_mb_score(MPVEncContext *s, int mx, int my, int src_index, int ref_index, int size, int h, int add_rate)
Definition: motion_est_template.c:192
MotionEstContext::motion_est
int motion_est
ME algorithm.
Definition: motion_est.h:51
MotionEstContext::direct_basis_mv
int direct_basis_mv[4][2]
Definition: motion_est.h:54
MotionEstContext::sub_flags
int sub_flags
Definition: motion_est.h:68
avcodec.h
MotionEstContext::xmin
int xmin
Definition: motion_est.h:72
MotionEstContext::uvstride
int uvstride
Definition: motion_est.h:81
MotionEstContext::penalty_factor
int penalty_factor
an estimate of the bits required to code a given mv value, e.g.
Definition: motion_est.h:60
MotionEstContext::pre_penalty_factor
int pre_penalty_factor
Definition: motion_est.h:59
MotionEstContext::src
const uint8_t * src[4][4]
Definition: motion_est.h:78
MotionEstContext::scratchpad
uint8_t * scratchpad
data area for the ME algo, so that the ME does not need to malloc/free.
Definition: motion_est.h:55
me_cmp.h
AVCodecContext
main external API structure.
Definition: avcodec.h:431
MotionEstContext::mc_mb_var_sum_temp
int64_t mc_mb_var_sum_temp
Definition: motion_est.h:83
MotionEstContext::map_generation
unsigned map_generation
Definition: motion_est.h:58
MotionEstContext::pre_pass
int pre_pass
= 1 for the pre pass
Definition: motion_est.h:70
ff_epzs_motion_search
int ff_epzs_motion_search(MPVEncContext *s, int *mx_ptr, int *my_ptr, int P[10][2], int src_index, int ref_index, const int16_t(*last_mv)[2], int ref_mv_scale, int size, int h)
Definition: motion_est_template.c:977
MotionEstContext::sse
me_cmp_func sse
Definition: motion_est.h:93
ff_me_init_pic
void ff_me_init_pic(MPVEncContext *s)
Definition: motion_est.c:371
hpeldsp.h
MotionEstContext::mb_flags
int mb_flags
Definition: motion_est.h:69
MotionEstContext::scene_change_score
int scene_change_score
Definition: motion_est.h:85
h
h
Definition: vp9dsp_template.c:2070
MotionEstContext::pix_abs
me_cmp_func pix_abs[2][4]
Definition: motion_est.h:92
MotionEstContext::pred_x
int pred_x
Definition: motion_est.h:76
ff_get_best_fcode
int ff_get_best_fcode(MPVMainEncContext *m, const int16_t(*mv_table)[2], int type)
Definition: motion_est.c:1605
MotionEstContext::me_cmp
me_cmp_func me_cmp[6]
Definition: motion_est.h:88