annotate motion_est.c @ 289:648e9245546d libavcodec

seems the old intra/inter decission is slightly better with a threshold, than the new one
author michaelni
date Sun, 24 Mar 2002 04:58:54 +0000
parents f82cce6cb182
children 944632089814
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1 /*
986e461dc072 Initial revision
glantau
parents:
diff changeset
2 * Motion estimation
986e461dc072 Initial revision
glantau
parents:
diff changeset
3 * Copyright (c) 2000,2001 Gerard Lantau.
986e461dc072 Initial revision
glantau
parents:
diff changeset
4 *
986e461dc072 Initial revision
glantau
parents:
diff changeset
5 *
986e461dc072 Initial revision
glantau
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
986e461dc072 Initial revision
glantau
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
986e461dc072 Initial revision
glantau
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
986e461dc072 Initial revision
glantau
parents:
diff changeset
9 * (at your option) any later version.
986e461dc072 Initial revision
glantau
parents:
diff changeset
10 *
986e461dc072 Initial revision
glantau
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
986e461dc072 Initial revision
glantau
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
986e461dc072 Initial revision
glantau
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
986e461dc072 Initial revision
glantau
parents:
diff changeset
14 * GNU General Public License for more details.
986e461dc072 Initial revision
glantau
parents:
diff changeset
15 *
986e461dc072 Initial revision
glantau
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
986e461dc072 Initial revision
glantau
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
986e461dc072 Initial revision
glantau
parents:
diff changeset
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
277
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
19 *
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
20 * new Motion Estimation (X1/EPZS) by Michael Niedermayer <michaelni@gmx.at>
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
21 */
986e461dc072 Initial revision
glantau
parents:
diff changeset
22 #include <stdlib.h>
986e461dc072 Initial revision
glantau
parents:
diff changeset
23 #include <stdio.h>
986e461dc072 Initial revision
glantau
parents:
diff changeset
24 #include "avcodec.h"
986e461dc072 Initial revision
glantau
parents:
diff changeset
25 #include "dsputil.h"
986e461dc072 Initial revision
glantau
parents:
diff changeset
26 #include "mpegvideo.h"
986e461dc072 Initial revision
glantau
parents:
diff changeset
27
284
0778d4e1d584 better inter/intra decission algo (same as xvid)
michaelni
parents: 281
diff changeset
28 #define ABS(a) ((a)>0 ? (a) : -(a))
0778d4e1d584 better inter/intra decission algo (same as xvid)
michaelni
parents: 281
diff changeset
29 #define INTER_BIAS 257
0778d4e1d584 better inter/intra decission algo (same as xvid)
michaelni
parents: 281
diff changeset
30
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
31 static void halfpel_motion_search(MpegEncContext * s,
986e461dc072 Initial revision
glantau
parents:
diff changeset
32 int *mx_ptr, int *my_ptr, int dmin,
277
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
33 int xmin, int ymin, int xmax, int ymax,
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
34 int pred_x, int pred_y);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
35
986e461dc072 Initial revision
glantau
parents:
diff changeset
36 /* config it to test motion vector encoding (send random vectors) */
986e461dc072 Initial revision
glantau
parents:
diff changeset
37 //#define CONFIG_TEST_MV_ENCODE
986e461dc072 Initial revision
glantau
parents:
diff changeset
38
986e461dc072 Initial revision
glantau
parents:
diff changeset
39 static int pix_sum(UINT8 * pix, int line_size)
986e461dc072 Initial revision
glantau
parents:
diff changeset
40 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
41 int s, i, j;
986e461dc072 Initial revision
glantau
parents:
diff changeset
42
986e461dc072 Initial revision
glantau
parents:
diff changeset
43 s = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
44 for (i = 0; i < 16; i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
45 for (j = 0; j < 16; j += 8) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
46 s += pix[0];
986e461dc072 Initial revision
glantau
parents:
diff changeset
47 s += pix[1];
986e461dc072 Initial revision
glantau
parents:
diff changeset
48 s += pix[2];
986e461dc072 Initial revision
glantau
parents:
diff changeset
49 s += pix[3];
986e461dc072 Initial revision
glantau
parents:
diff changeset
50 s += pix[4];
986e461dc072 Initial revision
glantau
parents:
diff changeset
51 s += pix[5];
986e461dc072 Initial revision
glantau
parents:
diff changeset
52 s += pix[6];
986e461dc072 Initial revision
glantau
parents:
diff changeset
53 s += pix[7];
986e461dc072 Initial revision
glantau
parents:
diff changeset
54 pix += 8;
986e461dc072 Initial revision
glantau
parents:
diff changeset
55 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
56 pix += line_size - 16;
986e461dc072 Initial revision
glantau
parents:
diff changeset
57 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
58 return s;
986e461dc072 Initial revision
glantau
parents:
diff changeset
59 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
60
284
0778d4e1d584 better inter/intra decission algo (same as xvid)
michaelni
parents: 281
diff changeset
61 static int pix_dev(UINT8 * pix, int line_size, int mean)
0778d4e1d584 better inter/intra decission algo (same as xvid)
michaelni
parents: 281
diff changeset
62 {
0778d4e1d584 better inter/intra decission algo (same as xvid)
michaelni
parents: 281
diff changeset
63 int s, i, j;
0778d4e1d584 better inter/intra decission algo (same as xvid)
michaelni
parents: 281
diff changeset
64
0778d4e1d584 better inter/intra decission algo (same as xvid)
michaelni
parents: 281
diff changeset
65 s = 0;
0778d4e1d584 better inter/intra decission algo (same as xvid)
michaelni
parents: 281
diff changeset
66 for (i = 0; i < 16; i++) {
0778d4e1d584 better inter/intra decission algo (same as xvid)
michaelni
parents: 281
diff changeset
67 for (j = 0; j < 16; j += 8) {
0778d4e1d584 better inter/intra decission algo (same as xvid)
michaelni
parents: 281
diff changeset
68 s += ABS(pix[0]-mean);
0778d4e1d584 better inter/intra decission algo (same as xvid)
michaelni
parents: 281
diff changeset
69 s += ABS(pix[1]-mean);
0778d4e1d584 better inter/intra decission algo (same as xvid)
michaelni
parents: 281
diff changeset
70 s += ABS(pix[2]-mean);
0778d4e1d584 better inter/intra decission algo (same as xvid)
michaelni
parents: 281
diff changeset
71 s += ABS(pix[3]-mean);
0778d4e1d584 better inter/intra decission algo (same as xvid)
michaelni
parents: 281
diff changeset
72 s += ABS(pix[4]-mean);
0778d4e1d584 better inter/intra decission algo (same as xvid)
michaelni
parents: 281
diff changeset
73 s += ABS(pix[5]-mean);
0778d4e1d584 better inter/intra decission algo (same as xvid)
michaelni
parents: 281
diff changeset
74 s += ABS(pix[6]-mean);
0778d4e1d584 better inter/intra decission algo (same as xvid)
michaelni
parents: 281
diff changeset
75 s += ABS(pix[7]-mean);
0778d4e1d584 better inter/intra decission algo (same as xvid)
michaelni
parents: 281
diff changeset
76 pix += 8;
0778d4e1d584 better inter/intra decission algo (same as xvid)
michaelni
parents: 281
diff changeset
77 }
0778d4e1d584 better inter/intra decission algo (same as xvid)
michaelni
parents: 281
diff changeset
78 pix += line_size - 16;
0778d4e1d584 better inter/intra decission algo (same as xvid)
michaelni
parents: 281
diff changeset
79 }
0778d4e1d584 better inter/intra decission algo (same as xvid)
michaelni
parents: 281
diff changeset
80 return s;
0778d4e1d584 better inter/intra decission algo (same as xvid)
michaelni
parents: 281
diff changeset
81 }
0778d4e1d584 better inter/intra decission algo (same as xvid)
michaelni
parents: 281
diff changeset
82
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
83 static int pix_norm1(UINT8 * pix, int line_size)
986e461dc072 Initial revision
glantau
parents:
diff changeset
84 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
85 int s, i, j;
986e461dc072 Initial revision
glantau
parents:
diff changeset
86 UINT32 *sq = squareTbl + 256;
986e461dc072 Initial revision
glantau
parents:
diff changeset
87
986e461dc072 Initial revision
glantau
parents:
diff changeset
88 s = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
89 for (i = 0; i < 16; i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
90 for (j = 0; j < 16; j += 8) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
91 s += sq[pix[0]];
986e461dc072 Initial revision
glantau
parents:
diff changeset
92 s += sq[pix[1]];
986e461dc072 Initial revision
glantau
parents:
diff changeset
93 s += sq[pix[2]];
986e461dc072 Initial revision
glantau
parents:
diff changeset
94 s += sq[pix[3]];
986e461dc072 Initial revision
glantau
parents:
diff changeset
95 s += sq[pix[4]];
986e461dc072 Initial revision
glantau
parents:
diff changeset
96 s += sq[pix[5]];
986e461dc072 Initial revision
glantau
parents:
diff changeset
97 s += sq[pix[6]];
986e461dc072 Initial revision
glantau
parents:
diff changeset
98 s += sq[pix[7]];
986e461dc072 Initial revision
glantau
parents:
diff changeset
99 pix += 8;
986e461dc072 Initial revision
glantau
parents:
diff changeset
100 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
101 pix += line_size - 16;
986e461dc072 Initial revision
glantau
parents:
diff changeset
102 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
103 return s;
986e461dc072 Initial revision
glantau
parents:
diff changeset
104 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
105
986e461dc072 Initial revision
glantau
parents:
diff changeset
106 static int pix_norm(UINT8 * pix1, UINT8 * pix2, int line_size)
986e461dc072 Initial revision
glantau
parents:
diff changeset
107 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
108 int s, i, j;
986e461dc072 Initial revision
glantau
parents:
diff changeset
109 UINT32 *sq = squareTbl + 256;
986e461dc072 Initial revision
glantau
parents:
diff changeset
110
986e461dc072 Initial revision
glantau
parents:
diff changeset
111 s = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
112 for (i = 0; i < 16; i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
113 for (j = 0; j < 16; j += 8) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
114 s += sq[pix1[0] - pix2[0]];
986e461dc072 Initial revision
glantau
parents:
diff changeset
115 s += sq[pix1[1] - pix2[1]];
986e461dc072 Initial revision
glantau
parents:
diff changeset
116 s += sq[pix1[2] - pix2[2]];
986e461dc072 Initial revision
glantau
parents:
diff changeset
117 s += sq[pix1[3] - pix2[3]];
986e461dc072 Initial revision
glantau
parents:
diff changeset
118 s += sq[pix1[4] - pix2[4]];
986e461dc072 Initial revision
glantau
parents:
diff changeset
119 s += sq[pix1[5] - pix2[5]];
986e461dc072 Initial revision
glantau
parents:
diff changeset
120 s += sq[pix1[6] - pix2[6]];
986e461dc072 Initial revision
glantau
parents:
diff changeset
121 s += sq[pix1[7] - pix2[7]];
986e461dc072 Initial revision
glantau
parents:
diff changeset
122 pix1 += 8;
986e461dc072 Initial revision
glantau
parents:
diff changeset
123 pix2 += 8;
986e461dc072 Initial revision
glantau
parents:
diff changeset
124 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
125 pix1 += line_size - 16;
986e461dc072 Initial revision
glantau
parents:
diff changeset
126 pix2 += line_size - 16;
986e461dc072 Initial revision
glantau
parents:
diff changeset
127 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
128 return s;
986e461dc072 Initial revision
glantau
parents:
diff changeset
129 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
130
986e461dc072 Initial revision
glantau
parents:
diff changeset
131 static void no_motion_search(MpegEncContext * s,
986e461dc072 Initial revision
glantau
parents:
diff changeset
132 int *mx_ptr, int *my_ptr)
986e461dc072 Initial revision
glantau
parents:
diff changeset
133 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
134 *mx_ptr = 16 * s->mb_x;
986e461dc072 Initial revision
glantau
parents:
diff changeset
135 *my_ptr = 16 * s->mb_y;
986e461dc072 Initial revision
glantau
parents:
diff changeset
136 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
137
986e461dc072 Initial revision
glantau
parents:
diff changeset
138 static int full_motion_search(MpegEncContext * s,
986e461dc072 Initial revision
glantau
parents:
diff changeset
139 int *mx_ptr, int *my_ptr, int range,
986e461dc072 Initial revision
glantau
parents:
diff changeset
140 int xmin, int ymin, int xmax, int ymax)
986e461dc072 Initial revision
glantau
parents:
diff changeset
141 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
142 int x1, y1, x2, y2, xx, yy, x, y;
986e461dc072 Initial revision
glantau
parents:
diff changeset
143 int mx, my, dmin, d;
986e461dc072 Initial revision
glantau
parents:
diff changeset
144 UINT8 *pix;
986e461dc072 Initial revision
glantau
parents:
diff changeset
145
986e461dc072 Initial revision
glantau
parents:
diff changeset
146 xx = 16 * s->mb_x;
986e461dc072 Initial revision
glantau
parents:
diff changeset
147 yy = 16 * s->mb_y;
986e461dc072 Initial revision
glantau
parents:
diff changeset
148 x1 = xx - range + 1; /* we loose one pixel to avoid boundary pb with half pixel pred */
986e461dc072 Initial revision
glantau
parents:
diff changeset
149 if (x1 < xmin)
986e461dc072 Initial revision
glantau
parents:
diff changeset
150 x1 = xmin;
986e461dc072 Initial revision
glantau
parents:
diff changeset
151 x2 = xx + range - 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
152 if (x2 > xmax)
986e461dc072 Initial revision
glantau
parents:
diff changeset
153 x2 = xmax;
986e461dc072 Initial revision
glantau
parents:
diff changeset
154 y1 = yy - range + 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
155 if (y1 < ymin)
986e461dc072 Initial revision
glantau
parents:
diff changeset
156 y1 = ymin;
986e461dc072 Initial revision
glantau
parents:
diff changeset
157 y2 = yy + range - 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
158 if (y2 > ymax)
986e461dc072 Initial revision
glantau
parents:
diff changeset
159 y2 = ymax;
986e461dc072 Initial revision
glantau
parents:
diff changeset
160 pix = s->new_picture[0] + (yy * s->linesize) + xx;
986e461dc072 Initial revision
glantau
parents:
diff changeset
161 dmin = 0x7fffffff;
986e461dc072 Initial revision
glantau
parents:
diff changeset
162 mx = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
163 my = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
164 for (y = y1; y <= y2; y++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
165 for (x = x1; x <= x2; x++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
166 d = pix_abs16x16(pix, s->last_picture[0] + (y * s->linesize) + x,
986e461dc072 Initial revision
glantau
parents:
diff changeset
167 s->linesize, 16);
986e461dc072 Initial revision
glantau
parents:
diff changeset
168 if (d < dmin ||
986e461dc072 Initial revision
glantau
parents:
diff changeset
169 (d == dmin &&
986e461dc072 Initial revision
glantau
parents:
diff changeset
170 (abs(x - xx) + abs(y - yy)) <
986e461dc072 Initial revision
glantau
parents:
diff changeset
171 (abs(mx - xx) + abs(my - yy)))) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
172 dmin = d;
986e461dc072 Initial revision
glantau
parents:
diff changeset
173 mx = x;
986e461dc072 Initial revision
glantau
parents:
diff changeset
174 my = y;
986e461dc072 Initial revision
glantau
parents:
diff changeset
175 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
176 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
177 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
178
986e461dc072 Initial revision
glantau
parents:
diff changeset
179 *mx_ptr = mx;
986e461dc072 Initial revision
glantau
parents:
diff changeset
180 *my_ptr = my;
986e461dc072 Initial revision
glantau
parents:
diff changeset
181
986e461dc072 Initial revision
glantau
parents:
diff changeset
182 #if 0
986e461dc072 Initial revision
glantau
parents:
diff changeset
183 if (*mx_ptr < -(2 * range) || *mx_ptr >= (2 * range) ||
986e461dc072 Initial revision
glantau
parents:
diff changeset
184 *my_ptr < -(2 * range) || *my_ptr >= (2 * range)) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
185 fprintf(stderr, "error %d %d\n", *mx_ptr, *my_ptr);
986e461dc072 Initial revision
glantau
parents:
diff changeset
186 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
187 #endif
986e461dc072 Initial revision
glantau
parents:
diff changeset
188 return dmin;
986e461dc072 Initial revision
glantau
parents:
diff changeset
189 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
190
986e461dc072 Initial revision
glantau
parents:
diff changeset
191
986e461dc072 Initial revision
glantau
parents:
diff changeset
192 static int log_motion_search(MpegEncContext * s,
986e461dc072 Initial revision
glantau
parents:
diff changeset
193 int *mx_ptr, int *my_ptr, int range,
986e461dc072 Initial revision
glantau
parents:
diff changeset
194 int xmin, int ymin, int xmax, int ymax)
986e461dc072 Initial revision
glantau
parents:
diff changeset
195 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
196 int x1, y1, x2, y2, xx, yy, x, y;
986e461dc072 Initial revision
glantau
parents:
diff changeset
197 int mx, my, dmin, d;
986e461dc072 Initial revision
glantau
parents:
diff changeset
198 UINT8 *pix;
986e461dc072 Initial revision
glantau
parents:
diff changeset
199
986e461dc072 Initial revision
glantau
parents:
diff changeset
200 xx = s->mb_x << 4;
986e461dc072 Initial revision
glantau
parents:
diff changeset
201 yy = s->mb_y << 4;
986e461dc072 Initial revision
glantau
parents:
diff changeset
202
986e461dc072 Initial revision
glantau
parents:
diff changeset
203 /* Left limit */
986e461dc072 Initial revision
glantau
parents:
diff changeset
204 x1 = xx - range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
205 if (x1 < xmin)
986e461dc072 Initial revision
glantau
parents:
diff changeset
206 x1 = xmin;
986e461dc072 Initial revision
glantau
parents:
diff changeset
207
986e461dc072 Initial revision
glantau
parents:
diff changeset
208 /* Right limit */
986e461dc072 Initial revision
glantau
parents:
diff changeset
209 x2 = xx + range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
210 if (x2 > xmax)
986e461dc072 Initial revision
glantau
parents:
diff changeset
211 x2 = xmax;
986e461dc072 Initial revision
glantau
parents:
diff changeset
212
986e461dc072 Initial revision
glantau
parents:
diff changeset
213 /* Upper limit */
986e461dc072 Initial revision
glantau
parents:
diff changeset
214 y1 = yy - range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
215 if (y1 < ymin)
986e461dc072 Initial revision
glantau
parents:
diff changeset
216 y1 = ymin;
986e461dc072 Initial revision
glantau
parents:
diff changeset
217
986e461dc072 Initial revision
glantau
parents:
diff changeset
218 /* Lower limit */
986e461dc072 Initial revision
glantau
parents:
diff changeset
219 y2 = yy + range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
220 if (y2 > ymax)
986e461dc072 Initial revision
glantau
parents:
diff changeset
221 y2 = ymax;
986e461dc072 Initial revision
glantau
parents:
diff changeset
222
986e461dc072 Initial revision
glantau
parents:
diff changeset
223 pix = s->new_picture[0] + (yy * s->linesize) + xx;
986e461dc072 Initial revision
glantau
parents:
diff changeset
224 dmin = 0x7fffffff;
986e461dc072 Initial revision
glantau
parents:
diff changeset
225 mx = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
226 my = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
227
986e461dc072 Initial revision
glantau
parents:
diff changeset
228 do {
986e461dc072 Initial revision
glantau
parents:
diff changeset
229 for (y = y1; y <= y2; y += range) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
230 for (x = x1; x <= x2; x += range) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
231 d = pix_abs16x16(pix, s->last_picture[0] + (y * s->linesize) + x, s->linesize, 16);
986e461dc072 Initial revision
glantau
parents:
diff changeset
232 if (d < dmin || (d == dmin && (abs(x - xx) + abs(y - yy)) < (abs(mx - xx) + abs(my - yy)))) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
233 dmin = d;
986e461dc072 Initial revision
glantau
parents:
diff changeset
234 mx = x;
986e461dc072 Initial revision
glantau
parents:
diff changeset
235 my = y;
986e461dc072 Initial revision
glantau
parents:
diff changeset
236 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
237 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
238 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
239
986e461dc072 Initial revision
glantau
parents:
diff changeset
240 range = range >> 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
241
986e461dc072 Initial revision
glantau
parents:
diff changeset
242 x1 = mx - range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
243 if (x1 < xmin)
986e461dc072 Initial revision
glantau
parents:
diff changeset
244 x1 = xmin;
986e461dc072 Initial revision
glantau
parents:
diff changeset
245
986e461dc072 Initial revision
glantau
parents:
diff changeset
246 x2 = mx + range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
247 if (x2 > xmax)
986e461dc072 Initial revision
glantau
parents:
diff changeset
248 x2 = xmax;
986e461dc072 Initial revision
glantau
parents:
diff changeset
249
986e461dc072 Initial revision
glantau
parents:
diff changeset
250 y1 = my - range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
251 if (y1 < ymin)
986e461dc072 Initial revision
glantau
parents:
diff changeset
252 y1 = ymin;
986e461dc072 Initial revision
glantau
parents:
diff changeset
253
986e461dc072 Initial revision
glantau
parents:
diff changeset
254 y2 = my + range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
255 if (y2 > ymax)
986e461dc072 Initial revision
glantau
parents:
diff changeset
256 y2 = ymax;
986e461dc072 Initial revision
glantau
parents:
diff changeset
257
986e461dc072 Initial revision
glantau
parents:
diff changeset
258 } while (range >= 1);
986e461dc072 Initial revision
glantau
parents:
diff changeset
259
986e461dc072 Initial revision
glantau
parents:
diff changeset
260 #ifdef DEBUG
986e461dc072 Initial revision
glantau
parents:
diff changeset
261 fprintf(stderr, "log - MX: %d\tMY: %d\n", mx, my);
986e461dc072 Initial revision
glantau
parents:
diff changeset
262 #endif
986e461dc072 Initial revision
glantau
parents:
diff changeset
263 *mx_ptr = mx;
986e461dc072 Initial revision
glantau
parents:
diff changeset
264 *my_ptr = my;
986e461dc072 Initial revision
glantau
parents:
diff changeset
265 return dmin;
986e461dc072 Initial revision
glantau
parents:
diff changeset
266 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
267
986e461dc072 Initial revision
glantau
parents:
diff changeset
268 static int phods_motion_search(MpegEncContext * s,
986e461dc072 Initial revision
glantau
parents:
diff changeset
269 int *mx_ptr, int *my_ptr, int range,
986e461dc072 Initial revision
glantau
parents:
diff changeset
270 int xmin, int ymin, int xmax, int ymax)
986e461dc072 Initial revision
glantau
parents:
diff changeset
271 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
272 int x1, y1, x2, y2, xx, yy, x, y, lastx, d;
986e461dc072 Initial revision
glantau
parents:
diff changeset
273 int mx, my, dminx, dminy;
986e461dc072 Initial revision
glantau
parents:
diff changeset
274 UINT8 *pix;
986e461dc072 Initial revision
glantau
parents:
diff changeset
275
986e461dc072 Initial revision
glantau
parents:
diff changeset
276 xx = s->mb_x << 4;
986e461dc072 Initial revision
glantau
parents:
diff changeset
277 yy = s->mb_y << 4;
986e461dc072 Initial revision
glantau
parents:
diff changeset
278
986e461dc072 Initial revision
glantau
parents:
diff changeset
279 /* Left limit */
986e461dc072 Initial revision
glantau
parents:
diff changeset
280 x1 = xx - range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
281 if (x1 < xmin)
986e461dc072 Initial revision
glantau
parents:
diff changeset
282 x1 = xmin;
986e461dc072 Initial revision
glantau
parents:
diff changeset
283
986e461dc072 Initial revision
glantau
parents:
diff changeset
284 /* Right limit */
986e461dc072 Initial revision
glantau
parents:
diff changeset
285 x2 = xx + range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
286 if (x2 > xmax)
986e461dc072 Initial revision
glantau
parents:
diff changeset
287 x2 = xmax;
986e461dc072 Initial revision
glantau
parents:
diff changeset
288
986e461dc072 Initial revision
glantau
parents:
diff changeset
289 /* Upper limit */
986e461dc072 Initial revision
glantau
parents:
diff changeset
290 y1 = yy - range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
291 if (y1 < ymin)
986e461dc072 Initial revision
glantau
parents:
diff changeset
292 y1 = ymin;
986e461dc072 Initial revision
glantau
parents:
diff changeset
293
986e461dc072 Initial revision
glantau
parents:
diff changeset
294 /* Lower limit */
986e461dc072 Initial revision
glantau
parents:
diff changeset
295 y2 = yy + range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
296 if (y2 > ymax)
986e461dc072 Initial revision
glantau
parents:
diff changeset
297 y2 = ymax;
986e461dc072 Initial revision
glantau
parents:
diff changeset
298
986e461dc072 Initial revision
glantau
parents:
diff changeset
299 pix = s->new_picture[0] + (yy * s->linesize) + xx;
986e461dc072 Initial revision
glantau
parents:
diff changeset
300 mx = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
301 my = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
302
986e461dc072 Initial revision
glantau
parents:
diff changeset
303 x = xx;
986e461dc072 Initial revision
glantau
parents:
diff changeset
304 y = yy;
986e461dc072 Initial revision
glantau
parents:
diff changeset
305 do {
986e461dc072 Initial revision
glantau
parents:
diff changeset
306 dminx = 0x7fffffff;
986e461dc072 Initial revision
glantau
parents:
diff changeset
307 dminy = 0x7fffffff;
986e461dc072 Initial revision
glantau
parents:
diff changeset
308
986e461dc072 Initial revision
glantau
parents:
diff changeset
309 lastx = x;
986e461dc072 Initial revision
glantau
parents:
diff changeset
310 for (x = x1; x <= x2; x += range) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
311 d = pix_abs16x16(pix, s->last_picture[0] + (y * s->linesize) + x, s->linesize, 16);
986e461dc072 Initial revision
glantau
parents:
diff changeset
312 if (d < dminx || (d == dminx && (abs(x - xx) + abs(y - yy)) < (abs(mx - xx) + abs(my - yy)))) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
313 dminx = d;
986e461dc072 Initial revision
glantau
parents:
diff changeset
314 mx = x;
986e461dc072 Initial revision
glantau
parents:
diff changeset
315 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
316 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
317
986e461dc072 Initial revision
glantau
parents:
diff changeset
318 x = lastx;
986e461dc072 Initial revision
glantau
parents:
diff changeset
319 for (y = y1; y <= y2; y += range) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
320 d = pix_abs16x16(pix, s->last_picture[0] + (y * s->linesize) + x, s->linesize, 16);
986e461dc072 Initial revision
glantau
parents:
diff changeset
321 if (d < dminy || (d == dminy && (abs(x - xx) + abs(y - yy)) < (abs(mx - xx) + abs(my - yy)))) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
322 dminy = d;
986e461dc072 Initial revision
glantau
parents:
diff changeset
323 my = y;
986e461dc072 Initial revision
glantau
parents:
diff changeset
324 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
325 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
326
986e461dc072 Initial revision
glantau
parents:
diff changeset
327 range = range >> 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
328
986e461dc072 Initial revision
glantau
parents:
diff changeset
329 x = mx;
986e461dc072 Initial revision
glantau
parents:
diff changeset
330 y = my;
986e461dc072 Initial revision
glantau
parents:
diff changeset
331 x1 = mx - range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
332 if (x1 < xmin)
986e461dc072 Initial revision
glantau
parents:
diff changeset
333 x1 = xmin;
986e461dc072 Initial revision
glantau
parents:
diff changeset
334
986e461dc072 Initial revision
glantau
parents:
diff changeset
335 x2 = mx + range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
336 if (x2 > xmax)
986e461dc072 Initial revision
glantau
parents:
diff changeset
337 x2 = xmax;
986e461dc072 Initial revision
glantau
parents:
diff changeset
338
986e461dc072 Initial revision
glantau
parents:
diff changeset
339 y1 = my - range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
340 if (y1 < ymin)
986e461dc072 Initial revision
glantau
parents:
diff changeset
341 y1 = ymin;
986e461dc072 Initial revision
glantau
parents:
diff changeset
342
986e461dc072 Initial revision
glantau
parents:
diff changeset
343 y2 = my + range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
344 if (y2 > ymax)
986e461dc072 Initial revision
glantau
parents:
diff changeset
345 y2 = ymax;
986e461dc072 Initial revision
glantau
parents:
diff changeset
346
986e461dc072 Initial revision
glantau
parents:
diff changeset
347 } while (range >= 1);
986e461dc072 Initial revision
glantau
parents:
diff changeset
348
986e461dc072 Initial revision
glantau
parents:
diff changeset
349 #ifdef DEBUG
986e461dc072 Initial revision
glantau
parents:
diff changeset
350 fprintf(stderr, "phods - MX: %d\tMY: %d\n", mx, my);
986e461dc072 Initial revision
glantau
parents:
diff changeset
351 #endif
986e461dc072 Initial revision
glantau
parents:
diff changeset
352
986e461dc072 Initial revision
glantau
parents:
diff changeset
353 /* half pixel search */
986e461dc072 Initial revision
glantau
parents:
diff changeset
354 *mx_ptr = mx;
986e461dc072 Initial revision
glantau
parents:
diff changeset
355 *my_ptr = my;
986e461dc072 Initial revision
glantau
parents:
diff changeset
356 return dminy;
986e461dc072 Initial revision
glantau
parents:
diff changeset
357 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
358
277
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
359
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
360 #define Z_THRESHOLD 256
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
361
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
362 #define CHECK_MV(x,y)\
281
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
363 {\
277
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
364 d = pix_abs16x16(new_pic, old_pic + (x) + (y)*pic_stride, pic_stride, 16);\
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
365 d += (mv_penalty[((x)<<shift)-pred_x] + mv_penalty[((y)<<shift)-pred_y])*quant;\
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
366 if(d<dmin){\
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
367 best[0]=x;\
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
368 best[1]=y;\
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
369 dmin=d;\
281
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
370 }\
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
371 }
277
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
372
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
373 #define CHECK_MV_DIR(x,y,new_dir)\
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
374 {\
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
375 d = pix_abs16x16(new_pic, old_pic + (x) + (y)*pic_stride, pic_stride, 16);\
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
376 d += (mv_penalty[((x)<<shift)-pred_x] + mv_penalty[((y)<<shift)-pred_y])*quant;\
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
377 if(d<dmin){\
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
378 best[0]=x;\
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
379 best[1]=y;\
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
380 dmin=d;\
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
381 next_dir= new_dir;\
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
382 }\
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
383 }
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
384
281
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
385 #define check(x,y,S,v)\
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
386 if( (x)<(xmin<<(S)) ) printf("%d %d %d %d xmin" #v, (x), (y), s->mb_x, s->mb_y);\
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
387 if( (x)>(xmax<<(S)) ) printf("%d %d %d %d xmax" #v, (x), (y), s->mb_x, s->mb_y);\
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
388 if( (y)<(ymin<<(S)) ) printf("%d %d %d %d ymin" #v, (x), (y), s->mb_x, s->mb_y);\
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
389 if( (y)>(ymax<<(S)) ) printf("%d %d %d %d ymax" #v, (x), (y), s->mb_x, s->mb_y);\
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
390
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
391
277
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
392 static inline int small_diamond_search(MpegEncContext * s, int *best, int dmin,
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
393 UINT8 *new_pic, UINT8 *old_pic, int pic_stride,
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
394 int pred_x, int pred_y, UINT16 *mv_penalty, int quant,
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
395 int xmin, int ymin, int xmax, int ymax, int shift)
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
396 {
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
397 int next_dir=-1;
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
398
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
399 for(;;){
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
400 int d;
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
401 const int dir= next_dir;
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
402 const int x= best[0];
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
403 const int y= best[1];
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
404 next_dir=-1;
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
405
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
406 //printf("%d", dir);
280
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
407 if(dir!=2 && x>xmin) CHECK_MV_DIR(x-1, y , 0)
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
408 if(dir!=3 && y>ymin) CHECK_MV_DIR(x , y-1, 1)
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
409 if(dir!=0 && x<xmax) CHECK_MV_DIR(x+1, y , 2)
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
410 if(dir!=1 && y<ymax) CHECK_MV_DIR(x , y+1, 3)
277
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
411
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
412 if(next_dir==-1){
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
413 return dmin;
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
414 }
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
415 }
281
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
416
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
417 /* for(;;){
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
418 int d;
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
419 const int x= best[0];
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
420 const int y= best[1];
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
421 const int last_min=dmin;
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
422 if(x>xmin) CHECK_MV(x-1, y )
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
423 if(y>xmin) CHECK_MV(x , y-1)
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
424 if(x<xmax) CHECK_MV(x+1, y )
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
425 if(y<xmax) CHECK_MV(x , y+1)
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
426 if(x>xmin && y>ymin) CHECK_MV(x-1, y-1)
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
427 if(x>xmin && y<ymax) CHECK_MV(x-1, y+1)
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
428 if(x<xmax && y>ymin) CHECK_MV(x+1, y-1)
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
429 if(x<xmax && y<ymax) CHECK_MV(x+1, y+1)
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
430 if(x-1>xmin) CHECK_MV(x-2, y )
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
431 if(y-1>xmin) CHECK_MV(x , y-2)
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
432 if(x+1<xmax) CHECK_MV(x+2, y )
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
433 if(y+1<xmax) CHECK_MV(x , y+2)
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
434 if(x-1>xmin && y-1>ymin) CHECK_MV(x-2, y-2)
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
435 if(x-1>xmin && y+1<ymax) CHECK_MV(x-2, y+2)
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
436 if(x+1<xmax && y-1>ymin) CHECK_MV(x+2, y-2)
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
437 if(x+1<xmax && y+1<ymax) CHECK_MV(x+2, y+2)
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
438 if(dmin==last_min) return dmin;
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
439 }
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
440 */
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
441 }
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
442
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
443 static inline int snake_search(MpegEncContext * s, int *best, int dmin,
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
444 UINT8 *new_pic, UINT8 *old_pic, int pic_stride,
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
445 int pred_x, int pred_y, UINT16 *mv_penalty, int quant,
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
446 int xmin, int ymin, int xmax, int ymax, int shift)
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
447 {
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
448 int dir=0;
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
449 int c=1;
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
450 static int x_dir[8]= {1,1,0,-1,-1,-1, 0, 1};
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
451 static int y_dir[8]= {0,1,1, 1, 0,-1,-1,-1};
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
452 int fails=0;
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
453 int last_d[2]={dmin, dmin};
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
454
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
455 /*static int good=0;
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
456 static int bad=0;
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
457 static int point=0;
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
458
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
459 point++;
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
460 if(256*256*256*64%point==0)
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
461 {
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
462 printf("%d %d %d\n", good, bad, point);
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
463 }*/
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
464
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
465 for(;;){
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
466 int x= best[0];
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
467 int y= best[1];
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
468 int d;
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
469 x+=x_dir[dir];
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
470 y+=y_dir[dir];
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
471 if(x>=xmin && x<=xmax && y>=ymin && y<=ymax){
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
472 d = pix_abs16x16(new_pic, old_pic + (x) + (y)*pic_stride, pic_stride, 16);
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
473 d += (mv_penalty[((x)<<shift)-pred_x] + mv_penalty[((y)<<shift)-pred_y])*quant;
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
474 }else{
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
475 d = dmin + 10000; //FIXME smarter boundary handling
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
476 }
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
477 if(d<dmin){
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
478 best[0]=x;
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
479 best[1]=y;
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
480 dmin=d;
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
481
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
482 if(last_d[1] - last_d[0] > last_d[0] - d) c= -c;
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
483 dir+=c;
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
484
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
485 fails=0;
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
486 //good++;
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
487 last_d[1]=last_d[0];
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
488 last_d[0]=d;
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
489 }else{
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
490 //bad++;
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
491 if(fails){
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
492 if(fails>=3) return dmin;
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
493 }else{
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
494 c= -c;
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
495 }
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
496 dir+=c*2;
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
497 fails++;
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
498 }
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
499 dir&=7;
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
500 }
277
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
501 }
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
502
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
503 static int epzs_motion_search(MpegEncContext * s,
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
504 int *mx_ptr, int *my_ptr,
280
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
505 int P[5][2], int pred_x, int pred_y,
277
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
506 int xmin, int ymin, int xmax, int ymax)
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
507 {
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
508 int best[2]={0, 0};
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
509 int d, dmin;
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
510 UINT8 *new_pic, *old_pic;
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
511 const int pic_stride= s->linesize;
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
512 const int pic_xy= (s->mb_y*pic_stride + s->mb_x)*16;
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
513 UINT16 *mv_penalty= s->mv_penalty[s->f_code] + MAX_MV; // f_code of the prev frame
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
514 int quant= s->qscale; // qscale of the prev frame
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
515 const int shift= 1+s->quarter_sample;
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
516
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
517 new_pic = s->new_picture[0] + pic_xy;
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
518 old_pic = s->last_picture[0] + pic_xy;
281
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
519
277
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
520 dmin = pix_abs16x16(new_pic, old_pic, pic_stride, 16);
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
521 if(dmin<Z_THRESHOLD){
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
522 *mx_ptr= 0;
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
523 *my_ptr= 0;
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
524 //printf("Z");
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
525 return dmin;
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
526 }
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
527
280
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
528 /* first line */
277
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
529 if ((s->mb_y == 0 || s->first_slice_line || s->first_gob_line)) {
280
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
530 CHECK_MV(P[1][0]>>shift, P[1][1]>>shift)
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
531 }else{
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
532 CHECK_MV(P[4][0]>>shift, P[4][1]>>shift)
277
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
533 if(dmin<Z_THRESHOLD){
280
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
534 *mx_ptr= P[4][0]>>shift;
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
535 *my_ptr= P[4][1]>>shift;
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
536 //printf("M\n");
277
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
537 return dmin;
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
538 }
280
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
539 CHECK_MV(P[1][0]>>shift, P[1][1]>>shift)
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
540 CHECK_MV(P[2][0]>>shift, P[2][1]>>shift)
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
541 CHECK_MV(P[3][0]>>shift, P[3][1]>>shift)
277
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
542 }
280
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
543 CHECK_MV(P[0][0]>>shift, P[0][1]>>shift)
277
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
544
281
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
545 //check(best[0],best[1],0, b0)
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
546 if(s->full_search==ME_EPZS)
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
547 dmin= small_diamond_search(s, best, dmin, new_pic, old_pic, pic_stride,
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
548 pred_x, pred_y, mv_penalty, quant, xmin, ymin, xmax, ymax, shift);
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
549 else
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
550 dmin= snake_search(s, best, dmin, new_pic, old_pic, pic_stride,
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
551 pred_x, pred_y, mv_penalty, quant, xmin, ymin, xmax, ymax, shift);
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
552 //check(best[0],best[1],0, b1)
277
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
553 *mx_ptr= best[0];
280
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
554 *my_ptr= best[1];
277
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
555
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
556 // printf("%d %d %d \n", best[0], best[1], dmin);
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
557 return dmin;
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
558 }
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
559
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
560 #define CHECK_HALF_MV(suffix, x, y) \
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
561 d= pix_abs16x16_ ## suffix(pix, ptr+((x)>>1), s->linesize, 16);\
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
562 d += (mv_penalty[pen_x + x] + mv_penalty[pen_y + y])*quant;\
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
563 if(d<dminh){\
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
564 dminh= d;\
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
565 mx= mx1 + x;\
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
566 my= my1 + y;\
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
567 }
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
568
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
569 /* The idea would be to make half pel ME after Inter/Intra decision to
986e461dc072 Initial revision
glantau
parents:
diff changeset
570 save time. */
277
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
571 static inline void halfpel_motion_search(MpegEncContext * s,
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
572 int *mx_ptr, int *my_ptr, int dmin,
277
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
573 int xmin, int ymin, int xmax, int ymax,
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
574 int pred_x, int pred_y)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
575 {
277
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
576 UINT16 *mv_penalty= s->mv_penalty[s->f_code] + MAX_MV; // f_code of the prev frame
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
577 const int quant= s->qscale;
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
578 int pen_x, pen_y;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
579 int mx, my, mx1, my1, d, xx, yy, dminh;
277
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
580 UINT8 *pix, *ptr;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
581
277
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
582 mx = *mx_ptr;
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
583 my = *my_ptr;
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
584 ptr = s->last_picture[0] + (my * s->linesize) + mx;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
585
986e461dc072 Initial revision
glantau
parents:
diff changeset
586 xx = 16 * s->mb_x;
986e461dc072 Initial revision
glantau
parents:
diff changeset
587 yy = 16 * s->mb_y;
277
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
588 pix = s->new_picture[0] + (yy * s->linesize) + xx;
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
589
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
590 dminh = dmin;
986e461dc072 Initial revision
glantau
parents:
diff changeset
591
277
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
592 if (mx > xmin && mx < xmax &&
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
593 my > ymin && my < ymax) {
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
594
277
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
595 mx= mx1= 2*(mx - xx);
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
596 my= my1= 2*(my - yy);
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
597 if(dmin < Z_THRESHOLD && mx==0 && my==0){
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
598 *mx_ptr = 0;
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
599 *my_ptr = 0;
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
600 return;
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
601 }
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
602
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
603 pen_x= pred_x + mx;
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
604 pen_y= pred_y + my;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
605
277
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
606 ptr-= s->linesize;
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
607 CHECK_HALF_MV(xy2, -1, -1)
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
608 CHECK_HALF_MV(y2 , 0, -1)
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
609 CHECK_HALF_MV(xy2, +1, -1)
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
610
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
611 ptr+= s->linesize;
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
612 CHECK_HALF_MV(x2 , -1, 0)
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
613 CHECK_HALF_MV(x2 , +1, 0)
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
614 CHECK_HALF_MV(xy2, -1, +1)
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
615 CHECK_HALF_MV(y2 , 0, +1)
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
616 CHECK_HALF_MV(xy2, +1, +1)
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
617 }else{
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
618 mx= 2*(mx - xx);
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
619 my= 2*(my - yy);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
620 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
621
277
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
622 *mx_ptr = mx;
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
623 *my_ptr = my;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
624 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
625
986e461dc072 Initial revision
glantau
parents:
diff changeset
626 #ifndef CONFIG_TEST_MV_ENCODE
986e461dc072 Initial revision
glantau
parents:
diff changeset
627
986e461dc072 Initial revision
glantau
parents:
diff changeset
628 int estimate_motion(MpegEncContext * s,
986e461dc072 Initial revision
glantau
parents:
diff changeset
629 int mb_x, int mb_y,
986e461dc072 Initial revision
glantau
parents:
diff changeset
630 int *mx_ptr, int *my_ptr)
986e461dc072 Initial revision
glantau
parents:
diff changeset
631 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
632 UINT8 *pix, *ppix;
986e461dc072 Initial revision
glantau
parents:
diff changeset
633 int sum, varc, vard, mx, my, range, dmin, xx, yy;
986e461dc072 Initial revision
glantau
parents:
diff changeset
634 int xmin, ymin, xmax, ymax;
280
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
635 int rel_xmin, rel_ymin, rel_xmax, rel_ymax;
277
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
636 int pred_x=0, pred_y=0;
280
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
637 int P[5][2];
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
638 const int shift= 1+s->quarter_sample;
233
3f5b72726118 - More work on preliminary bit rate control, just to be able to get an
pulento
parents: 232
diff changeset
639
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
640 range = 8 * (1 << (s->f_code - 1));
986e461dc072 Initial revision
glantau
parents:
diff changeset
641 /* XXX: temporary kludge to avoid overflow for msmpeg4 */
986e461dc072 Initial revision
glantau
parents:
diff changeset
642 if (s->out_format == FMT_H263 && !s->h263_msmpeg4)
986e461dc072 Initial revision
glantau
parents:
diff changeset
643 range = range * 2;
986e461dc072 Initial revision
glantau
parents:
diff changeset
644
986e461dc072 Initial revision
glantau
parents:
diff changeset
645 if (s->unrestricted_mv) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
646 xmin = -16;
986e461dc072 Initial revision
glantau
parents:
diff changeset
647 ymin = -16;
275
7ebb3f9aaf3b - Added video coding statistics for ffmpeg. Needs more work.
pulento
parents: 268
diff changeset
648 if (s->h263_plus)
7ebb3f9aaf3b - Added video coding statistics for ffmpeg. Needs more work.
pulento
parents: 268
diff changeset
649 range *= 2;
218
9df2d13e64b2 (commit by michael)
arpi_esp
parents: 6
diff changeset
650 if(s->avctx==NULL || s->avctx->codec->id!=CODEC_ID_MPEG4){
9df2d13e64b2 (commit by michael)
arpi_esp
parents: 6
diff changeset
651 xmax = s->mb_width*16;
9df2d13e64b2 (commit by michael)
arpi_esp
parents: 6
diff changeset
652 ymax = s->mb_height*16;
9df2d13e64b2 (commit by michael)
arpi_esp
parents: 6
diff changeset
653 }else {
9df2d13e64b2 (commit by michael)
arpi_esp
parents: 6
diff changeset
654 /* XXX: dunno if this is correct but ffmpeg4 decoder wont like it otherwise
9df2d13e64b2 (commit by michael)
arpi_esp
parents: 6
diff changeset
655 (cuz the drawn edge isnt large enough))*/
9df2d13e64b2 (commit by michael)
arpi_esp
parents: 6
diff changeset
656 xmax = s->width;
9df2d13e64b2 (commit by michael)
arpi_esp
parents: 6
diff changeset
657 ymax = s->height;
232
b640ec5948b0 - Now the ME is done for the entire picture when enconding, the
pulento
parents: 218
diff changeset
658 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
659 } else {
986e461dc072 Initial revision
glantau
parents:
diff changeset
660 xmin = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
661 ymin = 0;
218
9df2d13e64b2 (commit by michael)
arpi_esp
parents: 6
diff changeset
662 xmax = s->mb_width*16 - 16;
9df2d13e64b2 (commit by michael)
arpi_esp
parents: 6
diff changeset
663 ymax = s->mb_height*16 - 16;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
664 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
665 switch(s->full_search) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
666 case ME_ZERO:
986e461dc072 Initial revision
glantau
parents:
diff changeset
667 default:
986e461dc072 Initial revision
glantau
parents:
diff changeset
668 no_motion_search(s, &mx, &my);
986e461dc072 Initial revision
glantau
parents:
diff changeset
669 dmin = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
670 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
671 case ME_FULL:
986e461dc072 Initial revision
glantau
parents:
diff changeset
672 dmin = full_motion_search(s, &mx, &my, range, xmin, ymin, xmax, ymax);
986e461dc072 Initial revision
glantau
parents:
diff changeset
673 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
674 case ME_LOG:
986e461dc072 Initial revision
glantau
parents:
diff changeset
675 dmin = log_motion_search(s, &mx, &my, range / 2, xmin, ymin, xmax, ymax);
986e461dc072 Initial revision
glantau
parents:
diff changeset
676 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
677 case ME_PHODS:
986e461dc072 Initial revision
glantau
parents:
diff changeset
678 dmin = phods_motion_search(s, &mx, &my, range / 2, xmin, ymin, xmax, ymax);
986e461dc072 Initial revision
glantau
parents:
diff changeset
679 break;
288
f82cce6cb182 10l (motion_val was uninitilized)
michaelni
parents: 284
diff changeset
680 case ME_X1:
277
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
681 case ME_EPZS:
288
f82cce6cb182 10l (motion_val was uninitilized)
michaelni
parents: 284
diff changeset
682 {
280
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
683 static const int off[4]= {2, 1, 1, -1};
281
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
684 const int mot_stride = s->mb_width*2 + 2;
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
685 const int mot_xy = (s->mb_y*2 + 1)*mot_stride + s->mb_x*2 + 1;
288
f82cce6cb182 10l (motion_val was uninitilized)
michaelni
parents: 284
diff changeset
686
f82cce6cb182 10l (motion_val was uninitilized)
michaelni
parents: 284
diff changeset
687 rel_xmin= xmin - s->mb_x*16;
f82cce6cb182 10l (motion_val was uninitilized)
michaelni
parents: 284
diff changeset
688 rel_xmax= xmax - s->mb_x*16;
f82cce6cb182 10l (motion_val was uninitilized)
michaelni
parents: 284
diff changeset
689 rel_ymin= ymin - s->mb_y*16;
f82cce6cb182 10l (motion_val was uninitilized)
michaelni
parents: 284
diff changeset
690 rel_ymax= ymax - s->mb_y*16;
f82cce6cb182 10l (motion_val was uninitilized)
michaelni
parents: 284
diff changeset
691
280
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
692 P[0][0] = s->motion_val[mot_xy ][0];
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
693 P[0][1] = s->motion_val[mot_xy ][1];
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
694 P[1][0] = s->motion_val[mot_xy - 1][0];
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
695 P[1][1] = s->motion_val[mot_xy - 1][1];
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
696 if(P[1][0] > (rel_xmax<<shift)) P[1][0]= (rel_xmax<<shift);
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
697
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
698 /* special case for first line */
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
699 if ((s->mb_y == 0 || s->first_slice_line || s->first_gob_line)) {
288
f82cce6cb182 10l (motion_val was uninitilized)
michaelni
parents: 284
diff changeset
700 P[4][0] = P[1][0];
f82cce6cb182 10l (motion_val was uninitilized)
michaelni
parents: 284
diff changeset
701 P[4][1] = P[1][1];
280
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
702 } else {
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
703 P[2][0] = s->motion_val[mot_xy - mot_stride ][0];
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
704 P[2][1] = s->motion_val[mot_xy - mot_stride ][1];
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
705 P[3][0] = s->motion_val[mot_xy - mot_stride + off[0] ][0];
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
706 P[3][1] = s->motion_val[mot_xy - mot_stride + off[0] ][1];
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
707 if(P[2][1] > (rel_ymax<<shift)) P[2][1]= (rel_ymax<<shift);
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
708 if(P[3][0] < (rel_xmin<<shift)) P[3][0]= (rel_xmin<<shift);
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
709 if(P[3][1] > (rel_ymax<<shift)) P[3][1]= (rel_ymax<<shift);
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
710
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
711 P[4][0]= mid_pred(P[1][0], P[2][0], P[3][0]);
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
712 P[4][1]= mid_pred(P[1][1], P[2][1], P[3][1]);
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
713 }
288
f82cce6cb182 10l (motion_val was uninitilized)
michaelni
parents: 284
diff changeset
714 if(s->out_format == FMT_H263){
f82cce6cb182 10l (motion_val was uninitilized)
michaelni
parents: 284
diff changeset
715 pred_x = P[4][0];
f82cce6cb182 10l (motion_val was uninitilized)
michaelni
parents: 284
diff changeset
716 pred_y = P[4][1];
f82cce6cb182 10l (motion_val was uninitilized)
michaelni
parents: 284
diff changeset
717 }else { /* mpeg1 at least */
f82cce6cb182 10l (motion_val was uninitilized)
michaelni
parents: 284
diff changeset
718 pred_x= P[1][0];
f82cce6cb182 10l (motion_val was uninitilized)
michaelni
parents: 284
diff changeset
719 pred_y= P[1][1];
f82cce6cb182 10l (motion_val was uninitilized)
michaelni
parents: 284
diff changeset
720 }
280
3dc1ca4ba717 fixing epzs & mpeg1 (hopefully now really ...)
michaelni
parents: 277
diff changeset
721 }
281
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
722 dmin = epzs_motion_search(s, &mx, &my, P, pred_x, pred_y, rel_xmin, rel_ymin, rel_xmax, rel_ymax);
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
723
277
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
724 mx+= s->mb_x*16;
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
725 my+= s->mb_y*16;
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
726 break;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
727 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
728
986e461dc072 Initial revision
glantau
parents:
diff changeset
729 /* intra / predictive decision */
986e461dc072 Initial revision
glantau
parents:
diff changeset
730 xx = mb_x * 16;
986e461dc072 Initial revision
glantau
parents:
diff changeset
731 yy = mb_y * 16;
986e461dc072 Initial revision
glantau
parents:
diff changeset
732
986e461dc072 Initial revision
glantau
parents:
diff changeset
733 pix = s->new_picture[0] + (yy * s->linesize) + xx;
986e461dc072 Initial revision
glantau
parents:
diff changeset
734 /* At this point (mx,my) are full-pell and the absolute displacement */
986e461dc072 Initial revision
glantau
parents:
diff changeset
735 ppix = s->last_picture[0] + (my * s->linesize) + mx;
289
648e9245546d seems the old intra/inter decission is slightly better with a threshold, than the new one
michaelni
parents: 288
diff changeset
736
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
737 sum = pix_sum(pix, s->linesize);
289
648e9245546d seems the old intra/inter decission is slightly better with a threshold, than the new one
michaelni
parents: 288
diff changeset
738 #if 0
648e9245546d seems the old intra/inter decission is slightly better with a threshold, than the new one
michaelni
parents: 288
diff changeset
739 varc = pix_dev(pix, s->linesize, (sum+128)>>8) + INTER_BIAS;
284
0778d4e1d584 better inter/intra decission algo (same as xvid)
michaelni
parents: 281
diff changeset
740 vard = pix_abs16x16(pix, ppix, s->linesize, 16);
289
648e9245546d seems the old intra/inter decission is slightly better with a threshold, than the new one
michaelni
parents: 288
diff changeset
741 #else
648e9245546d seems the old intra/inter decission is slightly better with a threshold, than the new one
michaelni
parents: 288
diff changeset
742 sum= (sum+8)>>4;
648e9245546d seems the old intra/inter decission is slightly better with a threshold, than the new one
michaelni
parents: 288
diff changeset
743 varc = ((pix_norm1(pix, s->linesize) - sum*sum + 128 + 500)>>8);
648e9245546d seems the old intra/inter decission is slightly better with a threshold, than the new one
michaelni
parents: 288
diff changeset
744 vard = (pix_norm(pix, ppix, s->linesize)+128)>>8;
648e9245546d seems the old intra/inter decission is slightly better with a threshold, than the new one
michaelni
parents: 288
diff changeset
745 #endif
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
746
239
16cd8a9c4da4 - Minor changes on bitrate control
pulento
parents: 233
diff changeset
747 s->mb_var[s->mb_width * mb_y + mb_x] = varc;
233
3f5b72726118 - More work on preliminary bit rate control, just to be able to get an
pulento
parents: 232
diff changeset
748 s->avg_mb_var += varc;
268
09ae29b27ed9 hopefully better bitrate controll
michaelni
parents: 239
diff changeset
749 s->mc_mb_var += vard;
284
0778d4e1d584 better inter/intra decission algo (same as xvid)
michaelni
parents: 281
diff changeset
750
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
751 #if 0
233
3f5b72726118 - More work on preliminary bit rate control, just to be able to get an
pulento
parents: 232
diff changeset
752 printf("varc=%4d avg_var=%4d (sum=%4d) vard=%4d mx=%2d my=%2d\n",
3f5b72726118 - More work on preliminary bit rate control, just to be able to get an
pulento
parents: 232
diff changeset
753 varc, s->avg_mb_var, sum, vard, mx - xx, my - yy);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
754 #endif
289
648e9245546d seems the old intra/inter decission is slightly better with a threshold, than the new one
michaelni
parents: 288
diff changeset
755 if (vard <= 64 || vard < varc) {
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
756 if (s->full_search != ME_ZERO) {
277
5cb2978e701f new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents: 275
diff changeset
757 halfpel_motion_search(s, &mx, &my, dmin, xmin, ymin, xmax, ymax, pred_x, pred_y);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
758 } else {
986e461dc072 Initial revision
glantau
parents:
diff changeset
759 mx -= 16 * s->mb_x;
986e461dc072 Initial revision
glantau
parents:
diff changeset
760 my -= 16 * s->mb_y;
986e461dc072 Initial revision
glantau
parents:
diff changeset
761 }
281
1fc96b02142e mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents: 280
diff changeset
762 // check(mx + 32*s->mb_x, my + 32*s->mb_y, 1, end)
284
0778d4e1d584 better inter/intra decission algo (same as xvid)
michaelni
parents: 281
diff changeset
763
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
764 *mx_ptr = mx;
986e461dc072 Initial revision
glantau
parents:
diff changeset
765 *my_ptr = my;
986e461dc072 Initial revision
glantau
parents:
diff changeset
766 return 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
767 } else {
986e461dc072 Initial revision
glantau
parents:
diff changeset
768 *mx_ptr = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
769 *my_ptr = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
770 return 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
771 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
772 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
773
986e461dc072 Initial revision
glantau
parents:
diff changeset
774 #else
986e461dc072 Initial revision
glantau
parents:
diff changeset
775
986e461dc072 Initial revision
glantau
parents:
diff changeset
776 /* test version which generates valid random vectors */
986e461dc072 Initial revision
glantau
parents:
diff changeset
777 int estimate_motion(MpegEncContext * s,
986e461dc072 Initial revision
glantau
parents:
diff changeset
778 int mb_x, int mb_y,
986e461dc072 Initial revision
glantau
parents:
diff changeset
779 int *mx_ptr, int *my_ptr)
986e461dc072 Initial revision
glantau
parents:
diff changeset
780 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
781 int xx, yy, x1, y1, x2, y2, range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
782
986e461dc072 Initial revision
glantau
parents:
diff changeset
783 if ((random() % 10) >= 5) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
784 range = 8 * (1 << (s->f_code - 1));
986e461dc072 Initial revision
glantau
parents:
diff changeset
785 if (s->out_format == FMT_H263 && !s->h263_msmpeg4)
986e461dc072 Initial revision
glantau
parents:
diff changeset
786 range = range * 2;
986e461dc072 Initial revision
glantau
parents:
diff changeset
787
986e461dc072 Initial revision
glantau
parents:
diff changeset
788 xx = 16 * s->mb_x;
986e461dc072 Initial revision
glantau
parents:
diff changeset
789 yy = 16 * s->mb_y;
986e461dc072 Initial revision
glantau
parents:
diff changeset
790 x1 = xx - range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
791 if (x1 < 0)
986e461dc072 Initial revision
glantau
parents:
diff changeset
792 x1 = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
793 x2 = xx + range - 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
794 if (x2 > (s->width - 16))
986e461dc072 Initial revision
glantau
parents:
diff changeset
795 x2 = s->width - 16;
986e461dc072 Initial revision
glantau
parents:
diff changeset
796 y1 = yy - range;
986e461dc072 Initial revision
glantau
parents:
diff changeset
797 if (y1 < 0)
986e461dc072 Initial revision
glantau
parents:
diff changeset
798 y1 = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
799 y2 = yy + range - 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
800 if (y2 > (s->height - 16))
986e461dc072 Initial revision
glantau
parents:
diff changeset
801 y2 = s->height - 16;
986e461dc072 Initial revision
glantau
parents:
diff changeset
802
986e461dc072 Initial revision
glantau
parents:
diff changeset
803 *mx_ptr = (random() % (2 * (x2 - x1 + 1))) + 2 * (x1 - xx);
986e461dc072 Initial revision
glantau
parents:
diff changeset
804 *my_ptr = (random() % (2 * (y2 - y1 + 1))) + 2 * (y1 - yy);
986e461dc072 Initial revision
glantau
parents:
diff changeset
805 return 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
806 } else {
986e461dc072 Initial revision
glantau
parents:
diff changeset
807 *mx_ptr = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
808 *my_ptr = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
809 return 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
810 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
811 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
812
986e461dc072 Initial revision
glantau
parents:
diff changeset
813 #endif