Mercurial > libavcodec.hg
annotate mpegvideo.c @ 554:3eb6fe38019a libavcodec
4mv & qpel edge emu
author | michaelni |
---|---|
date | Mon, 15 Jul 2002 00:25:53 +0000 |
parents | 18ad513d92fe |
children | 762c67fd4078 |
rev | line source |
---|---|
0 | 1 /* |
2 * The simplest mpeg encoder (well, it was the simplest!) | |
429 | 3 * Copyright (c) 2000,2001 Fabrice Bellard. |
0 | 4 * |
429 | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Lesser General Public | |
7 * License as published by the Free Software Foundation; either | |
8 * version 2 of the License, or (at your option) any later version. | |
0 | 9 * |
429 | 10 * This library is distributed in the hope that it will be useful, |
0 | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
429 | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 * Lesser General Public License for more details. | |
0 | 14 * |
429 | 15 * You should have received a copy of the GNU Lesser General Public |
16 * License along with this library; if not, write to the Free Software | |
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
295 | 18 * |
325 | 19 * 4MV & hq & b-frame encoding stuff by Michael Niedermayer <michaelni@gmx.at> |
0 | 20 */ |
21 #include "avcodec.h" | |
22 #include "dsputil.h" | |
23 #include "mpegvideo.h" | |
24 | |
17
b69fe46fd708
Adding fastmemcpy stuff to speedup mplayer project
nickols_k
parents:
13
diff
changeset
|
25 #ifdef USE_FASTMEMCPY |
b69fe46fd708
Adding fastmemcpy stuff to speedup mplayer project
nickols_k
parents:
13
diff
changeset
|
26 #include "fastmemcpy.h" |
b69fe46fd708
Adding fastmemcpy stuff to speedup mplayer project
nickols_k
parents:
13
diff
changeset
|
27 #endif |
b69fe46fd708
Adding fastmemcpy stuff to speedup mplayer project
nickols_k
parents:
13
diff
changeset
|
28 |
13
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
29 static void encode_picture(MpegEncContext *s, int picture_number); |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
30 static void dct_unquantize_mpeg1_c(MpegEncContext *s, |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
31 DCTELEM *block, int n, int qscale); |
325 | 32 static void dct_unquantize_mpeg2_c(MpegEncContext *s, |
33 DCTELEM *block, int n, int qscale); | |
13
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
34 static void dct_unquantize_h263_c(MpegEncContext *s, |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
35 DCTELEM *block, int n, int qscale); |
206 | 36 static void draw_edges_c(UINT8 *buf, int wrap, int width, int height, int w); |
344 | 37 static int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow); |
206 | 38 |
344 | 39 int (*dct_quantize)(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow)= dct_quantize_c; |
206 | 40 void (*draw_edges)(UINT8 *buf, int wrap, int width, int height, int w)= draw_edges_c; |
41 | |
0 | 42 #define EDGE_WIDTH 16 |
43 | |
44 /* enable all paranoid tests for rounding, overflows, etc... */ | |
45 //#define PARANOID | |
46 | |
47 //#define DEBUG | |
48 | |
321 | 49 |
0 | 50 /* for jpeg fast DCT */ |
51 #define CONST_BITS 14 | |
52 | |
53 static const unsigned short aanscales[64] = { | |
54 /* precomputed values scaled up by 14 bits */ | |
55 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, | |
56 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270, | |
57 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906, | |
58 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315, | |
59 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, | |
60 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552, | |
61 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446, | |
62 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247 | |
63 }; | |
64 | |
65 static UINT8 h263_chroma_roundtab[16] = { | |
66 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, | |
67 }; | |
68 | |
292
73a9ce3d9715
fcode_tables where too small, found by Klaas-Pieter Vlieg <vlieg@eurescom.de>
michaelni
parents:
288
diff
changeset
|
69 static UINT16 default_mv_penalty[MAX_FCODE+1][MAX_MV*2+1]; |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
70 static UINT8 default_fcode_tab[MAX_MV*2+1]; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
71 |
321 | 72 extern UINT8 zigzag_end[64]; |
73 | |
0 | 74 /* default motion estimation */ |
321 | 75 int motion_estimation_method = ME_EPZS; |
200 | 76 |
344 | 77 static void convert_matrix(int (*qmat)[64], uint16_t (*qmat16)[64], uint16_t (*qmat16_bias)[64], |
78 const UINT16 *quant_matrix, int bias) | |
0 | 79 { |
344 | 80 int qscale; |
0 | 81 |
344 | 82 for(qscale=1; qscale<32; qscale++){ |
83 int i; | |
474
11dbd00682fc
avoid name clash with libjpeg - added missing externs
bellard
parents:
467
diff
changeset
|
84 if (av_fdct == fdct_ifast) { |
344 | 85 for(i=0;i<64;i++) { |
86 const int j= block_permute_op(i); | |
87 /* 16 <= qscale * quant_matrix[i] <= 7905 */ | |
88 /* 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 */ | |
89 /* (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */ | |
90 /* 3444240 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */ | |
91 | |
92 qmat[qscale][j] = (int)((UINT64_C(1) << (QMAT_SHIFT + 11)) / | |
93 (aanscales[i] * qscale * quant_matrix[j])); | |
94 } | |
95 } else { | |
96 for(i=0;i<64;i++) { | |
97 /* We can safely suppose that 16 <= quant_matrix[i] <= 255 | |
98 So 16 <= qscale * quant_matrix[i] <= 7905 | |
99 so (1<<19) / 16 >= (1<<19) / (qscale * quant_matrix[i]) >= (1<<19) / 7905 | |
100 so 32768 >= (1<<19) / (qscale * quant_matrix[i]) >= 67 | |
101 */ | |
102 qmat [qscale][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[i]); | |
103 qmat16[qscale][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[block_permute_op(i)]); | |
104 | |
105 if(qmat16[qscale][i]==0 || qmat16[qscale][i]==128*256) qmat16[qscale][i]=128*256-1; | |
106 | |
107 qmat16_bias[qscale][i]= ROUNDED_DIV(bias<<(16-QUANT_BIAS_SHIFT), qmat16[qscale][i]); | |
108 } | |
0 | 109 } |
110 } | |
111 } | |
456 | 112 // move into common.c perhaps |
113 #define CHECKED_ALLOCZ(p, size)\ | |
114 {\ | |
115 p= av_mallocz(size);\ | |
116 if(p==NULL){\ | |
117 perror("malloc");\ | |
118 goto fail;\ | |
119 }\ | |
120 } | |
0 | 121 |
122 /* init common structure for both encoder and decoder */ | |
123 int MPV_common_init(MpegEncContext *s) | |
124 { | |
125 int c_size, i; | |
126 UINT8 *pict; | |
127 | |
312 | 128 s->dct_unquantize_h263 = dct_unquantize_h263_c; |
325 | 129 s->dct_unquantize_mpeg1 = dct_unquantize_mpeg1_c; |
130 s->dct_unquantize_mpeg2 = dct_unquantize_mpeg2_c; | |
13
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
131 |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
132 #ifdef HAVE_MMX |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
133 MPV_common_init_mmx(s); |
8 | 134 #endif |
514
c9f724e3a797
Update and activate dct_unquantize_h263_mvi. Thanks to M«©ns Rullg«©rd
mellum
parents:
506
diff
changeset
|
135 #ifdef ARCH_ALPHA |
c9f724e3a797
Update and activate dct_unquantize_h263_mvi. Thanks to M«©ns Rullg«©rd
mellum
parents:
506
diff
changeset
|
136 MPV_common_init_axp(s); |
c9f724e3a797
Update and activate dct_unquantize_h263_mvi. Thanks to M«©ns Rullg«©rd
mellum
parents:
506
diff
changeset
|
137 #endif |
312 | 138 //setup default unquantizers (mpeg4 might change it later) |
139 if(s->out_format == FMT_H263) | |
140 s->dct_unquantize = s->dct_unquantize_h263; | |
141 else | |
325 | 142 s->dct_unquantize = s->dct_unquantize_mpeg1; |
312 | 143 |
0 | 144 s->mb_width = (s->width + 15) / 16; |
145 s->mb_height = (s->height + 15) / 16; | |
233
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
146 s->mb_num = s->mb_width * s->mb_height; |
553 | 147 if(!(s->flags&CODEC_FLAG_DR1)){ |
148 s->linesize = s->mb_width * 16 + 2 * EDGE_WIDTH; | |
0 | 149 |
553 | 150 for(i=0;i<3;i++) { |
0 | 151 int w, h, shift, pict_start; |
152 | |
153 w = s->linesize; | |
154 h = s->mb_height * 16 + 2 * EDGE_WIDTH; | |
155 shift = (i == 0) ? 0 : 1; | |
156 c_size = (w >> shift) * (h >> shift); | |
157 pict_start = (w >> shift) * (EDGE_WIDTH >> shift) + (EDGE_WIDTH >> shift); | |
158 | |
456 | 159 CHECKED_ALLOCZ(pict, c_size) |
0 | 160 s->last_picture_base[i] = pict; |
161 s->last_picture[i] = pict + pict_start; | |
485 | 162 if(i>0) memset(s->last_picture_base[i], 128, c_size); |
0 | 163 |
456 | 164 CHECKED_ALLOCZ(pict, c_size) |
0 | 165 s->next_picture_base[i] = pict; |
166 s->next_picture[i] = pict + pict_start; | |
485 | 167 if(i>0) memset(s->next_picture_base[i], 128, c_size); |
324 | 168 |
365
fdeec2834c79
there are divx5? encoded files without a userdata section but with b-frames :(
michaelni
parents:
350
diff
changeset
|
169 if (s->has_b_frames || s->codec_id==CODEC_ID_MPEG4) { |
fdeec2834c79
there are divx5? encoded files without a userdata section but with b-frames :(
michaelni
parents:
350
diff
changeset
|
170 /* Note the MPEG4 stuff is here cuz of buggy encoders which dont set the low_delay flag but |
fdeec2834c79
there are divx5? encoded files without a userdata section but with b-frames :(
michaelni
parents:
350
diff
changeset
|
171 do low-delay encoding, so we cant allways distinguish b-frame containing streams from low_delay streams */ |
456 | 172 CHECKED_ALLOCZ(pict, c_size) |
0 | 173 s->aux_picture_base[i] = pict; |
174 s->aux_picture[i] = pict + pict_start; | |
485 | 175 if(i>0) memset(s->aux_picture_base[i], 128, c_size); |
0 | 176 } |
553 | 177 } |
0 | 178 } |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
179 |
553 | 180 CHECKED_ALLOCZ(s->edge_emu_buffer, (s->width+32)*2*17); |
181 | |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
182 if (s->encoding) { |
324 | 183 int j; |
184 int mv_table_size= (s->mb_width+2)*(s->mb_height+2); | |
239 | 185 |
456 | 186 CHECKED_ALLOCZ(s->mb_var , s->mb_num * sizeof(INT16)) |
187 CHECKED_ALLOCZ(s->mc_mb_var, s->mb_num * sizeof(INT16)) | |
324 | 188 |
189 /* Allocate MV tables */ | |
456 | 190 CHECKED_ALLOCZ(s->p_mv_table , mv_table_size * 2 * sizeof(INT16)) |
191 CHECKED_ALLOCZ(s->b_forw_mv_table , mv_table_size * 2 * sizeof(INT16)) | |
192 CHECKED_ALLOCZ(s->b_back_mv_table , mv_table_size * 2 * sizeof(INT16)) | |
193 CHECKED_ALLOCZ(s->b_bidir_forw_mv_table , mv_table_size * 2 * sizeof(INT16)) | |
194 CHECKED_ALLOCZ(s->b_bidir_back_mv_table , mv_table_size * 2 * sizeof(INT16)) | |
195 CHECKED_ALLOCZ(s->b_direct_forw_mv_table, mv_table_size * 2 * sizeof(INT16)) | |
196 CHECKED_ALLOCZ(s->b_direct_back_mv_table, mv_table_size * 2 * sizeof(INT16)) | |
197 CHECKED_ALLOCZ(s->b_direct_mv_table , mv_table_size * 2 * sizeof(INT16)) | |
324 | 198 |
456 | 199 CHECKED_ALLOCZ(s->me_scratchpad, s->linesize*16*3*sizeof(uint8_t)) |
200 | |
201 CHECKED_ALLOCZ(s->me_map , ME_MAP_SIZE*sizeof(uint32_t)) | |
202 CHECKED_ALLOCZ(s->me_score_map, ME_MAP_SIZE*sizeof(uint16_t)) | |
327 | 203 |
324 | 204 if(s->max_b_frames){ |
205 for(j=0; j<REORDER_BUFFER_SIZE; j++){ | |
206 int i; | |
207 for(i=0;i<3;i++) { | |
208 int w, h, shift; | |
209 | |
210 w = s->linesize; | |
211 h = s->mb_height * 16; | |
212 shift = (i == 0) ? 0 : 1; | |
213 c_size = (w >> shift) * (h >> shift); | |
214 | |
456 | 215 CHECKED_ALLOCZ(pict, c_size); |
324 | 216 s->picture_buffer[j][i] = pict; |
217 } | |
218 } | |
219 } | |
456 | 220 |
221 if(s->codec_id==CODEC_ID_MPEG4){ | |
222 CHECKED_ALLOCZ(s->tex_pb_buffer, PB_BUFFER_SIZE); | |
223 CHECKED_ALLOCZ( s->pb2_buffer, PB_BUFFER_SIZE); | |
224 } | |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
225 } |
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
226 |
288 | 227 if (s->out_format == FMT_H263 || s->encoding) { |
0 | 228 int size; |
456 | 229 /* Allocate MB type table */ |
230 CHECKED_ALLOCZ(s->mb_type , s->mb_num * sizeof(UINT8)) | |
231 | |
0 | 232 /* MV prediction */ |
233 size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2); | |
456 | 234 CHECKED_ALLOCZ(s->motion_val, size * 2 * sizeof(INT16)); |
0 | 235 } |
236 | |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
237 if (s->h263_pred || s->h263_plus) { |
0 | 238 int y_size, c_size, i, size; |
239 | |
240 /* dc values */ | |
241 | |
242 y_size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2); | |
243 c_size = (s->mb_width + 2) * (s->mb_height + 2); | |
244 size = y_size + 2 * c_size; | |
456 | 245 CHECKED_ALLOCZ(s->dc_val[0], size * sizeof(INT16)); |
0 | 246 s->dc_val[1] = s->dc_val[0] + y_size; |
247 s->dc_val[2] = s->dc_val[1] + c_size; | |
248 for(i=0;i<size;i++) | |
249 s->dc_val[0][i] = 1024; | |
250 | |
251 /* ac values */ | |
456 | 252 CHECKED_ALLOCZ(s->ac_val[0], size * sizeof(INT16) * 16); |
0 | 253 s->ac_val[1] = s->ac_val[0] + y_size; |
254 s->ac_val[2] = s->ac_val[1] + c_size; | |
255 | |
256 /* cbp values */ | |
456 | 257 CHECKED_ALLOCZ(s->coded_block, y_size); |
191
883f184537e6
AC table reset (memset) optimization - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
189
diff
changeset
|
258 |
883f184537e6
AC table reset (memset) optimization - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
189
diff
changeset
|
259 /* which mb is a intra block */ |
456 | 260 CHECKED_ALLOCZ(s->mbintra_table, s->mb_num); |
233
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
261 memset(s->mbintra_table, 1, s->mb_num); |
333 | 262 |
263 /* divx501 bitstream reorder buffer */ | |
456 | 264 CHECKED_ALLOCZ(s->bitstream_buffer, BITSTREAM_BUFFER_SIZE); |
265 | |
266 /* cbp, ac_pred, pred_dir */ | |
267 CHECKED_ALLOCZ(s->cbp_table , s->mb_num * sizeof(UINT8)) | |
268 CHECKED_ALLOCZ(s->pred_dir_table, s->mb_num * sizeof(UINT8)) | |
269 | |
270 CHECKED_ALLOCZ(s->qscale_table , s->mb_num * sizeof(UINT8)) | |
197
21abf1b20016
different fix, s->mbintra_table used only if h263_pred set. - patch by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
196
diff
changeset
|
271 } |
0 | 272 /* default structure is frame */ |
273 s->picture_structure = PICT_FRAME; | |
553 | 274 |
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
275 /* init macroblock skip table */ |
456 | 276 CHECKED_ALLOCZ(s->mbskip_table, s->mb_num); |
294 | 277 |
327 | 278 s->block= s->blocks[0]; |
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
279 |
0 | 280 s->context_initialized = 1; |
281 return 0; | |
282 fail: | |
244 | 283 MPV_common_end(s); |
284 return -1; | |
285 } | |
286 | |
456 | 287 |
288 //extern int sads; | |
289 | |
244 | 290 /* init common structure for both encoder and decoder */ |
291 void MPV_common_end(MpegEncContext *s) | |
292 { | |
293 int i; | |
294 | |
396
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
295 av_freep(&s->mb_type); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
296 av_freep(&s->mb_var); |
456 | 297 av_freep(&s->mc_mb_var); |
396
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
298 av_freep(&s->p_mv_table); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
299 av_freep(&s->b_forw_mv_table); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
300 av_freep(&s->b_back_mv_table); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
301 av_freep(&s->b_bidir_forw_mv_table); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
302 av_freep(&s->b_bidir_back_mv_table); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
303 av_freep(&s->b_direct_forw_mv_table); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
304 av_freep(&s->b_direct_back_mv_table); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
305 av_freep(&s->b_direct_mv_table); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
306 av_freep(&s->motion_val); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
307 av_freep(&s->dc_val[0]); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
308 av_freep(&s->ac_val[0]); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
309 av_freep(&s->coded_block); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
310 av_freep(&s->mbintra_table); |
456 | 311 av_freep(&s->cbp_table); |
312 av_freep(&s->pred_dir_table); | |
313 av_freep(&s->qscale_table); | |
396
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
314 av_freep(&s->me_scratchpad); |
456 | 315 av_freep(&s->me_map); |
316 av_freep(&s->me_score_map); | |
317 | |
396
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
318 av_freep(&s->mbskip_table); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
319 av_freep(&s->bitstream_buffer); |
456 | 320 av_freep(&s->tex_pb_buffer); |
321 av_freep(&s->pb2_buffer); | |
553 | 322 av_freep(&s->edge_emu_buffer); |
323 | |
0 | 324 for(i=0;i<3;i++) { |
324 | 325 int j; |
553 | 326 if(!(s->flags&CODEC_FLAG_DR1)){ |
327 av_freep(&s->last_picture_base[i]); | |
328 av_freep(&s->next_picture_base[i]); | |
329 av_freep(&s->aux_picture_base[i]); | |
330 } | |
331 s->last_picture_base[i]= | |
332 s->next_picture_base[i]= | |
333 s->aux_picture_base [i] = NULL; | |
334 s->last_picture[i]= | |
335 s->next_picture[i]= | |
336 s->aux_picture [i] = NULL; | |
337 | |
324 | 338 for(j=0; j<REORDER_BUFFER_SIZE; j++){ |
396
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
339 av_freep(&s->picture_buffer[j][i]); |
324 | 340 } |
0 | 341 } |
342 s->context_initialized = 0; | |
343 } | |
344 | |
345 /* init video encoder */ | |
346 int MPV_encode_init(AVCodecContext *avctx) | |
347 { | |
348 MpegEncContext *s = avctx->priv_data; | |
60 | 349 int i; |
0 | 350 |
315 | 351 avctx->pix_fmt = PIX_FMT_YUV420P; |
352 | |
0 | 353 s->bit_rate = avctx->bit_rate; |
268 | 354 s->bit_rate_tolerance = avctx->bit_rate_tolerance; |
0 | 355 s->frame_rate = avctx->frame_rate; |
356 s->width = avctx->width; | |
357 s->height = avctx->height; | |
456 | 358 if(avctx->gop_size > 600){ |
462
3fdd0627f6bd
typo (found by Bohdan Horst <nexus at hoth.amu.edu.pl>)
michaelni
parents:
461
diff
changeset
|
359 fprintf(stderr, "Warning keyframe interval too large! reducing it ...\n"); |
456 | 360 avctx->gop_size=600; |
361 } | |
0 | 362 s->gop_size = avctx->gop_size; |
162 | 363 s->rtp_mode = avctx->rtp_mode; |
364 s->rtp_payload_size = avctx->rtp_payload_size; | |
231 | 365 if (avctx->rtp_callback) |
366 s->rtp_callback = avctx->rtp_callback; | |
268 | 367 s->qmin= avctx->qmin; |
368 s->qmax= avctx->qmax; | |
369 s->max_qdiff= avctx->max_qdiff; | |
370 s->qcompress= avctx->qcompress; | |
371 s->qblur= avctx->qblur; | |
329 | 372 s->b_quant_factor= avctx->b_quant_factor; |
456 | 373 s->b_quant_offset= avctx->b_quant_offset; |
194
27d1773552c9
mpeg4 encoder fix by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
191
diff
changeset
|
374 s->avctx = avctx; |
281
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
280
diff
changeset
|
375 s->aspect_ratio_info= avctx->aspect_ratio_info; |
294 | 376 s->flags= avctx->flags; |
324 | 377 s->max_b_frames= avctx->max_b_frames; |
329 | 378 s->rc_strategy= avctx->rc_strategy; |
379 s->b_frame_strategy= avctx->b_frame_strategy; | |
344 | 380 s->codec_id= avctx->codec->id; |
456 | 381 s->luma_elim_threshold = avctx->luma_elim_threshold; |
382 s->chroma_elim_threshold= avctx->chroma_elim_threshold; | |
383 s->strict_std_compliance= avctx->strict_std_compliance; | |
384 s->data_partitioning= avctx->flags & CODEC_FLAG_PART; | |
344 | 385 |
0 | 386 if (s->gop_size <= 1) { |
387 s->intra_only = 1; | |
388 s->gop_size = 12; | |
389 } else { | |
390 s->intra_only = 0; | |
391 } | |
320
cda7d0857baf
- ME setting moved to AVCodecContext/MpegEncContext, no longer a global.
pulento
parents:
315
diff
changeset
|
392 |
cda7d0857baf
- ME setting moved to AVCodecContext/MpegEncContext, no longer a global.
pulento
parents:
315
diff
changeset
|
393 /* ME algorithm */ |
321 | 394 if (avctx->me_method == 0) |
395 /* For compatibility */ | |
396 s->me_method = motion_estimation_method; | |
397 else | |
398 s->me_method = avctx->me_method; | |
399 | |
320
cda7d0857baf
- ME setting moved to AVCodecContext/MpegEncContext, no longer a global.
pulento
parents:
315
diff
changeset
|
400 /* Fixed QSCALE */ |
0 | 401 s->fixed_qscale = (avctx->flags & CODEC_FLAG_QSCALE); |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
402 |
0 | 403 switch(avctx->codec->id) { |
404 case CODEC_ID_MPEG1VIDEO: | |
405 s->out_format = FMT_MPEG1; | |
336 | 406 avctx->delay=0; //FIXME not sure, should check the spec |
0 | 407 break; |
408 case CODEC_ID_MJPEG: | |
409 s->out_format = FMT_MJPEG; | |
410 s->intra_only = 1; /* force intra only for jpeg */ | |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
411 s->mjpeg_write_tables = 1; /* write all tables */ |
370
0eca28d16cbd
clamp intra matrix to 8bit for mjpeg (workaround for qscale>=25)
al3x
parents:
365
diff
changeset
|
412 s->mjpeg_data_only_frames = 0; /* write all the needed headers */ |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
413 s->mjpeg_vsample[0] = 2; /* set up default sampling factors */ |
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
414 s->mjpeg_vsample[1] = 1; /* the only currently supported values */ |
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
415 s->mjpeg_vsample[2] = 1; |
370
0eca28d16cbd
clamp intra matrix to 8bit for mjpeg (workaround for qscale>=25)
al3x
parents:
365
diff
changeset
|
416 s->mjpeg_hsample[0] = 2; |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
417 s->mjpeg_hsample[1] = 1; |
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
418 s->mjpeg_hsample[2] = 1; |
0 | 419 if (mjpeg_init(s) < 0) |
420 return -1; | |
336 | 421 avctx->delay=0; |
0 | 422 break; |
423 case CODEC_ID_H263: | |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
424 if (h263_get_picture_format(s->width, s->height) == 7) { |
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
425 printf("Input picture size isn't suitable for h263 codec! try h263+\n"); |
0 | 426 return -1; |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
427 } |
0 | 428 s->out_format = FMT_H263; |
336 | 429 avctx->delay=0; |
0 | 430 break; |
431 case CODEC_ID_H263P: | |
432 s->out_format = FMT_H263; | |
162 | 433 s->rtp_mode = 1; |
434 s->rtp_payload_size = 1200; | |
0 | 435 s->h263_plus = 1; |
78 | 436 s->unrestricted_mv = 1; |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
437 s->h263_aic = 1; |
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
438 |
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
439 /* These are just to be sure */ |
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
440 s->umvplus = 0; |
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
441 s->umvplus_dec = 0; |
336 | 442 avctx->delay=0; |
0 | 443 break; |
444 case CODEC_ID_RV10: | |
445 s->out_format = FMT_H263; | |
446 s->h263_rv10 = 1; | |
336 | 447 avctx->delay=0; |
0 | 448 break; |
71 | 449 case CODEC_ID_MPEG4: |
0 | 450 s->out_format = FMT_H263; |
451 s->h263_pred = 1; | |
452 s->unrestricted_mv = 1; | |
324 | 453 s->has_b_frames= s->max_b_frames ? 1 : 0; |
336 | 454 s->low_delay=0; |
455 avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1); | |
0 | 456 break; |
307 | 457 case CODEC_ID_MSMPEG4V1: |
0 | 458 s->out_format = FMT_H263; |
459 s->h263_msmpeg4 = 1; | |
460 s->h263_pred = 1; | |
461 s->unrestricted_mv = 1; | |
307 | 462 s->msmpeg4_version= 1; |
336 | 463 avctx->delay=0; |
307 | 464 break; |
465 case CODEC_ID_MSMPEG4V2: | |
466 s->out_format = FMT_H263; | |
467 s->h263_msmpeg4 = 1; | |
468 s->h263_pred = 1; | |
469 s->unrestricted_mv = 1; | |
470 s->msmpeg4_version= 2; | |
336 | 471 avctx->delay=0; |
307 | 472 break; |
473 case CODEC_ID_MSMPEG4V3: | |
474 s->out_format = FMT_H263; | |
475 s->h263_msmpeg4 = 1; | |
476 s->h263_pred = 1; | |
477 s->unrestricted_mv = 1; | |
478 s->msmpeg4_version= 3; | |
336 | 479 avctx->delay=0; |
0 | 480 break; |
499 | 481 case CODEC_ID_WMV1: |
482 s->out_format = FMT_H263; | |
483 s->h263_msmpeg4 = 1; | |
484 s->h263_pred = 1; | |
485 s->unrestricted_mv = 1; | |
486 s->msmpeg4_version= 4; | |
487 avctx->delay=0; | |
488 break; | |
489 case CODEC_ID_WMV2: | |
490 s->out_format = FMT_H263; | |
491 s->h263_msmpeg4 = 1; | |
492 s->h263_pred = 1; | |
493 s->unrestricted_mv = 1; | |
494 s->msmpeg4_version= 5; | |
495 avctx->delay=0; | |
496 break; | |
0 | 497 default: |
498 return -1; | |
499 } | |
295 | 500 |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
501 { /* set up some save defaults, some codecs might override them later */ |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
502 static int done=0; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
503 if(!done){ |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
504 int i; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
505 done=1; |
292
73a9ce3d9715
fcode_tables where too small, found by Klaas-Pieter Vlieg <vlieg@eurescom.de>
michaelni
parents:
288
diff
changeset
|
506 memset(default_mv_penalty, 0, sizeof(UINT16)*(MAX_FCODE+1)*(2*MAX_MV+1)); |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
507 memset(default_fcode_tab , 0, sizeof(UINT8)*(2*MAX_MV+1)); |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
508 |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
509 for(i=-16; i<16; i++){ |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
510 default_fcode_tab[i + MAX_MV]= 1; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
511 } |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
512 } |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
513 } |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
514 s->mv_penalty= default_mv_penalty; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
515 s->fcode_tab= default_fcode_tab; |
506
b9ed0ae72d51
init dc_scale tables to defaults (fixes mjpeg sig11)
michaelni
parents:
499
diff
changeset
|
516 s->y_dc_scale_table= |
b9ed0ae72d51
init dc_scale tables to defaults (fixes mjpeg sig11)
michaelni
parents:
499
diff
changeset
|
517 s->c_dc_scale_table= ff_mpeg1_dc_scale_table; |
b9ed0ae72d51
init dc_scale tables to defaults (fixes mjpeg sig11)
michaelni
parents:
499
diff
changeset
|
518 |
0 | 519 if (s->out_format == FMT_H263) |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
520 h263_encode_init(s); |
281
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
280
diff
changeset
|
521 else if (s->out_format == FMT_MPEG1) |
499 | 522 ff_mpeg1_encode_init(s); |
523 if(s->msmpeg4_version) | |
524 ff_msmpeg4_encode_init(s); | |
0 | 525 |
287 | 526 /* dont use mv_penalty table for crap MV as it would be confused */ |
324 | 527 if (s->me_method < ME_EPZS) s->mv_penalty = default_mv_penalty; |
287 | 528 |
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
529 s->encoding = 1; |
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
530 |
0 | 531 /* init */ |
532 if (MPV_common_init(s) < 0) | |
533 return -1; | |
534 | |
60 | 535 /* init default q matrix */ |
536 for(i=0;i<64;i++) { | |
344 | 537 if(s->out_format == FMT_H263) |
533
3c07cf9595de
adding ff prefix to avoid global name conficts with xvid (patch by Marko Kreen <marko at l-t.ee>)
michaelni
parents:
514
diff
changeset
|
538 s->intra_matrix[i] = ff_mpeg1_default_non_intra_matrix[i]; |
344 | 539 else |
533
3c07cf9595de
adding ff prefix to avoid global name conficts with xvid (patch by Marko Kreen <marko at l-t.ee>)
michaelni
parents:
514
diff
changeset
|
540 s->intra_matrix[i] = ff_mpeg1_default_intra_matrix[i]; |
344 | 541 |
533
3c07cf9595de
adding ff prefix to avoid global name conficts with xvid (patch by Marko Kreen <marko at l-t.ee>)
michaelni
parents:
514
diff
changeset
|
542 s->inter_matrix[i] = ff_mpeg1_default_non_intra_matrix[i]; |
344 | 543 } |
544 | |
545 /* precompute matrix */ | |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
546 /* for mjpeg, we do include qscale in the matrix */ |
344 | 547 if (s->out_format != FMT_MJPEG) { |
548 convert_matrix(s->q_intra_matrix, s->q_intra_matrix16, s->q_intra_matrix16_bias, | |
549 s->intra_matrix, s->intra_quant_bias); | |
550 convert_matrix(s->q_inter_matrix, s->q_inter_matrix16, s->q_inter_matrix16_bias, | |
551 s->inter_matrix, s->inter_quant_bias); | |
60 | 552 } |
553 | |
329 | 554 if(ff_rate_control_init(s) < 0) |
555 return -1; | |
0 | 556 |
557 s->picture_number = 0; | |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
558 s->picture_in_gop_number = 0; |
0 | 559 s->fake_picture_number = 0; |
560 /* motion detector init */ | |
561 s->f_code = 1; | |
324 | 562 s->b_code = 1; |
0 | 563 |
564 return 0; | |
565 } | |
566 | |
567 int MPV_encode_end(AVCodecContext *avctx) | |
568 { | |
569 MpegEncContext *s = avctx->priv_data; | |
570 | |
571 #ifdef STATS | |
572 print_stats(); | |
573 #endif | |
329 | 574 |
575 ff_rate_control_uninit(s); | |
576 | |
0 | 577 MPV_common_end(s); |
578 if (s->out_format == FMT_MJPEG) | |
579 mjpeg_close(s); | |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
580 |
0 | 581 return 0; |
582 } | |
583 | |
584 /* draw the edges of width 'w' of an image of size width, height */ | |
206 | 585 static void draw_edges_c(UINT8 *buf, int wrap, int width, int height, int w) |
0 | 586 { |
587 UINT8 *ptr, *last_line; | |
588 int i; | |
589 | |
590 last_line = buf + (height - 1) * wrap; | |
591 for(i=0;i<w;i++) { | |
592 /* top and bottom */ | |
593 memcpy(buf - (i + 1) * wrap, buf, width); | |
594 memcpy(last_line + (i + 1) * wrap, last_line, width); | |
595 } | |
596 /* left and right */ | |
597 ptr = buf; | |
598 for(i=0;i<height;i++) { | |
599 memset(ptr - w, ptr[0], w); | |
600 memset(ptr + width, ptr[width-1], w); | |
601 ptr += wrap; | |
602 } | |
603 /* corners */ | |
604 for(i=0;i<w;i++) { | |
605 memset(buf - (i + 1) * wrap - w, buf[0], w); /* top left */ | |
606 memset(buf - (i + 1) * wrap + width, buf[width-1], w); /* top right */ | |
607 memset(last_line + (i + 1) * wrap - w, last_line[0], w); /* top left */ | |
608 memset(last_line + (i + 1) * wrap + width, last_line[width-1], w); /* top right */ | |
609 } | |
610 } | |
611 | |
612 /* generic function for encode/decode called before a frame is coded/decoded */ | |
553 | 613 void MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx) |
0 | 614 { |
615 int i; | |
616 UINT8 *tmp; | |
617 | |
46
931417475f5b
fixed mpeg1 first block bug (pb with black picture optimisation for B frames)
glantau
parents:
40
diff
changeset
|
618 s->mb_skiped = 0; |
456 | 619 s->decoding_error=0; |
620 | |
553 | 621 if(avctx->flags&CODEC_FLAG_DR1){ |
622 int i; | |
623 avctx->get_buffer_callback(avctx, s->width, s->height, s->pict_type); | |
624 | |
625 s->linesize= avctx->dr_stride; | |
626 } | |
627 | |
0 | 628 if (s->pict_type == B_TYPE) { |
629 for(i=0;i<3;i++) { | |
553 | 630 if(avctx->flags&CODEC_FLAG_DR1) |
631 s->aux_picture[i]= avctx->dr_buffer[i]; | |
632 | |
0 | 633 s->current_picture[i] = s->aux_picture[i]; |
634 } | |
635 } else { | |
636 for(i=0;i<3;i++) { | |
637 /* swap next and last */ | |
553 | 638 if(avctx->flags&CODEC_FLAG_DR1) |
639 tmp= avctx->dr_buffer[i]; | |
640 else | |
641 tmp = s->last_picture[i]; | |
642 | |
0 | 643 s->last_picture[i] = s->next_picture[i]; |
644 s->next_picture[i] = tmp; | |
645 s->current_picture[i] = tmp; | |
553 | 646 |
647 s->last_dr_opaque= s->next_dr_opaque; | |
648 s->next_dr_opaque= avctx->dr_opaque_frame; | |
649 | |
650 if(s->has_b_frames && s->last_dr_opaque) | |
651 avctx->dr_opaque_frame= s->last_dr_opaque; | |
652 else | |
653 avctx->dr_opaque_frame= s->next_dr_opaque; | |
0 | 654 } |
655 } | |
656 } | |
13
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
657 |
0 | 658 /* generic function for encode/decode called after a frame has been coded/decoded */ |
659 void MPV_frame_end(MpegEncContext *s) | |
660 { | |
456 | 661 // if((s->picture_number%100)==0 && s->encoding) printf("sads:%d //\n", sads); |
662 | |
0 | 663 /* draw edge for correct motion prediction if outside */ |
553 | 664 if (s->pict_type != B_TYPE && !s->intra_only && !(s->flags&CODEC_FLAG_EMU_EDGE)) { |
461 | 665 if(s->avctx==NULL || s->avctx->codec->id!=CODEC_ID_MPEG4 || s->divx_version>=500){ |
176
9ce215ee9216
unrestricted MC fixed - thanks to Michael Niedermayer for idea
arpi_esp
parents:
162
diff
changeset
|
666 draw_edges(s->current_picture[0], s->linesize, s->mb_width*16, s->mb_height*16, EDGE_WIDTH); |
9ce215ee9216
unrestricted MC fixed - thanks to Michael Niedermayer for idea
arpi_esp
parents:
162
diff
changeset
|
667 draw_edges(s->current_picture[1], s->linesize/2, s->mb_width*8, s->mb_height*8, EDGE_WIDTH/2); |
9ce215ee9216
unrestricted MC fixed - thanks to Michael Niedermayer for idea
arpi_esp
parents:
162
diff
changeset
|
668 draw_edges(s->current_picture[2], s->linesize/2, s->mb_width*8, s->mb_height*8, EDGE_WIDTH/2); |
189
42552c1cf360
fix different UMV handling for mpeg4 vs. h263 - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
187
diff
changeset
|
669 }else{ |
257 | 670 /* mpeg4? / opendivx / xvid */ |
0 | 671 draw_edges(s->current_picture[0], s->linesize, s->width, s->height, EDGE_WIDTH); |
672 draw_edges(s->current_picture[1], s->linesize/2, s->width/2, s->height/2, EDGE_WIDTH/2); | |
673 draw_edges(s->current_picture[2], s->linesize/2, s->width/2, s->height/2, EDGE_WIDTH/2); | |
189
42552c1cf360
fix different UMV handling for mpeg4 vs. h263 - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
187
diff
changeset
|
674 } |
0 | 675 } |
207 | 676 emms_c(); |
329 | 677 |
678 if(s->pict_type!=B_TYPE){ | |
679 s->last_non_b_pict_type= s->pict_type; | |
680 s->last_non_b_qscale= s->qscale; | |
456 | 681 s->last_non_b_mc_mb_var= s->mc_mb_var_sum; |
341 | 682 s->num_available_buffers++; |
683 if(s->num_available_buffers>2) s->num_available_buffers= 2; | |
329 | 684 } |
0 | 685 } |
686 | |
324 | 687 /* reorder input for encoding */ |
688 void reorder_input(MpegEncContext *s, AVPicture *pict) | |
689 { | |
690 int i, j, index; | |
691 | |
692 if(s->max_b_frames > FF_MAX_B_FRAMES) s->max_b_frames= FF_MAX_B_FRAMES; | |
693 | |
694 // delay= s->max_b_frames+1; (or 0 if no b frames cuz decoder diff) | |
695 | |
696 for(j=0; j<REORDER_BUFFER_SIZE-1; j++){ | |
697 s->coded_order[j]= s->coded_order[j+1]; | |
698 } | |
699 s->coded_order[j].picture[0]= s->coded_order[j].picture[1]= s->coded_order[j].picture[2]= NULL; //catch uninitalized buffers | |
339 | 700 s->coded_order[j].pict_type=0; |
324 | 701 |
702 switch(s->input_pict_type){ | |
703 default: | |
704 case I_TYPE: | |
705 case S_TYPE: | |
706 case P_TYPE: | |
707 index= s->max_b_frames - s->b_frames_since_non_b; | |
708 s->b_frames_since_non_b=0; | |
709 break; | |
710 case B_TYPE: | |
711 index= s->max_b_frames + 1; | |
712 s->b_frames_since_non_b++; | |
713 break; | |
714 } | |
715 //printf("index:%d type:%d strides: %d %d\n", index, s->input_pict_type, pict->linesize[0], s->linesize); | |
716 if( (index==0 || (s->flags&CODEC_FLAG_INPUT_PRESERVED)) | |
717 && pict->linesize[0] == s->linesize | |
718 && pict->linesize[1] == s->linesize>>1 | |
719 && pict->linesize[2] == s->linesize>>1){ | |
720 //printf("ptr\n"); | |
721 for(i=0; i<3; i++){ | |
722 s->coded_order[index].picture[i]= pict->data[i]; | |
723 } | |
724 }else{ | |
725 //printf("copy\n"); | |
726 for(i=0; i<3; i++){ | |
727 uint8_t *src = pict->data[i]; | |
728 uint8_t *dest; | |
729 int src_wrap = pict->linesize[i]; | |
730 int dest_wrap = s->linesize; | |
731 int w = s->width; | |
732 int h = s->height; | |
733 | |
734 if(index==0) dest= s->last_picture[i]+16; //is current_picture indeed but the switch hapens after reordering | |
735 else dest= s->picture_buffer[s->picture_buffer_index][i]; | |
736 | |
737 if (i >= 1) { | |
738 dest_wrap >>= 1; | |
739 w >>= 1; | |
740 h >>= 1; | |
741 } | |
742 | |
743 s->coded_order[index].picture[i]= dest; | |
744 for(j=0;j<h;j++) { | |
745 memcpy(dest, src, w); | |
746 dest += dest_wrap; | |
747 src += src_wrap; | |
748 } | |
749 } | |
750 if(index!=0){ | |
751 s->picture_buffer_index++; | |
752 if(s->picture_buffer_index >= REORDER_BUFFER_SIZE-1) s->picture_buffer_index=0; | |
753 } | |
754 } | |
755 s->coded_order[index].pict_type = s->input_pict_type; | |
756 s->coded_order[index].qscale = s->input_qscale; | |
757 s->coded_order[index].force_type= s->force_input_type; | |
758 s->coded_order[index].picture_in_gop_number= s->input_picture_in_gop_number; | |
759 s->coded_order[index].picture_number= s->input_picture_number; | |
760 | |
761 for(i=0; i<3; i++){ | |
762 s->new_picture[i]= s->coded_order[0].picture[i]; | |
763 } | |
764 } | |
765 | |
0 | 766 int MPV_encode_picture(AVCodecContext *avctx, |
767 unsigned char *buf, int buf_size, void *data) | |
768 { | |
769 MpegEncContext *s = avctx->priv_data; | |
770 AVPicture *pict = data; | |
771 | |
324 | 772 s->input_qscale = avctx->quality; |
0 | 773 |
774 init_put_bits(&s->pb, buf, buf_size, NULL, NULL); | |
775 | |
329 | 776 if(avctx->flags&CODEC_FLAG_TYPE){ |
777 s->input_pict_type= | |
778 s->force_input_type= avctx->key_frame ? I_TYPE : P_TYPE; | |
779 }else if(s->flags&CODEC_FLAG_PASS2){ | |
780 s->input_pict_type= | |
781 s->force_input_type= s->rc_context.entry[s->input_picture_number].new_pict_type; | |
782 }else{ | |
783 s->force_input_type=0; | |
784 if (!s->intra_only) { | |
785 /* first picture of GOP is intra */ | |
786 if (s->input_picture_in_gop_number % s->gop_size==0){ | |
787 s->input_pict_type = I_TYPE; | |
788 }else if(s->max_b_frames==0){ | |
789 s->input_pict_type = P_TYPE; | |
790 }else{ | |
791 if(s->b_frames_since_non_b < s->max_b_frames) //FIXME more IQ | |
792 s->input_pict_type = B_TYPE; | |
793 else | |
794 s->input_pict_type = P_TYPE; | |
795 } | |
796 } else { | |
324 | 797 s->input_pict_type = I_TYPE; |
798 } | |
0 | 799 } |
800 | |
329 | 801 if(s->input_pict_type==I_TYPE) |
802 s->input_picture_in_gop_number=0; | |
803 | |
324 | 804 reorder_input(s, pict); |
805 | |
806 /* output? */ | |
807 if(s->coded_order[0].picture[0]){ | |
808 | |
809 s->pict_type= s->coded_order[0].pict_type; | |
810 if (s->fixed_qscale) /* the ratecontrol needs the last qscale so we dont touch it for CBR */ | |
811 s->qscale= s->coded_order[0].qscale; | |
812 s->force_type= s->coded_order[0].force_type; | |
813 s->picture_in_gop_number= s->coded_order[0].picture_in_gop_number; | |
814 s->picture_number= s->coded_order[0].picture_number; | |
815 | |
553 | 816 MPV_frame_start(s, avctx); |
286 | 817 |
324 | 818 encode_picture(s, s->picture_number); |
376 | 819 avctx->key_frame = (s->pict_type == I_TYPE); |
820 avctx->pict_type = s->pict_type; | |
821 avctx->real_pict_num = s->picture_number; | |
324 | 822 avctx->header_bits = s->header_bits; |
823 avctx->mv_bits = s->mv_bits; | |
824 avctx->misc_bits = s->misc_bits; | |
825 avctx->i_tex_bits = s->i_tex_bits; | |
826 avctx->p_tex_bits = s->p_tex_bits; | |
827 avctx->i_count = s->i_count; | |
828 avctx->p_count = s->p_count; | |
829 avctx->skip_count = s->skip_count; | |
0 | 830 |
324 | 831 MPV_frame_end(s); |
832 | |
833 if (s->out_format == FMT_MJPEG) | |
834 mjpeg_picture_trailer(s); | |
835 | |
836 avctx->quality = s->qscale; | |
329 | 837 |
838 if(s->flags&CODEC_FLAG_PASS1) | |
839 ff_write_pass1_stats(s); | |
456 | 840 |
324 | 841 } |
842 | |
843 s->input_picture_number++; | |
844 s->input_picture_in_gop_number++; | |
0 | 845 |
846 flush_put_bits(&s->pb); | |
268 | 847 s->frame_bits = (pbBufPtr(&s->pb) - s->pb.buf) * 8; |
329 | 848 if(s->pict_type==B_TYPE) s->pb_frame_bits+= s->frame_bits; |
849 else s->pb_frame_bits= s->frame_bits; | |
850 | |
268 | 851 s->total_bits += s->frame_bits; |
286 | 852 avctx->frame_bits = s->frame_bits; |
853 //printf("fcode: %d, type: %d, head: %d, mv: %d, misc: %d, frame: %d, itex: %d, ptex: %d\n", | |
854 //s->f_code, avctx->key_frame, s->header_bits, s->mv_bits, s->misc_bits, s->frame_bits, s->i_tex_bits, s->p_tex_bits); | |
234
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
233
diff
changeset
|
855 |
252
ddb1a0e94cf4
- Added PSNR feature to libavcodec and ffmpeg. By now just Y PSNR until I'm
pulento
parents:
251
diff
changeset
|
856 if (avctx->get_psnr) { |
ddb1a0e94cf4
- Added PSNR feature to libavcodec and ffmpeg. By now just Y PSNR until I'm
pulento
parents:
251
diff
changeset
|
857 /* At this point pict->data should have the original frame */ |
ddb1a0e94cf4
- Added PSNR feature to libavcodec and ffmpeg. By now just Y PSNR until I'm
pulento
parents:
251
diff
changeset
|
858 /* an s->current_picture should have the coded/decoded frame */ |
ddb1a0e94cf4
- Added PSNR feature to libavcodec and ffmpeg. By now just Y PSNR until I'm
pulento
parents:
251
diff
changeset
|
859 get_psnr(pict->data, s->current_picture, |
ddb1a0e94cf4
- Added PSNR feature to libavcodec and ffmpeg. By now just Y PSNR until I'm
pulento
parents:
251
diff
changeset
|
860 pict->linesize, s->linesize, avctx); |
324 | 861 // printf("%f\n", avctx->psnr_y); |
252
ddb1a0e94cf4
- Added PSNR feature to libavcodec and ffmpeg. By now just Y PSNR until I'm
pulento
parents:
251
diff
changeset
|
862 } |
234
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
233
diff
changeset
|
863 return pbBufPtr(&s->pb) - s->pb.buf; |
0 | 864 } |
865 | |
255 | 866 static inline void gmc1_motion(MpegEncContext *s, |
867 UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr, | |
868 int dest_offset, | |
869 UINT8 **ref_picture, int src_offset, | |
870 int h) | |
871 { | |
872 UINT8 *ptr; | |
324 | 873 int offset, src_x, src_y, linesize; |
255 | 874 int motion_x, motion_y; |
875 | |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
262
diff
changeset
|
876 if(s->real_sprite_warping_points>1) printf("more than 1 warp point isnt supported\n"); |
255 | 877 motion_x= s->sprite_offset[0][0]; |
878 motion_y= s->sprite_offset[0][1]; | |
879 src_x = s->mb_x * 16 + (motion_x >> (s->sprite_warping_accuracy+1)); | |
880 src_y = s->mb_y * 16 + (motion_y >> (s->sprite_warping_accuracy+1)); | |
881 motion_x<<=(3-s->sprite_warping_accuracy); | |
882 motion_y<<=(3-s->sprite_warping_accuracy); | |
883 src_x = clip(src_x, -16, s->width); | |
884 if (src_x == s->width) | |
885 motion_x =0; | |
886 src_y = clip(src_y, -16, s->height); | |
887 if (src_y == s->height) | |
888 motion_y =0; | |
889 | |
890 linesize = s->linesize; | |
891 ptr = ref_picture[0] + (src_y * linesize) + src_x + src_offset; | |
892 | |
893 dest_y+=dest_offset; | |
894 gmc1(dest_y , ptr , linesize, h, motion_x&15, motion_y&15, s->no_rounding); | |
895 gmc1(dest_y+8, ptr+8, linesize, h, motion_x&15, motion_y&15, s->no_rounding); | |
896 | |
897 motion_x= s->sprite_offset[1][0]; | |
898 motion_y= s->sprite_offset[1][1]; | |
899 src_x = s->mb_x * 8 + (motion_x >> (s->sprite_warping_accuracy+1)); | |
900 src_y = s->mb_y * 8 + (motion_y >> (s->sprite_warping_accuracy+1)); | |
901 motion_x<<=(3-s->sprite_warping_accuracy); | |
902 motion_y<<=(3-s->sprite_warping_accuracy); | |
903 src_x = clip(src_x, -8, s->width>>1); | |
904 if (src_x == s->width>>1) | |
905 motion_x =0; | |
906 src_y = clip(src_y, -8, s->height>>1); | |
907 if (src_y == s->height>>1) | |
908 motion_y =0; | |
909 | |
910 offset = (src_y * linesize>>1) + src_x + (src_offset>>1); | |
911 ptr = ref_picture[1] + offset; | |
912 gmc1(dest_cb + (dest_offset>>1), ptr, linesize>>1, h>>1, motion_x&15, motion_y&15, s->no_rounding); | |
913 ptr = ref_picture[2] + offset; | |
914 gmc1(dest_cr + (dest_offset>>1), ptr, linesize>>1, h>>1, motion_x&15, motion_y&15, s->no_rounding); | |
915 | |
916 return; | |
917 } | |
918 | |
553 | 919 static void emulated_edge_mc(UINT8 *buf, UINT8 *src, int linesize, int block_w, int block_h, |
920 int src_x, int src_y, int w, int h){ | |
921 int x, y; | |
922 int start_y, start_x, end_y, end_x; | |
923 | |
924 if(src_y>= h){ | |
925 src+= (h-1-src_y)*linesize; | |
926 src_y=h-1; | |
554 | 927 }else if(src_y<=-block_h){ |
928 src+= (1-block_h-src_y)*linesize; | |
929 src_y=1-block_h; | |
553 | 930 } |
931 if(src_x>= w){ | |
932 src+= (w-1-src_x); | |
933 src_x=w-1; | |
554 | 934 }else if(src_x<=-block_w){ |
935 src+= (1-block_w-src_x); | |
936 src_x=1-block_w; | |
553 | 937 } |
938 | |
939 start_y= MAX(0, -src_y); | |
940 start_x= MAX(0, -src_x); | |
941 end_y= MIN(block_h, h-src_y); | |
942 end_x= MIN(block_w, w-src_x); | |
943 | |
944 // copy existing part | |
945 for(y=start_y; y<end_y; y++){ | |
946 for(x=start_x; x<end_x; x++){ | |
947 buf[x + y*linesize]= src[x + y*linesize]; | |
948 } | |
949 } | |
950 | |
951 //top | |
952 for(y=0; y<start_y; y++){ | |
953 for(x=start_x; x<end_x; x++){ | |
954 buf[x + y*linesize]= buf[x + start_y*linesize]; | |
955 } | |
956 } | |
957 | |
958 //bottom | |
959 for(y=end_y; y<block_h; y++){ | |
960 for(x=start_x; x<end_x; x++){ | |
961 buf[x + y*linesize]= buf[x + (end_y-1)*linesize]; | |
962 } | |
963 } | |
964 | |
965 for(y=0; y<block_h; y++){ | |
966 //left | |
967 for(x=0; x<start_x; x++){ | |
968 buf[x + y*linesize]= buf[start_x + y*linesize]; | |
969 } | |
970 | |
971 //right | |
972 for(x=end_x; x<block_w; x++){ | |
973 buf[x + y*linesize]= buf[end_x - 1 + y*linesize]; | |
974 } | |
975 } | |
976 } | |
977 | |
978 | |
0 | 979 /* apply one mpeg motion vector to the three components */ |
980 static inline void mpeg_motion(MpegEncContext *s, | |
981 UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr, | |
982 int dest_offset, | |
983 UINT8 **ref_picture, int src_offset, | |
984 int field_based, op_pixels_func *pix_op, | |
985 int motion_x, int motion_y, int h) | |
986 { | |
987 UINT8 *ptr; | |
988 int dxy, offset, mx, my, src_x, src_y, height, linesize; | |
553 | 989 int emu=0; |
990 | |
255 | 991 if(s->quarter_sample) |
992 { | |
993 motion_x>>=1; | |
994 motion_y>>=1; | |
995 } | |
0 | 996 dxy = ((motion_y & 1) << 1) | (motion_x & 1); |
997 src_x = s->mb_x * 16 + (motion_x >> 1); | |
998 src_y = s->mb_y * (16 >> field_based) + (motion_y >> 1); | |
999 | |
1000 /* WARNING: do no forget half pels */ | |
1001 height = s->height >> field_based; | |
1002 src_x = clip(src_x, -16, s->width); | |
1003 if (src_x == s->width) | |
1004 dxy &= ~1; | |
1005 src_y = clip(src_y, -16, height); | |
1006 if (src_y == height) | |
1007 dxy &= ~2; | |
1008 linesize = s->linesize << field_based; | |
1009 ptr = ref_picture[0] + (src_y * linesize) + (src_x) + src_offset; | |
1010 dest_y += dest_offset; | |
553 | 1011 |
1012 if(s->flags&CODEC_FLAG_EMU_EDGE){ | |
1013 if(src_x<0 || src_y<0 || src_x + (motion_x&1) + 16 > s->width | |
1014 || src_y + (motion_y&1) + h > height){ | |
1015 emulated_edge_mc(s->edge_emu_buffer, ptr, linesize, 17, h+1, src_x, src_y, s->width, height); | |
1016 ptr= s->edge_emu_buffer; | |
1017 emu=1; | |
1018 } | |
1019 } | |
0 | 1020 pix_op[dxy](dest_y, ptr, linesize, h); |
1021 pix_op[dxy](dest_y + 8, ptr + 8, linesize, h); | |
1022 | |
485 | 1023 if(s->flags&CODEC_FLAG_GRAY) return; |
1024 | |
0 | 1025 if (s->out_format == FMT_H263) { |
1026 dxy = 0; | |
1027 if ((motion_x & 3) != 0) | |
1028 dxy |= 1; | |
1029 if ((motion_y & 3) != 0) | |
1030 dxy |= 2; | |
1031 mx = motion_x >> 2; | |
1032 my = motion_y >> 2; | |
1033 } else { | |
1034 mx = motion_x / 2; | |
1035 my = motion_y / 2; | |
1036 dxy = ((my & 1) << 1) | (mx & 1); | |
1037 mx >>= 1; | |
1038 my >>= 1; | |
1039 } | |
1040 | |
1041 src_x = s->mb_x * 8 + mx; | |
1042 src_y = s->mb_y * (8 >> field_based) + my; | |
1043 src_x = clip(src_x, -8, s->width >> 1); | |
1044 if (src_x == (s->width >> 1)) | |
1045 dxy &= ~1; | |
1046 src_y = clip(src_y, -8, height >> 1); | |
1047 if (src_y == (height >> 1)) | |
1048 dxy &= ~2; | |
1049 | |
1050 offset = (src_y * (linesize >> 1)) + src_x + (src_offset >> 1); | |
1051 ptr = ref_picture[1] + offset; | |
553 | 1052 if(emu){ |
1053 emulated_edge_mc(s->edge_emu_buffer, ptr, linesize>>1, 9, (h>>1)+1, src_x, src_y, s->width>>1, height>>1); | |
1054 ptr= s->edge_emu_buffer; | |
1055 } | |
0 | 1056 pix_op[dxy](dest_cb + (dest_offset >> 1), ptr, linesize >> 1, h >> 1); |
553 | 1057 |
0 | 1058 ptr = ref_picture[2] + offset; |
553 | 1059 if(emu){ |
1060 emulated_edge_mc(s->edge_emu_buffer, ptr, linesize>>1, 9, (h>>1)+1, src_x, src_y, s->width>>1, height>>1); | |
1061 ptr= s->edge_emu_buffer; | |
1062 } | |
0 | 1063 pix_op[dxy](dest_cr + (dest_offset >> 1), ptr, linesize >> 1, h >> 1); |
1064 } | |
1065 | |
255 | 1066 static inline void qpel_motion(MpegEncContext *s, |
1067 UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr, | |
1068 int dest_offset, | |
1069 UINT8 **ref_picture, int src_offset, | |
1070 int field_based, op_pixels_func *pix_op, | |
1071 qpel_mc_func *qpix_op, | |
1072 int motion_x, int motion_y, int h) | |
1073 { | |
1074 UINT8 *ptr; | |
1075 int dxy, offset, mx, my, src_x, src_y, height, linesize; | |
554 | 1076 int emu=0; |
255 | 1077 |
1078 dxy = ((motion_y & 3) << 2) | (motion_x & 3); | |
1079 src_x = s->mb_x * 16 + (motion_x >> 2); | |
1080 src_y = s->mb_y * (16 >> field_based) + (motion_y >> 2); | |
1081 | |
1082 height = s->height >> field_based; | |
1083 src_x = clip(src_x, -16, s->width); | |
1084 if (src_x == s->width) | |
1085 dxy &= ~3; | |
1086 src_y = clip(src_y, -16, height); | |
1087 if (src_y == height) | |
1088 dxy &= ~12; | |
1089 linesize = s->linesize << field_based; | |
1090 ptr = ref_picture[0] + (src_y * linesize) + src_x + src_offset; | |
1091 dest_y += dest_offset; | |
1092 //printf("%d %d %d\n", src_x, src_y, dxy); | |
554 | 1093 |
1094 if(s->flags&CODEC_FLAG_EMU_EDGE){ | |
1095 if(src_x<0 || src_y<0 || src_x + (motion_x&3) + 16 > s->width | |
1096 || src_y + (motion_y&3) + h > height){ | |
1097 emulated_edge_mc(s->edge_emu_buffer, ptr, linesize, 17, h+1, src_x, src_y, s->width, height); | |
1098 ptr= s->edge_emu_buffer; | |
1099 emu=1; | |
1100 } | |
1101 } | |
255 | 1102 qpix_op[dxy](dest_y , ptr , linesize, linesize, motion_x&3, motion_y&3); |
1103 qpix_op[dxy](dest_y + 8, ptr + 8, linesize, linesize, motion_x&3, motion_y&3); | |
1104 qpix_op[dxy](dest_y + linesize*8 , ptr + linesize*8 , linesize, linesize, motion_x&3, motion_y&3); | |
1105 qpix_op[dxy](dest_y + linesize*8 + 8, ptr + linesize*8 + 8, linesize, linesize, motion_x&3, motion_y&3); | |
1106 | |
485 | 1107 if(s->flags&CODEC_FLAG_GRAY) return; |
1108 | |
255 | 1109 mx= (motion_x>>1) | (motion_x&1); |
1110 my= (motion_y>>1) | (motion_y&1); | |
1111 | |
1112 dxy = 0; | |
1113 if ((mx & 3) != 0) | |
1114 dxy |= 1; | |
1115 if ((my & 3) != 0) | |
1116 dxy |= 2; | |
1117 mx = mx >> 2; | |
1118 my = my >> 2; | |
1119 | |
1120 src_x = s->mb_x * 8 + mx; | |
1121 src_y = s->mb_y * (8 >> field_based) + my; | |
1122 src_x = clip(src_x, -8, s->width >> 1); | |
1123 if (src_x == (s->width >> 1)) | |
1124 dxy &= ~1; | |
1125 src_y = clip(src_y, -8, height >> 1); | |
1126 if (src_y == (height >> 1)) | |
1127 dxy &= ~2; | |
1128 | |
1129 offset = (src_y * (linesize >> 1)) + src_x + (src_offset >> 1); | |
1130 ptr = ref_picture[1] + offset; | |
554 | 1131 if(emu){ |
1132 emulated_edge_mc(s->edge_emu_buffer, ptr, linesize>>1, 9, (h>>1)+1, src_x, src_y, s->width>>1, height>>1); | |
1133 ptr= s->edge_emu_buffer; | |
1134 } | |
255 | 1135 pix_op[dxy](dest_cb + (dest_offset >> 1), ptr, linesize >> 1, h >> 1); |
554 | 1136 |
255 | 1137 ptr = ref_picture[2] + offset; |
554 | 1138 if(emu){ |
1139 emulated_edge_mc(s->edge_emu_buffer, ptr, linesize>>1, 9, (h>>1)+1, src_x, src_y, s->width>>1, height>>1); | |
1140 ptr= s->edge_emu_buffer; | |
1141 } | |
255 | 1142 pix_op[dxy](dest_cr + (dest_offset >> 1), ptr, linesize >> 1, h >> 1); |
1143 } | |
1144 | |
1145 | |
0 | 1146 static inline void MPV_motion(MpegEncContext *s, |
1147 UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr, | |
1148 int dir, UINT8 **ref_picture, | |
255 | 1149 op_pixels_func *pix_op, qpel_mc_func *qpix_op) |
0 | 1150 { |
1151 int dxy, offset, mx, my, src_x, src_y, motion_x, motion_y; | |
1152 int mb_x, mb_y, i; | |
1153 UINT8 *ptr, *dest; | |
554 | 1154 int emu=0; |
0 | 1155 |
1156 mb_x = s->mb_x; | |
1157 mb_y = s->mb_y; | |
1158 | |
1159 switch(s->mv_type) { | |
1160 case MV_TYPE_16X16: | |
255 | 1161 if(s->mcsel){ |
1162 #if 0 | |
1163 mpeg_motion(s, dest_y, dest_cb, dest_cr, 0, | |
1164 ref_picture, 0, | |
1165 0, pix_op, | |
1166 s->sprite_offset[0][0]>>3, | |
1167 s->sprite_offset[0][1]>>3, | |
1168 16); | |
1169 #else | |
1170 gmc1_motion(s, dest_y, dest_cb, dest_cr, 0, | |
1171 ref_picture, 0, | |
1172 16); | |
1173 #endif | |
262 | 1174 }else if(s->quarter_sample && dir==0){ //FIXME |
255 | 1175 qpel_motion(s, dest_y, dest_cb, dest_cr, 0, |
1176 ref_picture, 0, | |
1177 0, pix_op, qpix_op, | |
1178 s->mv[dir][0][0], s->mv[dir][0][1], 16); | |
1179 }else{ | |
1180 mpeg_motion(s, dest_y, dest_cb, dest_cr, 0, | |
1181 ref_picture, 0, | |
1182 0, pix_op, | |
1183 s->mv[dir][0][0], s->mv[dir][0][1], 16); | |
1184 } | |
0 | 1185 break; |
1186 case MV_TYPE_8X8: | |
1187 for(i=0;i<4;i++) { | |
1188 motion_x = s->mv[dir][i][0]; | |
1189 motion_y = s->mv[dir][i][1]; | |
1190 | |
1191 dxy = ((motion_y & 1) << 1) | (motion_x & 1); | |
1192 src_x = mb_x * 16 + (motion_x >> 1) + (i & 1) * 8; | |
295 | 1193 src_y = mb_y * 16 + (motion_y >> 1) + (i >>1) * 8; |
0 | 1194 |
1195 /* WARNING: do no forget half pels */ | |
1196 src_x = clip(src_x, -16, s->width); | |
1197 if (src_x == s->width) | |
1198 dxy &= ~1; | |
1199 src_y = clip(src_y, -16, s->height); | |
1200 if (src_y == s->height) | |
1201 dxy &= ~2; | |
1202 | |
1203 ptr = ref_picture[0] + (src_y * s->linesize) + (src_x); | |
554 | 1204 if(s->flags&CODEC_FLAG_EMU_EDGE){ |
1205 if(src_x<0 || src_y<0 || src_x + (motion_x&1) + 8 > s->width | |
1206 || src_y + (motion_y&1) + 8 > s->height){ | |
1207 emulated_edge_mc(s->edge_emu_buffer, ptr, s->linesize, 9, 9, src_x, src_y, s->width, s->height); | |
1208 ptr= s->edge_emu_buffer; | |
1209 } | |
1210 } | |
0 | 1211 dest = dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize; |
1212 pix_op[dxy](dest, ptr, s->linesize, 8); | |
1213 } | |
485 | 1214 |
1215 if(s->flags&CODEC_FLAG_GRAY) break; | |
0 | 1216 /* In case of 8X8, we construct a single chroma motion vector |
1217 with a special rounding */ | |
1218 mx = 0; | |
1219 my = 0; | |
1220 for(i=0;i<4;i++) { | |
1221 mx += s->mv[dir][i][0]; | |
1222 my += s->mv[dir][i][1]; | |
1223 } | |
1224 if (mx >= 0) | |
1225 mx = (h263_chroma_roundtab[mx & 0xf] + ((mx >> 3) & ~1)); | |
1226 else { | |
1227 mx = -mx; | |
1228 mx = -(h263_chroma_roundtab[mx & 0xf] + ((mx >> 3) & ~1)); | |
1229 } | |
1230 if (my >= 0) | |
1231 my = (h263_chroma_roundtab[my & 0xf] + ((my >> 3) & ~1)); | |
1232 else { | |
1233 my = -my; | |
1234 my = -(h263_chroma_roundtab[my & 0xf] + ((my >> 3) & ~1)); | |
1235 } | |
1236 dxy = ((my & 1) << 1) | (mx & 1); | |
1237 mx >>= 1; | |
1238 my >>= 1; | |
1239 | |
1240 src_x = mb_x * 8 + mx; | |
1241 src_y = mb_y * 8 + my; | |
1242 src_x = clip(src_x, -8, s->width/2); | |
1243 if (src_x == s->width/2) | |
1244 dxy &= ~1; | |
1245 src_y = clip(src_y, -8, s->height/2); | |
1246 if (src_y == s->height/2) | |
1247 dxy &= ~2; | |
1248 | |
1249 offset = (src_y * (s->linesize >> 1)) + src_x; | |
1250 ptr = ref_picture[1] + offset; | |
554 | 1251 if(s->flags&CODEC_FLAG_EMU_EDGE){ |
1252 if(src_x<0 || src_y<0 || src_x + (dxy &1) + 8 > s->width >>1 | |
1253 || src_y + (dxy>>1) + 8 > s->height>>1){ | |
1254 emulated_edge_mc(s->edge_emu_buffer, ptr, s->linesize>>1, 9, 9, src_x, src_y, s->width>>1, s->height>>1); | |
1255 ptr= s->edge_emu_buffer; | |
1256 emu=1; | |
1257 } | |
1258 } | |
0 | 1259 pix_op[dxy](dest_cb, ptr, s->linesize >> 1, 8); |
554 | 1260 |
0 | 1261 ptr = ref_picture[2] + offset; |
554 | 1262 if(emu){ |
1263 emulated_edge_mc(s->edge_emu_buffer, ptr, s->linesize>>1, 9, 9, src_x, src_y, s->width>>1, s->height>>1); | |
1264 ptr= s->edge_emu_buffer; | |
1265 } | |
0 | 1266 pix_op[dxy](dest_cr, ptr, s->linesize >> 1, 8); |
1267 break; | |
1268 case MV_TYPE_FIELD: | |
1269 if (s->picture_structure == PICT_FRAME) { | |
1270 /* top field */ | |
1271 mpeg_motion(s, dest_y, dest_cb, dest_cr, 0, | |
1272 ref_picture, s->field_select[dir][0] ? s->linesize : 0, | |
1273 1, pix_op, | |
1274 s->mv[dir][0][0], s->mv[dir][0][1], 8); | |
1275 /* bottom field */ | |
1276 mpeg_motion(s, dest_y, dest_cb, dest_cr, s->linesize, | |
1277 ref_picture, s->field_select[dir][1] ? s->linesize : 0, | |
1278 1, pix_op, | |
1279 s->mv[dir][1][0], s->mv[dir][1][1], 8); | |
1280 } else { | |
1281 | |
1282 | |
1283 } | |
1284 break; | |
1285 } | |
1286 } | |
1287 | |
1288 | |
1289 /* put block[] to dest[] */ | |
1290 static inline void put_dct(MpegEncContext *s, | |
1291 DCTELEM *block, int i, UINT8 *dest, int line_size) | |
1292 { | |
1293 if (!s->mpeg2) | |
13
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
1294 s->dct_unquantize(s, block, i, s->qscale); |
478 | 1295 ff_idct_put (dest, line_size, block); |
0 | 1296 } |
1297 | |
1298 /* add block[] to dest[] */ | |
1299 static inline void add_dct(MpegEncContext *s, | |
1300 DCTELEM *block, int i, UINT8 *dest, int line_size) | |
1301 { | |
1302 if (s->block_last_index[i] >= 0) { | |
481 | 1303 ff_idct_add (dest, line_size, block); |
1304 } | |
1305 } | |
1306 | |
1307 static inline void add_dequant_dct(MpegEncContext *s, | |
1308 DCTELEM *block, int i, UINT8 *dest, int line_size) | |
1309 { | |
1310 if (s->block_last_index[i] >= 0) { | |
1311 s->dct_unquantize(s, block, i, s->qscale); | |
324 | 1312 |
478 | 1313 ff_idct_add (dest, line_size, block); |
0 | 1314 } |
1315 } | |
1316 | |
456 | 1317 /** |
1318 * cleans dc, ac, coded_block for the current non intra MB | |
1319 */ | |
1320 void ff_clean_intra_table_entries(MpegEncContext *s) | |
1321 { | |
1322 int wrap = s->block_wrap[0]; | |
1323 int xy = s->block_index[0]; | |
1324 | |
1325 s->dc_val[0][xy ] = | |
1326 s->dc_val[0][xy + 1 ] = | |
1327 s->dc_val[0][xy + wrap] = | |
1328 s->dc_val[0][xy + 1 + wrap] = 1024; | |
1329 /* ac pred */ | |
1330 memset(s->ac_val[0][xy ], 0, 32 * sizeof(INT16)); | |
1331 memset(s->ac_val[0][xy + wrap], 0, 32 * sizeof(INT16)); | |
1332 if (s->msmpeg4_version>=3) { | |
1333 s->coded_block[xy ] = | |
1334 s->coded_block[xy + 1 ] = | |
1335 s->coded_block[xy + wrap] = | |
1336 s->coded_block[xy + 1 + wrap] = 0; | |
1337 } | |
1338 /* chroma */ | |
1339 wrap = s->block_wrap[4]; | |
1340 xy = s->mb_x + 1 + (s->mb_y + 1) * wrap; | |
1341 s->dc_val[1][xy] = | |
1342 s->dc_val[2][xy] = 1024; | |
1343 /* ac pred */ | |
1344 memset(s->ac_val[1][xy], 0, 16 * sizeof(INT16)); | |
1345 memset(s->ac_val[2][xy], 0, 16 * sizeof(INT16)); | |
1346 | |
1347 s->mbintra_table[s->mb_x + s->mb_y*s->mb_width]= 0; | |
1348 } | |
1349 | |
0 | 1350 /* generic function called after a macroblock has been parsed by the |
1351 decoder or after it has been encoded by the encoder. | |
1352 | |
1353 Important variables used: | |
1354 s->mb_intra : true if intra macroblock | |
1355 s->mv_dir : motion vector direction | |
1356 s->mv_type : motion vector type | |
1357 s->mv : motion vector | |
1358 s->interlaced_dct : true if interlaced dct used (mpeg2) | |
1359 */ | |
1360 void MPV_decode_mb(MpegEncContext *s, DCTELEM block[6][64]) | |
1361 { | |
244 | 1362 int mb_x, mb_y; |
481 | 1363 const int mb_xy = s->mb_y * s->mb_width + s->mb_x; |
0 | 1364 |
1365 mb_x = s->mb_x; | |
1366 mb_y = s->mb_y; | |
1367 | |
108
1e4a4af694d1
exporting qscale data for postprocessing (for MPlayer)
arpi_esp
parents:
79
diff
changeset
|
1368 #ifdef FF_POSTPROCESS |
466
805714c0c10f
new field for communicating with external postprocessing
nickols_k
parents:
462
diff
changeset
|
1369 /* Obsolete. Exists for compatibility with mplayer only. */ |
108
1e4a4af694d1
exporting qscale data for postprocessing (for MPlayer)
arpi_esp
parents:
79
diff
changeset
|
1370 quant_store[mb_y][mb_x]=s->qscale; |
1e4a4af694d1
exporting qscale data for postprocessing (for MPlayer)
arpi_esp
parents:
79
diff
changeset
|
1371 //printf("[%02d][%02d] %d\n",mb_x,mb_y,s->qscale); |
466
805714c0c10f
new field for communicating with external postprocessing
nickols_k
parents:
462
diff
changeset
|
1372 #else |
467 | 1373 if(s->avctx->quant_store) s->avctx->quant_store[mb_y*s->avctx->qstride+mb_x] = s->qscale; |
108
1e4a4af694d1
exporting qscale data for postprocessing (for MPlayer)
arpi_esp
parents:
79
diff
changeset
|
1374 #endif |
1e4a4af694d1
exporting qscale data for postprocessing (for MPlayer)
arpi_esp
parents:
79
diff
changeset
|
1375 |
0 | 1376 /* update DC predictors for P macroblocks */ |
1377 if (!s->mb_intra) { | |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1378 if (s->h263_pred || s->h263_aic) { |
481 | 1379 if(s->mbintra_table[mb_xy]) |
456 | 1380 ff_clean_intra_table_entries(s); |
0 | 1381 } else { |
456 | 1382 s->last_dc[0] = |
1383 s->last_dc[1] = | |
0 | 1384 s->last_dc[2] = 128 << s->intra_dc_precision; |
1385 } | |
1386 } | |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1387 else if (s->h263_pred || s->h263_aic) |
481 | 1388 s->mbintra_table[mb_xy]=1; |
191
883f184537e6
AC table reset (memset) optimization - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
189
diff
changeset
|
1389 |
280 | 1390 /* update motion predictor, not for B-frames as they need the motion_val from the last P/S-Frame */ |
481 | 1391 if (s->out_format == FMT_H263 && s->pict_type!=B_TYPE) { //FIXME move into h263.c if possible, format specific stuff shouldnt be here |
1392 int motion_x, motion_y; | |
0 | 1393 |
481 | 1394 const int wrap = s->block_wrap[0]; |
1395 const int xy = s->block_index[0]; | |
0 | 1396 if (s->mb_intra) { |
1397 motion_x = 0; | |
1398 motion_y = 0; | |
1399 goto motion_init; | |
1400 } else if (s->mv_type == MV_TYPE_16X16) { | |
1401 motion_x = s->mv[0][0][0]; | |
1402 motion_y = s->mv[0][0][1]; | |
1403 motion_init: | |
1404 /* no update if 8X8 because it has been done during parsing */ | |
244 | 1405 s->motion_val[xy][0] = motion_x; |
1406 s->motion_val[xy][1] = motion_y; | |
1407 s->motion_val[xy + 1][0] = motion_x; | |
1408 s->motion_val[xy + 1][1] = motion_y; | |
1409 s->motion_val[xy + wrap][0] = motion_x; | |
1410 s->motion_val[xy + wrap][1] = motion_y; | |
1411 s->motion_val[xy + 1 + wrap][0] = motion_x; | |
1412 s->motion_val[xy + 1 + wrap][1] = motion_y; | |
0 | 1413 } |
1414 } | |
1415 | |
324 | 1416 if (!(s->encoding && (s->intra_only || s->pict_type==B_TYPE))) { |
0 | 1417 UINT8 *dest_y, *dest_cb, *dest_cr; |
481 | 1418 int dct_linesize, dct_offset; |
1419 op_pixels_func *op_pix; | |
1420 qpel_mc_func *op_qpix; | |
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1421 |
324 | 1422 /* avoid copy if macroblock skipped in last frame too |
1423 dont touch it for B-frames as they need the skip info from the next p-frame */ | |
1424 if (s->pict_type != B_TYPE) { | |
481 | 1425 UINT8 *mbskip_ptr = &s->mbskip_table[mb_xy]; |
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1426 if (s->mb_skiped) { |
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1427 s->mb_skiped = 0; |
324 | 1428 /* if previous was skipped too, then nothing to do ! |
1429 skip only during decoding as we might trash the buffers during encoding a bit */ | |
1430 if (*mbskip_ptr != 0 && !s->encoding) | |
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1431 goto the_end; |
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1432 *mbskip_ptr = 1; /* indicate that this time we skiped it */ |
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1433 } else { |
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1434 *mbskip_ptr = 0; /* not skipped */ |
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1435 } |
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1436 } |
0 | 1437 |
1438 dest_y = s->current_picture[0] + (mb_y * 16 * s->linesize) + mb_x * 16; | |
1439 dest_cb = s->current_picture[1] + (mb_y * 8 * (s->linesize >> 1)) + mb_x * 8; | |
1440 dest_cr = s->current_picture[2] + (mb_y * 8 * (s->linesize >> 1)) + mb_x * 8; | |
1441 | |
1442 if (s->interlaced_dct) { | |
1443 dct_linesize = s->linesize * 2; | |
1444 dct_offset = s->linesize; | |
1445 } else { | |
1446 dct_linesize = s->linesize; | |
1447 dct_offset = s->linesize * 8; | |
1448 } | |
1449 | |
1450 if (!s->mb_intra) { | |
1451 /* motion handling */ | |
456 | 1452 /* decoding or more than one mb_type (MC was allready done otherwise) */ |
481 | 1453 if((!s->encoding) || (s->mb_type[mb_xy]&(s->mb_type[mb_xy]-1))){ |
327 | 1454 if ((!s->no_rounding) || s->pict_type==B_TYPE){ |
324 | 1455 op_pix = put_pixels_tab; |
1456 op_qpix= qpel_mc_rnd_tab; | |
1457 }else{ | |
1458 op_pix = put_no_rnd_pixels_tab; | |
1459 op_qpix= qpel_mc_no_rnd_tab; | |
1460 } | |
0 | 1461 |
324 | 1462 if (s->mv_dir & MV_DIR_FORWARD) { |
1463 MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture, op_pix, op_qpix); | |
327 | 1464 if ((!s->no_rounding) || s->pict_type==B_TYPE) |
324 | 1465 op_pix = avg_pixels_tab; |
1466 else | |
1467 op_pix = avg_no_rnd_pixels_tab; | |
1468 } | |
1469 if (s->mv_dir & MV_DIR_BACKWARD) { | |
1470 MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture, op_pix, op_qpix); | |
1471 } | |
0 | 1472 } |
1473 | |
481 | 1474 /* skip dequant / idct if we are really late ;) */ |
1475 if(s->hurry_up>1) goto the_end; | |
1476 | |
0 | 1477 /* add dct residue */ |
549 | 1478 if(s->encoding || !(s->mpeg2 || s->h263_msmpeg4 || s->codec_id==CODEC_ID_MPEG4)){ |
481 | 1479 add_dequant_dct(s, block[0], 0, dest_y, dct_linesize); |
1480 add_dequant_dct(s, block[1], 1, dest_y + 8, dct_linesize); | |
1481 add_dequant_dct(s, block[2], 2, dest_y + dct_offset, dct_linesize); | |
1482 add_dequant_dct(s, block[3], 3, dest_y + dct_offset + 8, dct_linesize); | |
0 | 1483 |
485 | 1484 if(!(s->flags&CODEC_FLAG_GRAY)){ |
1485 add_dequant_dct(s, block[4], 4, dest_cb, s->linesize >> 1); | |
1486 add_dequant_dct(s, block[5], 5, dest_cr, s->linesize >> 1); | |
1487 } | |
481 | 1488 } else { |
1489 add_dct(s, block[0], 0, dest_y, dct_linesize); | |
1490 add_dct(s, block[1], 1, dest_y + 8, dct_linesize); | |
1491 add_dct(s, block[2], 2, dest_y + dct_offset, dct_linesize); | |
1492 add_dct(s, block[3], 3, dest_y + dct_offset + 8, dct_linesize); | |
1493 | |
485 | 1494 if(!(s->flags&CODEC_FLAG_GRAY)){ |
1495 add_dct(s, block[4], 4, dest_cb, s->linesize >> 1); | |
1496 add_dct(s, block[5], 5, dest_cr, s->linesize >> 1); | |
1497 } | |
481 | 1498 } |
0 | 1499 } else { |
1500 /* dct only in intra block */ | |
1501 put_dct(s, block[0], 0, dest_y, dct_linesize); | |
1502 put_dct(s, block[1], 1, dest_y + 8, dct_linesize); | |
1503 put_dct(s, block[2], 2, dest_y + dct_offset, dct_linesize); | |
1504 put_dct(s, block[3], 3, dest_y + dct_offset + 8, dct_linesize); | |
1505 | |
485 | 1506 if(!(s->flags&CODEC_FLAG_GRAY)){ |
1507 put_dct(s, block[4], 4, dest_cb, s->linesize >> 1); | |
1508 put_dct(s, block[5], 5, dest_cr, s->linesize >> 1); | |
1509 } | |
0 | 1510 } |
1511 } | |
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1512 the_end: |
294 | 1513 emms_c(); //FIXME remove |
1514 } | |
1515 | |
456 | 1516 static inline void dct_single_coeff_elimination(MpegEncContext *s, int n, int threshold, int skip_dc) |
1517 { | |
1518 static const char tab[64]= | |
1519 {3,2,2,1,1,1,1,1, | |
1520 1,1,1,1,1,1,1,1, | |
1521 1,1,1,1,1,1,1,1, | |
1522 0,0,0,0,0,0,0,0, | |
1523 0,0,0,0,0,0,0,0, | |
1524 0,0,0,0,0,0,0,0, | |
1525 0,0,0,0,0,0,0,0, | |
1526 0,0,0,0,0,0,0,0}; | |
1527 int score=0; | |
1528 int run=0; | |
1529 int i; | |
1530 DCTELEM *block= s->block[n]; | |
1531 const int last_index= s->block_last_index[n]; | |
1532 | |
1533 if(skip_dc) skip_dc=1; | |
1534 | |
1535 /* are all which we could set to zero are allready zero? */ | |
1536 if(last_index<=skip_dc - 1) return; | |
1537 | |
1538 for(i=0; i<=last_index; i++){ | |
1539 const int j = zigzag_direct[i]; | |
1540 const int level = ABS(block[j]); | |
1541 if(level==1){ | |
1542 if(skip_dc && i==0) continue; | |
1543 score+= tab[run]; | |
1544 run=0; | |
1545 }else if(level>1){ | |
1546 return; | |
1547 }else{ | |
1548 run++; | |
1549 } | |
1550 } | |
1551 if(score >= threshold) return; | |
1552 for(i=skip_dc; i<=last_index; i++){ | |
1553 const int j = zigzag_direct[i]; | |
1554 block[j]=0; | |
1555 } | |
1556 if(block[0]) s->block_last_index[n]= 0; | |
1557 else s->block_last_index[n]= -1; | |
1558 } | |
1559 | |
344 | 1560 static inline void clip_coeffs(MpegEncContext *s, DCTELEM *block, int last_index) |
1561 { | |
1562 int i; | |
1563 const int maxlevel= s->max_qcoeff; | |
1564 const int minlevel= s->min_qcoeff; | |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
1565 |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
1566 for(i=0;i<=last_index; i++){ |
344 | 1567 const int j = zigzag_direct[i]; |
1568 int level = block[j]; | |
1569 | |
1570 if (level>maxlevel) level=maxlevel; | |
1571 else if(level<minlevel) level=minlevel; | |
1572 block[j]= level; | |
1573 } | |
1574 } | |
324 | 1575 |
1576 static void encode_mb(MpegEncContext *s, int motion_x, int motion_y) | |
294 | 1577 { |
1578 const int mb_x= s->mb_x; | |
1579 const int mb_y= s->mb_y; | |
1580 int i; | |
456 | 1581 int skip_dct[6]; |
324 | 1582 #if 0 |
1583 if (s->interlaced_dct) { | |
1584 dct_linesize = s->linesize * 2; | |
1585 dct_offset = s->linesize; | |
1586 } else { | |
1587 dct_linesize = s->linesize; | |
1588 dct_offset = s->linesize * 8; | |
1589 } | |
1590 #endif | |
456 | 1591 for(i=0; i<6; i++) skip_dct[i]=0; |
294 | 1592 |
324 | 1593 if (s->mb_intra) { |
1594 UINT8 *ptr; | |
1595 int wrap; | |
294 | 1596 |
324 | 1597 wrap = s->linesize; |
1598 ptr = s->new_picture[0] + (mb_y * 16 * wrap) + mb_x * 16; | |
1599 get_pixels(s->block[0], ptr , wrap); | |
1600 get_pixels(s->block[1], ptr + 8, wrap); | |
1601 get_pixels(s->block[2], ptr + 8 * wrap , wrap); | |
1602 get_pixels(s->block[3], ptr + 8 * wrap + 8, wrap); | |
294 | 1603 |
487 | 1604 if(s->flags&CODEC_FLAG_GRAY){ |
1605 skip_dct[4]= 1; | |
1606 skip_dct[5]= 1; | |
1607 }else{ | |
1608 wrap >>=1; | |
1609 ptr = s->new_picture[1] + (mb_y * 8 * wrap) + mb_x * 8; | |
1610 get_pixels(s->block[4], ptr, wrap); | |
294 | 1611 |
487 | 1612 ptr = s->new_picture[2] + (mb_y * 8 * wrap) + mb_x * 8; |
1613 get_pixels(s->block[5], ptr, wrap); | |
1614 } | |
324 | 1615 }else{ |
1616 op_pixels_func *op_pix; | |
1617 qpel_mc_func *op_qpix; | |
1618 UINT8 *dest_y, *dest_cb, *dest_cr; | |
456 | 1619 UINT8 *ptr_y, *ptr_cb, *ptr_cr; |
1620 int wrap_y, wrap_c; | |
294 | 1621 |
324 | 1622 dest_y = s->current_picture[0] + (mb_y * 16 * s->linesize ) + mb_x * 16; |
1623 dest_cb = s->current_picture[1] + (mb_y * 8 * (s->linesize >> 1)) + mb_x * 8; | |
1624 dest_cr = s->current_picture[2] + (mb_y * 8 * (s->linesize >> 1)) + mb_x * 8; | |
456 | 1625 wrap_y = s->linesize; |
1626 wrap_c = wrap_y>>1; | |
1627 ptr_y = s->new_picture[0] + (mb_y * 16 * wrap_y) + mb_x * 16; | |
1628 ptr_cb = s->new_picture[1] + (mb_y * 8 * wrap_c) + mb_x * 8; | |
1629 ptr_cr = s->new_picture[2] + (mb_y * 8 * wrap_c) + mb_x * 8; | |
324 | 1630 |
327 | 1631 if ((!s->no_rounding) || s->pict_type==B_TYPE){ |
324 | 1632 op_pix = put_pixels_tab; |
1633 op_qpix= qpel_mc_rnd_tab; | |
295 | 1634 }else{ |
324 | 1635 op_pix = put_no_rnd_pixels_tab; |
1636 op_qpix= qpel_mc_no_rnd_tab; | |
1637 } | |
295 | 1638 |
324 | 1639 if (s->mv_dir & MV_DIR_FORWARD) { |
1640 MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture, op_pix, op_qpix); | |
327 | 1641 if ((!s->no_rounding) || s->pict_type==B_TYPE) |
324 | 1642 op_pix = avg_pixels_tab; |
1643 else | |
1644 op_pix = avg_no_rnd_pixels_tab; | |
1645 } | |
1646 if (s->mv_dir & MV_DIR_BACKWARD) { | |
1647 MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture, op_pix, op_qpix); | |
1648 } | |
295 | 1649 |
456 | 1650 diff_pixels(s->block[0], ptr_y , dest_y , wrap_y); |
1651 diff_pixels(s->block[1], ptr_y + 8, dest_y + 8, wrap_y); | |
1652 diff_pixels(s->block[2], ptr_y + 8 * wrap_y , dest_y + 8 * wrap_y , wrap_y); | |
1653 diff_pixels(s->block[3], ptr_y + 8 * wrap_y + 8, dest_y + 8 * wrap_y + 8, wrap_y); | |
487 | 1654 |
1655 if(s->flags&CODEC_FLAG_GRAY){ | |
1656 skip_dct[4]= 1; | |
1657 skip_dct[5]= 1; | |
1658 }else{ | |
1659 diff_pixels(s->block[4], ptr_cb, dest_cb, wrap_c); | |
1660 diff_pixels(s->block[5], ptr_cr, dest_cr, wrap_c); | |
1661 } | |
1662 | |
456 | 1663 /* pre quantization */ |
1664 if(s->mc_mb_var[s->mb_width*mb_y+ mb_x]<2*s->qscale*s->qscale){ | |
1665 if(pix_abs8x8(ptr_y , dest_y , wrap_y) < 20*s->qscale) skip_dct[0]= 1; | |
1666 if(pix_abs8x8(ptr_y + 8, dest_y + 8, wrap_y) < 20*s->qscale) skip_dct[1]= 1; | |
1667 if(pix_abs8x8(ptr_y + 8*wrap_y , dest_y + 8*wrap_y , wrap_y) < 20*s->qscale) skip_dct[2]= 1; | |
1668 if(pix_abs8x8(ptr_y + 8*wrap_y + 8, dest_y + 8*wrap_y + 8, wrap_y) < 20*s->qscale) skip_dct[3]= 1; | |
1669 if(pix_abs8x8(ptr_cb , dest_cb , wrap_y) < 20*s->qscale) skip_dct[4]= 1; | |
1670 if(pix_abs8x8(ptr_cr , dest_cr , wrap_y) < 20*s->qscale) skip_dct[5]= 1; | |
1671 #if 0 | |
1672 { | |
1673 static int stat[7]; | |
1674 int num=0; | |
1675 for(i=0; i<6; i++) | |
1676 if(skip_dct[i]) num++; | |
1677 stat[num]++; | |
1678 | |
1679 if(s->mb_x==0 && s->mb_y==0){ | |
1680 for(i=0; i<7; i++){ | |
1681 printf("%6d %1d\n", stat[i], i); | |
1682 } | |
1683 } | |
1684 } | |
1685 #endif | |
1686 } | |
324 | 1687 |
294 | 1688 } |
1689 | |
1690 #if 0 | |
1691 { | |
1692 float adap_parm; | |
1693 | |
1694 adap_parm = ((s->avg_mb_var << 1) + s->mb_var[s->mb_width*mb_y+mb_x] + 1.0) / | |
1695 ((s->mb_var[s->mb_width*mb_y+mb_x] << 1) + s->avg_mb_var + 1.0); | |
1696 | |
1697 printf("\ntype=%c qscale=%2d adap=%0.2f dquant=%4.2f var=%4d avgvar=%4d", | |
1698 (s->mb_type[s->mb_width*mb_y+mb_x] > 0) ? 'I' : 'P', | |
1699 s->qscale, adap_parm, s->qscale*adap_parm, | |
1700 s->mb_var[s->mb_width*mb_y+mb_x], s->avg_mb_var); | |
1701 } | |
1702 #endif | |
1703 /* DCT & quantize */ | |
344 | 1704 if(s->out_format==FMT_MJPEG){ |
1705 for(i=0;i<6;i++) { | |
1706 int overflow; | |
1707 s->block_last_index[i] = dct_quantize(s, s->block[i], i, 8, &overflow); | |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
1708 if (overflow) clip_coeffs(s, s->block[i], s->block_last_index[i]); |
344 | 1709 } |
1710 }else{ | |
1711 for(i=0;i<6;i++) { | |
456 | 1712 if(!skip_dct[i]){ |
1713 int overflow; | |
1714 s->block_last_index[i] = dct_quantize(s, s->block[i], i, s->qscale, &overflow); | |
344 | 1715 // FIXME we could decide to change to quantizer instead of clipping |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
1716 // JS: I don't think that would be a good idea it could lower quality instead |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
1717 // of improve it. Just INTRADC clipping deserves changes in quantizer |
456 | 1718 if (overflow) clip_coeffs(s, s->block[i], s->block_last_index[i]); |
1719 }else | |
1720 s->block_last_index[i]= -1; | |
344 | 1721 } |
456 | 1722 if(s->luma_elim_threshold && !s->mb_intra) |
1723 for(i=0; i<4; i++) | |
1724 dct_single_coeff_elimination(s, i, s->luma_elim_threshold, 0); | |
1725 if(s->chroma_elim_threshold && !s->mb_intra) | |
1726 for(i=4; i<6; i++) | |
1727 dct_single_coeff_elimination(s, i, s->chroma_elim_threshold, 1); | |
294 | 1728 } |
1729 | |
487 | 1730 if((s->flags&CODEC_FLAG_GRAY) && s->mb_intra){ |
1731 s->block_last_index[4]= | |
1732 s->block_last_index[5]= 0; | |
1733 s->block[4][0]= | |
1734 s->block[5][0]= 128; | |
1735 } | |
1736 | |
294 | 1737 /* huffman encode */ |
1738 switch(s->out_format) { | |
1739 case FMT_MPEG1: | |
1740 mpeg1_encode_mb(s, s->block, motion_x, motion_y); | |
1741 break; | |
1742 case FMT_H263: | |
1743 if (s->h263_msmpeg4) | |
1744 msmpeg4_encode_mb(s, s->block, motion_x, motion_y); | |
1745 else if(s->h263_pred) | |
1746 mpeg4_encode_mb(s, s->block, motion_x, motion_y); | |
1747 else | |
1748 h263_encode_mb(s, s->block, motion_x, motion_y); | |
1749 break; | |
1750 case FMT_MJPEG: | |
1751 mjpeg_encode_mb(s, s->block); | |
1752 break; | |
1753 } | |
1754 } | |
1755 | |
456 | 1756 void ff_copy_bits(PutBitContext *pb, UINT8 *src, int length) |
294 | 1757 { |
326 | 1758 int bytes= length>>4; |
1759 int bits= length&15; | |
1760 int i; | |
1761 | |
456 | 1762 if(length==0) return; |
1763 | |
326 | 1764 for(i=0; i<bytes; i++) put_bits(pb, 16, be2me_16(((uint16_t*)src)[i])); |
1765 put_bits(pb, bits, be2me_16(((uint16_t*)src)[i])>>(16-bits)); | |
0 | 1766 } |
1767 | |
456 | 1768 static inline void copy_context_before_encode(MpegEncContext *d, MpegEncContext *s, int type){ |
326 | 1769 int i; |
1770 | |
1771 memcpy(d->last_mv, s->last_mv, 2*2*2*sizeof(int)); //FIXME is memcpy faster then a loop? | |
1772 | |
1773 /* mpeg1 */ | |
1774 d->mb_incr= s->mb_incr; | |
1775 for(i=0; i<3; i++) | |
1776 d->last_dc[i]= s->last_dc[i]; | |
1777 | |
1778 /* statistics */ | |
1779 d->mv_bits= s->mv_bits; | |
1780 d->i_tex_bits= s->i_tex_bits; | |
1781 d->p_tex_bits= s->p_tex_bits; | |
1782 d->i_count= s->i_count; | |
1783 d->p_count= s->p_count; | |
1784 d->skip_count= s->skip_count; | |
1785 d->misc_bits= s->misc_bits; | |
329 | 1786 d->last_bits= 0; |
327 | 1787 |
1788 d->mb_skiped= s->mb_skiped; | |
326 | 1789 } |
1790 | |
456 | 1791 static inline void copy_context_after_encode(MpegEncContext *d, MpegEncContext *s, int type){ |
326 | 1792 int i; |
1793 | |
1794 memcpy(d->mv, s->mv, 2*4*2*sizeof(int)); | |
1795 memcpy(d->last_mv, s->last_mv, 2*2*2*sizeof(int)); //FIXME is memcpy faster then a loop? | |
1796 | |
1797 /* mpeg1 */ | |
1798 d->mb_incr= s->mb_incr; | |
1799 for(i=0; i<3; i++) | |
1800 d->last_dc[i]= s->last_dc[i]; | |
1801 | |
1802 /* statistics */ | |
1803 d->mv_bits= s->mv_bits; | |
1804 d->i_tex_bits= s->i_tex_bits; | |
1805 d->p_tex_bits= s->p_tex_bits; | |
1806 d->i_count= s->i_count; | |
1807 d->p_count= s->p_count; | |
1808 d->skip_count= s->skip_count; | |
1809 d->misc_bits= s->misc_bits; | |
1810 | |
1811 d->mb_intra= s->mb_intra; | |
327 | 1812 d->mb_skiped= s->mb_skiped; |
326 | 1813 d->mv_type= s->mv_type; |
1814 d->mv_dir= s->mv_dir; | |
1815 d->pb= s->pb; | |
456 | 1816 if(s->data_partitioning){ |
1817 d->pb2= s->pb2; | |
1818 d->tex_pb= s->tex_pb; | |
1819 } | |
326 | 1820 d->block= s->block; |
1821 for(i=0; i<6; i++) | |
1822 d->block_last_index[i]= s->block_last_index[i]; | |
1823 } | |
1824 | |
456 | 1825 static inline void encode_mb_hq(MpegEncContext *s, MpegEncContext *backup, MpegEncContext *best, int type, |
1826 PutBitContext pb[2], PutBitContext pb2[2], PutBitContext tex_pb[2], | |
1827 int *dmin, int *next_block, int motion_x, int motion_y) | |
1828 { | |
1829 int bits_count; | |
1830 | |
1831 copy_context_before_encode(s, backup, type); | |
1832 | |
1833 s->block= s->blocks[*next_block]; | |
1834 s->pb= pb[*next_block]; | |
1835 if(s->data_partitioning){ | |
1836 s->pb2 = pb2 [*next_block]; | |
1837 s->tex_pb= tex_pb[*next_block]; | |
1838 } | |
1839 | |
1840 encode_mb(s, motion_x, motion_y); | |
1841 | |
1842 bits_count= get_bit_count(&s->pb); | |
1843 if(s->data_partitioning){ | |
1844 bits_count+= get_bit_count(&s->pb2); | |
1845 bits_count+= get_bit_count(&s->tex_pb); | |
1846 } | |
1847 | |
1848 if(bits_count<*dmin){ | |
1849 *dmin= bits_count; | |
1850 *next_block^=1; | |
1851 | |
1852 copy_context_after_encode(best, s, type); | |
1853 } | |
1854 } | |
326 | 1855 |
0 | 1856 static void encode_picture(MpegEncContext *s, int picture_number) |
1857 { | |
294 | 1858 int mb_x, mb_y, last_gob, pdif = 0; |
1859 int i; | |
286 | 1860 int bits; |
326 | 1861 MpegEncContext best_s, backup_s; |
456 | 1862 UINT8 bit_buf[2][3000]; |
1863 UINT8 bit_buf2[2][3000]; | |
1864 UINT8 bit_buf_tex[2][3000]; | |
1865 PutBitContext pb[2], pb2[2], tex_pb[2]; | |
1866 | |
1867 for(i=0; i<2; i++){ | |
1868 init_put_bits(&pb [i], bit_buf [i], 3000, NULL, NULL); | |
1869 init_put_bits(&pb2 [i], bit_buf2 [i], 3000, NULL, NULL); | |
1870 init_put_bits(&tex_pb[i], bit_buf_tex[i], 3000, NULL, NULL); | |
1871 } | |
0 | 1872 |
1873 s->picture_number = picture_number; | |
268 | 1874 |
294 | 1875 s->block_wrap[0]= |
1876 s->block_wrap[1]= | |
1877 s->block_wrap[2]= | |
1878 s->block_wrap[3]= s->mb_width*2 + 2; | |
1879 s->block_wrap[4]= | |
1880 s->block_wrap[5]= s->mb_width + 2; | |
1881 | |
268 | 1882 /* Reset the average MB variance */ |
456 | 1883 s->mb_var_sum = 0; |
1884 s->mc_mb_var_sum = 0; | |
327 | 1885 |
1886 /* we need to initialize some time vars before we can encode b-frames */ | |
1887 if (s->h263_pred && !s->h263_msmpeg4) | |
1888 ff_set_mpeg4_time(s, s->picture_number); | |
1889 | |
268 | 1890 /* Estimate motion for every MB */ |
324 | 1891 if(s->pict_type != I_TYPE){ |
294 | 1892 for(mb_y=0; mb_y < s->mb_height; mb_y++) { |
1893 s->block_index[0]= s->block_wrap[0]*(mb_y*2 + 1) - 1; | |
1894 s->block_index[1]= s->block_wrap[0]*(mb_y*2 + 1); | |
1895 s->block_index[2]= s->block_wrap[0]*(mb_y*2 + 2) - 1; | |
1896 s->block_index[3]= s->block_wrap[0]*(mb_y*2 + 2); | |
1897 for(mb_x=0; mb_x < s->mb_width; mb_x++) { | |
1898 s->mb_x = mb_x; | |
1899 s->mb_y = mb_y; | |
1900 s->block_index[0]+=2; | |
1901 s->block_index[1]+=2; | |
1902 s->block_index[2]+=2; | |
1903 s->block_index[3]+=2; | |
268 | 1904 |
294 | 1905 /* compute motion vector & mb_type and store in context */ |
324 | 1906 if(s->pict_type==B_TYPE) |
1907 ff_estimate_b_frame_motion(s, mb_x, mb_y); | |
1908 else | |
1909 ff_estimate_p_frame_motion(s, mb_x, mb_y); | |
294 | 1910 // s->mb_type[mb_y*s->mb_width + mb_x]=MB_TYPE_INTER; |
268 | 1911 } |
1912 } | |
294 | 1913 emms_c(); |
456 | 1914 }else /* if(s->pict_type == I_TYPE) */{ |
294 | 1915 /* I-Frame */ |
1916 //FIXME do we need to zero them? | |
1917 memset(s->motion_val[0], 0, sizeof(INT16)*(s->mb_width*2 + 2)*(s->mb_height*2 + 2)*2); | |
324 | 1918 memset(s->p_mv_table , 0, sizeof(INT16)*(s->mb_width+2)*(s->mb_height+2)*2); |
294 | 1919 memset(s->mb_type , MB_TYPE_INTRA, sizeof(UINT8)*s->mb_width*s->mb_height); |
268 | 1920 } |
1921 | |
456 | 1922 if(s->mb_var_sum < s->mc_mb_var_sum && s->pict_type == P_TYPE){ //FIXME subtract MV bits |
271 | 1923 s->pict_type= I_TYPE; |
294 | 1924 memset(s->mb_type , MB_TYPE_INTRA, sizeof(UINT8)*s->mb_width*s->mb_height); |
329 | 1925 if(s->max_b_frames==0){ |
1926 s->input_pict_type= I_TYPE; | |
1927 s->input_picture_in_gop_number=0; | |
1928 } | |
294 | 1929 //printf("Scene change detected, encoding as I Frame\n"); |
271 | 1930 } |
324 | 1931 |
1932 if(s->pict_type==P_TYPE || s->pict_type==S_TYPE) | |
1933 s->f_code= ff_get_best_fcode(s, s->p_mv_table, MB_TYPE_INTER); | |
1934 ff_fix_long_p_mvs(s); | |
1935 if(s->pict_type==B_TYPE){ | |
1936 s->f_code= ff_get_best_fcode(s, s->b_forw_mv_table, MB_TYPE_FORWARD); | |
1937 s->b_code= ff_get_best_fcode(s, s->b_back_mv_table, MB_TYPE_BACKWARD); | |
327 | 1938 |
1939 ff_fix_long_b_mvs(s, s->b_forw_mv_table, s->f_code, MB_TYPE_FORWARD); | |
1940 ff_fix_long_b_mvs(s, s->b_back_mv_table, s->b_code, MB_TYPE_BACKWARD); | |
1941 ff_fix_long_b_mvs(s, s->b_bidir_forw_mv_table, s->f_code, MB_TYPE_BIDIR); | |
1942 ff_fix_long_b_mvs(s, s->b_bidir_back_mv_table, s->b_code, MB_TYPE_BIDIR); | |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1943 } |
324 | 1944 |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1945 //printf("f_code %d ///\n", s->f_code); |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1946 |
271 | 1947 // printf("%d %d\n", s->avg_mb_var, s->mc_mb_var); |
1948 | |
329 | 1949 if(s->flags&CODEC_FLAG_PASS2) |
1950 s->qscale = ff_rate_estimate_qscale_pass2(s); | |
1951 else if (!s->fixed_qscale) | |
1952 s->qscale = ff_rate_estimate_qscale(s); | |
1953 | |
0 | 1954 if (s->out_format == FMT_MJPEG) { |
1955 /* for mjpeg, we do include qscale in the matrix */ | |
533
3c07cf9595de
adding ff prefix to avoid global name conficts with xvid (patch by Marko Kreen <marko at l-t.ee>)
michaelni
parents:
514
diff
changeset
|
1956 s->intra_matrix[0] = ff_mpeg1_default_intra_matrix[0]; |
0 | 1957 for(i=1;i<64;i++) |
533
3c07cf9595de
adding ff prefix to avoid global name conficts with xvid (patch by Marko Kreen <marko at l-t.ee>)
michaelni
parents:
514
diff
changeset
|
1958 s->intra_matrix[i] = CLAMP_TO_8BIT((ff_mpeg1_default_intra_matrix[i] * s->qscale) >> 3); |
344 | 1959 convert_matrix(s->q_intra_matrix, s->q_intra_matrix16, |
1960 s->q_intra_matrix16_bias, s->intra_matrix, s->intra_quant_bias); | |
0 | 1961 } |
1962 | |
286 | 1963 s->last_bits= get_bit_count(&s->pb); |
0 | 1964 switch(s->out_format) { |
1965 case FMT_MJPEG: | |
1966 mjpeg_picture_header(s); | |
1967 break; | |
1968 case FMT_H263: | |
1969 if (s->h263_msmpeg4) | |
1970 msmpeg4_encode_picture_header(s, picture_number); | |
1971 else if (s->h263_pred) | |
1972 mpeg4_encode_picture_header(s, picture_number); | |
1973 else if (s->h263_rv10) | |
1974 rv10_encode_picture_header(s, picture_number); | |
1975 else | |
1976 h263_encode_picture_header(s, picture_number); | |
1977 break; | |
1978 case FMT_MPEG1: | |
1979 mpeg1_encode_picture_header(s, picture_number); | |
1980 break; | |
1981 } | |
286 | 1982 bits= get_bit_count(&s->pb); |
1983 s->header_bits= bits - s->last_bits; | |
1984 s->last_bits= bits; | |
1985 s->mv_bits=0; | |
1986 s->misc_bits=0; | |
1987 s->i_tex_bits=0; | |
1988 s->p_tex_bits=0; | |
1989 s->i_count=0; | |
1990 s->p_count=0; | |
1991 s->skip_count=0; | |
1992 | |
0 | 1993 /* init last dc values */ |
1994 /* note: quant matrix value (8) is implied here */ | |
1995 s->last_dc[0] = 128; | |
1996 s->last_dc[1] = 128; | |
1997 s->last_dc[2] = 128; | |
1998 s->mb_incr = 1; | |
1999 s->last_mv[0][0][0] = 0; | |
2000 s->last_mv[0][0][1] = 0; | |
2001 | |
162 | 2002 /* Get the GOB height based on picture height */ |
231 | 2003 if (s->out_format == FMT_H263 && !s->h263_pred && !s->h263_msmpeg4) { |
162 | 2004 if (s->height <= 400) |
2005 s->gob_index = 1; | |
2006 else if (s->height <= 800) | |
2007 s->gob_index = 2; | |
2008 else | |
2009 s->gob_index = 4; | |
456 | 2010 }else if(s->codec_id==CODEC_ID_MPEG4){ |
2011 s->gob_index = 1; | |
162 | 2012 } |
456 | 2013 |
2014 if(s->codec_id==CODEC_ID_MPEG4 && s->data_partitioning && s->pict_type!=B_TYPE) | |
2015 ff_mpeg4_init_partitions(s); | |
2016 | |
2017 s->resync_mb_x=0; | |
2018 s->resync_mb_y=0; | |
233
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
2019 for(mb_y=0; mb_y < s->mb_height; mb_y++) { |
456 | 2020 /* Put GOB header based on RTP MTU for formats which support it per line (H263*)*/ |
233
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
2021 /* TODO: Put all this stuff in a separate generic function */ |
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
2022 if (s->rtp_mode) { |
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
2023 if (!mb_y) { |
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
2024 s->ptr_lastgob = s->pb.buf; |
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
2025 s->ptr_last_mb_line = s->pb.buf; |
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
2026 } else if (s->out_format == FMT_H263 && !s->h263_pred && !s->h263_msmpeg4 && !(mb_y % s->gob_index)) { |
456 | 2027 // MN: we could move the space check from h263 -> here, as its not h263 specific |
233
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
2028 last_gob = h263_encode_gob_header(s, mb_y); |
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
2029 if (last_gob) { |
456 | 2030 s->first_slice_line = 1; |
2031 }else{ | |
2032 /*MN: we reset it here instead at the end of each line cuz mpeg4 can have | |
2033 slice lines starting & ending in the middle*/ | |
2034 s->first_slice_line = 0; | |
233
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
2035 } |
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
2036 } |
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
2037 } |
499 | 2038 |
2039 s->y_dc_scale= s->y_dc_scale_table[ s->qscale ]; | |
2040 s->c_dc_scale= s->c_dc_scale_table[ s->qscale ]; | |
233
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
2041 |
266 | 2042 s->block_index[0]= s->block_wrap[0]*(mb_y*2 + 1) - 1; |
2043 s->block_index[1]= s->block_wrap[0]*(mb_y*2 + 1); | |
2044 s->block_index[2]= s->block_wrap[0]*(mb_y*2 + 2) - 1; | |
2045 s->block_index[3]= s->block_wrap[0]*(mb_y*2 + 2); | |
2046 s->block_index[4]= s->block_wrap[4]*(mb_y + 1) + s->block_wrap[0]*(s->mb_height*2 + 2); | |
2047 s->block_index[5]= s->block_wrap[4]*(mb_y + 1 + s->mb_height + 2) + s->block_wrap[0]*(s->mb_height*2 + 2); | |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
2048 for(mb_x=0; mb_x < s->mb_width; mb_x++) { |
327 | 2049 const int mb_type= s->mb_type[mb_y * s->mb_width + mb_x]; |
2050 const int xy= (mb_y+1) * (s->mb_width+2) + mb_x + 1; | |
456 | 2051 // int d; |
294 | 2052 int dmin=10000000; |
0 | 2053 |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
2054 s->mb_x = mb_x; |
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
2055 s->mb_y = mb_y; |
266 | 2056 s->block_index[0]+=2; |
2057 s->block_index[1]+=2; | |
2058 s->block_index[2]+=2; | |
2059 s->block_index[3]+=2; | |
2060 s->block_index[4]++; | |
2061 s->block_index[5]++; | |
456 | 2062 |
2063 /* write gob / video packet header for formats which support it at any MB (MPEG4) */ | |
2064 if(s->rtp_mode && s->mb_y>0 && s->codec_id==CODEC_ID_MPEG4){ | |
2065 int pdif= pbBufPtr(&s->pb) - s->ptr_lastgob; | |
2066 | |
2067 //the *2 is there so we stay below the requested size | |
2068 if(pdif + s->mb_line_avgsize/s->mb_width >= s->rtp_payload_size){ | |
2069 if(s->codec_id==CODEC_ID_MPEG4){ | |
2070 if(s->data_partitioning && s->pict_type!=B_TYPE){ | |
2071 ff_mpeg4_merge_partitions(s); | |
2072 ff_mpeg4_init_partitions(s); | |
2073 } | |
2074 ff_mpeg4_encode_video_packet_header(s); | |
2075 | |
2076 if(s->flags&CODEC_FLAG_PASS1){ | |
2077 int bits= get_bit_count(&s->pb); | |
2078 s->misc_bits+= bits - s->last_bits; | |
2079 s->last_bits= bits; | |
2080 } | |
2081 ff_mpeg4_clean_buffers(s); | |
2082 } | |
2083 s->ptr_lastgob = pbBufPtr(&s->pb); | |
2084 s->first_slice_line=1; | |
2085 s->resync_mb_x=mb_x; | |
2086 s->resync_mb_y=mb_y; | |
2087 } | |
2088 | |
2089 if( (s->resync_mb_x == s->mb_x) | |
2090 && s->resync_mb_y+1 == s->mb_y){ | |
2091 s->first_slice_line=0; | |
2092 } | |
2093 } | |
2094 | |
294 | 2095 if(mb_type & (mb_type-1)){ // more than 1 MB type possible |
327 | 2096 int next_block=0; |
456 | 2097 int pb_bits_count, pb2_bits_count, tex_pb_bits_count; |
326 | 2098 |
2099 copy_context_before_encode(&backup_s, s, -1); | |
456 | 2100 backup_s.pb= s->pb; |
2101 best_s.data_partitioning= s->data_partitioning; | |
2102 if(s->data_partitioning){ | |
2103 backup_s.pb2= s->pb2; | |
2104 backup_s.tex_pb= s->tex_pb; | |
2105 } | |
326 | 2106 |
294 | 2107 if(mb_type&MB_TYPE_INTER){ |
327 | 2108 s->mv_dir = MV_DIR_FORWARD; |
295 | 2109 s->mv_type = MV_TYPE_16X16; |
294 | 2110 s->mb_intra= 0; |
324 | 2111 s->mv[0][0][0] = s->p_mv_table[xy][0]; |
2112 s->mv[0][0][1] = s->p_mv_table[xy][1]; | |
456 | 2113 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_INTER, pb, pb2, tex_pb, |
2114 &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]); | |
0 | 2115 } |
326 | 2116 if(mb_type&MB_TYPE_INTER4V){ |
327 | 2117 s->mv_dir = MV_DIR_FORWARD; |
295 | 2118 s->mv_type = MV_TYPE_8X8; |
2119 s->mb_intra= 0; | |
2120 for(i=0; i<4; i++){ | |
2121 s->mv[0][i][0] = s->motion_val[s->block_index[i]][0]; | |
2122 s->mv[0][i][1] = s->motion_val[s->block_index[i]][1]; | |
2123 } | |
456 | 2124 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_INTER4V, pb, pb2, tex_pb, |
2125 &dmin, &next_block, 0, 0); | |
327 | 2126 } |
2127 if(mb_type&MB_TYPE_FORWARD){ | |
2128 s->mv_dir = MV_DIR_FORWARD; | |
2129 s->mv_type = MV_TYPE_16X16; | |
2130 s->mb_intra= 0; | |
2131 s->mv[0][0][0] = s->b_forw_mv_table[xy][0]; | |
2132 s->mv[0][0][1] = s->b_forw_mv_table[xy][1]; | |
456 | 2133 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_FORWARD, pb, pb2, tex_pb, |
2134 &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]); | |
327 | 2135 } |
2136 if(mb_type&MB_TYPE_BACKWARD){ | |
2137 s->mv_dir = MV_DIR_BACKWARD; | |
2138 s->mv_type = MV_TYPE_16X16; | |
2139 s->mb_intra= 0; | |
2140 s->mv[1][0][0] = s->b_back_mv_table[xy][0]; | |
2141 s->mv[1][0][1] = s->b_back_mv_table[xy][1]; | |
456 | 2142 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_BACKWARD, pb, pb2, tex_pb, |
2143 &dmin, &next_block, s->mv[1][0][0], s->mv[1][0][1]); | |
327 | 2144 } |
2145 if(mb_type&MB_TYPE_BIDIR){ | |
2146 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; | |
2147 s->mv_type = MV_TYPE_16X16; | |
2148 s->mb_intra= 0; | |
2149 s->mv[0][0][0] = s->b_bidir_forw_mv_table[xy][0]; | |
2150 s->mv[0][0][1] = s->b_bidir_forw_mv_table[xy][1]; | |
2151 s->mv[1][0][0] = s->b_bidir_back_mv_table[xy][0]; | |
2152 s->mv[1][0][1] = s->b_bidir_back_mv_table[xy][1]; | |
456 | 2153 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_BIDIR, pb, pb2, tex_pb, |
2154 &dmin, &next_block, 0, 0); | |
327 | 2155 } |
2156 if(mb_type&MB_TYPE_DIRECT){ | |
2157 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; | |
2158 s->mv_type = MV_TYPE_16X16; //FIXME | |
2159 s->mb_intra= 0; | |
2160 s->mv[0][0][0] = s->b_direct_forw_mv_table[xy][0]; | |
2161 s->mv[0][0][1] = s->b_direct_forw_mv_table[xy][1]; | |
2162 s->mv[1][0][0] = s->b_direct_back_mv_table[xy][0]; | |
2163 s->mv[1][0][1] = s->b_direct_back_mv_table[xy][1]; | |
456 | 2164 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_DIRECT, pb, pb2, tex_pb, |
2165 &dmin, &next_block, s->b_direct_mv_table[xy][0], s->b_direct_mv_table[xy][1]); | |
295 | 2166 } |
294 | 2167 if(mb_type&MB_TYPE_INTRA){ |
327 | 2168 s->mv_dir = MV_DIR_FORWARD; |
295 | 2169 s->mv_type = MV_TYPE_16X16; |
294 | 2170 s->mb_intra= 1; |
2171 s->mv[0][0][0] = 0; | |
2172 s->mv[0][0][1] = 0; | |
456 | 2173 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_INTRA, pb, pb2, tex_pb, |
2174 &dmin, &next_block, 0, 0); | |
326 | 2175 /* force cleaning of ac/dc pred stuff if needed ... */ |
2176 if(s->h263_pred || s->h263_aic) | |
2177 s->mbintra_table[mb_x + mb_y*s->mb_width]=1; | |
295 | 2178 } |
326 | 2179 copy_context_after_encode(s, &best_s, -1); |
456 | 2180 |
2181 pb_bits_count= get_bit_count(&s->pb); | |
2182 flush_put_bits(&s->pb); | |
2183 ff_copy_bits(&backup_s.pb, bit_buf[next_block^1], pb_bits_count); | |
2184 s->pb= backup_s.pb; | |
2185 | |
2186 if(s->data_partitioning){ | |
2187 pb2_bits_count= get_bit_count(&s->pb2); | |
2188 flush_put_bits(&s->pb2); | |
2189 ff_copy_bits(&backup_s.pb2, bit_buf2[next_block^1], pb2_bits_count); | |
2190 s->pb2= backup_s.pb2; | |
2191 | |
2192 tex_pb_bits_count= get_bit_count(&s->tex_pb); | |
2193 flush_put_bits(&s->tex_pb); | |
2194 ff_copy_bits(&backup_s.tex_pb, bit_buf_tex[next_block^1], tex_pb_bits_count); | |
2195 s->tex_pb= backup_s.tex_pb; | |
2196 } | |
329 | 2197 s->last_bits= get_bit_count(&s->pb); |
294 | 2198 } else { |
324 | 2199 int motion_x, motion_y; |
2200 s->mv_type=MV_TYPE_16X16; | |
294 | 2201 // only one MB-Type possible |
327 | 2202 switch(mb_type){ |
2203 case MB_TYPE_INTRA: | |
324 | 2204 s->mv_dir = MV_DIR_FORWARD; |
294 | 2205 s->mb_intra= 1; |
324 | 2206 motion_x= s->mv[0][0][0] = 0; |
2207 motion_y= s->mv[0][0][1] = 0; | |
327 | 2208 break; |
2209 case MB_TYPE_INTER: | |
324 | 2210 s->mv_dir = MV_DIR_FORWARD; |
2211 s->mb_intra= 0; | |
2212 motion_x= s->mv[0][0][0] = s->p_mv_table[xy][0]; | |
2213 motion_y= s->mv[0][0][1] = s->p_mv_table[xy][1]; | |
327 | 2214 break; |
456 | 2215 case MB_TYPE_INTER4V: |
2216 s->mv_dir = MV_DIR_FORWARD; | |
2217 s->mv_type = MV_TYPE_8X8; | |
2218 s->mb_intra= 0; | |
2219 for(i=0; i<4; i++){ | |
2220 s->mv[0][i][0] = s->motion_val[s->block_index[i]][0]; | |
2221 s->mv[0][i][1] = s->motion_val[s->block_index[i]][1]; | |
2222 } | |
2223 motion_x= motion_y= 0; | |
2224 break; | |
327 | 2225 case MB_TYPE_DIRECT: |
324 | 2226 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; |
2227 s->mb_intra= 0; | |
327 | 2228 motion_x=s->b_direct_mv_table[xy][0]; |
2229 motion_y=s->b_direct_mv_table[xy][1]; | |
2230 s->mv[0][0][0] = s->b_direct_forw_mv_table[xy][0]; | |
2231 s->mv[0][0][1] = s->b_direct_forw_mv_table[xy][1]; | |
2232 s->mv[1][0][0] = s->b_direct_back_mv_table[xy][0]; | |
2233 s->mv[1][0][1] = s->b_direct_back_mv_table[xy][1]; | |
2234 break; | |
2235 case MB_TYPE_BIDIR: | |
324 | 2236 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; |
294 | 2237 s->mb_intra= 0; |
324 | 2238 motion_x=0; |
2239 motion_y=0; | |
2240 s->mv[0][0][0] = s->b_bidir_forw_mv_table[xy][0]; | |
2241 s->mv[0][0][1] = s->b_bidir_forw_mv_table[xy][1]; | |
2242 s->mv[1][0][0] = s->b_bidir_back_mv_table[xy][0]; | |
2243 s->mv[1][0][1] = s->b_bidir_back_mv_table[xy][1]; | |
327 | 2244 break; |
2245 case MB_TYPE_BACKWARD: | |
324 | 2246 s->mv_dir = MV_DIR_BACKWARD; |
2247 s->mb_intra= 0; | |
2248 motion_x= s->mv[1][0][0] = s->b_back_mv_table[xy][0]; | |
2249 motion_y= s->mv[1][0][1] = s->b_back_mv_table[xy][1]; | |
327 | 2250 break; |
2251 case MB_TYPE_FORWARD: | |
324 | 2252 s->mv_dir = MV_DIR_FORWARD; |
2253 s->mb_intra= 0; | |
2254 motion_x= s->mv[0][0][0] = s->b_forw_mv_table[xy][0]; | |
2255 motion_y= s->mv[0][0][1] = s->b_forw_mv_table[xy][1]; | |
2256 // printf(" %d %d ", motion_x, motion_y); | |
327 | 2257 break; |
2258 default: | |
324 | 2259 motion_x=motion_y=0; //gcc warning fix |
2260 printf("illegal MB type\n"); | |
294 | 2261 } |
324 | 2262 encode_mb(s, motion_x, motion_y); |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
2263 } |
327 | 2264 /* clean the MV table in IPS frames for direct mode in B frames */ |
2265 if(s->mb_intra /* && I,P,S_TYPE */){ | |
2266 s->p_mv_table[xy][0]=0; | |
2267 s->p_mv_table[xy][1]=0; | |
2268 } | |
0 | 2269 |
13
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
2270 MPV_decode_mb(s, s->block); |
456 | 2271 //printf("MB %d %d bits\n", s->mb_x+s->mb_y*s->mb_width, get_bit_count(&s->pb)); |
0 | 2272 } |
234
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
233
diff
changeset
|
2273 |
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
233
diff
changeset
|
2274 |
231 | 2275 /* Obtain average GOB size for RTP */ |
2276 if (s->rtp_mode) { | |
2277 if (!mb_y) | |
234
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
233
diff
changeset
|
2278 s->mb_line_avgsize = pbBufPtr(&s->pb) - s->ptr_last_mb_line; |
231 | 2279 else if (!(mb_y % s->gob_index)) { |
234
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
233
diff
changeset
|
2280 s->mb_line_avgsize = (s->mb_line_avgsize + pbBufPtr(&s->pb) - s->ptr_last_mb_line) >> 1; |
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
233
diff
changeset
|
2281 s->ptr_last_mb_line = pbBufPtr(&s->pb); |
231 | 2282 } |
2283 //fprintf(stderr, "\nMB line: %d\tSize: %u\tAvg. Size: %u", s->mb_y, | |
2284 // (s->pb.buf_ptr - s->ptr_last_mb_line), s->mb_line_avgsize); | |
456 | 2285 if(s->codec_id!=CODEC_ID_MPEG4) s->first_slice_line = 0; //FIXME clean |
231 | 2286 } |
0 | 2287 } |
294 | 2288 emms_c(); |
286 | 2289 |
456 | 2290 if(s->codec_id==CODEC_ID_MPEG4 && s->data_partitioning && s->pict_type!=B_TYPE) |
2291 ff_mpeg4_merge_partitions(s); | |
2292 | |
2293 if (s->msmpeg4_version && s->msmpeg4_version<4 && s->pict_type == I_TYPE) | |
208 | 2294 msmpeg4_encode_ext_header(s); |
2295 | |
456 | 2296 if(s->codec_id==CODEC_ID_MPEG4) |
2297 ff_mpeg4_stuffing(&s->pb); | |
2298 | |
162 | 2299 //if (s->gob_number) |
2300 // fprintf(stderr,"\nNumber of GOB: %d", s->gob_number); | |
231 | 2301 |
2302 /* Send the last GOB if RTP */ | |
2303 if (s->rtp_mode) { | |
2304 flush_put_bits(&s->pb); | |
234
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
233
diff
changeset
|
2305 pdif = pbBufPtr(&s->pb) - s->ptr_lastgob; |
231 | 2306 /* Call the RTP callback to send the last GOB */ |
2307 if (s->rtp_callback) | |
2308 s->rtp_callback(s->ptr_lastgob, pdif, s->gob_number); | |
234
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
233
diff
changeset
|
2309 s->ptr_lastgob = pbBufPtr(&s->pb); |
231 | 2310 //fprintf(stderr,"\nGOB: %2d size: %d (last)", s->gob_number, pdif); |
2311 } | |
0 | 2312 } |
2313 | |
220 | 2314 static int dct_quantize_c(MpegEncContext *s, |
0 | 2315 DCTELEM *block, int n, |
344 | 2316 int qscale, int *overflow) |
0 | 2317 { |
2318 int i, j, level, last_non_zero, q; | |
2319 const int *qmat; | |
344 | 2320 int bias; |
2321 int max=0; | |
2322 unsigned int threshold1, threshold2; | |
456 | 2323 |
0 | 2324 av_fdct (block); |
2325 | |
64 | 2326 /* we need this permutation so that we correct the IDCT |
2327 permutation. will be moved into DCT code */ | |
2328 block_permute(block); | |
2329 | |
0 | 2330 if (s->mb_intra) { |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
2331 if (!s->h263_aic) { |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
2332 if (n < 4) |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
2333 q = s->y_dc_scale; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
2334 else |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
2335 q = s->c_dc_scale; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
2336 q = q << 3; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
2337 } else |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
2338 /* For AIC we skip quant/dequant of INTRADC */ |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
2339 q = 1 << 3; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
2340 |
0 | 2341 /* note: block[0] is assumed to be positive */ |
2342 block[0] = (block[0] + (q >> 1)) / q; | |
2343 i = 1; | |
2344 last_non_zero = 0; | |
344 | 2345 qmat = s->q_intra_matrix[qscale]; |
2346 bias= s->intra_quant_bias<<(QMAT_SHIFT - 3 - QUANT_BIAS_SHIFT); | |
0 | 2347 } else { |
2348 i = 0; | |
2349 last_non_zero = -1; | |
344 | 2350 qmat = s->q_inter_matrix[qscale]; |
2351 bias= s->inter_quant_bias<<(QMAT_SHIFT - 3 - QUANT_BIAS_SHIFT); | |
0 | 2352 } |
344 | 2353 threshold1= (1<<(QMAT_SHIFT - 3)) - bias - 1; |
2354 threshold2= threshold1<<1; | |
0 | 2355 |
2356 for(;i<64;i++) { | |
2357 j = zigzag_direct[i]; | |
2358 level = block[j]; | |
2359 level = level * qmat[j]; | |
344 | 2360 |
2361 // if( bias+level >= (1<<(QMAT_SHIFT - 3)) | |
2362 // || bias-level >= (1<<(QMAT_SHIFT - 3))){ | |
2363 if(((unsigned)(level+threshold1))>threshold2){ | |
2364 if(level>0){ | |
2365 level= (bias + level)>>(QMAT_SHIFT - 3); | |
2366 block[j]= level; | |
2367 }else{ | |
2368 level= (bias - level)>>(QMAT_SHIFT - 3); | |
2369 block[j]= -level; | |
0 | 2370 } |
344 | 2371 max |=level; |
0 | 2372 last_non_zero = i; |
344 | 2373 }else{ |
2374 block[j]=0; | |
0 | 2375 } |
2376 } | |
344 | 2377 *overflow= s->max_qcoeff < max; //overflow might have happend |
2378 | |
0 | 2379 return last_non_zero; |
2380 } | |
2381 | |
13
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
2382 static void dct_unquantize_mpeg1_c(MpegEncContext *s, |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
2383 DCTELEM *block, int n, int qscale) |
0 | 2384 { |
200 | 2385 int i, level, nCoeffs; |
0 | 2386 const UINT16 *quant_matrix; |
2387 | |
200 | 2388 if(s->alternate_scan) nCoeffs= 64; |
2389 else nCoeffs= s->block_last_index[n]+1; | |
2390 | |
0 | 2391 if (s->mb_intra) { |
2392 if (n < 4) | |
2393 block[0] = block[0] * s->y_dc_scale; | |
2394 else | |
2395 block[0] = block[0] * s->c_dc_scale; | |
2396 /* XXX: only mpeg1 */ | |
2397 quant_matrix = s->intra_matrix; | |
200 | 2398 for(i=1;i<nCoeffs;i++) { |
2399 int j= zigzag_direct[i]; | |
2400 level = block[j]; | |
0 | 2401 if (level) { |
2402 if (level < 0) { | |
2403 level = -level; | |
200 | 2404 level = (int)(level * qscale * quant_matrix[j]) >> 3; |
0 | 2405 level = (level - 1) | 1; |
2406 level = -level; | |
2407 } else { | |
200 | 2408 level = (int)(level * qscale * quant_matrix[j]) >> 3; |
0 | 2409 level = (level - 1) | 1; |
2410 } | |
2411 #ifdef PARANOID | |
2412 if (level < -2048 || level > 2047) | |
2413 fprintf(stderr, "unquant error %d %d\n", i, level); | |
2414 #endif | |
200 | 2415 block[j] = level; |
0 | 2416 } |
2417 } | |
2418 } else { | |
2419 i = 0; | |
344 | 2420 quant_matrix = s->inter_matrix; |
217 | 2421 for(;i<nCoeffs;i++) { |
200 | 2422 int j= zigzag_direct[i]; |
2423 level = block[j]; | |
0 | 2424 if (level) { |
2425 if (level < 0) { | |
2426 level = -level; | |
2427 level = (((level << 1) + 1) * qscale * | |
200 | 2428 ((int) (quant_matrix[j]))) >> 4; |
0 | 2429 level = (level - 1) | 1; |
2430 level = -level; | |
2431 } else { | |
2432 level = (((level << 1) + 1) * qscale * | |
200 | 2433 ((int) (quant_matrix[j]))) >> 4; |
0 | 2434 level = (level - 1) | 1; |
2435 } | |
2436 #ifdef PARANOID | |
2437 if (level < -2048 || level > 2047) | |
2438 fprintf(stderr, "unquant error %d %d\n", i, level); | |
2439 #endif | |
200 | 2440 block[j] = level; |
0 | 2441 } |
2442 } | |
2443 } | |
2444 } | |
13
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
2445 |
325 | 2446 static void dct_unquantize_mpeg2_c(MpegEncContext *s, |
2447 DCTELEM *block, int n, int qscale) | |
2448 { | |
2449 int i, level, nCoeffs; | |
2450 const UINT16 *quant_matrix; | |
2451 | |
2452 if(s->alternate_scan) nCoeffs= 64; | |
2453 else nCoeffs= s->block_last_index[n]+1; | |
2454 | |
2455 if (s->mb_intra) { | |
2456 if (n < 4) | |
2457 block[0] = block[0] * s->y_dc_scale; | |
2458 else | |
2459 block[0] = block[0] * s->c_dc_scale; | |
2460 quant_matrix = s->intra_matrix; | |
2461 for(i=1;i<nCoeffs;i++) { | |
2462 int j= zigzag_direct[i]; | |
2463 level = block[j]; | |
2464 if (level) { | |
2465 if (level < 0) { | |
2466 level = -level; | |
2467 level = (int)(level * qscale * quant_matrix[j]) >> 3; | |
2468 level = -level; | |
2469 } else { | |
2470 level = (int)(level * qscale * quant_matrix[j]) >> 3; | |
2471 } | |
2472 #ifdef PARANOID | |
2473 if (level < -2048 || level > 2047) | |
2474 fprintf(stderr, "unquant error %d %d\n", i, level); | |
2475 #endif | |
2476 block[j] = level; | |
2477 } | |
2478 } | |
2479 } else { | |
2480 int sum=-1; | |
2481 i = 0; | |
344 | 2482 quant_matrix = s->inter_matrix; |
325 | 2483 for(;i<nCoeffs;i++) { |
2484 int j= zigzag_direct[i]; | |
2485 level = block[j]; | |
2486 if (level) { | |
2487 if (level < 0) { | |
2488 level = -level; | |
2489 level = (((level << 1) + 1) * qscale * | |
2490 ((int) (quant_matrix[j]))) >> 4; | |
2491 level = -level; | |
2492 } else { | |
2493 level = (((level << 1) + 1) * qscale * | |
2494 ((int) (quant_matrix[j]))) >> 4; | |
2495 } | |
2496 #ifdef PARANOID | |
2497 if (level < -2048 || level > 2047) | |
2498 fprintf(stderr, "unquant error %d %d\n", i, level); | |
2499 #endif | |
2500 block[j] = level; | |
2501 sum+=level; | |
2502 } | |
2503 } | |
2504 block[63]^=sum&1; | |
2505 } | |
2506 } | |
2507 | |
2508 | |
13
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
2509 static void dct_unquantize_h263_c(MpegEncContext *s, |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
2510 DCTELEM *block, int n, int qscale) |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
2511 { |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
2512 int i, level, qmul, qadd; |
200 | 2513 int nCoeffs; |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2514 |
13
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
2515 if (s->mb_intra) { |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2516 if (!s->h263_aic) { |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2517 if (n < 4) |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2518 block[0] = block[0] * s->y_dc_scale; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2519 else |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2520 block[0] = block[0] * s->c_dc_scale; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2521 } |
13
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
2522 i = 1; |
200 | 2523 nCoeffs= 64; //does not allways use zigzag table |
13
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
2524 } else { |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
2525 i = 0; |
200 | 2526 nCoeffs= zigzag_end[ s->block_last_index[n] ]; |
13
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
2527 } |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
2528 |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
2529 qmul = s->qscale << 1; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
2530 if (s->h263_aic && s->mb_intra) |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
2531 qadd = 0; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
2532 else |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
2533 qadd = (s->qscale - 1) | 1; |
13
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
2534 |
200 | 2535 for(;i<nCoeffs;i++) { |
13
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
2536 level = block[i]; |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
2537 if (level) { |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
2538 if (level < 0) { |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
2539 level = level * qmul - qadd; |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
2540 } else { |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
2541 level = level * qmul + qadd; |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
2542 } |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
2543 #ifdef PARANOID |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
2544 if (level < -2048 || level > 2047) |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
2545 fprintf(stderr, "unquant error %d %d\n", i, level); |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
2546 #endif |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
2547 block[i] = level; |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
2548 } |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
2549 } |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
2550 } |
0 | 2551 |
456 | 2552 static void remove_ac(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, int mb_x, int mb_y) |
2553 { | |
2554 int dc, dcb, dcr, y, i; | |
2555 for(i=0; i<4; i++){ | |
2556 dc= s->dc_val[0][mb_x*2+1 + (i&1) + (mb_y*2+1 + (i>>1))*(s->mb_width*2+2)]; | |
2557 for(y=0; y<8; y++){ | |
2558 int x; | |
2559 for(x=0; x<8; x++){ | |
2560 dest_y[x + (i&1)*8 + (y + (i>>1)*8)*s->linesize]= dc/8; | |
2561 } | |
2562 } | |
2563 } | |
2564 dcb = s->dc_val[1][mb_x+1 + (mb_y+1)*(s->mb_width+2)]; | |
2565 dcr= s->dc_val[2][mb_x+1 + (mb_y+1)*(s->mb_width+2)]; | |
2566 for(y=0; y<8; y++){ | |
2567 int x; | |
2568 for(x=0; x<8; x++){ | |
2569 dest_cb[x + y*(s->linesize>>1)]= dcb/8; | |
2570 dest_cr[x + y*(s->linesize>>1)]= dcr/8; | |
2571 } | |
2572 } | |
2573 } | |
2574 | |
2575 /** | |
2576 * will conceal past errors, and allso drop b frames if needed | |
2577 * | |
2578 */ | |
2579 void ff_conceal_past_errors(MpegEncContext *s, int unknown_pos) | |
2580 { | |
2581 int mb_x= s->mb_x; | |
2582 int mb_y= s->mb_y; | |
2583 int mb_dist=0; | |
2584 int i, intra_count=0, inter_count=0; | |
2585 int intra_conceal= s->msmpeg4_version ? 50 : 50; //FIXME finetune | |
2586 int inter_conceal= s->msmpeg4_version ? 50 : 50; | |
2587 | |
2588 // for last block | |
2589 if(mb_x>=s->mb_width) mb_x= s->mb_width -1; | |
2590 if(mb_y>=s->mb_height) mb_y= s->mb_height-1; | |
2591 | |
2592 if(s->decoding_error==0 && unknown_pos){ | |
2593 if(s->data_partitioning && s->pict_type!=B_TYPE) | |
2594 s->decoding_error= DECODING_AC_LOST; | |
2595 else | |
2596 s->decoding_error= DECODING_DESYNC; | |
2597 } | |
2598 | |
2599 if(s->decoding_error==DECODING_DESYNC && s->pict_type!=B_TYPE) s->next_p_frame_damaged=1; | |
2600 | |
2601 for(i=mb_x + mb_y*s->mb_width; i>=0; i--){ | |
2602 if(s->mbintra_table[i]) intra_count++; | |
2603 else inter_count++; | |
2604 } | |
2605 | |
2606 if(s->decoding_error==DECODING_AC_LOST){ | |
2607 intra_conceal*=2; | |
2608 inter_conceal*=2; | |
2609 }else if(s->decoding_error==DECODING_ACDC_LOST){ | |
2610 intra_conceal*=2; | |
2611 inter_conceal*=2; | |
2612 } | |
2613 | |
2614 if(unknown_pos && (intra_count<inter_count)){ | |
2615 intra_conceal= inter_conceal= s->mb_num; | |
2616 // printf("%d %d\n",intra_count, inter_count); | |
2617 } | |
2618 | |
2619 fprintf(stderr, "concealing errors\n"); | |
2620 | |
2621 /* for all MBs from the current one back until the last resync marker */ | |
2622 for(; mb_y>=0 && mb_y>=s->resync_mb_y; mb_y--){ | |
2623 for(; mb_x>=0; mb_x--){ | |
2624 uint8_t *dest_y = s->current_picture[0] + (mb_y * 16* s->linesize ) + mb_x * 16; | |
2625 uint8_t *dest_cb = s->current_picture[1] + (mb_y * 8 * (s->linesize >> 1)) + mb_x * 8; | |
2626 uint8_t *dest_cr = s->current_picture[2] + (mb_y * 8 * (s->linesize >> 1)) + mb_x * 8; | |
2627 int mb_x_backup= s->mb_x; //FIXME pass xy to mpeg_motion | |
2628 int mb_y_backup= s->mb_y; | |
2629 s->mb_x=mb_x; | |
2630 s->mb_y=mb_y; | |
2631 if(s->mbintra_table[mb_y*s->mb_width + mb_x] && mb_dist<intra_conceal){ | |
2632 if(s->decoding_error==DECODING_AC_LOST){ | |
2633 remove_ac(s, dest_y, dest_cb, dest_cr, mb_x, mb_y); | |
2634 // printf("remove ac to %d %d\n", mb_x, mb_y); | |
2635 }else{ | |
2636 mpeg_motion(s, dest_y, dest_cb, dest_cr, 0, | |
2637 s->last_picture, 0, 0, put_pixels_tab, | |
2638 0/*mx*/, 0/*my*/, 16); | |
2639 } | |
2640 } | |
2641 else if(!s->mbintra_table[mb_y*s->mb_width + mb_x] && mb_dist<inter_conceal){ | |
2642 int mx=0; | |
2643 int my=0; | |
2644 | |
2645 if(s->decoding_error!=DECODING_DESYNC){ | |
2646 int xy= mb_x*2+1 + (mb_y*2+1)*(s->mb_width*2+2); | |
2647 mx= s->motion_val[ xy ][0]; | |
2648 my= s->motion_val[ xy ][1]; | |
2649 } | |
2650 | |
2651 mpeg_motion(s, dest_y, dest_cb, dest_cr, 0, | |
2652 s->last_picture, 0, 0, put_pixels_tab, | |
2653 mx, my, 16); | |
2654 } | |
2655 s->mb_x= mb_x_backup; | |
2656 s->mb_y= mb_y_backup; | |
2657 | |
2658 if(mb_x== s->resync_mb_x && mb_y== s->resync_mb_y) return; | |
2659 if(!s->mbskip_table[mb_x + mb_y*s->mb_width]) mb_dist++; | |
2660 } | |
2661 mb_x=s->mb_width-1; | |
2662 } | |
2663 } | |
2664 | |
0 | 2665 AVCodec mpeg1video_encoder = { |
2666 "mpeg1video", | |
2667 CODEC_TYPE_VIDEO, | |
2668 CODEC_ID_MPEG1VIDEO, | |
2669 sizeof(MpegEncContext), | |
2670 MPV_encode_init, | |
2671 MPV_encode_picture, | |
2672 MPV_encode_end, | |
2673 }; | |
2674 | |
2675 AVCodec h263_encoder = { | |
2676 "h263", | |
2677 CODEC_TYPE_VIDEO, | |
2678 CODEC_ID_H263, | |
2679 sizeof(MpegEncContext), | |
2680 MPV_encode_init, | |
2681 MPV_encode_picture, | |
2682 MPV_encode_end, | |
2683 }; | |
2684 | |
2685 AVCodec h263p_encoder = { | |
2686 "h263p", | |
2687 CODEC_TYPE_VIDEO, | |
2688 CODEC_ID_H263P, | |
2689 sizeof(MpegEncContext), | |
2690 MPV_encode_init, | |
2691 MPV_encode_picture, | |
2692 MPV_encode_end, | |
2693 }; | |
2694 | |
2695 AVCodec rv10_encoder = { | |
2696 "rv10", | |
2697 CODEC_TYPE_VIDEO, | |
2698 CODEC_ID_RV10, | |
2699 sizeof(MpegEncContext), | |
2700 MPV_encode_init, | |
2701 MPV_encode_picture, | |
2702 MPV_encode_end, | |
2703 }; | |
2704 | |
2705 AVCodec mjpeg_encoder = { | |
2706 "mjpeg", | |
2707 CODEC_TYPE_VIDEO, | |
2708 CODEC_ID_MJPEG, | |
2709 sizeof(MpegEncContext), | |
2710 MPV_encode_init, | |
2711 MPV_encode_picture, | |
2712 MPV_encode_end, | |
2713 }; | |
2714 | |
71 | 2715 AVCodec mpeg4_encoder = { |
2716 "mpeg4", | |
0 | 2717 CODEC_TYPE_VIDEO, |
71 | 2718 CODEC_ID_MPEG4, |
0 | 2719 sizeof(MpegEncContext), |
2720 MPV_encode_init, | |
2721 MPV_encode_picture, | |
2722 MPV_encode_end, | |
2723 }; | |
2724 | |
307 | 2725 AVCodec msmpeg4v1_encoder = { |
2726 "msmpeg4v1", | |
0 | 2727 CODEC_TYPE_VIDEO, |
307 | 2728 CODEC_ID_MSMPEG4V1, |
0 | 2729 sizeof(MpegEncContext), |
2730 MPV_encode_init, | |
2731 MPV_encode_picture, | |
2732 MPV_encode_end, | |
2733 }; | |
307 | 2734 |
2735 AVCodec msmpeg4v2_encoder = { | |
2736 "msmpeg4v2", | |
2737 CODEC_TYPE_VIDEO, | |
2738 CODEC_ID_MSMPEG4V2, | |
2739 sizeof(MpegEncContext), | |
2740 MPV_encode_init, | |
2741 MPV_encode_picture, | |
2742 MPV_encode_end, | |
2743 }; | |
2744 | |
2745 AVCodec msmpeg4v3_encoder = { | |
2746 "msmpeg4", | |
2747 CODEC_TYPE_VIDEO, | |
2748 CODEC_ID_MSMPEG4V3, | |
2749 sizeof(MpegEncContext), | |
2750 MPV_encode_init, | |
2751 MPV_encode_picture, | |
2752 MPV_encode_end, | |
2753 }; | |
499 | 2754 |
2755 AVCodec wmv1_encoder = { | |
2756 "wmv1", | |
2757 CODEC_TYPE_VIDEO, | |
2758 CODEC_ID_WMV1, | |
2759 sizeof(MpegEncContext), | |
2760 MPV_encode_init, | |
2761 MPV_encode_picture, | |
2762 MPV_encode_end, | |
2763 }; | |
2764 | |
2765 AVCodec wmv2_encoder = { | |
2766 "wmv2", | |
2767 CODEC_TYPE_VIDEO, | |
2768 CODEC_ID_WMV2, | |
2769 sizeof(MpegEncContext), | |
2770 MPV_encode_init, | |
2771 MPV_encode_picture, | |
2772 MPV_encode_end, | |
2773 }; |