FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups 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 "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. */
57  int best_bits;
58  uint32_t *map; ///< map to avoid duplicate evaluations
59  uint32_t *score_map; ///< map to store the scores
60  unsigned map_generation;
62  int penalty_factor; /**< an estimate of the bits required to
63  * code a given mv value, e.g. (1,0) takes
64  * more bits than (0,0). We have to
65  * estimate whether any reduction in
66  * residual is worth the extra bits. */
69  int flags;
70  int sub_flags;
71  int mb_flags;
72  int pre_pass; ///< = 1 for the pre pass
73  int dia_size;
74  int xmin;
75  int xmax;
76  int ymin;
77  int ymax;
78  int pred_x;
79  int pred_y;
80  uint8_t *src[4][4];
81  uint8_t *ref[4][4];
82  int stride;
83  int uvstride;
84  /* temp variables for picture complexity calculation */
86  int64_t mb_var_sum_temp;
88 
93  uint8_t (*mv_penalty)[MAX_DMV * 2 + 1]; ///< bit amount needed to encode a MV
96  int *mx_ptr, int *my_ptr, int dmin,
97  int src_index, int ref_index,
98  int size, int h);
100 
101 static inline int ff_h263_round_chroma(int x)
102 {
103  //FIXME static or not?
104  static const uint8_t h263_chroma_roundtab[16] = {
105  // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
106  0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1,
107  };
108  return h263_chroma_roundtab[x & 0xf] + (x >> 3);
109 }
110 
111 int ff_init_me(struct MpegEncContext *s);
112 
113 void ff_estimate_p_frame_motion(struct MpegEncContext *s, int mb_x, int mb_y);
114 void ff_estimate_b_frame_motion(struct MpegEncContext *s, int mb_x, int mb_y);
115 
117  int mb_x, int mb_y);
118 
119 int ff_epzs_motion_search(struct MpegEncContext *s, int *mx_ptr, int *my_ptr,
120  int P[10][2], int src_index, int ref_index,
121  int16_t (*last_mv)[2], int ref_mv_scale, int size,
122  int h);
123 
124 int ff_get_mb_score(struct MpegEncContext *s, int mx, int my, int src_index,
125  int ref_index, int size, int h, int add_rate);
126 
127 int ff_get_best_fcode(struct MpegEncContext *s,
128  int16_t (*mv_table)[2], int type);
129 
130 void ff_fix_long_p_mvs(struct MpegEncContext *s);
131 void ff_fix_long_mvs(struct MpegEncContext *s, uint8_t *field_select_table,
132  int field_select, int16_t (*mv_table)[2], int f_code,
133  int type, int truncate);
134 
135 #endif /* AVCODEC_MOTION_EST_H */
uint8_t * scratchpad
data area for the ME algo, so that the ME does not need to malloc/free.
Definition: motion_est.h:52
const char * s
Definition: avisynth_c.h:768
#define P
int skip
set if ME is skipped for the current MB
Definition: motion_est.h:49
int last_mv[2][2][2]
last MV, used for MV prediction in MPEG-1 & B-frame MPEG-4
Definition: mpegvideo.h:278
int pre_pass
= 1 for the pre pass
Definition: motion_est.h:72
int ff_epzs_motion_search(struct 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)
uint8_t * current_mv_penalty
Definition: motion_est.h:94
int sub_penalty_factor
Definition: motion_est.h:67
void(* qpel_mc_func)(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)
Definition: qpeldsp.h:65
uint32_t * score_map
map to store the scores
Definition: motion_est.h:59
int pre_penalty_factor
Definition: motion_est.h:61
int scene_change_score
Definition: motion_est.h:87
uint8_t(* mv_penalty)[MAX_DMV *2+1]
bit amount needed to encode a MV
Definition: motion_est.h:93
uint8_t * ref[4][4]
Definition: motion_est.h:81
int field_select[2][2]
Definition: mpegvideo.h:277
op_pixels_func(* hpel_put)[4]
Definition: motion_est.h:89
uint8_t
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)
int ff_get_best_fcode(struct MpegEncContext *s, int16_t(*mv_table)[2], int type)
Definition: motion_est.c:1598
Motion estimation context.
Definition: motion_est.h:47
qpel_mc_func(* qpel_put)[16]
Definition: motion_est.h:91
quarterpel DSP functions
op_pixels_func(* hpel_avg)[4]
Definition: motion_est.h:90
void ff_fix_long_p_mvs(struct MpegEncContext *s)
Definition: motion_est.c:1651
ptrdiff_t size
Definition: opengl_enc.c:101
int ff_pre_estimate_p_frame_motion(struct MpegEncContext *s, int mb_x, int mb_y)
Definition: motion_est.c:1061
#define MAX_DMV
Definition: motion_est.h:37
void ff_estimate_p_frame_motion(struct MpegEncContext *s, int mb_x, int mb_y)
Definition: motion_est.c:885
int64_t mb_var_sum_temp
Definition: motion_est.h:86
uint8_t * src[4][4]
Definition: motion_est.h:80
void(* op_pixels_func)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
Definition: hpeldsp.h:38
unsigned map_generation
Definition: motion_est.h:60
int penalty_factor
an estimate of the bits required to code a given mv value, e.g.
Definition: motion_est.h:62
Half-pel DSP functions.
Libavcodec external API header.
AVCodecContext * avctx
Definition: motion_est.h:48
main external API structure.
Definition: avcodec.h:1518
GLint GLenum type
Definition: opengl_enc.c:105
static int ff_h263_round_chroma(int x)
Definition: motion_est.h:101
int f_code
forward MV resolution
Definition: mpegvideo.h:238
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:1700
qpel_mc_func(* qpel_avg)[16]
Definition: motion_est.h:92
int64_t mc_mb_var_sum_temp
Definition: motion_est.h:85
uint8_t * best_mb
Definition: motion_est.h:54
MpegEncContext.
Definition: mpegvideo.h:81
int
int direct_basis_mv[4][2]
Definition: motion_est.h:51
int ff_init_me(struct MpegEncContext *s)
Definition: motion_est.c:306
int co_located_mv[4][2]
mv from last P-frame for direct mode ME
Definition: motion_est.h:50
uint32_t * map
map to avoid duplicate evaluations
Definition: motion_est.h:58
void ff_estimate_b_frame_motion(struct MpegEncContext *s, int mb_x, int mb_y)
Definition: motion_est.c:1490
uint8_t * temp_mb[2]
Definition: motion_est.h:55
uint8_t * temp
Definition: motion_est.h:56
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:95