Mercurial > libavcodec.hg
annotate motion_est.c @ 4305:4e75fbc983c9 libavcodec
warn user if the selected diamond size is larger then the motion estimation score cache size
author | michael |
---|---|
date | Sun, 17 Dec 2006 13:11:34 +0000 |
parents | dbaae8e5ec55 |
children | 649e51394b6f |
rev | line source |
---|---|
0 | 1 /* |
2967 | 2 * Motion estimation |
429 | 3 * Copyright (c) 2000,2001 Fabrice Bellard. |
1739
07a484280a82
copyright year update of the files i touched and remembered, things look annoyingly unmaintained otherwise
michael
parents:
1729
diff
changeset
|
4 * Copyright (c) 2002-2004 Michael Niedermayer |
2967 | 5 * |
0 | 6 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3575
diff
changeset
|
7 * This file is part of FFmpeg. |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3575
diff
changeset
|
8 * |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3575
diff
changeset
|
9 * FFmpeg is free software; you can redistribute it and/or |
429 | 10 * modify it under the terms of the GNU Lesser General Public |
11 * License as published by the Free Software Foundation; either | |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3575
diff
changeset
|
12 * version 2.1 of the License, or (at your option) any later version. |
0 | 13 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3575
diff
changeset
|
14 * FFmpeg is distributed in the hope that it will be useful, |
0 | 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
429 | 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 * Lesser General Public License for more details. | |
0 | 18 * |
429 | 19 * You should have received a copy of the GNU Lesser General Public |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3575
diff
changeset
|
20 * License along with FFmpeg; if not, write to the Free Software |
3036
0b546eab515d
Update licensing information: The FSF changed postal address.
diego
parents:
3026
diff
changeset
|
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
275
diff
changeset
|
22 * |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
275
diff
changeset
|
23 * new Motion Estimation (X1/EPZS) by Michael Niedermayer <michaelni@gmx.at> |
0 | 24 */ |
2967 | 25 |
1106 | 26 /** |
27 * @file motion_est.c | |
28 * Motion estimation. | |
29 */ | |
2967 | 30 |
0 | 31 #include <stdlib.h> |
32 #include <stdio.h> | |
1426 | 33 #include <limits.h> |
0 | 34 #include "avcodec.h" |
35 #include "dsputil.h" | |
36 #include "mpegvideo.h" | |
37 | |
1950 | 38 #undef NDEBUG |
39 #include <assert.h> | |
936 | 40 |
455 | 41 #define SQ(a) ((a)*(a)) |
284 | 42 |
455 | 43 #define P_LEFT P[1] |
44 #define P_TOP P[2] | |
45 #define P_TOPRIGHT P[3] | |
46 #define P_MEDIAN P[4] | |
47 #define P_MV1 P[9] | |
48 | |
936 | 49 static inline int sad_hpel_motion_search(MpegEncContext * s, |
2979 | 50 int *mx_ptr, int *my_ptr, int dmin, |
1950 | 51 int src_index, int ref_index, |
52 int size, int h); | |
0 | 53 |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
54 static inline int update_map_generation(MotionEstContext *c) |
936 | 55 { |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
56 c->map_generation+= 1<<(ME_MAP_MV_BITS*2); |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
57 if(c->map_generation==0){ |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
58 c->map_generation= 1<<(ME_MAP_MV_BITS*2); |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
59 memset(c->map, 0, sizeof(uint32_t)*ME_MAP_SIZE); |
936 | 60 } |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
61 return c->map_generation; |
936 | 62 } |
63 | |
948 | 64 /* shape adaptive search stuff */ |
65 typedef struct Minima{ | |
66 int height; | |
67 int x, y; | |
68 int checked; | |
69 }Minima; | |
936 | 70 |
948 | 71 static int minima_cmp(const void *a, const void *b){ |
1057 | 72 const Minima *da = (const Minima *) a; |
73 const Minima *db = (const Minima *) b; | |
2967 | 74 |
948 | 75 return da->height - db->height; |
76 } | |
1950 | 77 |
78 #define FLAG_QPEL 1 //must be 1 | |
79 #define FLAG_CHROMA 2 | |
80 #define FLAG_DIRECT 4 | |
936 | 81 |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
82 static inline void init_ref(MotionEstContext *c, uint8_t *src[3], uint8_t *ref[3], uint8_t *ref2[3], int x, int y, int ref_index){ |
1950 | 83 const int offset[3]= { |
84 y*c-> stride + x, | |
85 ((y*c->uvstride + x)>>1), | |
86 ((y*c->uvstride + x)>>1), | |
87 }; | |
88 int i; | |
89 for(i=0; i<3; i++){ | |
90 c->src[0][i]= src [i] + offset[i]; | |
91 c->ref[0][i]= ref [i] + offset[i]; | |
92 } | |
93 if(ref_index){ | |
94 for(i=0; i<3; i++){ | |
95 c->ref[ref_index][i]= ref2[i] + offset[i]; | |
96 } | |
97 } | |
936 | 98 } |
99 | |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
100 static int get_flags(MotionEstContext *c, int direct, int chroma){ |
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
101 return ((c->avctx->flags&CODEC_FLAG_QPEL) ? FLAG_QPEL : 0) |
2967 | 102 + (direct ? FLAG_DIRECT : 0) |
1950 | 103 + (chroma ? FLAG_CHROMA : 0); |
104 } | |
1708 | 105 |
4283
d6f83e2f8804
rename always_inline to av_always_inline and move to common.h
mru
parents:
4259
diff
changeset
|
106 static av_always_inline int cmp(MpegEncContext *s, const int x, const int y, const int subx, const int suby, |
1950 | 107 const int size, const int h, int ref_index, int src_index, |
108 me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags){ | |
109 MotionEstContext * const c= &s->me; | |
110 const int stride= c->stride; | |
111 const int uvstride= c->uvstride; | |
112 const int qpel= flags&FLAG_QPEL; | |
113 const int chroma= flags&FLAG_CHROMA; | |
114 const int dxy= subx + (suby<<(1+qpel)); //FIXME log2_subpel? | |
115 const int hx= subx + (x<<(1+qpel)); | |
116 const int hy= suby + (y<<(1+qpel)); | |
117 uint8_t * const * const ref= c->ref[ref_index]; | |
118 uint8_t * const * const src= c->src[src_index]; | |
119 int d; | |
120 //FIXME check chroma 4mv, (no crashes ...) | |
121 if(flags&FLAG_DIRECT){ | |
122 if(x >= c->xmin && hx <= c->xmax<<(qpel+1) && y >= c->ymin && hy <= c->ymax<<(qpel+1)){ | |
123 const int time_pp= s->pp_time; | |
124 const int time_pb= s->pb_time; | |
125 const int mask= 2*qpel+1; | |
126 if(s->mv_type==MV_TYPE_8X8){ | |
127 int i; | |
128 for(i=0; i<4; i++){ | |
129 int fx = c->direct_basis_mv[i][0] + hx; | |
130 int fy = c->direct_basis_mv[i][1] + hy; | |
131 int bx = hx ? fx - c->co_located_mv[i][0] : c->co_located_mv[i][0]*(time_pb - time_pp)/time_pp + ((i &1)<<(qpel+4)); | |
132 int by = hy ? fy - c->co_located_mv[i][1] : c->co_located_mv[i][1]*(time_pb - time_pp)/time_pp + ((i>>1)<<(qpel+4)); | |
133 int fxy= (fx&mask) + ((fy&mask)<<(qpel+1)); | |
134 int bxy= (bx&mask) + ((by&mask)<<(qpel+1)); | |
2967 | 135 |
1950 | 136 uint8_t *dst= c->temp + 8*(i&1) + 8*stride*(i>>1); |
137 if(qpel){ | |
138 c->qpel_put[1][fxy](dst, ref[0] + (fx>>2) + (fy>>2)*stride, stride); | |
139 c->qpel_avg[1][bxy](dst, ref[8] + (bx>>2) + (by>>2)*stride, stride); | |
140 }else{ | |
141 c->hpel_put[1][fxy](dst, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 8); | |
142 c->hpel_avg[1][bxy](dst, ref[8] + (bx>>1) + (by>>1)*stride, stride, 8); | |
143 } | |
144 } | |
145 }else{ | |
146 int fx = c->direct_basis_mv[0][0] + hx; | |
147 int fy = c->direct_basis_mv[0][1] + hy; | |
148 int bx = hx ? fx - c->co_located_mv[0][0] : (c->co_located_mv[0][0]*(time_pb - time_pp)/time_pp); | |
149 int by = hy ? fy - c->co_located_mv[0][1] : (c->co_located_mv[0][1]*(time_pb - time_pp)/time_pp); | |
150 int fxy= (fx&mask) + ((fy&mask)<<(qpel+1)); | |
151 int bxy= (bx&mask) + ((by&mask)<<(qpel+1)); | |
2967 | 152 |
1950 | 153 if(qpel){ |
154 c->qpel_put[1][fxy](c->temp , ref[0] + (fx>>2) + (fy>>2)*stride , stride); | |
155 c->qpel_put[1][fxy](c->temp + 8 , ref[0] + (fx>>2) + (fy>>2)*stride + 8 , stride); | |
156 c->qpel_put[1][fxy](c->temp + 8*stride, ref[0] + (fx>>2) + (fy>>2)*stride + 8*stride, stride); | |
157 c->qpel_put[1][fxy](c->temp + 8 + 8*stride, ref[0] + (fx>>2) + (fy>>2)*stride + 8 + 8*stride, stride); | |
158 c->qpel_avg[1][bxy](c->temp , ref[8] + (bx>>2) + (by>>2)*stride , stride); | |
159 c->qpel_avg[1][bxy](c->temp + 8 , ref[8] + (bx>>2) + (by>>2)*stride + 8 , stride); | |
160 c->qpel_avg[1][bxy](c->temp + 8*stride, ref[8] + (bx>>2) + (by>>2)*stride + 8*stride, stride); | |
161 c->qpel_avg[1][bxy](c->temp + 8 + 8*stride, ref[8] + (bx>>2) + (by>>2)*stride + 8 + 8*stride, stride); | |
2967 | 162 }else{ |
1950 | 163 assert((fx>>1) + 16*s->mb_x >= -16); |
164 assert((fy>>1) + 16*s->mb_y >= -16); | |
165 assert((fx>>1) + 16*s->mb_x <= s->width); | |
166 assert((fy>>1) + 16*s->mb_y <= s->height); | |
167 assert((bx>>1) + 16*s->mb_x >= -16); | |
168 assert((by>>1) + 16*s->mb_y >= -16); | |
169 assert((bx>>1) + 16*s->mb_x <= s->width); | |
170 assert((by>>1) + 16*s->mb_y <= s->height); | |
936 | 171 |
1950 | 172 c->hpel_put[0][fxy](c->temp, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 16); |
173 c->hpel_avg[0][bxy](c->temp, ref[8] + (bx>>1) + (by>>1)*stride, stride, 16); | |
174 } | |
175 } | |
176 d = cmp_func(s, c->temp, src[0], stride, 16); | |
177 }else | |
178 d= 256*256*256*32; | |
179 }else{ | |
2834 | 180 int uvdxy; /* no, it might not be used uninitialized */ |
1950 | 181 if(dxy){ |
182 if(qpel){ | |
183 c->qpel_put[size][dxy](c->temp, ref[0] + x + y*stride, stride); //FIXME prototype (add h) | |
184 if(chroma){ | |
185 int cx= hx/2; | |
186 int cy= hy/2; | |
187 cx= (cx>>1)|(cx&1); | |
188 cy= (cy>>1)|(cy&1); | |
189 uvdxy= (cx&1) + 2*(cy&1); | |
190 //FIXME x/y wrong, but mpeg4 qpel is sick anyway, we should drop as much of it as possible in favor for h264 | |
191 } | |
192 }else{ | |
193 c->hpel_put[size][dxy](c->temp, ref[0] + x + y*stride, stride, h); | |
194 if(chroma) | |
195 uvdxy= dxy | (x&1) | (2*(y&1)); | |
196 } | |
2967 | 197 d = cmp_func(s, c->temp, src[0], stride, h); |
1950 | 198 }else{ |
2967 | 199 d = cmp_func(s, src[0], ref[0] + x + y*stride, stride, h); |
1950 | 200 if(chroma) |
201 uvdxy= (x&1) + 2*(y&1); | |
202 } | |
203 if(chroma){ | |
204 uint8_t * const uvtemp= c->temp + 16*stride; | |
205 c->hpel_put[size+1][uvdxy](uvtemp , ref[1] + (x>>1) + (y>>1)*uvstride, uvstride, h>>1); | |
206 c->hpel_put[size+1][uvdxy](uvtemp+8, ref[2] + (x>>1) + (y>>1)*uvstride, uvstride, h>>1); | |
2967 | 207 d += chroma_cmp_func(s, uvtemp , src[1], uvstride, h>>1); |
208 d += chroma_cmp_func(s, uvtemp+8, src[2], uvstride, h>>1); | |
1950 | 209 } |
210 } | |
211 #if 0 | |
212 if(full_pel){ | |
213 const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1); | |
214 score_map[index]= d; | |
215 } | |
936 | 216 |
1950 | 217 d += (c->mv_penalty[hx - c->pred_x] + c->mv_penalty[hy - c->pred_y])*c->penalty_factor; |
218 #endif | |
219 return d; | |
936 | 220 } |
221 | |
222 #include "motion_est_template.c" | |
223 | |
2075 | 224 static int zero_cmp(void *s, uint8_t *a, uint8_t *b, int stride, int h){ |
225 return 0; | |
226 } | |
227 | |
228 static void zero_hpel(uint8_t *a, const uint8_t *b, int stride, int h){ | |
229 } | |
230 | |
936 | 231 void ff_init_me(MpegEncContext *s){ |
1962 | 232 MotionEstContext * const c= &s->me; |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
233 c->avctx= s->avctx; |
4305
4e75fbc983c9
warn user if the selected diamond size is larger then the motion estimation score cache size
michael
parents:
4304
diff
changeset
|
234 int cache_size= FFMIN(ME_MAP_SIZE>>ME_MAP_SHIFT, 1<<ME_MAP_SHIFT); |
4e75fbc983c9
warn user if the selected diamond size is larger then the motion estimation score cache size
michael
parents:
4304
diff
changeset
|
235 int dia_size= FFMAX(FFABS(s->avctx->dia_size)&255, FFABS(s->avctx->pre_dia_size)&255); |
4e75fbc983c9
warn user if the selected diamond size is larger then the motion estimation score cache size
michael
parents:
4304
diff
changeset
|
236 |
4e75fbc983c9
warn user if the selected diamond size is larger then the motion estimation score cache size
michael
parents:
4304
diff
changeset
|
237 if(cache_size < 2*dia_size && !c->stride){ |
4e75fbc983c9
warn user if the selected diamond size is larger then the motion estimation score cache size
michael
parents:
4304
diff
changeset
|
238 av_log(s->avctx, AV_LOG_INFO, "ME_MAP size may be a little small for the selected diamond size\n"); |
4e75fbc983c9
warn user if the selected diamond size is larger then the motion estimation score cache size
michael
parents:
4304
diff
changeset
|
239 } |
1962 | 240 |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
241 ff_set_cmp(&s->dsp, s->dsp.me_pre_cmp, c->avctx->me_pre_cmp); |
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
242 ff_set_cmp(&s->dsp, s->dsp.me_cmp, c->avctx->me_cmp); |
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
243 ff_set_cmp(&s->dsp, s->dsp.me_sub_cmp, c->avctx->me_sub_cmp); |
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
244 ff_set_cmp(&s->dsp, s->dsp.mb_cmp, c->avctx->mb_cmp); |
2967 | 245 |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
246 c->flags = get_flags(c, 0, c->avctx->me_cmp &FF_CMP_CHROMA); |
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
247 c->sub_flags= get_flags(c, 0, c->avctx->me_sub_cmp&FF_CMP_CHROMA); |
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
248 c->mb_flags = get_flags(c, 0, c->avctx->mb_cmp &FF_CMP_CHROMA); |
936 | 249 |
1962 | 250 /*FIXME s->no_rounding b_type*/ |
936 | 251 if(s->flags&CODEC_FLAG_QPEL){ |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
252 c->sub_motion_search= qpel_motion_search; |
1962 | 253 c->qpel_avg= s->dsp.avg_qpel_pixels_tab; |
254 if(s->no_rounding) c->qpel_put= s->dsp.put_no_rnd_qpel_pixels_tab; | |
255 else c->qpel_put= s->dsp.put_qpel_pixels_tab; | |
936 | 256 }else{ |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
257 if(c->avctx->me_sub_cmp&FF_CMP_CHROMA) |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
258 c->sub_motion_search= hpel_motion_search; |
2967 | 259 else if( c->avctx->me_sub_cmp == FF_CMP_SAD |
260 && c->avctx-> me_cmp == FF_CMP_SAD | |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
261 && c->avctx-> mb_cmp == FF_CMP_SAD) |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
262 c->sub_motion_search= sad_hpel_motion_search; // 2050 vs. 2450 cycles |
936 | 263 else |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
264 c->sub_motion_search= hpel_motion_search; |
936 | 265 } |
2075 | 266 c->hpel_avg= s->dsp.avg_pixels_tab; |
267 if(s->no_rounding) c->hpel_put= s->dsp.put_no_rnd_pixels_tab; | |
268 else c->hpel_put= s->dsp.put_pixels_tab; | |
269 | |
1950 | 270 if(s->linesize){ |
2967 | 271 c->stride = s->linesize; |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
272 c->uvstride= s->uvlinesize; |
954 | 273 }else{ |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
274 c->stride = 16*s->mb_width + 32; |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
275 c->uvstride= 8*s->mb_width + 16; |
1013 | 276 } |
1962 | 277 |
2075 | 278 // 8x8 fullpel search would need a 4x4 chroma compare, which we dont have yet, and even if we had the motion estimation code doesnt expect it |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2184
diff
changeset
|
279 if(s->codec_id != CODEC_ID_SNOW){ |
2643
8e42a0463f68
fix segfault with 'ffmpeg -i 1.avi -cmp 257 -4mv 2.avi'
michael
parents:
2628
diff
changeset
|
280 if((c->avctx->me_cmp&FF_CMP_CHROMA)/* && !s->dsp.me_cmp[2]*/){ |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2184
diff
changeset
|
281 s->dsp.me_cmp[2]= zero_cmp; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2184
diff
changeset
|
282 } |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2184
diff
changeset
|
283 if((c->avctx->me_sub_cmp&FF_CMP_CHROMA) && !s->dsp.me_sub_cmp[2]){ |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2184
diff
changeset
|
284 s->dsp.me_sub_cmp[2]= zero_cmp; |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2184
diff
changeset
|
285 } |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2184
diff
changeset
|
286 c->hpel_put[2][0]= c->hpel_put[2][1]= |
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2184
diff
changeset
|
287 c->hpel_put[2][2]= c->hpel_put[2][3]= zero_hpel; |
2075 | 288 } |
289 | |
2327
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2302
diff
changeset
|
290 if(s->codec_id == CODEC_ID_H261){ |
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2302
diff
changeset
|
291 c->sub_motion_search= no_sub_motion_search; |
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2302
diff
changeset
|
292 } |
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2302
diff
changeset
|
293 |
1962 | 294 c->temp= c->scratchpad; |
936 | 295 } |
2967 | 296 |
1419 | 297 #if 0 |
1064 | 298 static int pix_dev(uint8_t * pix, int line_size, int mean) |
284 | 299 { |
300 int s, i, j; | |
301 | |
302 s = 0; | |
303 for (i = 0; i < 16; i++) { | |
2979 | 304 for (j = 0; j < 16; j += 8) { |
4001 | 305 s += FFABS(pix[0]-mean); |
306 s += FFABS(pix[1]-mean); | |
307 s += FFABS(pix[2]-mean); | |
308 s += FFABS(pix[3]-mean); | |
309 s += FFABS(pix[4]-mean); | |
310 s += FFABS(pix[5]-mean); | |
311 s += FFABS(pix[6]-mean); | |
312 s += FFABS(pix[7]-mean); | |
2979 | 313 pix += 8; |
314 } | |
315 pix += line_size - 16; | |
284 | 316 } |
317 return s; | |
318 } | |
1419 | 319 #endif |
284 | 320 |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
321 static inline void no_motion_search(MpegEncContext * s, |
2979 | 322 int *mx_ptr, int *my_ptr) |
0 | 323 { |
324 *mx_ptr = 16 * s->mb_x; | |
325 *my_ptr = 16 * s->mb_y; | |
326 } | |
327 | |
2522
e25782262d7d
kill warnings patch by (M¸«©ns Rullg¸«©rd <mru inprovide com>)
michael
parents:
2354
diff
changeset
|
328 #if 0 /* the use of these functions is inside #if 0 */ |
0 | 329 static int full_motion_search(MpegEncContext * s, |
330 int *mx_ptr, int *my_ptr, int range, | |
324 | 331 int xmin, int ymin, int xmax, int ymax, uint8_t *ref_picture) |
0 | 332 { |
333 int x1, y1, x2, y2, xx, yy, x, y; | |
334 int mx, my, dmin, d; | |
1064 | 335 uint8_t *pix; |
0 | 336 |
337 xx = 16 * s->mb_x; | |
338 yy = 16 * s->mb_y; | |
2979 | 339 x1 = xx - range + 1; /* we loose one pixel to avoid boundary pb with half pixel pred */ |
0 | 340 if (x1 < xmin) |
2979 | 341 x1 = xmin; |
0 | 342 x2 = xx + range - 1; |
343 if (x2 > xmax) | |
2979 | 344 x2 = xmax; |
0 | 345 y1 = yy - range + 1; |
346 if (y1 < ymin) | |
2979 | 347 y1 = ymin; |
0 | 348 y2 = yy + range - 1; |
349 if (y2 > ymax) | |
2979 | 350 y2 = ymax; |
903 | 351 pix = s->new_picture.data[0] + (yy * s->linesize) + xx; |
0 | 352 dmin = 0x7fffffff; |
353 mx = 0; | |
354 my = 0; | |
355 for (y = y1; y <= y2; y++) { | |
2979 | 356 for (x = x1; x <= x2; x++) { |
357 d = s->dsp.pix_abs[0][0](NULL, pix, ref_picture + (y * s->linesize) + x, | |
358 s->linesize, 16); | |
359 if (d < dmin || | |
360 (d == dmin && | |
361 (abs(x - xx) + abs(y - yy)) < | |
362 (abs(mx - xx) + abs(my - yy)))) { | |
363 dmin = d; | |
364 mx = x; | |
365 my = y; | |
366 } | |
367 } | |
0 | 368 } |
369 | |
370 *mx_ptr = mx; | |
371 *my_ptr = my; | |
372 | |
373 #if 0 | |
374 if (*mx_ptr < -(2 * range) || *mx_ptr >= (2 * range) || | |
2979 | 375 *my_ptr < -(2 * range) || *my_ptr >= (2 * range)) { |
3177 | 376 av_log(NULL, AV_LOG_ERROR, "error %d %d\n", *mx_ptr, *my_ptr); |
0 | 377 } |
378 #endif | |
379 return dmin; | |
380 } | |
381 | |
382 | |
383 static int log_motion_search(MpegEncContext * s, | |
384 int *mx_ptr, int *my_ptr, int range, | |
324 | 385 int xmin, int ymin, int xmax, int ymax, uint8_t *ref_picture) |
0 | 386 { |
387 int x1, y1, x2, y2, xx, yy, x, y; | |
388 int mx, my, dmin, d; | |
1064 | 389 uint8_t *pix; |
0 | 390 |
391 xx = s->mb_x << 4; | |
392 yy = s->mb_y << 4; | |
393 | |
394 /* Left limit */ | |
395 x1 = xx - range; | |
396 if (x1 < xmin) | |
2979 | 397 x1 = xmin; |
0 | 398 |
399 /* Right limit */ | |
400 x2 = xx + range; | |
401 if (x2 > xmax) | |
2979 | 402 x2 = xmax; |
0 | 403 |
404 /* Upper limit */ | |
405 y1 = yy - range; | |
406 if (y1 < ymin) | |
2979 | 407 y1 = ymin; |
0 | 408 |
409 /* Lower limit */ | |
410 y2 = yy + range; | |
411 if (y2 > ymax) | |
2979 | 412 y2 = ymax; |
0 | 413 |
903 | 414 pix = s->new_picture.data[0] + (yy * s->linesize) + xx; |
0 | 415 dmin = 0x7fffffff; |
416 mx = 0; | |
417 my = 0; | |
418 | |
419 do { | |
2979 | 420 for (y = y1; y <= y2; y += range) { |
421 for (x = x1; x <= x2; x += range) { | |
422 d = s->dsp.pix_abs[0][0](NULL, pix, ref_picture + (y * s->linesize) + x, s->linesize, 16); | |
423 if (d < dmin || (d == dmin && (abs(x - xx) + abs(y - yy)) < (abs(mx - xx) + abs(my - yy)))) { | |
424 dmin = d; | |
425 mx = x; | |
426 my = y; | |
427 } | |
428 } | |
429 } | |
0 | 430 |
2979 | 431 range = range >> 1; |
0 | 432 |
2979 | 433 x1 = mx - range; |
434 if (x1 < xmin) | |
435 x1 = xmin; | |
0 | 436 |
2979 | 437 x2 = mx + range; |
438 if (x2 > xmax) | |
439 x2 = xmax; | |
0 | 440 |
2979 | 441 y1 = my - range; |
442 if (y1 < ymin) | |
443 y1 = ymin; | |
0 | 444 |
2979 | 445 y2 = my + range; |
446 if (y2 > ymax) | |
447 y2 = ymax; | |
0 | 448 |
449 } while (range >= 1); | |
450 | |
451 #ifdef DEBUG | |
2846
40765c51a7a9
Compilation fixes part 1 patch by (Arvind R. and Burkhard Plaum, plaum, ipf uni-stuttgart de)
michael
parents:
2834
diff
changeset
|
452 av_log(s->avctx, AV_LOG_DEBUG, "log - MX: %d\tMY: %d\n", mx, my); |
0 | 453 #endif |
454 *mx_ptr = mx; | |
455 *my_ptr = my; | |
456 return dmin; | |
457 } | |
458 | |
459 static int phods_motion_search(MpegEncContext * s, | |
460 int *mx_ptr, int *my_ptr, int range, | |
324 | 461 int xmin, int ymin, int xmax, int ymax, uint8_t *ref_picture) |
0 | 462 { |
463 int x1, y1, x2, y2, xx, yy, x, y, lastx, d; | |
464 int mx, my, dminx, dminy; | |
1064 | 465 uint8_t *pix; |
0 | 466 |
467 xx = s->mb_x << 4; | |
468 yy = s->mb_y << 4; | |
469 | |
470 /* Left limit */ | |
471 x1 = xx - range; | |
472 if (x1 < xmin) | |
2979 | 473 x1 = xmin; |
0 | 474 |
475 /* Right limit */ | |
476 x2 = xx + range; | |
477 if (x2 > xmax) | |
2979 | 478 x2 = xmax; |
0 | 479 |
480 /* Upper limit */ | |
481 y1 = yy - range; | |
482 if (y1 < ymin) | |
2979 | 483 y1 = ymin; |
0 | 484 |
485 /* Lower limit */ | |
486 y2 = yy + range; | |
487 if (y2 > ymax) | |
2979 | 488 y2 = ymax; |
0 | 489 |
903 | 490 pix = s->new_picture.data[0] + (yy * s->linesize) + xx; |
0 | 491 mx = 0; |
492 my = 0; | |
493 | |
494 x = xx; | |
495 y = yy; | |
496 do { | |
497 dminx = 0x7fffffff; | |
498 dminy = 0x7fffffff; | |
499 | |
2979 | 500 lastx = x; |
501 for (x = x1; x <= x2; x += range) { | |
502 d = s->dsp.pix_abs[0][0](NULL, pix, ref_picture + (y * s->linesize) + x, s->linesize, 16); | |
503 if (d < dminx || (d == dminx && (abs(x - xx) + abs(y - yy)) < (abs(mx - xx) + abs(my - yy)))) { | |
504 dminx = d; | |
505 mx = x; | |
506 } | |
507 } | |
0 | 508 |
2979 | 509 x = lastx; |
510 for (y = y1; y <= y2; y += range) { | |
511 d = s->dsp.pix_abs[0][0](NULL, pix, ref_picture + (y * s->linesize) + x, s->linesize, 16); | |
512 if (d < dminy || (d == dminy && (abs(x - xx) + abs(y - yy)) < (abs(mx - xx) + abs(my - yy)))) { | |
513 dminy = d; | |
514 my = y; | |
515 } | |
516 } | |
0 | 517 |
2979 | 518 range = range >> 1; |
0 | 519 |
2979 | 520 x = mx; |
521 y = my; | |
522 x1 = mx - range; | |
523 if (x1 < xmin) | |
524 x1 = xmin; | |
0 | 525 |
2979 | 526 x2 = mx + range; |
527 if (x2 > xmax) | |
528 x2 = xmax; | |
0 | 529 |
2979 | 530 y1 = my - range; |
531 if (y1 < ymin) | |
532 y1 = ymin; | |
0 | 533 |
2979 | 534 y2 = my + range; |
535 if (y2 > ymax) | |
536 y2 = ymax; | |
0 | 537 |
538 } while (range >= 1); | |
539 | |
540 #ifdef DEBUG | |
2846
40765c51a7a9
Compilation fixes part 1 patch by (Arvind R. and Burkhard Plaum, plaum, ipf uni-stuttgart de)
michael
parents:
2834
diff
changeset
|
541 av_log(s->avctx, AV_LOG_DEBUG, "phods - MX: %d\tMY: %d\n", mx, my); |
0 | 542 #endif |
543 | |
544 /* half pixel search */ | |
545 *mx_ptr = mx; | |
546 *my_ptr = my; | |
547 return dminy; | |
548 } | |
2522
e25782262d7d
kill warnings patch by (M¸«©ns Rullg¸«©rd <mru inprovide com>)
michael
parents:
2354
diff
changeset
|
549 #endif /* 0 */ |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
275
diff
changeset
|
550 |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
275
diff
changeset
|
551 #define Z_THRESHOLD 256 |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
275
diff
changeset
|
552 |
936 | 553 #define CHECK_SAD_HALF_MV(suffix, x, y) \ |
455 | 554 {\ |
1708 | 555 d= s->dsp.pix_abs[size][(x?1:0)+(y?2:0)](NULL, pix, ptr+((x)>>1), stride, h);\ |
936 | 556 d += (mv_penalty[pen_x + x] + mv_penalty[pen_y + y])*penalty_factor;\ |
455 | 557 COPY3_IF_LT(dminh, d, dx, x, dy, y)\ |
558 } | |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
275
diff
changeset
|
559 |
936 | 560 static inline int sad_hpel_motion_search(MpegEncContext * s, |
2979 | 561 int *mx_ptr, int *my_ptr, int dmin, |
1950 | 562 int src_index, int ref_index, |
563 int size, int h) | |
0 | 564 { |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
565 MotionEstContext * const c= &s->me; |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
566 const int penalty_factor= c->sub_penalty_factor; |
1708 | 567 int mx, my, dminh; |
1064 | 568 uint8_t *pix, *ptr; |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
569 int stride= c->stride; |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
570 const int flags= c->sub_flags; |
1950 | 571 LOAD_COMMON |
2967 | 572 |
1950 | 573 assert(flags == 0); |
455 | 574 |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
575 if(c->skip){ |
455 | 576 // printf("S"); |
577 *mx_ptr = 0; | |
578 *my_ptr = 0; | |
579 return dmin; | |
580 } | |
581 // printf("N"); | |
2967 | 582 |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
583 pix = c->src[src_index][0]; |
455 | 584 |
294 | 585 mx = *mx_ptr; |
586 my = *my_ptr; | |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
587 ptr = c->ref[ref_index][0] + (my * stride) + mx; |
2967 | 588 |
294 | 589 dminh = dmin; |
590 | |
2967 | 591 if (mx > xmin && mx < xmax && |
294 | 592 my > ymin && my < ymax) { |
455 | 593 int dx=0, dy=0; |
2967 | 594 int d, pen_x, pen_y; |
455 | 595 const int index= (my<<ME_MAP_SHIFT) + mx; |
596 const int t= score_map[(index-(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)]; | |
597 const int l= score_map[(index- 1 )&(ME_MAP_SIZE-1)]; | |
598 const int r= score_map[(index+ 1 )&(ME_MAP_SIZE-1)]; | |
599 const int b= score_map[(index+(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)]; | |
600 mx<<=1; | |
601 my<<=1; | |
294 | 602 |
2967 | 603 |
294 | 604 pen_x= pred_x + mx; |
605 pen_y= pred_y + my; | |
606 | |
1708 | 607 ptr-= stride; |
455 | 608 if(t<=b){ |
936 | 609 CHECK_SAD_HALF_MV(y2 , 0, -1) |
455 | 610 if(l<=r){ |
936 | 611 CHECK_SAD_HALF_MV(xy2, -1, -1) |
455 | 612 if(t+r<=b+l){ |
936 | 613 CHECK_SAD_HALF_MV(xy2, +1, -1) |
1708 | 614 ptr+= stride; |
455 | 615 }else{ |
1708 | 616 ptr+= stride; |
936 | 617 CHECK_SAD_HALF_MV(xy2, -1, +1) |
455 | 618 } |
936 | 619 CHECK_SAD_HALF_MV(x2 , -1, 0) |
455 | 620 }else{ |
936 | 621 CHECK_SAD_HALF_MV(xy2, +1, -1) |
455 | 622 if(t+l<=b+r){ |
936 | 623 CHECK_SAD_HALF_MV(xy2, -1, -1) |
1708 | 624 ptr+= stride; |
455 | 625 }else{ |
1708 | 626 ptr+= stride; |
936 | 627 CHECK_SAD_HALF_MV(xy2, +1, +1) |
455 | 628 } |
936 | 629 CHECK_SAD_HALF_MV(x2 , +1, 0) |
455 | 630 } |
631 }else{ | |
632 if(l<=r){ | |
633 if(t+l<=b+r){ | |
936 | 634 CHECK_SAD_HALF_MV(xy2, -1, -1) |
1708 | 635 ptr+= stride; |
455 | 636 }else{ |
1708 | 637 ptr+= stride; |
936 | 638 CHECK_SAD_HALF_MV(xy2, +1, +1) |
455 | 639 } |
936 | 640 CHECK_SAD_HALF_MV(x2 , -1, 0) |
641 CHECK_SAD_HALF_MV(xy2, -1, +1) | |
455 | 642 }else{ |
643 if(t+r<=b+l){ | |
936 | 644 CHECK_SAD_HALF_MV(xy2, +1, -1) |
1708 | 645 ptr+= stride; |
455 | 646 }else{ |
1708 | 647 ptr+= stride; |
936 | 648 CHECK_SAD_HALF_MV(xy2, -1, +1) |
455 | 649 } |
936 | 650 CHECK_SAD_HALF_MV(x2 , +1, 0) |
651 CHECK_SAD_HALF_MV(xy2, +1, +1) | |
455 | 652 } |
936 | 653 CHECK_SAD_HALF_MV(y2 , 0, +1) |
455 | 654 } |
655 mx+=dx; | |
656 my+=dy; | |
294 | 657 |
658 }else{ | |
455 | 659 mx<<=1; |
660 my<<=1; | |
294 | 661 } |
662 | |
663 *mx_ptr = mx; | |
664 *my_ptr = my; | |
455 | 665 return dminh; |
294 | 666 } |
667 | |
455 | 668 static inline void set_p_mv_tables(MpegEncContext * s, int mx, int my, int mv4) |
294 | 669 { |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1162
diff
changeset
|
670 const int xy= s->mb_x + s->mb_y*s->mb_stride; |
2967 | 671 |
324 | 672 s->p_mv_table[xy][0] = mx; |
673 s->p_mv_table[xy][1] = my; | |
294 | 674 |
2764 | 675 /* has already been set to the 4 MV if 4MV is done */ |
455 | 676 if(mv4){ |
294 | 677 int mot_xy= s->block_index[0]; |
678 | |
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1634
diff
changeset
|
679 s->current_picture.motion_val[0][mot_xy ][0]= mx; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1634
diff
changeset
|
680 s->current_picture.motion_val[0][mot_xy ][1]= my; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1634
diff
changeset
|
681 s->current_picture.motion_val[0][mot_xy+1][0]= mx; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1634
diff
changeset
|
682 s->current_picture.motion_val[0][mot_xy+1][1]= my; |
294 | 683 |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1904
diff
changeset
|
684 mot_xy += s->b8_stride; |
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1634
diff
changeset
|
685 s->current_picture.motion_val[0][mot_xy ][0]= mx; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1634
diff
changeset
|
686 s->current_picture.motion_val[0][mot_xy ][1]= my; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1634
diff
changeset
|
687 s->current_picture.motion_val[0][mot_xy+1][0]= mx; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1634
diff
changeset
|
688 s->current_picture.motion_val[0][mot_xy+1][1]= my; |
294 | 689 } |
690 } | |
691 | |
1086 | 692 /** |
693 * get fullpel ME search limits. | |
694 */ | |
1708 | 695 static inline void get_limits(MpegEncContext *s, int x, int y) |
324 | 696 { |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
697 MotionEstContext * const c= &s->me; |
4304 | 698 int range= c->avctx->me_range >> (1 + !!(c->flags&FLAG_QPEL)); |
1708 | 699 /* |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
700 if(c->avctx->me_range) c->range= c->avctx->me_range >> 1; |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
701 else c->range= 16; |
1708 | 702 */ |
324 | 703 if (s->unrestricted_mv) { |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
704 c->xmin = - x - 16; |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
705 c->ymin = - y - 16; |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
706 c->xmax = - x + s->mb_width *16; |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
707 c->ymax = - y + s->mb_height*16; |
2327
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2302
diff
changeset
|
708 } else if (s->out_format == FMT_H261){ |
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2302
diff
changeset
|
709 // Search range of H261 is different from other codec standards |
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2302
diff
changeset
|
710 c->xmin = (x > 15) ? - 15 : 0; |
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2302
diff
changeset
|
711 c->ymin = (y > 15) ? - 15 : 0; |
2967 | 712 c->xmax = (x < s->mb_width * 16 - 16) ? 15 : 0; |
2327
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2302
diff
changeset
|
713 c->ymax = (y < s->mb_height * 16 - 16) ? 15 : 0; |
324 | 714 } else { |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
715 c->xmin = - x; |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
716 c->ymin = - y; |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
717 c->xmax = - x + s->mb_width *16 - 16; |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
718 c->ymax = - y + s->mb_height*16 - 16; |
324 | 719 } |
4304 | 720 if(range){ |
721 c->xmin = FFMAX(c->xmin,-range); | |
722 c->xmax = FFMIN(c->xmax, range); | |
723 c->ymin = FFMAX(c->ymin,-range); | |
724 c->ymax = FFMIN(c->ymax, range); | |
725 } | |
324 | 726 } |
727 | |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
728 static inline void init_mv4_ref(MotionEstContext *c){ |
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
729 const int stride= c->stride; |
1962 | 730 |
731 c->ref[1][0] = c->ref[0][0] + 8; | |
732 c->ref[2][0] = c->ref[0][0] + 8*stride; | |
733 c->ref[3][0] = c->ref[2][0] + 8; | |
734 c->src[1][0] = c->src[0][0] + 8; | |
735 c->src[2][0] = c->src[0][0] + 8*stride; | |
736 c->src[3][0] = c->src[2][0] + 8; | |
737 } | |
738 | |
1708 | 739 static inline int h263_mv4_search(MpegEncContext *s, int mx, int my, int shift) |
455 | 740 { |
1950 | 741 MotionEstContext * const c= &s->me; |
1708 | 742 const int size= 1; |
743 const int h=8; | |
455 | 744 int block; |
745 int P[10][2]; | |
1013 | 746 int dmin_sum=0, mx4_sum=0, my4_sum=0; |
1494
3ee63c12ea30
optionally try to encode each MB with MV=<0,0> and choose the one with better RD
michaelni
parents:
1426
diff
changeset
|
747 int same=1; |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
748 const int stride= c->stride; |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
749 uint8_t *mv_penalty= c->current_mv_penalty; |
455 | 750 |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
751 init_mv4_ref(c); |
2967 | 752 |
455 | 753 for(block=0; block<4; block++){ |
754 int mx4, my4; | |
755 int pred_x4, pred_y4; | |
756 int dmin4; | |
757 static const int off[4]= {2, 1, 1, -1}; | |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1904
diff
changeset
|
758 const int mot_stride = s->b8_stride; |
455 | 759 const int mot_xy = s->block_index[block]; |
1708 | 760 |
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1634
diff
changeset
|
761 P_LEFT[0] = s->current_picture.motion_val[0][mot_xy - 1][0]; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1634
diff
changeset
|
762 P_LEFT[1] = s->current_picture.motion_val[0][mot_xy - 1][1]; |
455 | 763 |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
764 if(P_LEFT[0] > (c->xmax<<shift)) P_LEFT[0] = (c->xmax<<shift); |
455 | 765 |
766 /* special case for first line */ | |
1799 | 767 if (s->first_slice_line && block<2) { |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
768 c->pred_x= pred_x4= P_LEFT[0]; |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
769 c->pred_y= pred_y4= P_LEFT[1]; |
455 | 770 } else { |
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1634
diff
changeset
|
771 P_TOP[0] = s->current_picture.motion_val[0][mot_xy - mot_stride ][0]; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1634
diff
changeset
|
772 P_TOP[1] = s->current_picture.motion_val[0][mot_xy - mot_stride ][1]; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1634
diff
changeset
|
773 P_TOPRIGHT[0] = s->current_picture.motion_val[0][mot_xy - mot_stride + off[block]][0]; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1634
diff
changeset
|
774 P_TOPRIGHT[1] = s->current_picture.motion_val[0][mot_xy - mot_stride + off[block]][1]; |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
775 if(P_TOP[1] > (c->ymax<<shift)) P_TOP[1] = (c->ymax<<shift); |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
776 if(P_TOPRIGHT[0] < (c->xmin<<shift)) P_TOPRIGHT[0]= (c->xmin<<shift); |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
777 if(P_TOPRIGHT[0] > (c->xmax<<shift)) P_TOPRIGHT[0]= (c->xmax<<shift); |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
778 if(P_TOPRIGHT[1] > (c->ymax<<shift)) P_TOPRIGHT[1]= (c->ymax<<shift); |
2967 | 779 |
455 | 780 P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]); |
781 P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]); | |
782 | |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
783 c->pred_x= pred_x4 = P_MEDIAN[0]; |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
784 c->pred_y= pred_y4 = P_MEDIAN[1]; |
455 | 785 } |
786 P_MV1[0]= mx; | |
787 P_MV1[1]= my; | |
788 | |
1950 | 789 dmin4 = epzs_motion_search4(s, &mx4, &my4, P, block, block, s->p_mv_table, (1<<16)>>shift); |
455 | 790 |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
791 dmin4= c->sub_motion_search(s, &mx4, &my4, dmin4, block, block, size, h); |
2967 | 792 |
1950 | 793 if(s->dsp.me_sub_cmp[0] != s->dsp.mb_cmp[0]){ |
1013 | 794 int dxy; |
1708 | 795 const int offset= ((block&1) + (block>>1)*stride)*8; |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
796 uint8_t *dest_y = c->scratchpad + offset; |
1013 | 797 if(s->quarter_sample){ |
1950 | 798 uint8_t *ref= c->ref[block][0] + (mx4>>2) + (my4>>2)*stride; |
1013 | 799 dxy = ((my4 & 3) << 2) | (mx4 & 3); |
800 | |
801 if(s->no_rounding) | |
1799 | 802 s->dsp.put_no_rnd_qpel_pixels_tab[1][dxy](dest_y , ref , stride); |
1013 | 803 else |
1708 | 804 s->dsp.put_qpel_pixels_tab [1][dxy](dest_y , ref , stride); |
1013 | 805 }else{ |
1950 | 806 uint8_t *ref= c->ref[block][0] + (mx4>>1) + (my4>>1)*stride; |
1013 | 807 dxy = ((my4 & 1) << 1) | (mx4 & 1); |
808 | |
809 if(s->no_rounding) | |
1708 | 810 s->dsp.put_no_rnd_pixels_tab[1][dxy](dest_y , ref , stride, h); |
1013 | 811 else |
1708 | 812 s->dsp.put_pixels_tab [1][dxy](dest_y , ref , stride, h); |
1013 | 813 } |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
814 dmin_sum+= (mv_penalty[mx4-pred_x4] + mv_penalty[my4-pred_y4])*c->mb_penalty_factor; |
1013 | 815 }else |
816 dmin_sum+= dmin4; | |
817 | |
818 if(s->quarter_sample){ | |
819 mx4_sum+= mx4/2; | |
820 my4_sum+= my4/2; | |
821 }else{ | |
822 mx4_sum+= mx4; | |
823 my4_sum+= my4; | |
824 } | |
2967 | 825 |
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1634
diff
changeset
|
826 s->current_picture.motion_val[0][ s->block_index[block] ][0]= mx4; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1634
diff
changeset
|
827 s->current_picture.motion_val[0][ s->block_index[block] ][1]= my4; |
1494
3ee63c12ea30
optionally try to encode each MB with MV=<0,0> and choose the one with better RD
michaelni
parents:
1426
diff
changeset
|
828 |
3ee63c12ea30
optionally try to encode each MB with MV=<0,0> and choose the one with better RD
michaelni
parents:
1426
diff
changeset
|
829 if(mx4 != mx || my4 != my) same=0; |
1013 | 830 } |
2967 | 831 |
1494
3ee63c12ea30
optionally try to encode each MB with MV=<0,0> and choose the one with better RD
michaelni
parents:
1426
diff
changeset
|
832 if(same) |
3ee63c12ea30
optionally try to encode each MB with MV=<0,0> and choose the one with better RD
michaelni
parents:
1426
diff
changeset
|
833 return INT_MAX; |
2967 | 834 |
1038 | 835 if(s->dsp.me_sub_cmp[0] != s->dsp.mb_cmp[0]){ |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
836 dmin_sum += s->dsp.mb_cmp[0](s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*16*stride, c->scratchpad, stride, 16); |
455 | 837 } |
2967 | 838 |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
839 if(c->avctx->mb_cmp&FF_CMP_CHROMA){ |
1013 | 840 int dxy; |
841 int mx, my; | |
842 int offset; | |
843 | |
844 mx= ff_h263_round_chroma(mx4_sum); | |
845 my= ff_h263_round_chroma(my4_sum); | |
846 dxy = ((my & 1) << 1) | (mx & 1); | |
2967 | 847 |
1013 | 848 offset= (s->mb_x*8 + (mx>>1)) + (s->mb_y*8 + (my>>1))*s->uvlinesize; |
2967 | 849 |
1013 | 850 if(s->no_rounding){ |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
851 s->dsp.put_no_rnd_pixels_tab[1][dxy](c->scratchpad , s->last_picture.data[1] + offset, s->uvlinesize, 8); |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
852 s->dsp.put_no_rnd_pixels_tab[1][dxy](c->scratchpad+8 , s->last_picture.data[2] + offset, s->uvlinesize, 8); |
1013 | 853 }else{ |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
854 s->dsp.put_pixels_tab [1][dxy](c->scratchpad , s->last_picture.data[1] + offset, s->uvlinesize, 8); |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
855 s->dsp.put_pixels_tab [1][dxy](c->scratchpad+8 , s->last_picture.data[2] + offset, s->uvlinesize, 8); |
1013 | 856 } |
857 | |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
858 dmin_sum += s->dsp.mb_cmp[1](s, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*8*s->uvlinesize, c->scratchpad , s->uvlinesize, 8); |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
859 dmin_sum += s->dsp.mb_cmp[1](s, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*8*s->uvlinesize, c->scratchpad+8, s->uvlinesize, 8); |
1013 | 860 } |
2967 | 861 |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
862 c->pred_x= mx; |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
863 c->pred_y= my; |
1013 | 864 |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
865 switch(c->avctx->mb_cmp&0xFF){ |
1013 | 866 /*case FF_CMP_SSE: |
867 return dmin_sum+ 32*s->qscale*s->qscale;*/ | |
868 case FF_CMP_RD: | |
869 return dmin_sum; | |
870 default: | |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
871 return dmin_sum+ 11*c->mb_penalty_factor; |
1013 | 872 } |
455 | 873 } |
874 | |
1962 | 875 static inline void init_interlaced_ref(MpegEncContext *s, int ref_index){ |
876 MotionEstContext * const c= &s->me; | |
877 | |
878 c->ref[1+ref_index][0] = c->ref[0+ref_index][0] + s->linesize; | |
879 c->src[1][0] = c->src[0][0] + s->linesize; | |
880 if(c->flags & FLAG_CHROMA){ | |
881 c->ref[1+ref_index][1] = c->ref[0+ref_index][1] + s->uvlinesize; | |
882 c->ref[1+ref_index][2] = c->ref[0+ref_index][2] + s->uvlinesize; | |
883 c->src[1][1] = c->src[0][1] + s->uvlinesize; | |
884 c->src[1][2] = c->src[0][2] + s->uvlinesize; | |
885 } | |
886 } | |
887 | |
2967 | 888 static int interlaced_search(MpegEncContext *s, int ref_index, |
1968
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
889 int16_t (*mv_tables[2][2])[2], uint8_t *field_select_tables[2], int mx, int my, int user_field_select) |
1708 | 890 { |
1950 | 891 MotionEstContext * const c= &s->me; |
1708 | 892 const int size=0; |
893 const int h=8; | |
894 int block; | |
895 int P[10][2]; | |
1950 | 896 uint8_t * const mv_penalty= c->current_mv_penalty; |
1708 | 897 int same=1; |
898 const int stride= 2*s->linesize; | |
899 int dmin_sum= 0; | |
900 const int mot_stride= s->mb_stride; | |
901 const int xy= s->mb_x + s->mb_y*mot_stride; | |
2967 | 902 |
1950 | 903 c->ymin>>=1; |
904 c->ymax>>=1; | |
905 c->stride<<=1; | |
906 c->uvstride<<=1; | |
1962 | 907 init_interlaced_ref(s, ref_index); |
2967 | 908 |
1708 | 909 for(block=0; block<2; block++){ |
910 int field_select; | |
911 int best_dmin= INT_MAX; | |
912 int best_field= -1; | |
913 | |
914 for(field_select=0; field_select<2; field_select++){ | |
1950 | 915 int dmin, mx_i, my_i; |
1708 | 916 int16_t (*mv_table)[2]= mv_tables[block][field_select]; |
2967 | 917 |
1968
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
918 if(user_field_select){ |
3188
04636faaa720
asserts to check if assumed conditions really are true
michael
parents:
3177
diff
changeset
|
919 assert(field_select==0 || field_select==1); |
04636faaa720
asserts to check if assumed conditions really are true
michael
parents:
3177
diff
changeset
|
920 assert(field_select_tables[block][xy]==0 || field_select_tables[block][xy]==1); |
1968
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
921 if(field_select_tables[block][xy] != field_select) |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
922 continue; |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
923 } |
2967 | 924 |
1708 | 925 P_LEFT[0] = mv_table[xy - 1][0]; |
926 P_LEFT[1] = mv_table[xy - 1][1]; | |
1950 | 927 if(P_LEFT[0] > (c->xmax<<1)) P_LEFT[0] = (c->xmax<<1); |
2967 | 928 |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
929 c->pred_x= P_LEFT[0]; |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
930 c->pred_y= P_LEFT[1]; |
2967 | 931 |
1799 | 932 if(!s->first_slice_line){ |
1708 | 933 P_TOP[0] = mv_table[xy - mot_stride][0]; |
934 P_TOP[1] = mv_table[xy - mot_stride][1]; | |
935 P_TOPRIGHT[0] = mv_table[xy - mot_stride + 1][0]; | |
936 P_TOPRIGHT[1] = mv_table[xy - mot_stride + 1][1]; | |
1950 | 937 if(P_TOP[1] > (c->ymax<<1)) P_TOP[1] = (c->ymax<<1); |
938 if(P_TOPRIGHT[0] < (c->xmin<<1)) P_TOPRIGHT[0]= (c->xmin<<1); | |
939 if(P_TOPRIGHT[0] > (c->xmax<<1)) P_TOPRIGHT[0]= (c->xmax<<1); | |
940 if(P_TOPRIGHT[1] > (c->ymax<<1)) P_TOPRIGHT[1]= (c->ymax<<1); | |
2967 | 941 |
1708 | 942 P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]); |
943 P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]); | |
944 } | |
945 P_MV1[0]= mx; //FIXME not correct if block != field_select | |
946 P_MV1[1]= my / 2; | |
2967 | 947 |
1950 | 948 dmin = epzs_motion_search2(s, &mx_i, &my_i, P, block, field_select+ref_index, mv_table, (1<<16)>>1); |
1708 | 949 |
1950 | 950 dmin= c->sub_motion_search(s, &mx_i, &my_i, dmin, block, field_select+ref_index, size, h); |
2967 | 951 |
1708 | 952 mv_table[xy][0]= mx_i; |
953 mv_table[xy][1]= my_i; | |
2967 | 954 |
1950 | 955 if(s->dsp.me_sub_cmp[0] != s->dsp.mb_cmp[0]){ |
1708 | 956 int dxy; |
957 | |
958 //FIXME chroma ME | |
1950 | 959 uint8_t *ref= c->ref[field_select+ref_index][0] + (mx_i>>1) + (my_i>>1)*stride; |
1708 | 960 dxy = ((my_i & 1) << 1) | (mx_i & 1); |
961 | |
962 if(s->no_rounding){ | |
1950 | 963 s->dsp.put_no_rnd_pixels_tab[size][dxy](c->scratchpad, ref , stride, h); |
1708 | 964 }else{ |
1950 | 965 s->dsp.put_pixels_tab [size][dxy](c->scratchpad, ref , stride, h); |
1708 | 966 } |
1950 | 967 dmin= s->dsp.mb_cmp[size](s, c->src[block][0], c->scratchpad, stride, h); |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
968 dmin+= (mv_penalty[mx_i-c->pred_x] + mv_penalty[my_i-c->pred_y] + 1)*c->mb_penalty_factor; |
1708 | 969 }else |
1950 | 970 dmin+= c->mb_penalty_factor; //field_select bits |
2967 | 971 |
1708 | 972 dmin += field_select != block; //slightly prefer same field |
2967 | 973 |
1708 | 974 if(dmin < best_dmin){ |
975 best_dmin= dmin; | |
976 best_field= field_select; | |
977 } | |
978 } | |
979 { | |
980 int16_t (*mv_table)[2]= mv_tables[block][best_field]; | |
981 | |
982 if(mv_table[xy][0] != mx) same=0; //FIXME check if these checks work and are any good at all | |
983 if(mv_table[xy][1]&1) same=0; | |
2967 | 984 if(mv_table[xy][1]*2 != my) same=0; |
1708 | 985 if(best_field != block) same=0; |
986 } | |
987 | |
988 field_select_tables[block][xy]= best_field; | |
989 dmin_sum += best_dmin; | |
990 } | |
2967 | 991 |
1950 | 992 c->ymin<<=1; |
993 c->ymax<<=1; | |
994 c->stride>>=1; | |
995 c->uvstride>>=1; | |
1708 | 996 |
997 if(same) | |
998 return INT_MAX; | |
2967 | 999 |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
1000 switch(c->avctx->mb_cmp&0xFF){ |
1708 | 1001 /*case FF_CMP_SSE: |
1002 return dmin_sum+ 32*s->qscale*s->qscale;*/ | |
1003 case FF_CMP_RD: | |
1004 return dmin_sum; | |
1005 default: | |
1950 | 1006 return dmin_sum+ 11*c->mb_penalty_factor; |
1708 | 1007 } |
1008 } | |
1009 | |
2072 | 1010 static void clip_input_mv(MpegEncContext * s, int16_t *mv, int interlaced){ |
1011 int ymax= s->me.ymax>>interlaced; | |
1012 int ymin= s->me.ymin>>interlaced; | |
2967 | 1013 |
2072 | 1014 if(mv[0] < s->me.xmin) mv[0] = s->me.xmin; |
1015 if(mv[0] > s->me.xmax) mv[0] = s->me.xmax; | |
1016 if(mv[1] < ymin) mv[1] = ymin; | |
1017 if(mv[1] > ymax) mv[1] = ymax; | |
1018 } | |
1019 | |
1955
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1020 static inline int check_input_motion(MpegEncContext * s, int mb_x, int mb_y, int p_type){ |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1021 MotionEstContext * const c= &s->me; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1022 Picture *p= s->current_picture_ptr; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1023 int mb_xy= mb_x + mb_y*s->mb_stride; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1024 int xy= 2*mb_x + 2*mb_y*s->b8_stride; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1025 int mb_type= s->current_picture.mb_type[mb_xy]; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1026 int flags= c->flags; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1027 int shift= (flags&FLAG_QPEL) + 1; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1028 int mask= (1<<shift)-1; |
1962 | 1029 int x, y, i; |
1955
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1030 int d=0; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1031 me_cmp_func cmpf= s->dsp.sse[0]; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1032 me_cmp_func chroma_cmpf= s->dsp.sse[1]; |
2967 | 1033 |
2072 | 1034 if(p_type && USES_LIST(mb_type, 1)){ |
1035 av_log(c->avctx, AV_LOG_ERROR, "backward motion vector in P frame\n"); | |
2576
e237d9bd0f8c
check mb/me_threshold range, fixes assertion failure
michael
parents:
2522
diff
changeset
|
1036 return INT_MAX/2; |
2072 | 1037 } |
1955
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1038 assert(IS_INTRA(mb_type) || USES_LIST(mb_type,0) || USES_LIST(mb_type,1)); |
2967 | 1039 |
2072 | 1040 for(i=0; i<4; i++){ |
1041 int xy= s->block_index[i]; | |
1042 clip_input_mv(s, p->motion_val[0][xy], !!IS_INTERLACED(mb_type)); | |
1043 clip_input_mv(s, p->motion_val[1][xy], !!IS_INTERLACED(mb_type)); | |
1044 } | |
1045 | |
1955
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1046 if(IS_INTERLACED(mb_type)){ |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1047 int xy2= xy + s->b8_stride; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1048 s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTRA; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1049 c->stride<<=1; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1050 c->uvstride<<=1; |
2967 | 1051 |
1995 | 1052 if(!(s->flags & CODEC_FLAG_INTERLACED_ME)){ |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
1053 av_log(c->avctx, AV_LOG_ERROR, "Interlaced macroblock selected but interlaced motion estimation disabled\n"); |
2576
e237d9bd0f8c
check mb/me_threshold range, fixes assertion failure
michael
parents:
2522
diff
changeset
|
1054 return INT_MAX/2; |
1995 | 1055 } |
1962 | 1056 |
1955
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1057 if(USES_LIST(mb_type, 0)){ |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1058 int field_select0= p->ref_index[0][xy ]; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1059 int field_select1= p->ref_index[0][xy2]; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1060 assert(field_select0==0 ||field_select0==1); |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1061 assert(field_select1==0 ||field_select1==1); |
1968
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1062 init_interlaced_ref(s, 0); |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1063 |
1955
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1064 if(p_type){ |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1065 s->p_field_select_table[0][mb_xy]= field_select0; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1066 s->p_field_select_table[1][mb_xy]= field_select1; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1067 *(uint32_t*)s->p_field_mv_table[0][field_select0][mb_xy]= *(uint32_t*)p->motion_val[0][xy ]; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1068 *(uint32_t*)s->p_field_mv_table[1][field_select1][mb_xy]= *(uint32_t*)p->motion_val[0][xy2]; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1069 s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTER_I; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1070 }else{ |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1071 s->b_field_select_table[0][0][mb_xy]= field_select0; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1072 s->b_field_select_table[0][1][mb_xy]= field_select1; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1073 *(uint32_t*)s->b_field_mv_table[0][0][field_select0][mb_xy]= *(uint32_t*)p->motion_val[0][xy ]; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1074 *(uint32_t*)s->b_field_mv_table[0][1][field_select1][mb_xy]= *(uint32_t*)p->motion_val[0][xy2]; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1075 s->mb_type[mb_xy]= CANDIDATE_MB_TYPE_FORWARD_I; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1076 } |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1077 |
2967 | 1078 x= p->motion_val[0][xy ][0]; |
1955
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1079 y= p->motion_val[0][xy ][1]; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1080 d = cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 8, field_select0, 0, cmpf, chroma_cmpf, flags); |
2967 | 1081 x= p->motion_val[0][xy2][0]; |
1955
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1082 y= p->motion_val[0][xy2][1]; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1083 d+= cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 8, field_select1, 1, cmpf, chroma_cmpf, flags); |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1084 } |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1085 if(USES_LIST(mb_type, 1)){ |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1086 int field_select0= p->ref_index[1][xy ]; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1087 int field_select1= p->ref_index[1][xy2]; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1088 assert(field_select0==0 ||field_select0==1); |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1089 assert(field_select1==0 ||field_select1==1); |
1968
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1090 init_interlaced_ref(s, 2); |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1091 |
1955
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1092 s->b_field_select_table[1][0][mb_xy]= field_select0; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1093 s->b_field_select_table[1][1][mb_xy]= field_select1; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1094 *(uint32_t*)s->b_field_mv_table[1][0][field_select0][mb_xy]= *(uint32_t*)p->motion_val[1][xy ]; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1095 *(uint32_t*)s->b_field_mv_table[1][1][field_select1][mb_xy]= *(uint32_t*)p->motion_val[1][xy2]; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1096 if(USES_LIST(mb_type, 0)){ |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1097 s->mb_type[mb_xy]= CANDIDATE_MB_TYPE_BIDIR_I; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1098 }else{ |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1099 s->mb_type[mb_xy]= CANDIDATE_MB_TYPE_BACKWARD_I; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1100 } |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1101 |
2967 | 1102 x= p->motion_val[1][xy ][0]; |
1955
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1103 y= p->motion_val[1][xy ][1]; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1104 d = cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 8, field_select0+2, 0, cmpf, chroma_cmpf, flags); |
2967 | 1105 x= p->motion_val[1][xy2][0]; |
1955
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1106 y= p->motion_val[1][xy2][1]; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1107 d+= cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 8, field_select1+2, 1, cmpf, chroma_cmpf, flags); |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1108 //FIXME bidir scores |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1109 } |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1110 c->stride>>=1; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1111 c->uvstride>>=1; |
1962 | 1112 }else if(IS_8X8(mb_type)){ |
1995 | 1113 if(!(s->flags & CODEC_FLAG_4MV)){ |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
1114 av_log(c->avctx, AV_LOG_ERROR, "4MV macroblock selected but 4MV encoding disabled\n"); |
2576
e237d9bd0f8c
check mb/me_threshold range, fixes assertion failure
michael
parents:
2522
diff
changeset
|
1115 return INT_MAX/2; |
1995 | 1116 } |
1962 | 1117 cmpf= s->dsp.sse[1]; |
1118 chroma_cmpf= s->dsp.sse[1]; | |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
1119 init_mv4_ref(c); |
1962 | 1120 for(i=0; i<4; i++){ |
1121 xy= s->block_index[i]; | |
2967 | 1122 x= p->motion_val[0][xy][0]; |
1962 | 1123 y= p->motion_val[0][xy][1]; |
1124 d+= cmp(s, x>>shift, y>>shift, x&mask, y&mask, 1, 8, i, i, cmpf, chroma_cmpf, flags); | |
1125 } | |
1126 s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTER4V; | |
1955
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1127 }else{ |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1128 if(USES_LIST(mb_type, 0)){ |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1129 if(p_type){ |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1130 *(uint32_t*)s->p_mv_table[mb_xy]= *(uint32_t*)p->motion_val[0][xy]; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1131 s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTER; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1132 }else if(USES_LIST(mb_type, 1)){ |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1133 *(uint32_t*)s->b_bidir_forw_mv_table[mb_xy]= *(uint32_t*)p->motion_val[0][xy]; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1134 *(uint32_t*)s->b_bidir_back_mv_table[mb_xy]= *(uint32_t*)p->motion_val[1][xy]; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1135 s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_BIDIR; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1136 }else{ |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1137 *(uint32_t*)s->b_forw_mv_table[mb_xy]= *(uint32_t*)p->motion_val[0][xy]; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1138 s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_FORWARD; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1139 } |
2967 | 1140 x= p->motion_val[0][xy][0]; |
1955
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1141 y= p->motion_val[0][xy][1]; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1142 d = cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 16, 0, 0, cmpf, chroma_cmpf, flags); |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1143 }else if(USES_LIST(mb_type, 1)){ |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1144 *(uint32_t*)s->b_back_mv_table[mb_xy]= *(uint32_t*)p->motion_val[1][xy]; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1145 s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_BACKWARD; |
2967 | 1146 |
1147 x= p->motion_val[1][xy][0]; | |
1955
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1148 y= p->motion_val[1][xy][1]; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1149 d = cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 16, 2, 0, cmpf, chroma_cmpf, flags); |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1150 }else |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1151 s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTRA; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1152 } |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1153 return d; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1154 } |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1155 |
324 | 1156 void ff_estimate_p_frame_motion(MpegEncContext * s, |
1157 int mb_x, int mb_y) | |
0 | 1158 { |
1950 | 1159 MotionEstContext * const c= &s->me; |
1064 | 1160 uint8_t *pix, *ppix; |
4299
ffa6f24a0c0f
Doxygen comments about variables described by Michael here:
gpoirier
parents:
4283
diff
changeset
|
1161 int sum, mx, my, dmin; |
ffa6f24a0c0f
Doxygen comments about variables described by Michael here:
gpoirier
parents:
4283
diff
changeset
|
1162 int varc; ///< the variance of the block (sum of squared (p[y][x]-average)) |
ffa6f24a0c0f
Doxygen comments about variables described by Michael here:
gpoirier
parents:
4283
diff
changeset
|
1163 int vard; ///< sum of squared differences with the estimated motion vector |
455 | 1164 int P[10][2]; |
280 | 1165 const int shift= 1+s->quarter_sample; |
294 | 1166 int mb_type=0; |
903 | 1167 Picture * const pic= &s->current_picture; |
2967 | 1168 |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1169 init_ref(c, s->new_picture.data, s->last_picture.data, NULL, 16*mb_x, 16*mb_y, 0); |
1708 | 1170 |
936 | 1171 assert(s->quarter_sample==0 || s->quarter_sample==1); |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1172 assert(s->linesize == c->stride); |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1173 assert(s->uvlinesize == c->uvstride); |
936 | 1174 |
2184 | 1175 c->penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_cmp); |
1176 c->sub_penalty_factor= get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_sub_cmp); | |
1177 c->mb_penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->mb_cmp); | |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1178 c->current_mv_penalty= c->mv_penalty[s->f_code] + MAX_MV; |
0 | 1179 |
1708 | 1180 get_limits(s, 16*mb_x, 16*mb_y); |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1181 c->skip=0; |
324 | 1182 |
1968
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1183 /* intra / predictive decision */ |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1184 pix = c->src[0][0]; |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1185 sum = s->dsp.pix_sum(pix, s->linesize); |
2987 | 1186 varc = s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)(sum*sum))>>8) + 500; |
1968
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1187 |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1188 pic->mb_mean[s->mb_stride * mb_y + mb_x] = (sum+128)>>8; |
2987 | 1189 pic->mb_var [s->mb_stride * mb_y + mb_x] = (varc+128)>>8; |
1190 c->mb_var_sum_temp += (varc+128)>>8; | |
1968
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1191 |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
1192 if(c->avctx->me_threshold){ |
2987 | 1193 vard= check_input_motion(s, mb_x, mb_y, 1); |
2967 | 1194 |
2987 | 1195 if((vard+128)>>8 < c->avctx->me_threshold){ |
4126 | 1196 int p_score= FFMIN(vard, varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*100); |
1197 int i_score= varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*20; | |
2987 | 1198 pic->mc_mb_var[s->mb_stride * mb_y + mb_x] = (vard+128)>>8; |
1199 c->mc_mb_var_sum_temp += (vard+128)>>8; | |
4126 | 1200 c->scene_change_score+= ff_sqrt(p_score) - ff_sqrt(i_score); |
1955
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1201 return; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1202 } |
2987 | 1203 if((vard+128)>>8 < c->avctx->mb_threshold) |
1968
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1204 mb_type= s->mb_type[mb_x + mb_y*s->mb_stride]; |
1955
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1205 } |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1206 |
320
cda7d0857baf
- ME setting moved to AVCodecContext/MpegEncContext, no longer a global.
pulento
parents:
304
diff
changeset
|
1207 switch(s->me_method) { |
0 | 1208 case ME_ZERO: |
1209 default: | |
2979 | 1210 no_motion_search(s, &mx, &my); |
455 | 1211 mx-= mb_x*16; |
1212 my-= mb_y*16; | |
0 | 1213 dmin = 0; |
1214 break; | |
1708 | 1215 #if 0 |
0 | 1216 case ME_FULL: |
2979 | 1217 dmin = full_motion_search(s, &mx, &my, range, ref_picture); |
455 | 1218 mx-= mb_x*16; |
1219 my-= mb_y*16; | |
0 | 1220 break; |
1221 case ME_LOG: | |
2979 | 1222 dmin = log_motion_search(s, &mx, &my, range / 2, ref_picture); |
455 | 1223 mx-= mb_x*16; |
1224 my-= mb_y*16; | |
0 | 1225 break; |
1226 case ME_PHODS: | |
2979 | 1227 dmin = phods_motion_search(s, &mx, &my, range / 2, ref_picture); |
455 | 1228 mx-= mb_x*16; |
1229 my-= mb_y*16; | |
0 | 1230 break; |
1708 | 1231 #endif |
288 | 1232 case ME_X1: |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
275
diff
changeset
|
1233 case ME_EPZS: |
288 | 1234 { |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1904
diff
changeset
|
1235 const int mot_stride = s->b8_stride; |
294 | 1236 const int mot_xy = s->block_index[0]; |
288 | 1237 |
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1634
diff
changeset
|
1238 P_LEFT[0] = s->current_picture.motion_val[0][mot_xy - 1][0]; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1634
diff
changeset
|
1239 P_LEFT[1] = s->current_picture.motion_val[0][mot_xy - 1][1]; |
288 | 1240 |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1241 if(P_LEFT[0] > (c->xmax<<shift)) P_LEFT[0] = (c->xmax<<shift); |
280 | 1242 |
1799 | 1243 if(!s->first_slice_line) { |
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1634
diff
changeset
|
1244 P_TOP[0] = s->current_picture.motion_val[0][mot_xy - mot_stride ][0]; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1634
diff
changeset
|
1245 P_TOP[1] = s->current_picture.motion_val[0][mot_xy - mot_stride ][1]; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1634
diff
changeset
|
1246 P_TOPRIGHT[0] = s->current_picture.motion_val[0][mot_xy - mot_stride + 2][0]; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1634
diff
changeset
|
1247 P_TOPRIGHT[1] = s->current_picture.motion_val[0][mot_xy - mot_stride + 2][1]; |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1248 if(P_TOP[1] > (c->ymax<<shift)) P_TOP[1] = (c->ymax<<shift); |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1249 if(P_TOPRIGHT[0] < (c->xmin<<shift)) P_TOPRIGHT[0]= (c->xmin<<shift); |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1250 if(P_TOPRIGHT[1] > (c->ymax<<shift)) P_TOPRIGHT[1]= (c->ymax<<shift); |
2967 | 1251 |
455 | 1252 P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]); |
1253 P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]); | |
1254 | |
1255 if(s->out_format == FMT_H263){ | |
1950 | 1256 c->pred_x = P_MEDIAN[0]; |
1257 c->pred_y = P_MEDIAN[1]; | |
455 | 1258 }else { /* mpeg1 at least */ |
1950 | 1259 c->pred_x= P_LEFT[0]; |
1260 c->pred_y= P_LEFT[1]; | |
455 | 1261 } |
952 | 1262 }else{ |
1950 | 1263 c->pred_x= P_LEFT[0]; |
1264 c->pred_y= P_LEFT[1]; | |
288 | 1265 } |
952 | 1266 |
280 | 1267 } |
2967 | 1268 dmin = ff_epzs_motion_search(s, &mx, &my, P, 0, 0, s->p_mv_table, (1<<16)>>shift, 0, 16); |
1950 | 1269 |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
275
diff
changeset
|
1270 break; |
0 | 1271 } |
1272 | |
455 | 1273 /* At this point (mx,my) are full-pell and the relative displacement */ |
1950 | 1274 ppix = c->ref[0][0] + (my * s->linesize) + mx; |
2967 | 1275 |
2987 | 1276 vard = s->dsp.sse[0](NULL, pix, ppix, s->linesize, 16); |
608 | 1277 |
2987 | 1278 pic->mc_mb_var[s->mb_stride * mb_y + mb_x] = (vard+128)>>8; |
2967 | 1279 // pic->mb_cmp_score[s->mb_stride * mb_y + mb_x] = dmin; |
2987 | 1280 c->mc_mb_var_sum_temp += (vard+128)>>8; |
2967 | 1281 |
0 | 1282 #if 0 |
233
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
1283 printf("varc=%4d avg_var=%4d (sum=%4d) vard=%4d mx=%2d my=%2d\n", |
2979 | 1284 varc, s->avg_mb_var, sum, vard, mx - xx, my - yy); |
0 | 1285 #endif |
1968
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1286 if(mb_type){ |
4126 | 1287 int p_score= FFMIN(vard, varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*100); |
1288 int i_score= varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*20; | |
1289 c->scene_change_score+= ff_sqrt(p_score) - ff_sqrt(i_score); | |
1968
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1290 |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1291 if(mb_type == CANDIDATE_MB_TYPE_INTER){ |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1292 c->sub_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16); |
1968
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1293 set_p_mv_tables(s, mx, my, 1); |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1294 }else{ |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1295 mx <<=shift; |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1296 my <<=shift; |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1297 } |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1298 if(mb_type == CANDIDATE_MB_TYPE_INTER4V){ |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1299 h263_mv4_search(s, mx, my, shift); |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1300 |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1301 set_p_mv_tables(s, mx, my, 0); |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1302 } |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1303 if(mb_type == CANDIDATE_MB_TYPE_INTER_I){ |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1304 interlaced_search(s, 0, s->p_field_mv_table, s->p_field_select_table, mx, my, 1); |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1305 } |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
1306 }else if(c->avctx->mb_decision > FF_MB_DECISION_SIMPLE){ |
4126 | 1307 int p_score= FFMIN(vard, varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*100); |
1308 int i_score= varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*20; | |
1309 c->scene_change_score+= ff_sqrt(p_score) - ff_sqrt(i_score); | |
608 | 1310 |
2987 | 1311 if (vard*2 + 200*256 > varc) |
1708 | 1312 mb_type|= CANDIDATE_MB_TYPE_INTRA; |
4100
bfab45292f1b
CANDIDATE_MB_TYPE_INTER heuristic doesnt work at really low quality where the distortion becomes less relevant then the overhead of intra blocks
michael
parents:
4001
diff
changeset
|
1313 if (varc*2 + 200*256 > vard || s->qscale > 24){ |
bfab45292f1b
CANDIDATE_MB_TYPE_INTER heuristic doesnt work at really low quality where the distortion becomes less relevant then the overhead of intra blocks
michael
parents:
4001
diff
changeset
|
1314 // if (varc*2 + 200*256 + 50*(s->lambda2>>FF_LAMBDA_SHIFT) > vard){ |
1708 | 1315 mb_type|= CANDIDATE_MB_TYPE_INTER; |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1316 c->sub_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16); |
1494
3ee63c12ea30
optionally try to encode each MB with MV=<0,0> and choose the one with better RD
michaelni
parents:
1426
diff
changeset
|
1317 if(s->flags&CODEC_FLAG_MV0) |
3ee63c12ea30
optionally try to encode each MB with MV=<0,0> and choose the one with better RD
michaelni
parents:
1426
diff
changeset
|
1318 if(mx || my) |
2628
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2576
diff
changeset
|
1319 mb_type |= CANDIDATE_MB_TYPE_SKIPPED; //FIXME check difference |
304 | 1320 }else{ |
936 | 1321 mx <<=shift; |
1322 my <<=shift; | |
0 | 1323 } |
455 | 1324 if((s->flags&CODEC_FLAG_4MV) |
2987 | 1325 && !c->skip && varc>50<<8 && vard>10<<8){ |
1708 | 1326 if(h263_mv4_search(s, mx, my, shift) < INT_MAX) |
1327 mb_type|=CANDIDATE_MB_TYPE_INTER4V; | |
455 | 1328 |
1329 set_p_mv_tables(s, mx, my, 0); | |
1330 }else | |
1331 set_p_mv_tables(s, mx, my, 1); | |
1708 | 1332 if((s->flags&CODEC_FLAG_INTERLACED_ME) |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1333 && !c->skip){ //FIXME varc/d checks |
1968
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1334 if(interlaced_search(s, 0, s->p_field_mv_table, s->p_field_select_table, mx, my, 0) < INT_MAX) |
1708 | 1335 mb_type |= CANDIDATE_MB_TYPE_INTER_I; |
1336 } | |
294 | 1337 }else{ |
1633 | 1338 int intra_score, i; |
1708 | 1339 mb_type= CANDIDATE_MB_TYPE_INTER; |
1013 | 1340 |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1341 dmin= c->sub_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16); |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
1342 if(c->avctx->me_sub_cmp != c->avctx->mb_cmp && !c->skip) |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2184
diff
changeset
|
1343 dmin= ff_get_mb_score(s, mx, my, 0, 0, 0, 16, 1); |
1013 | 1344 |
1345 if((s->flags&CODEC_FLAG_4MV) | |
2987 | 1346 && !c->skip && varc>50<<8 && vard>10<<8){ |
1708 | 1347 int dmin4= h263_mv4_search(s, mx, my, shift); |
1013 | 1348 if(dmin4 < dmin){ |
1708 | 1349 mb_type= CANDIDATE_MB_TYPE_INTER4V; |
1013 | 1350 dmin=dmin4; |
1351 } | |
1352 } | |
1708 | 1353 if((s->flags&CODEC_FLAG_INTERLACED_ME) |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1354 && !c->skip){ //FIXME varc/d checks |
1968
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1355 int dmin_i= interlaced_search(s, 0, s->p_field_mv_table, s->p_field_select_table, mx, my, 0); |
1708 | 1356 if(dmin_i < dmin){ |
1357 mb_type = CANDIDATE_MB_TYPE_INTER_I; | |
1358 dmin= dmin_i; | |
1359 } | |
1360 } | |
2967 | 1361 |
1362 // pic->mb_cmp_score[s->mb_stride * mb_y + mb_x] = dmin; | |
1708 | 1363 set_p_mv_tables(s, mx, my, mb_type!=CANDIDATE_MB_TYPE_INTER4V); |
1633 | 1364 |
1365 /* get intra luma score */ | |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
1366 if((c->avctx->mb_cmp&0xFF)==FF_CMP_SSE){ |
2987 | 1367 intra_score= varc - 500; |
1633 | 1368 }else{ |
1369 int mean= (sum+128)>>8; | |
1370 mean*= 0x01010101; | |
2967 | 1371 |
1633 | 1372 for(i=0; i<16; i++){ |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1373 *(uint32_t*)(&c->scratchpad[i*s->linesize+ 0]) = mean; |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1374 *(uint32_t*)(&c->scratchpad[i*s->linesize+ 4]) = mean; |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1375 *(uint32_t*)(&c->scratchpad[i*s->linesize+ 8]) = mean; |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1376 *(uint32_t*)(&c->scratchpad[i*s->linesize+12]) = mean; |
1633 | 1377 } |
1378 | |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1379 intra_score= s->dsp.mb_cmp[0](s, c->scratchpad, pix, s->linesize, 16); |
1633 | 1380 } |
1381 #if 0 //FIXME | |
1382 /* get chroma score */ | |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
1383 if(c->avctx->mb_cmp&FF_CMP_CHROMA){ |
1633 | 1384 for(i=1; i<3; i++){ |
1385 uint8_t *dest_c; | |
1386 int mean; | |
2967 | 1387 |
1633 | 1388 if(s->out_format == FMT_H263){ |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1904
diff
changeset
|
1389 mean= (s->dc_val[i][mb_x + mb_y*s->b8_stride] + 4)>>3; //FIXME not exact but simple ;) |
1633 | 1390 }else{ |
1391 mean= (s->last_dc[i] + 4)>>3; | |
1392 } | |
1393 dest_c = s->new_picture.data[i] + (mb_y * 8 * (s->uvlinesize)) + mb_x * 8; | |
2967 | 1394 |
1633 | 1395 mean*= 0x01010101; |
1396 for(i=0; i<8; i++){ | |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1397 *(uint32_t*)(&c->scratchpad[i*s->uvlinesize+ 0]) = mean; |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1398 *(uint32_t*)(&c->scratchpad[i*s->uvlinesize+ 4]) = mean; |
1633 | 1399 } |
2967 | 1400 |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1401 intra_score+= s->dsp.mb_cmp[1](s, c->scratchpad, dest_c, s->uvlinesize); |
2967 | 1402 } |
1633 | 1403 } |
1404 #endif | |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1405 intra_score += c->mb_penalty_factor*16; |
2967 | 1406 |
1633 | 1407 if(intra_score < dmin){ |
1708 | 1408 mb_type= CANDIDATE_MB_TYPE_INTRA; |
1409 s->current_picture.mb_type[mb_y*s->mb_stride + mb_x]= CANDIDATE_MB_TYPE_INTRA; //FIXME cleanup | |
1633 | 1410 }else |
1411 s->current_picture.mb_type[mb_y*s->mb_stride + mb_x]= 0; | |
2967 | 1412 |
4126 | 1413 { |
1414 int p_score= FFMIN(vard, varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*100); | |
1415 int i_score= varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*20; | |
1416 c->scene_change_score+= ff_sqrt(p_score) - ff_sqrt(i_score); | |
294 | 1417 } |
1418 } | |
284 | 1419 |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1162
diff
changeset
|
1420 s->mb_type[mb_y*s->mb_stride + mb_x]= mb_type; |
0 | 1421 } |
1422 | |
951 | 1423 int ff_pre_estimate_p_frame_motion(MpegEncContext * s, |
1424 int mb_x, int mb_y) | |
1425 { | |
1950 | 1426 MotionEstContext * const c= &s->me; |
1708 | 1427 int mx, my, dmin; |
951 | 1428 int P[10][2]; |
1429 const int shift= 1+s->quarter_sample; | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1162
diff
changeset
|
1430 const int xy= mb_x + mb_y*s->mb_stride; |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1431 init_ref(c, s->new_picture.data, s->last_picture.data, NULL, 16*mb_x, 16*mb_y, 0); |
2967 | 1432 |
951 | 1433 assert(s->quarter_sample==0 || s->quarter_sample==1); |
1434 | |
2184 | 1435 c->pre_penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_pre_cmp); |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1436 c->current_mv_penalty= c->mv_penalty[s->f_code] + MAX_MV; |
951 | 1437 |
1708 | 1438 get_limits(s, 16*mb_x, 16*mb_y); |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1439 c->skip=0; |
951 | 1440 |
1441 P_LEFT[0] = s->p_mv_table[xy + 1][0]; | |
1442 P_LEFT[1] = s->p_mv_table[xy + 1][1]; | |
1443 | |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1444 if(P_LEFT[0] < (c->xmin<<shift)) P_LEFT[0] = (c->xmin<<shift); |
951 | 1445 |
1446 /* special case for first line */ | |
1799 | 1447 if (s->first_slice_line) { |
1950 | 1448 c->pred_x= P_LEFT[0]; |
1449 c->pred_y= P_LEFT[1]; | |
952 | 1450 P_TOP[0]= P_TOPRIGHT[0]= P_MEDIAN[0]= |
2967 | 1451 P_TOP[1]= P_TOPRIGHT[1]= P_MEDIAN[1]= 0; //FIXME |
951 | 1452 } else { |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1162
diff
changeset
|
1453 P_TOP[0] = s->p_mv_table[xy + s->mb_stride ][0]; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1162
diff
changeset
|
1454 P_TOP[1] = s->p_mv_table[xy + s->mb_stride ][1]; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1162
diff
changeset
|
1455 P_TOPRIGHT[0] = s->p_mv_table[xy + s->mb_stride - 1][0]; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1162
diff
changeset
|
1456 P_TOPRIGHT[1] = s->p_mv_table[xy + s->mb_stride - 1][1]; |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1457 if(P_TOP[1] < (c->ymin<<shift)) P_TOP[1] = (c->ymin<<shift); |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1458 if(P_TOPRIGHT[0] > (c->xmax<<shift)) P_TOPRIGHT[0]= (c->xmax<<shift); |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1459 if(P_TOPRIGHT[1] < (c->ymin<<shift)) P_TOPRIGHT[1]= (c->ymin<<shift); |
2967 | 1460 |
951 | 1461 P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]); |
1462 P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]); | |
1463 | |
1950 | 1464 c->pred_x = P_MEDIAN[0]; |
1465 c->pred_y = P_MEDIAN[1]; | |
951 | 1466 } |
1950 | 1467 |
2967 | 1468 dmin = ff_epzs_motion_search(s, &mx, &my, P, 0, 0, s->p_mv_table, (1<<16)>>shift, 0, 16); |
952 | 1469 |
951 | 1470 s->p_mv_table[xy][0] = mx<<shift; |
1471 s->p_mv_table[xy][1] = my<<shift; | |
2967 | 1472 |
951 | 1473 return dmin; |
1474 } | |
1475 | |
1057 | 1476 static int ff_estimate_motion_b(MpegEncContext * s, |
1950 | 1477 int mb_x, int mb_y, int16_t (*mv_table)[2], int ref_index, int f_code) |
0 | 1478 { |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1479 MotionEstContext * const c= &s->me; |
1708 | 1480 int mx, my, dmin; |
455 | 1481 int P[10][2]; |
324 | 1482 const int shift= 1+s->quarter_sample; |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1162
diff
changeset
|
1483 const int mot_stride = s->mb_stride; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1162
diff
changeset
|
1484 const int mot_xy = mb_y*mot_stride + mb_x; |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1485 uint8_t * const mv_penalty= c->mv_penalty[f_code] + MAX_MV; |
948 | 1486 int mv_scale; |
2967 | 1487 |
2184 | 1488 c->penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_cmp); |
1489 c->sub_penalty_factor= get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_sub_cmp); | |
1490 c->mb_penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->mb_cmp); | |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1491 c->current_mv_penalty= mv_penalty; |
936 | 1492 |
1708 | 1493 get_limits(s, 16*mb_x, 16*mb_y); |
324 | 1494 |
1495 switch(s->me_method) { | |
1496 case ME_ZERO: | |
1497 default: | |
2979 | 1498 no_motion_search(s, &mx, &my); |
324 | 1499 dmin = 0; |
455 | 1500 mx-= mb_x*16; |
1501 my-= mb_y*16; | |
324 | 1502 break; |
1708 | 1503 #if 0 |
324 | 1504 case ME_FULL: |
2979 | 1505 dmin = full_motion_search(s, &mx, &my, range, ref_picture); |
455 | 1506 mx-= mb_x*16; |
1507 my-= mb_y*16; | |
324 | 1508 break; |
1509 case ME_LOG: | |
2979 | 1510 dmin = log_motion_search(s, &mx, &my, range / 2, ref_picture); |
455 | 1511 mx-= mb_x*16; |
1512 my-= mb_y*16; | |
324 | 1513 break; |
1514 case ME_PHODS: | |
2979 | 1515 dmin = phods_motion_search(s, &mx, &my, range / 2, ref_picture); |
455 | 1516 mx-= mb_x*16; |
1517 my-= mb_y*16; | |
324 | 1518 break; |
1708 | 1519 #endif |
324 | 1520 case ME_X1: |
1521 case ME_EPZS: | |
1522 { | |
455 | 1523 P_LEFT[0] = mv_table[mot_xy - 1][0]; |
1524 P_LEFT[1] = mv_table[mot_xy - 1][1]; | |
324 | 1525 |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1526 if(P_LEFT[0] > (c->xmax<<shift)) P_LEFT[0] = (c->xmax<<shift); |
324 | 1527 |
1528 /* special case for first line */ | |
1799 | 1529 if (!s->first_slice_line) { |
455 | 1530 P_TOP[0] = mv_table[mot_xy - mot_stride ][0]; |
1531 P_TOP[1] = mv_table[mot_xy - mot_stride ][1]; | |
1532 P_TOPRIGHT[0] = mv_table[mot_xy - mot_stride + 1 ][0]; | |
1533 P_TOPRIGHT[1] = mv_table[mot_xy - mot_stride + 1 ][1]; | |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1534 if(P_TOP[1] > (c->ymax<<shift)) P_TOP[1]= (c->ymax<<shift); |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1535 if(P_TOPRIGHT[0] < (c->xmin<<shift)) P_TOPRIGHT[0]= (c->xmin<<shift); |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1536 if(P_TOPRIGHT[1] > (c->ymax<<shift)) P_TOPRIGHT[1]= (c->ymax<<shift); |
2967 | 1537 |
455 | 1538 P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]); |
1539 P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]); | |
324 | 1540 } |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1541 c->pred_x= P_LEFT[0]; |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1542 c->pred_y= P_LEFT[1]; |
324 | 1543 } |
2967 | 1544 |
948 | 1545 if(mv_table == s->b_forw_mv_table){ |
1546 mv_scale= (s->pb_time<<16) / (s->pp_time<<shift); | |
1547 }else{ | |
1548 mv_scale= ((s->pb_time - s->pp_time)<<16) / (s->pp_time<<shift); | |
1549 } | |
2967 | 1550 |
2184 | 1551 dmin = ff_epzs_motion_search(s, &mx, &my, P, 0, ref_index, s->p_mv_table, mv_scale, 0, 16); |
2967 | 1552 |
324 | 1553 break; |
1554 } | |
2967 | 1555 |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1556 dmin= c->sub_motion_search(s, &mx, &my, dmin, 0, ref_index, 0, 16); |
2967 | 1557 |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
1558 if(c->avctx->me_sub_cmp != c->avctx->mb_cmp && !c->skip) |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2184
diff
changeset
|
1559 dmin= ff_get_mb_score(s, mx, my, 0, ref_index, 0, 16, 1); |
1013 | 1560 |
455 | 1561 //printf("%d %d %d %d//", s->mb_x, s->mb_y, mx, my); |
324 | 1562 // s->mb_type[mb_y*s->mb_width + mb_x]= mb_type; |
1563 mv_table[mot_xy][0]= mx; | |
1564 mv_table[mot_xy][1]= my; | |
936 | 1565 |
327 | 1566 return dmin; |
324 | 1567 } |
1568 | |
1950 | 1569 static inline int check_bidir_mv(MpegEncContext * s, |
327 | 1570 int motion_fx, int motion_fy, |
1571 int motion_bx, int motion_by, | |
1572 int pred_fx, int pred_fy, | |
1708 | 1573 int pred_bx, int pred_by, |
1574 int size, int h) | |
327 | 1575 { |
1576 //FIXME optimize? | |
936 | 1577 //FIXME better f_code prediction (max mv & distance) |
1708 | 1578 //FIXME pointers |
1950 | 1579 MotionEstContext * const c= &s->me; |
2982 | 1580 uint8_t * const mv_penalty_f= c->mv_penalty[s->f_code] + MAX_MV; // f_code of the prev frame |
1581 uint8_t * const mv_penalty_b= c->mv_penalty[s->b_code] + MAX_MV; // f_code of the prev frame | |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1582 int stride= c->stride; |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1583 uint8_t *dest_y = c->scratchpad; |
327 | 1584 uint8_t *ptr; |
1585 int dxy; | |
1586 int src_x, src_y; | |
1587 int fbmin; | |
1950 | 1588 uint8_t **src_data= c->src[0]; |
1589 uint8_t **ref_data= c->ref[0]; | |
1590 uint8_t **ref2_data= c->ref[2]; | |
327 | 1591 |
936 | 1592 if(s->quarter_sample){ |
1593 dxy = ((motion_fy & 3) << 2) | (motion_fx & 3); | |
1708 | 1594 src_x = motion_fx >> 2; |
1595 src_y = motion_fy >> 2; | |
327 | 1596 |
1708 | 1597 ptr = ref_data[0] + (src_y * stride) + src_x; |
1598 s->dsp.put_qpel_pixels_tab[0][dxy](dest_y , ptr , stride); | |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
1599 |
936 | 1600 dxy = ((motion_by & 3) << 2) | (motion_bx & 3); |
1708 | 1601 src_x = motion_bx >> 2; |
1602 src_y = motion_by >> 2; | |
2967 | 1603 |
1950 | 1604 ptr = ref2_data[0] + (src_y * stride) + src_x; |
1708 | 1605 s->dsp.avg_qpel_pixels_tab[size][dxy](dest_y , ptr , stride); |
936 | 1606 }else{ |
1607 dxy = ((motion_fy & 1) << 1) | (motion_fx & 1); | |
1708 | 1608 src_x = motion_fx >> 1; |
1609 src_y = motion_fy >> 1; | |
327 | 1610 |
1708 | 1611 ptr = ref_data[0] + (src_y * stride) + src_x; |
1612 s->dsp.put_pixels_tab[size][dxy](dest_y , ptr , stride, h); | |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
1613 |
936 | 1614 dxy = ((motion_by & 1) << 1) | (motion_bx & 1); |
1708 | 1615 src_x = motion_bx >> 1; |
1616 src_y = motion_by >> 1; | |
2967 | 1617 |
1950 | 1618 ptr = ref2_data[0] + (src_y * stride) + src_x; |
1708 | 1619 s->dsp.avg_pixels_tab[size][dxy](dest_y , ptr , stride, h); |
936 | 1620 } |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
1621 |
2982 | 1622 fbmin = (mv_penalty_f[motion_fx-pred_fx] + mv_penalty_f[motion_fy-pred_fy])*c->mb_penalty_factor |
1623 +(mv_penalty_b[motion_bx-pred_bx] + mv_penalty_b[motion_by-pred_by])*c->mb_penalty_factor | |
1708 | 1624 + s->dsp.mb_cmp[size](s, src_data[0], dest_y, stride, h); //FIXME new_pic |
2967 | 1625 |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
1626 if(c->avctx->mb_cmp&FF_CMP_CHROMA){ |
1013 | 1627 } |
1628 //FIXME CHROMA !!! | |
2967 | 1629 |
327 | 1630 return fbmin; |
1631 } | |
1632 | |
1633 /* refine the bidir vectors in hq mode and return the score in both lq & hq mode*/ | |
1950 | 1634 static inline int bidir_refine(MpegEncContext * s, int mb_x, int mb_y) |
327 | 1635 { |
2983 | 1636 MotionEstContext * const c= &s->me; |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1162
diff
changeset
|
1637 const int mot_stride = s->mb_stride; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1162
diff
changeset
|
1638 const int xy = mb_y *mot_stride + mb_x; |
327 | 1639 int fbmin; |
1640 int pred_fx= s->b_bidir_forw_mv_table[xy-1][0]; | |
1641 int pred_fy= s->b_bidir_forw_mv_table[xy-1][1]; | |
1642 int pred_bx= s->b_bidir_back_mv_table[xy-1][0]; | |
1643 int pred_by= s->b_bidir_back_mv_table[xy-1][1]; | |
1644 int motion_fx= s->b_bidir_forw_mv_table[xy][0]= s->b_forw_mv_table[xy][0]; | |
1645 int motion_fy= s->b_bidir_forw_mv_table[xy][1]= s->b_forw_mv_table[xy][1]; | |
1646 int motion_bx= s->b_bidir_back_mv_table[xy][0]= s->b_back_mv_table[xy][0]; | |
1647 int motion_by= s->b_bidir_back_mv_table[xy][1]= s->b_back_mv_table[xy][1]; | |
2983 | 1648 const int flags= c->sub_flags; |
1649 const int qpel= flags&FLAG_QPEL; | |
1650 const int shift= 1+qpel; | |
1651 const int xmin= c->xmin<<shift; | |
1652 const int ymin= c->ymin<<shift; | |
1653 const int xmax= c->xmax<<shift; | |
1654 const int ymax= c->ymax<<shift; | |
3026
10934895be5a
10l: bidir_refine didn't save the new mvs. also improve speed.
lorenm
parents:
2987
diff
changeset
|
1655 uint8_t map[8][8][8][8]; |
10934895be5a
10l: bidir_refine didn't save the new mvs. also improve speed.
lorenm
parents:
2987
diff
changeset
|
1656 |
10934895be5a
10l: bidir_refine didn't save the new mvs. also improve speed.
lorenm
parents:
2987
diff
changeset
|
1657 memset(map,0,sizeof(map)); |
10934895be5a
10l: bidir_refine didn't save the new mvs. also improve speed.
lorenm
parents:
2987
diff
changeset
|
1658 #define BIDIR_MAP(fx,fy,bx,by) \ |
10934895be5a
10l: bidir_refine didn't save the new mvs. also improve speed.
lorenm
parents:
2987
diff
changeset
|
1659 map[(motion_fx+fx)&7][(motion_fy+fy)&7][(motion_bx+bx)&7][(motion_by+by)&7] |
10934895be5a
10l: bidir_refine didn't save the new mvs. also improve speed.
lorenm
parents:
2987
diff
changeset
|
1660 BIDIR_MAP(0,0,0,0) = 1; |
2967 | 1661 |
1950 | 1662 fbmin= check_bidir_mv(s, motion_fx, motion_fy, |
327 | 1663 motion_bx, motion_by, |
1664 pred_fx, pred_fy, | |
1708 | 1665 pred_bx, pred_by, |
1666 0, 16); | |
327 | 1667 |
2983 | 1668 if(s->avctx->bidir_refine){ |
1669 int score, end; | |
1670 #define CHECK_BIDIR(fx,fy,bx,by)\ | |
3026
10934895be5a
10l: bidir_refine didn't save the new mvs. also improve speed.
lorenm
parents:
2987
diff
changeset
|
1671 if( !BIDIR_MAP(fx,fy,bx,by)\ |
10934895be5a
10l: bidir_refine didn't save the new mvs. also improve speed.
lorenm
parents:
2987
diff
changeset
|
1672 &&(fx<=0 || motion_fx+fx<=xmax) && (fy<=0 || motion_fy+fy<=ymax) && (bx<=0 || motion_bx+bx<=xmax) && (by<=0 || motion_by+by<=ymax)\ |
2984 | 1673 &&(fx>=0 || motion_fx+fx>=xmin) && (fy>=0 || motion_fy+fy>=ymin) && (bx>=0 || motion_bx+bx>=xmin) && (by>=0 || motion_by+by>=ymin)){\ |
3026
10934895be5a
10l: bidir_refine didn't save the new mvs. also improve speed.
lorenm
parents:
2987
diff
changeset
|
1674 BIDIR_MAP(fx,fy,bx,by) = 1;\ |
2984 | 1675 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);\ |
1676 if(score < fbmin){\ | |
1677 fbmin= score;\ | |
1678 motion_fx+=fx;\ | |
1679 motion_fy+=fy;\ | |
1680 motion_bx+=bx;\ | |
1681 motion_by+=by;\ | |
1682 end=0;\ | |
1683 }\ | |
2983 | 1684 } |
1685 #define CHECK_BIDIR2(a,b,c,d)\ | |
1686 CHECK_BIDIR(a,b,c,d)\ | |
3575
4baed6f6577b
Fix CHECK_BIDIR macro so it works with Intel's Compiler
gpoirier
parents:
3188
diff
changeset
|
1687 CHECK_BIDIR(-(a),-(b),-(c),-(d)) |
2983 | 1688 |
1689 #define CHECK_BIDIRR(a,b,c,d)\ | |
1690 CHECK_BIDIR2(a,b,c,d)\ | |
1691 CHECK_BIDIR2(b,c,d,a)\ | |
1692 CHECK_BIDIR2(c,d,a,b)\ | |
1693 CHECK_BIDIR2(d,a,b,c) | |
1694 | |
1695 do{ | |
1696 end=1; | |
1697 | |
1698 CHECK_BIDIRR( 0, 0, 0, 1) | |
1699 if(s->avctx->bidir_refine > 1){ | |
1700 CHECK_BIDIRR( 0, 0, 1, 1) | |
1701 CHECK_BIDIR2( 0, 1, 0, 1) | |
1702 CHECK_BIDIR2( 1, 0, 1, 0) | |
1703 CHECK_BIDIRR( 0, 0,-1, 1) | |
1704 CHECK_BIDIR2( 0,-1, 0, 1) | |
1705 CHECK_BIDIR2(-1, 0, 1, 0) | |
1706 if(s->avctx->bidir_refine > 2){ | |
1707 CHECK_BIDIRR( 0, 1, 1, 1) | |
1708 CHECK_BIDIRR( 0,-1, 1, 1) | |
1709 CHECK_BIDIRR( 0, 1,-1, 1) | |
1710 CHECK_BIDIRR( 0, 1, 1,-1) | |
1711 if(s->avctx->bidir_refine > 3){ | |
1712 CHECK_BIDIR2( 1, 1, 1, 1) | |
1713 CHECK_BIDIRR( 1, 1, 1,-1) | |
1714 CHECK_BIDIR2( 1, 1,-1,-1) | |
1715 CHECK_BIDIR2( 1,-1,-1, 1) | |
1716 CHECK_BIDIR2( 1,-1, 1,-1) | |
1717 } | |
1718 } | |
1719 } | |
1720 }while(!end); | |
1721 } | |
1722 | |
3026
10934895be5a
10l: bidir_refine didn't save the new mvs. also improve speed.
lorenm
parents:
2987
diff
changeset
|
1723 s->b_bidir_forw_mv_table[xy][0]= motion_fx; |
10934895be5a
10l: bidir_refine didn't save the new mvs. also improve speed.
lorenm
parents:
2987
diff
changeset
|
1724 s->b_bidir_forw_mv_table[xy][1]= motion_fy; |
10934895be5a
10l: bidir_refine didn't save the new mvs. also improve speed.
lorenm
parents:
2987
diff
changeset
|
1725 s->b_bidir_back_mv_table[xy][0]= motion_bx; |
10934895be5a
10l: bidir_refine didn't save the new mvs. also improve speed.
lorenm
parents:
2987
diff
changeset
|
1726 s->b_bidir_back_mv_table[xy][1]= motion_by; |
10934895be5a
10l: bidir_refine didn't save the new mvs. also improve speed.
lorenm
parents:
2987
diff
changeset
|
1727 |
2983 | 1728 return fbmin; |
327 | 1729 } |
1730 | |
1950 | 1731 static inline int direct_search(MpegEncContext * s, int mb_x, int mb_y) |
324 | 1732 { |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1733 MotionEstContext * const c= &s->me; |
455 | 1734 int P[10][2]; |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1162
diff
changeset
|
1735 const int mot_stride = s->mb_stride; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1162
diff
changeset
|
1736 const int mot_xy = mb_y*mot_stride + mb_x; |
936 | 1737 const int shift= 1+s->quarter_sample; |
1738 int dmin, i; | |
327 | 1739 const int time_pp= s->pp_time; |
664 | 1740 const int time_pb= s->pb_time; |
936 | 1741 int mx, my, xmin, xmax, ymin, ymax; |
327 | 1742 int16_t (*mv_table)[2]= s->b_direct_mv_table; |
2967 | 1743 |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1744 c->current_mv_penalty= c->mv_penalty[1] + MAX_MV; |
936 | 1745 ymin= xmin=(-32)>>shift; |
1746 ymax= xmax= 31>>shift; | |
1747 | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1162
diff
changeset
|
1748 if(IS_8X8(s->next_picture.mb_type[mot_xy])){ |
936 | 1749 s->mv_type= MV_TYPE_8X8; |
1750 }else{ | |
1751 s->mv_type= MV_TYPE_16X16; | |
327 | 1752 } |
936 | 1753 |
1754 for(i=0; i<4; i++){ | |
1755 int index= s->block_index[i]; | |
1756 int min, max; | |
2967 | 1757 |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1758 c->co_located_mv[i][0]= s->next_picture.motion_val[0][index][0]; |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1759 c->co_located_mv[i][1]= s->next_picture.motion_val[0][index][1]; |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1760 c->direct_basis_mv[i][0]= c->co_located_mv[i][0]*time_pb/time_pp + ((i& 1)<<(shift+3)); |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1761 c->direct_basis_mv[i][1]= c->co_located_mv[i][1]*time_pb/time_pp + ((i>>1)<<(shift+3)); |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1762 // c->direct_basis_mv[1][i][0]= c->co_located_mv[i][0]*(time_pb - time_pp)/time_pp + ((i &1)<<(shift+3); |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1763 // c->direct_basis_mv[1][i][1]= c->co_located_mv[i][1]*(time_pb - time_pp)/time_pp + ((i>>1)<<(shift+3); |
936 | 1764 |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1765 max= FFMAX(c->direct_basis_mv[i][0], c->direct_basis_mv[i][0] - c->co_located_mv[i][0])>>shift; |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1766 min= FFMIN(c->direct_basis_mv[i][0], c->direct_basis_mv[i][0] - c->co_located_mv[i][0])>>shift; |
1764 | 1767 max+= 16*mb_x + 1; // +-1 is for the simpler rounding |
1768 min+= 16*mb_x - 1; | |
960 | 1769 xmax= FFMIN(xmax, s->width - max); |
1770 xmin= FFMAX(xmin, - 16 - min); | |
936 | 1771 |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1772 max= FFMAX(c->direct_basis_mv[i][1], c->direct_basis_mv[i][1] - c->co_located_mv[i][1])>>shift; |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1773 min= FFMIN(c->direct_basis_mv[i][1], c->direct_basis_mv[i][1] - c->co_located_mv[i][1])>>shift; |
1764 | 1774 max+= 16*mb_y + 1; // +-1 is for the simpler rounding |
1775 min+= 16*mb_y - 1; | |
960 | 1776 ymax= FFMIN(ymax, s->height - max); |
1777 ymin= FFMAX(ymin, - 16 - min); | |
2967 | 1778 |
936 | 1779 if(s->mv_type == MV_TYPE_16X16) break; |
327 | 1780 } |
2967 | 1781 |
936 | 1782 assert(xmax <= 15 && ymax <= 15 && xmin >= -16 && ymin >= -16); |
2967 | 1783 |
936 | 1784 if(xmax < 0 || xmin >0 || ymax < 0 || ymin > 0){ |
1785 s->b_direct_mv_table[mot_xy][0]= 0; | |
1786 s->b_direct_mv_table[mot_xy][1]= 0; | |
1787 | |
1788 return 256*256*256*64; | |
1789 } | |
2967 | 1790 |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1791 c->xmin= xmin; |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1792 c->ymin= ymin; |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1793 c->xmax= xmax; |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1794 c->ymax= ymax; |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1795 c->flags |= FLAG_DIRECT; |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1796 c->sub_flags |= FLAG_DIRECT; |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1797 c->pred_x=0; |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1798 c->pred_y=0; |
936 | 1799 |
950 | 1800 P_LEFT[0] = clip(mv_table[mot_xy - 1][0], xmin<<shift, xmax<<shift); |
1801 P_LEFT[1] = clip(mv_table[mot_xy - 1][1], ymin<<shift, ymax<<shift); | |
1802 | |
1803 /* special case for first line */ | |
4259 | 1804 if (!s->first_slice_line) { //FIXME maybe allow this over thread boundary as its clipped |
950 | 1805 P_TOP[0] = clip(mv_table[mot_xy - mot_stride ][0], xmin<<shift, xmax<<shift); |
1806 P_TOP[1] = clip(mv_table[mot_xy - mot_stride ][1], ymin<<shift, ymax<<shift); | |
1807 P_TOPRIGHT[0] = clip(mv_table[mot_xy - mot_stride + 1 ][0], xmin<<shift, xmax<<shift); | |
1808 P_TOPRIGHT[1] = clip(mv_table[mot_xy - mot_stride + 1 ][1], ymin<<shift, ymax<<shift); | |
2967 | 1809 |
950 | 1810 P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]); |
1811 P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]); | |
1812 } | |
2967 | 1813 |
2184 | 1814 dmin = ff_epzs_motion_search(s, &mx, &my, P, 0, 0, mv_table, 1<<(16-shift), 0, 16); |
2967 | 1815 if(c->sub_flags&FLAG_QPEL) |
1950 | 1816 dmin = qpel_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16); |
1817 else | |
1818 dmin = hpel_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16); | |
2967 | 1819 |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
1820 if(c->avctx->me_sub_cmp != c->avctx->mb_cmp && !c->skip) |
2189
70b27300a496
quad tree based motion compensation (currently only 16x16 & 8x8 OBMC blocks, but can be extended to other block sizes easily)
michael
parents:
2184
diff
changeset
|
1821 dmin= ff_get_mb_score(s, mx, my, 0, 0, 0, 16, 1); |
2967 | 1822 |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1823 get_limits(s, 16*mb_x, 16*mb_y); //restore c->?min/max, maybe not needed |
327 | 1824 |
1825 s->b_direct_mv_table[mot_xy][0]= mx; | |
1826 s->b_direct_mv_table[mot_xy][1]= my; | |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1827 c->flags &= ~FLAG_DIRECT; |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1828 c->sub_flags &= ~FLAG_DIRECT; |
1950 | 1829 |
327 | 1830 return dmin; |
324 | 1831 } |
1832 | |
1833 void ff_estimate_b_frame_motion(MpegEncContext * s, | |
1834 int mb_x, int mb_y) | |
1835 { | |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1836 MotionEstContext * const c= &s->me; |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1837 const int penalty_factor= c->mb_penalty_factor; |
1708 | 1838 int fmin, bmin, dmin, fbmin, bimin, fimin; |
327 | 1839 int type=0; |
1968
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1840 const int xy = mb_y*s->mb_stride + mb_x; |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1841 init_ref(c, s->new_picture.data, s->last_picture.data, s->next_picture.data, 16*mb_x, 16*mb_y, 2); |
1968
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1842 |
2072 | 1843 get_limits(s, 16*mb_x, 16*mb_y); |
2967 | 1844 |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1845 c->skip=0; |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
1846 if(c->avctx->me_threshold){ |
2987 | 1847 int vard= check_input_motion(s, mb_x, mb_y, 0); |
2967 | 1848 |
2987 | 1849 if((vard+128)>>8 < c->avctx->me_threshold){ |
1955
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1850 // pix = c->src[0][0]; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1851 // sum = s->dsp.pix_sum(pix, s->linesize); |
2987 | 1852 // varc = s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)(sum*sum))>>8) + 500; |
2967 | 1853 |
2987 | 1854 // pic->mb_var [s->mb_stride * mb_y + mb_x] = (varc+128)>>8; |
1855 s->current_picture.mc_mb_var[s->mb_stride * mb_y + mb_x] = (vard+128)>>8; | |
1955
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1856 /* pic->mb_mean [s->mb_stride * mb_y + mb_x] = (sum+128)>>8; |
2987 | 1857 c->mb_var_sum_temp += (varc+128)>>8;*/ |
1858 c->mc_mb_var_sum_temp += (vard+128)>>8; | |
1859 /* if (vard <= 64<<8 || vard < varc) { | |
1860 c->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc); | |
1955
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1861 }else{ |
3061 | 1862 c->scene_change_score+= s->qscale * s->avctx->scenechange_factor; |
1955
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1863 }*/ |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1864 return; |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1865 } |
2987 | 1866 if((vard+128)>>8 < c->avctx->mb_threshold){ |
1968
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1867 type= s->mb_type[mb_y*s->mb_stride + mb_x]; |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1868 if(type == CANDIDATE_MB_TYPE_DIRECT){ |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1869 direct_search(s, mb_x, mb_y); |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1870 } |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1871 if(type == CANDIDATE_MB_TYPE_FORWARD || type == CANDIDATE_MB_TYPE_BIDIR){ |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1872 c->skip=0; |
1968
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1873 ff_estimate_motion_b(s, mb_x, mb_y, s->b_forw_mv_table, 0, s->f_code); |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1874 } |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1875 if(type == CANDIDATE_MB_TYPE_BACKWARD || type == CANDIDATE_MB_TYPE_BIDIR){ |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1876 c->skip=0; |
1968
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1877 ff_estimate_motion_b(s, mb_x, mb_y, s->b_back_mv_table, 2, s->b_code); |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1878 } |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1879 if(type == CANDIDATE_MB_TYPE_FORWARD_I || type == CANDIDATE_MB_TYPE_BIDIR_I){ |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1880 c->skip=0; |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1881 c->current_mv_penalty= c->mv_penalty[s->f_code] + MAX_MV; |
1968
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1882 interlaced_search(s, 0, |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1883 s->b_field_mv_table[0], s->b_field_select_table[0], |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1884 s->b_forw_mv_table[xy][0], s->b_forw_mv_table[xy][1], 1); |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1885 } |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1886 if(type == CANDIDATE_MB_TYPE_BACKWARD_I || type == CANDIDATE_MB_TYPE_BIDIR_I){ |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1887 c->skip=0; |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1888 c->current_mv_penalty= c->mv_penalty[s->b_code] + MAX_MV; |
1968
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1889 interlaced_search(s, 2, |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1890 s->b_field_mv_table[1], s->b_field_select_table[1], |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1891 s->b_back_mv_table[xy][0], s->b_back_mv_table[xy][1], 1); |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1892 } |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1893 return; |
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1894 } |
1955
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1895 } |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1950
diff
changeset
|
1896 |
1426 | 1897 if (s->codec_id == CODEC_ID_MPEG4) |
1950 | 1898 dmin= direct_search(s, mb_x, mb_y); |
1426 | 1899 else |
1900 dmin= INT_MAX; | |
1708 | 1901 //FIXME penalty stuff for non mpeg4 |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1902 c->skip=0; |
1950 | 1903 fmin= ff_estimate_motion_b(s, mb_x, mb_y, s->b_forw_mv_table, 0, s->f_code) + 3*penalty_factor; |
2967 | 1904 |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1905 c->skip=0; |
1950 | 1906 bmin= ff_estimate_motion_b(s, mb_x, mb_y, s->b_back_mv_table, 2, s->b_code) + 2*penalty_factor; |
324 | 1907 //printf(" %d %d ", s->b_forw_mv_table[xy][0], s->b_forw_mv_table[xy][1]); |
327 | 1908 |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1909 c->skip=0; |
1950 | 1910 fbmin= bidir_refine(s, mb_x, mb_y) + penalty_factor; |
1013 | 1911 //printf("%d %d %d %d\n", dmin, fmin, bmin, fbmin); |
2967 | 1912 |
1708 | 1913 if(s->flags & CODEC_FLAG_INTERLACED_ME){ |
1914 //FIXME mb type penalty | |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1915 c->skip=0; |
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1916 c->current_mv_penalty= c->mv_penalty[s->f_code] + MAX_MV; |
1950 | 1917 fimin= interlaced_search(s, 0, |
1918 s->b_field_mv_table[0], s->b_field_select_table[0], | |
1968
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1919 s->b_forw_mv_table[xy][0], s->b_forw_mv_table[xy][1], 0); |
2014
15c885db82a8
reduce dependancy between motion estimation and MpegEncContext
michael
parents:
1995
diff
changeset
|
1920 c->current_mv_penalty= c->mv_penalty[s->b_code] + MAX_MV; |
1950 | 1921 bimin= interlaced_search(s, 2, |
1922 s->b_field_mv_table[1], s->b_field_select_table[1], | |
1968
19c2344e800a
support reusing mb types and field select values of the source file, but use motion vectors just as additional predictors
michael
parents:
1963
diff
changeset
|
1923 s->b_back_mv_table[xy][0], s->b_back_mv_table[xy][1], 0); |
1708 | 1924 }else |
1925 fimin= bimin= INT_MAX; | |
1926 | |
612 | 1927 { |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1050
diff
changeset
|
1928 int score= fmin; |
1708 | 1929 type = CANDIDATE_MB_TYPE_FORWARD; |
2967 | 1930 |
1426 | 1931 if (dmin <= score){ |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1050
diff
changeset
|
1932 score = dmin; |
1708 | 1933 type = CANDIDATE_MB_TYPE_DIRECT; |
327 | 1934 } |
1935 if(bmin<score){ | |
1936 score=bmin; | |
2967 | 1937 type= CANDIDATE_MB_TYPE_BACKWARD; |
327 | 1938 } |
1939 if(fbmin<score){ | |
1940 score=fbmin; | |
1708 | 1941 type= CANDIDATE_MB_TYPE_BIDIR; |
1942 } | |
1943 if(fimin<score){ | |
1944 score=fimin; | |
1945 type= CANDIDATE_MB_TYPE_FORWARD_I; | |
1946 } | |
1947 if(bimin<score){ | |
1948 score=bimin; | |
1949 type= CANDIDATE_MB_TYPE_BACKWARD_I; | |
327 | 1950 } |
2967 | 1951 |
807
0e1d375c537f
fixing q>0.0 assert failure caused by overflow of variance for b frames
michaelni
parents:
765
diff
changeset
|
1952 score= ((unsigned)(score*score + 128*256))>>16; |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
1953 c->mc_mb_var_sum_temp += score; |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1162
diff
changeset
|
1954 s->current_picture.mc_mb_var[mb_y*s->mb_stride + mb_x] = score; //FIXME use SSE |
327 | 1955 } |
612 | 1956 |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
1957 if(c->avctx->mb_decision > FF_MB_DECISION_SIMPLE){ |
1708 | 1958 type= CANDIDATE_MB_TYPE_FORWARD | CANDIDATE_MB_TYPE_BACKWARD | CANDIDATE_MB_TYPE_BIDIR | CANDIDATE_MB_TYPE_DIRECT; |
1959 if(fimin < INT_MAX) | |
1960 type |= CANDIDATE_MB_TYPE_FORWARD_I; | |
1961 if(bimin < INT_MAX) | |
1962 type |= CANDIDATE_MB_TYPE_BACKWARD_I; | |
1963 if(fimin < INT_MAX && bimin < INT_MAX){ | |
1964 type |= CANDIDATE_MB_TYPE_BIDIR_I; | |
1965 } | |
1966 //FIXME something smarter | |
1967 if(dmin>256*256*16) type&= ~CANDIDATE_MB_TYPE_DIRECT; //dont try direct mode if its invalid for this MB | |
2967 | 1968 #if 0 |
1729 | 1969 if(s->out_format == FMT_MPEG1) |
1970 type |= CANDIDATE_MB_TYPE_INTRA; | |
1971 #endif | |
612 | 1972 } |
1973 | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1162
diff
changeset
|
1974 s->mb_type[mb_y*s->mb_stride + mb_x]= type; |
324 | 1975 } |
0 | 1976 |
324 | 1977 /* find best f_code for ME which do unlimited searches */ |
1978 int ff_get_best_fcode(MpegEncContext * s, int16_t (*mv_table)[2], int type) | |
1979 { | |
1980 if(s->me_method>=ME_EPZS){ | |
455 | 1981 int score[8]; |
2816 | 1982 int i, y, range= s->avctx->me_range ? s->avctx->me_range : (INT_MAX/2); |
1064 | 1983 uint8_t * fcode_tab= s->fcode_tab; |
455 | 1984 int best_fcode=-1; |
1985 int best_score=-10000000; | |
324 | 1986 |
2967 | 1987 if(s->msmpeg4_version) |
2811 | 1988 range= FFMIN(range, 16); |
1989 else if(s->codec_id == CODEC_ID_MPEG2VIDEO && s->avctx->strict_std_compliance >= FF_COMPLIANCE_NORMAL) | |
1990 range= FFMIN(range, 256); | |
1991 | |
936 | 1992 for(i=0; i<8; i++) score[i]= s->mb_num*(8-i); |
324 | 1993 |
1994 for(y=0; y<s->mb_height; y++){ | |
1995 int x; | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1162
diff
changeset
|
1996 int xy= y*s->mb_stride; |
324 | 1997 for(x=0; x<s->mb_width; x++){ |
1634 | 1998 if(s->mb_type[xy] & type){ |
2302 | 1999 int mx= mv_table[xy][0]; |
2000 int my= mv_table[xy][1]; | |
2001 int fcode= FFMAX(fcode_tab[mx + MAX_MV], | |
2002 fcode_tab[my + MAX_MV]); | |
455 | 2003 int j; |
2967 | 2004 |
2005 if(mx >= range || mx < -range || | |
2302 | 2006 my >= range || my < -range) |
2007 continue; | |
2967 | 2008 |
455 | 2009 for(j=0; j<fcode && j<8; j++){ |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1162
diff
changeset
|
2010 if(s->pict_type==B_TYPE || s->current_picture.mc_mb_var[xy] < s->current_picture.mb_var[xy]) |
455 | 2011 score[j]-= 170; |
2012 } | |
324 | 2013 } |
2014 xy++; | |
2015 } | |
2016 } | |
2967 | 2017 |
455 | 2018 for(i=1; i<8; i++){ |
2019 if(score[i] > best_score){ | |
2020 best_score= score[i]; | |
2021 best_fcode= i; | |
2022 } | |
2023 // printf("%d %d\n", i, score[i]); | |
2024 } | |
327 | 2025 |
324 | 2026 // printf("fcode: %d type: %d\n", i, s->pict_type); |
455 | 2027 return best_fcode; |
324 | 2028 /* for(i=0; i<=MAX_FCODE; i++){ |
2029 printf("%d ", mv_num[i]); | |
2030 } | |
2031 printf("\n");*/ | |
2032 }else{ | |
2033 return 1; | |
0 | 2034 } |
2035 } | |
2036 | |
324 | 2037 void ff_fix_long_p_mvs(MpegEncContext * s) |
2038 { | |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
2039 MotionEstContext * const c= &s->me; |
324 | 2040 const int f_code= s->f_code; |
1086 | 2041 int y, range; |
1421 | 2042 assert(s->pict_type==P_TYPE); |
1086 | 2043 |
2811 | 2044 range = (((s->out_format == FMT_MPEG1 || s->msmpeg4_version) ? 8 : 16) << f_code); |
2045 | |
2046 assert(range <= 16 || !s->msmpeg4_version); | |
2047 assert(range <=256 || !(s->codec_id == CODEC_ID_MPEG2VIDEO && s->avctx->strict_std_compliance >= FF_COMPLIANCE_NORMAL)); | |
2967 | 2048 |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
2049 if(c->avctx->me_range && range > c->avctx->me_range) range= c->avctx->me_range; |
2967 | 2050 |
455 | 2051 //printf("%d no:%d %d//\n", clip, noclip, f_code); |
324 | 2052 if(s->flags&CODEC_FLAG_4MV){ |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1904
diff
changeset
|
2053 const int wrap= s->b8_stride; |
324 | 2054 |
2055 /* clip / convert to intra 8x8 type MVs */ | |
2056 for(y=0; y<s->mb_height; y++){ | |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1904
diff
changeset
|
2057 int xy= y*2*wrap; |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1162
diff
changeset
|
2058 int i= y*s->mb_stride; |
324 | 2059 int x; |
2060 | |
2061 for(x=0; x<s->mb_width; x++){ | |
1708 | 2062 if(s->mb_type[i]&CANDIDATE_MB_TYPE_INTER4V){ |
324 | 2063 int block; |
2064 for(block=0; block<4; block++){ | |
2065 int off= (block& 1) + (block>>1)*wrap; | |
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1634
diff
changeset
|
2066 int mx= s->current_picture.motion_val[0][ xy + off ][0]; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1634
diff
changeset
|
2067 int my= s->current_picture.motion_val[0][ xy + off ][1]; |
324 | 2068 |
1086 | 2069 if( mx >=range || mx <-range |
2070 || my >=range || my <-range){ | |
1708 | 2071 s->mb_type[i] &= ~CANDIDATE_MB_TYPE_INTER4V; |
2072 s->mb_type[i] |= CANDIDATE_MB_TYPE_INTRA; | |
2073 s->current_picture.mb_type[i]= CANDIDATE_MB_TYPE_INTRA; | |
324 | 2074 } |
2075 } | |
2076 } | |
502 | 2077 xy+=2; |
2078 i++; | |
324 | 2079 } |
2080 } | |
2081 } | |
2082 } | |
2083 | |
1708 | 2084 /** |
2085 * | |
2086 * @param truncate 1 for truncation, 0 for using intra | |
2087 */ | |
2967 | 2088 void ff_fix_long_mvs(MpegEncContext * s, uint8_t *field_select_table, int field_select, |
1708 | 2089 int16_t (*mv_table)[2], int f_code, int type, int truncate) |
324 | 2090 { |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
2091 MotionEstContext * const c= &s->me; |
1708 | 2092 int y, h_range, v_range; |
324 | 2093 |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1050
diff
changeset
|
2094 // RAL: 8 in MPEG-1, 16 in MPEG-4 |
2811 | 2095 int range = (((s->out_format == FMT_MPEG1 || s->msmpeg4_version) ? 8 : 16) << f_code); |
1708 | 2096 |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
2014
diff
changeset
|
2097 if(c->avctx->me_range && range > c->avctx->me_range) range= c->avctx->me_range; |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1050
diff
changeset
|
2098 |
1708 | 2099 h_range= range; |
2100 v_range= field_select_table ? range>>1 : range; | |
2101 | |
324 | 2102 /* clip / convert to intra 16x16 type MVs */ |
2103 for(y=0; y<s->mb_height; y++){ | |
2104 int x; | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1162
diff
changeset
|
2105 int xy= y*s->mb_stride; |
1086 | 2106 for(x=0; x<s->mb_width; x++){ |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1162
diff
changeset
|
2107 if (s->mb_type[xy] & type){ // RAL: "type" test added... |
1708 | 2108 if(field_select_table==NULL || field_select_table[xy] == field_select){ |
2109 if( mv_table[xy][0] >=h_range || mv_table[xy][0] <-h_range | |
2110 || mv_table[xy][1] >=v_range || mv_table[xy][1] <-v_range){ | |
1086 | 2111 |
1708 | 2112 if(truncate){ |
2113 if (mv_table[xy][0] > h_range-1) mv_table[xy][0]= h_range-1; | |
2114 else if(mv_table[xy][0] < -h_range ) mv_table[xy][0]= -h_range; | |
2115 if (mv_table[xy][1] > v_range-1) mv_table[xy][1]= v_range-1; | |
2116 else if(mv_table[xy][1] < -v_range ) mv_table[xy][1]= -v_range; | |
2117 }else{ | |
2118 s->mb_type[xy] &= ~type; | |
2119 s->mb_type[xy] |= CANDIDATE_MB_TYPE_INTRA; | |
2120 mv_table[xy][0]= | |
2121 mv_table[xy][1]= 0; | |
2122 } | |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha¸«³l LEGRAND) with some modifications by me
michaelni
parents:
1050
diff
changeset
|
2123 } |
1086 | 2124 } |
324 | 2125 } |
2126 xy++; | |
2127 } | |
2128 } | |
2129 } |