FFmpeg
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 "qpeldsp.h"
29 
30 struct MpegEncContext;
31 
32 #if ARCH_IA64 // Limit static arrays to avoid gcc failing "short data segment overflowed"
33 #define MAX_MV 1024
34 #else
35 #define MAX_MV 4096
36 #endif
37 #define MAX_DMV (2*MAX_MV)
38 #define ME_MAP_SIZE 64
39 
40 #define FF_ME_ZERO 0
41 #define FF_ME_EPZS 1
42 #define FF_ME_XONE 2
43 
44 /**
45  * Motion estimation context.
46  */
47 typedef struct MotionEstContext {
49  int skip; ///< set if ME is skipped for the current MB
50  int co_located_mv[4][2]; ///< mv from last P-frame for direct mode ME
51  int direct_basis_mv[4][2];
52  uint8_t *scratchpad; /**< data area for the ME algo, so that
53  * the ME does not need to malloc/free. */
54  uint8_t *temp;
55  uint32_t *map; ///< map to avoid duplicate evaluations
56  uint32_t *score_map; ///< map to store the scores
57  unsigned map_generation;
59  int penalty_factor; /**< an estimate of the bits required to
60  * code a given mv value, e.g. (1,0) takes
61  * more bits than (0,0). We have to
62  * estimate whether any reduction in
63  * residual is worth the extra bits. */
66  int flags;
67  int sub_flags;
68  int mb_flags;
69  int pre_pass; ///< = 1 for the pre pass
70  int dia_size;
71  int xmin;
72  int xmax;
73  int ymin;
74  int ymax;
75  int pred_x;
76  int pred_y;
77  const uint8_t *src[4][4];
78  const uint8_t *ref[4][4];
79  int stride;
80  int uvstride;
81  /* temp variables for picture complexity calculation */
83  int64_t mb_var_sum_temp;
85 
90  const uint8_t (*mv_penalty)[MAX_DMV * 2 + 1]; ///< bit amount needed to encode a MV
91  const uint8_t *current_mv_penalty;
93  int *mx_ptr, int *my_ptr, int dmin,
94  int src_index, int ref_index,
95  int size, int h);
97 
98 static inline int ff_h263_round_chroma(int x)
99 {
100  //FIXME static or not?
101  static const uint8_t h263_chroma_roundtab[16] = {
102  // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
103  0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1,
104  };
105  return h263_chroma_roundtab[x & 0xf] + (x >> 3);
106 }
107 
108 int ff_init_me(struct MpegEncContext *s);
109 
110 void ff_estimate_p_frame_motion(struct MpegEncContext *s, int mb_x, int mb_y);
111 void ff_estimate_b_frame_motion(struct MpegEncContext *s, int mb_x, int mb_y);
112 
114  int mb_x, int mb_y);
115 
116 int ff_epzs_motion_search(struct MpegEncContext *s, int *mx_ptr, int *my_ptr,
117  int P[10][2], int src_index, int ref_index,
118  const int16_t (*last_mv)[2], int ref_mv_scale,
119  int size, int h);
120 
121 int ff_get_mb_score(struct MpegEncContext *s, int mx, int my, int src_index,
122  int ref_index, int size, int h, int add_rate);
123 
125  const int16_t (*mv_table)[2], int type);
126 
127 void ff_fix_long_p_mvs(struct MpegEncContext *s, int type);
128 void ff_fix_long_mvs(struct MpegEncContext *s, uint8_t *field_select_table,
129  int field_select, int16_t (*mv_table)[2], int f_code,
130  int type, int truncate);
131 
132 #endif /* AVCODEC_MOTION_EST_H */
ff_h263_round_chroma
static int ff_h263_round_chroma(int x)
Definition: motion_est.h:98
MotionEstContext::pred_y
int pred_y
Definition: motion_est.h:76
MotionEstContext::sub_penalty_factor
int sub_penalty_factor
Definition: motion_est.h:64
MotionEstContext::mb_penalty_factor
int mb_penalty_factor
Definition: motion_est.h:65
MotionEstContext
Motion estimation context.
Definition: motion_est.h:47
MAX_DMV
#define MAX_DMV
Definition: motion_est.h:37
MotionEstContext::current_mv_penalty
const uint8_t * current_mv_penalty
Definition: motion_est.h:91
ff_fix_long_p_mvs
void ff_fix_long_p_mvs(struct MpegEncContext *s, int type)
Definition: motion_est.c:1655
ff_init_me
int ff_init_me(struct MpegEncContext *s)
Definition: motion_est.c:308
MotionEstContext::co_located_mv
int co_located_mv[4][2]
mv from last P-frame for direct mode ME
Definition: motion_est.h:50
ff_estimate_p_frame_motion
void ff_estimate_p_frame_motion(struct MpegEncContext *s, int mb_x, int mb_y)
Definition: motion_est.c:890
MotionEstContext::qpel_avg
qpel_mc_func(* qpel_avg)[16]
Definition: motion_est.h:89
ff_get_best_fcode
int ff_get_best_fcode(struct MpegEncContext *s, const int16_t(*mv_table)[2], int type)
Definition: motion_est.c:1602
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
MotionEstContext::mb_var_sum_temp
int64_t mb_var_sum_temp
Definition: motion_est.h:83
MotionEstContext::hpel_avg
op_pixels_func(* hpel_avg)[4]
Definition: motion_est.h:87
s
#define s(width, name)
Definition: cbs_vp9.c:198
MotionEstContext::hpel_put
op_pixels_func(* hpel_put)[4]
Definition: motion_est.h:86
MotionEstContext::ymax
int ymax
Definition: motion_est.h:74
MotionEstContext::dia_size
int dia_size
Definition: motion_est.h:70
MpegEncContext::field_select
int field_select[2][2]
Definition: mpegvideo.h:272
MotionEstContext::flags
int flags
Definition: motion_est.h:66
ff_epzs_motion_search
int ff_epzs_motion_search(struct MpegEncContext *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
MpegEncContext::mb_y
int mb_y
Definition: mpegvideo.h:283
MpegEncContext::f_code
int f_code
forward MV resolution
Definition: mpegvideo.h:224
qpeldsp.h
MotionEstContext::skip
int skip
set if ME is skipped for the current MB
Definition: motion_est.h:49
ff_estimate_b_frame_motion
void ff_estimate_b_frame_motion(struct MpegEncContext *s, int mb_x, int mb_y)
Definition: motion_est.c:1494
op_pixels_func
void(* op_pixels_func)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
Definition: hpeldsp.h:38
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:72
MotionEstContext::qpel_put
qpel_mc_func(* qpel_put)[16]
Definition: motion_est.h:88
MotionEstContext::temp
uint8_t * temp
Definition: motion_est.h:54
MotionEstContext::avctx
AVCodecContext * avctx
Definition: motion_est.h:48
P
#define P
MotionEstContext::stride
int stride
Definition: motion_est.h:79
MotionEstContext::ymin
int ymin
Definition: motion_est.h:73
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:90
ff_get_mb_score
int ff_get_mb_score(struct MpegEncContext *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::ref
const uint8_t * ref[4][4]
Definition: motion_est.h:78
MotionEstContext::sub_motion_search
int(* sub_motion_search)(struct MpegEncContext *s, int *mx_ptr, int *my_ptr, int dmin, int src_index, int ref_index, int size, int h)
Definition: motion_est.h:92
MpegEncContext::last_mv
int last_mv[2][2][2]
last MV, used for MV prediction in MPEG-1 & B-frame MPEG-4
Definition: mpegvideo.h:273
MpegEncContext::mb_x
int mb_x
Definition: mpegvideo.h:283
MotionEstContext::direct_basis_mv
int direct_basis_mv[4][2]
Definition: motion_est.h:51
MotionEstContext::sub_flags
int sub_flags
Definition: motion_est.h:67
MotionEstContext::score_map
uint32_t * score_map
map to store the scores
Definition: motion_est.h:56
avcodec.h
ff_pre_estimate_p_frame_motion
int ff_pre_estimate_p_frame_motion(struct MpegEncContext *s, int mb_x, int mb_y)
Definition: motion_est.c:1065
MotionEstContext::xmin
int xmin
Definition: motion_est.h:71
MotionEstContext::uvstride
int uvstride
Definition: motion_est.h:80
MotionEstContext::penalty_factor
int penalty_factor
an estimate of the bits required to code a given mv value, e.g.
Definition: motion_est.h:59
MotionEstContext::pre_penalty_factor
int pre_penalty_factor
Definition: motion_est.h:58
MotionEstContext::src
const uint8_t * src[4][4]
Definition: motion_est.h:77
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:52
AVCodecContext
main external API structure.
Definition: avcodec.h:441
MotionEstContext::mc_mb_var_sum_temp
int64_t mc_mb_var_sum_temp
Definition: motion_est.h:82
MotionEstContext::map_generation
unsigned map_generation
Definition: motion_est.h:57
MotionEstContext::pre_pass
int pre_pass
= 1 for the pre pass
Definition: motion_est.h:69
MotionEstContext::map
uint32_t * map
map to avoid duplicate evaluations
Definition: motion_est.h:55
hpeldsp.h
MotionEstContext::mb_flags
int mb_flags
Definition: motion_est.h:68
MotionEstContext::scene_change_score
int scene_change_score
Definition: motion_est.h:84
h
h
Definition: vp9dsp_template.c:2038
ff_fix_long_mvs
void ff_fix_long_mvs(struct MpegEncContext *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:1704
int
int
Definition: ffmpeg_filter.c:368
MpegEncContext
MpegEncContext.
Definition: mpegvideo.h:67
MotionEstContext::pred_x
int pred_x
Definition: motion_est.h:75