2 * ITU H263 bitstream encoder
3 * Copyright (c) 2000,2001 Fabrice Bellard
5 * Copyright (c) 2001 Juan J. Sierralta P
6 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
8 * This file is part of FFmpeg.
10 * FFmpeg is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * FFmpeg is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with FFmpeg; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 * h263 bitstream encoder.
35 #include "mpegvideo.h"
40 #include "mpeg4video.h"
44 * Table of number of bits a motion vector component needs.
46 static uint8_t mv_penalty[MAX_FCODE+1][MAX_MV*2+1];
49 * Minimal fcode that a motion vector component would need.
51 static uint8_t fcode_tab[MAX_MV*2+1];
54 * Minimal fcode that a motion vector component would need in umv.
55 * All entries in this table are 1.
57 static uint8_t umv_fcode_tab[MAX_MV*2+1];
59 //unified encoding tables for run length encoding of coefficients
60 //unified in the sense that the specification specifies the encoding in several steps.
61 static uint8_t uni_h263_intra_aic_rl_len [64*64*2*2];
62 static uint8_t uni_h263_inter_rl_len [64*64*2*2];
63 //#define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128 + (run)*256 + (level))
64 //#define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128*64 + (run) + (level)*64)
65 #define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128*64 + (run)*128 + (level))
67 static const uint8_t wrong_run[102] = {
68 1, 2, 3, 5, 4, 10, 9, 8,
69 11, 15, 17, 16, 23, 22, 21, 20,
70 19, 18, 25, 24, 27, 26, 11, 7,
71 6, 1, 2, 13, 2, 2, 2, 2,
72 6, 12, 3, 9, 1, 3, 4, 3,
73 7, 4, 1, 1, 5, 5, 14, 6,
74 1, 7, 1, 8, 1, 1, 1, 1,
75 10, 1, 1, 5, 9, 17, 25, 24,
76 29, 33, 32, 41, 2, 23, 28, 31,
77 3, 22, 30, 4, 27, 40, 8, 26,
78 6, 39, 7, 38, 16, 37, 15, 10,
79 11, 12, 13, 14, 1, 21, 20, 18,
84 * Return the 4 bit value that specifies the given aspect ratio.
85 * This may be one of the standard aspect ratios or it specifies
86 * that the aspect will be stored explicitly later.
88 av_const int ff_h263_aspect_to_info(AVRational aspect){
91 if(aspect.num==0) aspect= (AVRational){1,1};
94 if(av_cmp_q(ff_h263_pixel_aspect[i], aspect) == 0){
99 return FF_ASPECT_EXTENDED;
102 void ff_h263_encode_picture_header(MpegEncContext * s, int picture_number)
104 int format, coded_frame_rate, coded_frame_rate_base, i, temp_ref;
105 int best_clock_code=1;
107 int best_error= INT_MAX;
112 div= (s->avctx->time_base.num*1800000LL + 500LL*s->avctx->time_base.den) / ((1000LL+i)*s->avctx->time_base.den);
113 div= av_clip(div, 1, 127);
114 error= FFABS(s->avctx->time_base.num*1800000LL - (1000LL+i)*s->avctx->time_base.den*div);
115 if(error < best_error){
122 s->custom_pcf= best_clock_code!=1 || best_divisor!=60;
123 coded_frame_rate= 1800000;
124 coded_frame_rate_base= (1000+best_clock_code)*best_divisor;
126 avpriv_align_put_bits(&s->pb);
128 /* Update the pointer to last GOB */
129 s->ptr_lastgob = put_bits_ptr(&s->pb);
130 put_bits(&s->pb, 22, 0x20); /* PSC */
131 temp_ref= s->picture_number * (int64_t)coded_frame_rate * s->avctx->time_base.num / //FIXME use timestamp
132 (coded_frame_rate_base * (int64_t)s->avctx->time_base.den);
133 put_sbits(&s->pb, 8, temp_ref); /* TemporalReference */
135 put_bits(&s->pb, 1, 1); /* marker */
136 put_bits(&s->pb, 1, 0); /* h263 id */
137 put_bits(&s->pb, 1, 0); /* split screen off */
138 put_bits(&s->pb, 1, 0); /* camera off */
139 put_bits(&s->pb, 1, 0); /* freeze picture release off */
141 format = ff_match_2uint16(ff_h263_format, FF_ARRAY_ELEMS(ff_h263_format), s->width, s->height);
144 put_bits(&s->pb, 3, format);
145 put_bits(&s->pb, 1, (s->pict_type == AV_PICTURE_TYPE_P));
146 /* By now UMV IS DISABLED ON H.263v1, since the restrictions
147 of H.263v1 UMV implies to check the predicted MV after
148 calculation of the current MB to see if we're on the limits */
149 put_bits(&s->pb, 1, 0); /* Unrestricted Motion Vector: off */
150 put_bits(&s->pb, 1, 0); /* SAC: off */
151 put_bits(&s->pb, 1, s->obmc); /* Advanced Prediction */
152 put_bits(&s->pb, 1, 0); /* only I/P frames, no PB frame */
153 put_bits(&s->pb, 5, s->qscale);
154 put_bits(&s->pb, 1, 0); /* Continuous Presence Multipoint mode: off */
158 /* H.263 Plus PTYPE */
160 put_bits(&s->pb, 3, 7);
161 put_bits(&s->pb,3,ufep); /* Update Full Extended PTYPE */
163 put_bits(&s->pb,3,6); /* Custom Source Format */
165 put_bits(&s->pb, 3, format);
167 put_bits(&s->pb,1, s->custom_pcf);
168 put_bits(&s->pb,1, s->umvplus); /* Unrestricted Motion Vector */
169 put_bits(&s->pb,1,0); /* SAC: off */
170 put_bits(&s->pb,1,s->obmc); /* Advanced Prediction Mode */
171 put_bits(&s->pb,1,s->h263_aic); /* Advanced Intra Coding */
172 put_bits(&s->pb,1,s->loop_filter); /* Deblocking Filter */
173 put_bits(&s->pb,1,s->h263_slice_structured); /* Slice Structured */
174 put_bits(&s->pb,1,0); /* Reference Picture Selection: off */
175 put_bits(&s->pb,1,0); /* Independent Segment Decoding: off */
176 put_bits(&s->pb,1,s->alt_inter_vlc); /* Alternative Inter VLC */
177 put_bits(&s->pb,1,s->modified_quant); /* Modified Quantization: */
178 put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */
179 put_bits(&s->pb,3,0); /* Reserved */
181 put_bits(&s->pb, 3, s->pict_type == AV_PICTURE_TYPE_P);
183 put_bits(&s->pb,1,0); /* Reference Picture Resampling: off */
184 put_bits(&s->pb,1,0); /* Reduced-Resolution Update: off */
185 put_bits(&s->pb,1,s->no_rounding); /* Rounding Type */
186 put_bits(&s->pb,2,0); /* Reserved */
187 put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */
189 /* This should be here if PLUSPTYPE */
190 put_bits(&s->pb, 1, 0); /* Continuous Presence Multipoint mode: off */
193 /* Custom Picture Format (CPFMT) */
194 s->aspect_ratio_info= ff_h263_aspect_to_info(s->avctx->sample_aspect_ratio);
196 put_bits(&s->pb,4,s->aspect_ratio_info);
197 put_bits(&s->pb,9,(s->width >> 2) - 1);
198 put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */
199 put_bits(&s->pb,9,(s->height >> 2));
200 if (s->aspect_ratio_info == FF_ASPECT_EXTENDED){
201 put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.num);
202 put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.den);
207 put_bits(&s->pb, 1, best_clock_code);
208 put_bits(&s->pb, 7, best_divisor);
210 put_sbits(&s->pb, 2, temp_ref>>8);
213 /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */
215 // put_bits(&s->pb,1,1); /* Limited according tables of Annex D */
216 //FIXME check actual requested range
217 put_bits(&s->pb,2,1); /* unlimited */
218 if(s->h263_slice_structured)
219 put_bits(&s->pb,2,0); /* no weird submodes */
221 put_bits(&s->pb, 5, s->qscale);
224 put_bits(&s->pb, 1, 0); /* no PEI */
226 if(s->h263_slice_structured){
227 put_bits(&s->pb, 1, 1);
229 av_assert1(s->mb_x == 0 && s->mb_y == 0);
230 ff_h263_encode_mba(s);
232 put_bits(&s->pb, 1, 1);
237 s->c_dc_scale_table= ff_aic_dc_scale_table;
240 s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
245 * Encode a group of blocks header.
247 void ff_h263_encode_gob_header(MpegEncContext * s, int mb_line)
249 put_bits(&s->pb, 17, 1); /* GBSC */
251 if(s->h263_slice_structured){
252 put_bits(&s->pb, 1, 1);
254 ff_h263_encode_mba(s);
257 put_bits(&s->pb, 1, 1);
258 put_bits(&s->pb, 5, s->qscale); /* GQUANT */
259 put_bits(&s->pb, 1, 1);
260 put_bits(&s->pb, 2, s->pict_type == AV_PICTURE_TYPE_I); /* GFID */
262 int gob_number= mb_line / s->gob_index;
264 put_bits(&s->pb, 5, gob_number); /* GN */
265 put_bits(&s->pb, 2, s->pict_type == AV_PICTURE_TYPE_I); /* GFID */
266 put_bits(&s->pb, 5, s->qscale); /* GQUANT */
271 * modify qscale so that encoding is actually possible in h263 (limit difference to -2..2)
273 void ff_clean_h263_qscales(MpegEncContext *s){
275 int8_t * const qscale_table = s->current_picture.f.qscale_table;
277 ff_init_qscale_tab(s);
279 for(i=1; i<s->mb_num; i++){
280 if(qscale_table[ s->mb_index2xy[i] ] - qscale_table[ s->mb_index2xy[i-1] ] >2)
281 qscale_table[ s->mb_index2xy[i] ]= qscale_table[ s->mb_index2xy[i-1] ]+2;
283 for(i=s->mb_num-2; i>=0; i--){
284 if(qscale_table[ s->mb_index2xy[i] ] - qscale_table[ s->mb_index2xy[i+1] ] >2)
285 qscale_table[ s->mb_index2xy[i] ]= qscale_table[ s->mb_index2xy[i+1] ]+2;
288 if(s->codec_id != AV_CODEC_ID_H263P){
289 for(i=1; i<s->mb_num; i++){
290 int mb_xy= s->mb_index2xy[i];
292 if(qscale_table[mb_xy] != qscale_table[s->mb_index2xy[i-1]] && (s->mb_type[mb_xy]&CANDIDATE_MB_TYPE_INTER4V)){
293 s->mb_type[mb_xy]|= CANDIDATE_MB_TYPE_INTER;
299 static const int dquant_code[5]= {1,0,9,2,3};
302 * Encode an 8x8 block.
303 * @param block the 8x8 block
304 * @param n block index (0-3 are luma, 4-5 are chroma)
306 static void h263_encode_block(MpegEncContext * s, DCTELEM * block, int n)
308 int level, run, last, i, j, last_index, last_non_zero, sign, slevel, code;
311 rl = &ff_h263_rl_inter;
312 if (s->mb_intra && !s->h263_aic) {
315 /* 255 cannot be represented, so we clamp */
320 /* 0 cannot be represented also */
321 else if (level < 1) {
325 if (level == 128) //FIXME check rv10
326 put_bits(&s->pb, 8, 0xff);
328 put_bits(&s->pb, 8, level);
332 if (s->h263_aic && s->mb_intra)
333 rl = &ff_rl_intra_aic;
335 if(s->alt_inter_vlc && !s->mb_intra){
337 int inter_vlc_bits=0;
341 last_index = s->block_last_index[n];
342 last_non_zero = i - 1;
343 for (; i <= last_index; i++) {
344 j = s->intra_scantable.permutated[i];
347 run = i - last_non_zero - 1;
348 last = (i == last_index);
350 if(level<0) level= -level;
352 code = get_rl_index(rl, last, run, level);
353 aic_code = get_rl_index(&ff_rl_intra_aic, last, run, level);
354 inter_vlc_bits += rl->table_vlc[code][1]+1;
355 aic_vlc_bits += ff_rl_intra_aic.table_vlc[aic_code][1]+1;
358 inter_vlc_bits += 1+6+8-1;
360 if (aic_code == ff_rl_intra_aic.n) {
361 aic_vlc_bits += 1+6+8-1;
362 wrong_pos += run + 1;
364 wrong_pos += wrong_run[aic_code];
369 if(aic_vlc_bits < inter_vlc_bits && wrong_pos > 63)
370 rl = &ff_rl_intra_aic;
375 last_index = s->block_last_index[n];
376 last_non_zero = i - 1;
377 for (; i <= last_index; i++) {
378 j = s->intra_scantable.permutated[i];
381 run = i - last_non_zero - 1;
382 last = (i == last_index);
389 code = get_rl_index(rl, last, run, level);
390 put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
392 if(!CONFIG_FLV_ENCODER || s->h263_flv <= 1){
393 put_bits(&s->pb, 1, last);
394 put_bits(&s->pb, 6, run);
396 av_assert2(slevel != 0);
399 put_sbits(&s->pb, 8, slevel);
401 put_bits(&s->pb, 8, 128);
402 put_sbits(&s->pb, 5, slevel);
403 put_sbits(&s->pb, 6, slevel>>5);
406 ff_flv2_encode_ac_esc(&s->pb, slevel, level, run, last);
409 put_bits(&s->pb, 1, sign);
416 /* Encode MV differences on H.263+ with Unrestricted MV mode */
417 static void h263p_encode_umotion(MpegEncContext * s, int val)
427 put_bits(&s->pb, 1, 1);
429 put_bits(&s->pb, 3, 0);
431 put_bits(&s->pb, 3, 2);
434 sval = ((val < 0) ? (short)(-val):(short)val);
437 while (temp_val != 0) {
438 temp_val = temp_val >> 1;
444 tcode = (sval & (1 << (i-1))) >> (i-1);
445 tcode = (tcode << 1) | 1;
446 code = (code << 2) | tcode;
449 code = ((code << 1) | (val < 0)) << 1;
450 put_bits(&s->pb, (2*n_bits)+1, code);
454 void ff_h263_encode_mb(MpegEncContext * s,
455 DCTELEM block[6][64],
456 int motion_x, int motion_y)
458 int cbpc, cbpy, i, cbp, pred_x, pred_y;
460 int16_t rec_intradc[6];
462 const int interleaved_stats= (s->flags&CODEC_FLAG_PASS1);
466 cbp= get_p_cbp(s, block, motion_x, motion_y);
468 if ((cbp | motion_x | motion_y | s->dquant | (s->mv_type - MV_TYPE_16X16)) == 0) {
469 /* skip macroblock */
470 put_bits(&s->pb, 1, 1);
471 if(interleaved_stats){
479 put_bits(&s->pb, 1, 0); /* mb coded */
483 if(s->alt_inter_vlc==0 || cbpc!=3)
485 if(s->dquant) cbpc+= 8;
486 if(s->mv_type==MV_TYPE_16X16){
488 ff_h263_inter_MCBPC_bits[cbpc],
489 ff_h263_inter_MCBPC_code[cbpc]);
491 put_bits(&s->pb, ff_h263_cbpy_tab[cbpy][1], ff_h263_cbpy_tab[cbpy][0]);
493 put_bits(&s->pb, 2, dquant_code[s->dquant+2]);
495 if(interleaved_stats){
496 s->misc_bits+= get_bits_diff(s);
499 /* motion vectors: 16x16 mode */
500 ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
503 ff_h263_encode_motion_vector(s, motion_x - pred_x,
504 motion_y - pred_y, 1);
507 h263p_encode_umotion(s, motion_x - pred_x);
508 h263p_encode_umotion(s, motion_y - pred_y);
509 if (((motion_x - pred_x) == 1) && ((motion_y - pred_y) == 1))
510 /* To prevent Start Code emulation */
511 put_bits(&s->pb,1,1);
515 ff_h263_inter_MCBPC_bits[cbpc+16],
516 ff_h263_inter_MCBPC_code[cbpc+16]);
517 put_bits(&s->pb, ff_h263_cbpy_tab[cbpy][1], ff_h263_cbpy_tab[cbpy][0]);
519 put_bits(&s->pb, 2, dquant_code[s->dquant+2]);
521 if(interleaved_stats){
522 s->misc_bits+= get_bits_diff(s);
526 /* motion vectors: 8x8 mode*/
527 ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y);
529 motion_x = s->current_picture.f.motion_val[0][s->block_index[i]][0];
530 motion_y = s->current_picture.f.motion_val[0][s->block_index[i]][1];
532 ff_h263_encode_motion_vector(s, motion_x - pred_x,
533 motion_y - pred_y, 1);
536 h263p_encode_umotion(s, motion_x - pred_x);
537 h263p_encode_umotion(s, motion_y - pred_y);
538 if (((motion_x - pred_x) == 1) && ((motion_y - pred_y) == 1))
539 /* To prevent Start Code emulation */
540 put_bits(&s->pb,1,1);
545 if(interleaved_stats){
546 s->mv_bits+= get_bits_diff(s);
549 av_assert2(s->mb_intra);
555 int16_t level = block[i][0];
558 if(i<4) scale= s->y_dc_scale;
559 else scale= s->c_dc_scale;
561 pred_dc = ff_h263_pred_dc(s, i, &dc_ptr[i]);
565 level = (level + (scale>>1))/scale;
567 level = (level - (scale>>1))/scale;
569 /* AIC can change CBP */
570 if (level == 0 && s->block_last_index[i] == 0)
571 s->block_last_index[i] = -1;
573 if(!s->modified_quant){
576 else if (level > 127)
582 rec_intradc[i] = scale*level + pred_dc;
585 //if ((rec_intradc[i] % 2) == 0)
588 if (rec_intradc[i] < 0)
590 else if (rec_intradc[i] > 2047)
591 rec_intradc[i] = 2047;
593 /* Update AC/DC tables */
594 *dc_ptr[i] = rec_intradc[i];
595 if (s->block_last_index[i] >= 0)
601 if (s->block_last_index[i] >= 1)
607 if (s->pict_type == AV_PICTURE_TYPE_I) {
608 if(s->dquant) cbpc+=4;
610 ff_h263_intra_MCBPC_bits[cbpc],
611 ff_h263_intra_MCBPC_code[cbpc]);
613 if(s->dquant) cbpc+=8;
614 put_bits(&s->pb, 1, 0); /* mb coded */
616 ff_h263_inter_MCBPC_bits[cbpc + 4],
617 ff_h263_inter_MCBPC_code[cbpc + 4]);
620 /* XXX: currently, we do not try to use ac prediction */
621 put_bits(&s->pb, 1, 0); /* no AC prediction */
624 put_bits(&s->pb, ff_h263_cbpy_tab[cbpy][1], ff_h263_cbpy_tab[cbpy][0]);
626 put_bits(&s->pb, 2, dquant_code[s->dquant+2]);
628 if(interleaved_stats){
629 s->misc_bits+= get_bits_diff(s);
634 /* encode each block */
635 h263_encode_block(s, block[i], i);
637 /* Update INTRADC for decoding */
638 if (s->h263_aic && s->mb_intra) {
639 block[i][0] = rec_intradc[i];
644 if(interleaved_stats){
646 s->p_tex_bits+= get_bits_diff(s);
649 s->i_tex_bits+= get_bits_diff(s);
655 void ff_h263_encode_motion(MpegEncContext * s, int val, int f_code)
657 int range, bit_size, sign, code, bits;
662 put_bits(&s->pb, ff_mvtab[code][1], ff_mvtab[code][0]);
664 bit_size = f_code - 1;
665 range = 1 << bit_size;
666 /* modulo encoding */
667 val = sign_extend(val, 6 + bit_size);
669 val= (val^sign)-sign;
673 code = (val >> bit_size) + 1;
674 bits = val & (range - 1);
676 put_bits(&s->pb, ff_mvtab[code][1] + 1, (ff_mvtab[code][0] << 1) | sign);
678 put_bits(&s->pb, bit_size, bits);
683 static void init_mv_penalty_and_fcode(MpegEncContext *s)
688 for(f_code=1; f_code<=MAX_FCODE; f_code++){
689 for(mv=-MAX_MV; mv<=MAX_MV; mv++){
692 if(mv==0) len= ff_mvtab[0][1];
694 int val, bit_size, code;
696 bit_size = f_code - 1;
702 code = (val >> bit_size) + 1;
704 len= ff_mvtab[code][1] + 1 + bit_size;
706 len= ff_mvtab[32][1] + av_log2(code>>5) + 2 + bit_size;
710 mv_penalty[f_code][mv+MAX_MV]= len;
714 for(f_code=MAX_FCODE; f_code>0; f_code--){
715 for(mv=-(16<<f_code); mv<(16<<f_code); mv++){
716 fcode_tab[mv+MAX_MV]= f_code;
720 for(mv=0; mv<MAX_MV*2+1; mv++){
721 umv_fcode_tab[mv]= 1;
725 static void init_uni_h263_rl_tab(RLTable *rl, uint32_t *bits_tab, uint8_t *len_tab){
726 int slevel, run, last;
728 av_assert0(MAX_LEVEL >= 64);
729 av_assert0(MAX_RUN >= 63);
731 for(slevel=-64; slevel<64; slevel++){
732 if(slevel==0) continue;
733 for(run=0; run<64; run++){
734 for(last=0; last<=1; last++){
735 const int index= UNI_MPEG4_ENC_INDEX(last, run, slevel+64);
736 int level= slevel < 0 ? -slevel : slevel;
737 int sign= slevel < 0 ? 1 : 0;
743 code= get_rl_index(rl, last, run, level);
744 bits= rl->table_vlc[code][0];
745 len= rl->table_vlc[code][1];
746 bits=bits*2+sign; len++;
748 if(code!=rl->n && len < len_tab[index]){
749 if(bits_tab) bits_tab[index]= bits;
750 len_tab [index]= len;
753 bits= rl->table_vlc[rl->n][0];
754 len = rl->table_vlc[rl->n][1];
755 bits=bits*2+last; len++;
756 bits=bits*64+run; len+=6;
757 bits=bits*256+(level&0xff); len+=8;
759 if(len < len_tab[index]){
760 if(bits_tab) bits_tab[index]= bits;
761 len_tab [index]= len;
768 void ff_h263_encode_init(MpegEncContext *s)
775 ff_init_rl(&ff_h263_rl_inter, ff_h263_static_rl_table_store[0]);
776 ff_init_rl(&ff_rl_intra_aic, ff_h263_static_rl_table_store[1]);
778 init_uni_h263_rl_tab(&ff_rl_intra_aic, NULL, uni_h263_intra_aic_rl_len);
779 init_uni_h263_rl_tab(&ff_h263_rl_inter , NULL, uni_h263_inter_rl_len);
781 init_mv_penalty_and_fcode(s);
783 s->me.mv_penalty= mv_penalty; //FIXME exact table for msmpeg4 & h263p
785 s->intra_ac_vlc_length =s->inter_ac_vlc_length = uni_h263_inter_rl_len;
786 s->intra_ac_vlc_last_length=s->inter_ac_vlc_last_length= uni_h263_inter_rl_len + 128*64;
788 s->intra_ac_vlc_length = uni_h263_intra_aic_rl_len;
789 s->intra_ac_vlc_last_length= uni_h263_intra_aic_rl_len + 128*64;
791 s->ac_esc_length= 7+1+6+8;
793 // use fcodes >1 only for mpeg4 & h263 & h263p FIXME
795 case AV_CODEC_ID_MPEG4:
796 s->fcode_tab= fcode_tab;
798 case AV_CODEC_ID_H263P:
800 s->fcode_tab= umv_fcode_tab;
801 if(s->modified_quant){
802 s->min_qcoeff= -2047;
809 //Note for mpeg4 & h263 the dc-scale table will be set per frame as needed later
810 case AV_CODEC_ID_FLV1:
811 if (s->h263_flv > 1) {
812 s->min_qcoeff= -1023;
819 s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
821 default: //nothing needed - default table already set in mpegvideo.c
825 s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
829 void ff_h263_encode_mba(MpegEncContext *s)
834 if(s->mb_num-1 <= ff_mba_max[i]) break;
836 mb_pos= s->mb_x + s->mb_width*s->mb_y;
837 put_bits(&s->pb, ff_mba_length[i], mb_pos);