FFmpeg
ituh263enc.c
Go to the documentation of this file.
1 /*
2  * ITU H.263 bitstream encoder
3  * Copyright (c) 2000,2001 Fabrice Bellard
4  * H.263+ support.
5  * Copyright (c) 2001 Juan J. Sierralta P
6  * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
7  *
8  * This file is part of FFmpeg.
9  *
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.
14  *
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.
19  *
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
23  */
24 
25 /**
26  * @file
27  * H.263 bitstream encoder.
28  */
29 
30 #include "config_components.h"
31 
32 #include <limits.h>
33 
34 #include "libavutil/attributes.h"
35 #include "libavutil/thread.h"
36 #include "avcodec.h"
37 #include "codec_internal.h"
38 #include "mpegvideo.h"
39 #include "mpegvideodata.h"
40 #include "flvenc.h"
41 #include "mpegvideoenc.h"
42 #include "h263.h"
43 #include "h263enc.h"
44 #include "h263data.h"
45 #include "h263dsp.h"
46 #include "mathops.h"
47 #include "mpegutils.h"
48 #include "internal.h"
49 
50 /**
51  * Table of number of bits a motion vector component needs.
52  */
53 static uint8_t mv_penalty[MAX_FCODE+1][MAX_DMV*2+1];
54 
55 /**
56  * Minimal fcode that a motion vector component would need.
57  */
58 static uint8_t fcode_tab[MAX_MV*2+1];
59 
60 /**
61  * Minimal fcode that a motion vector component would need in umv.
62  * All entries in this table are 1.
63  */
64 static uint8_t umv_fcode_tab[MAX_MV*2+1];
65 
66 //unified encoding tables for run length encoding of coefficients
67 //unified in the sense that the specification specifies the encoding in several steps.
68 static uint8_t uni_h263_intra_aic_rl_len [64*64*2*2];
69 static uint8_t uni_h263_inter_rl_len [64*64*2*2];
70 //#define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128 + (run)*256 + (level))
71 //#define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128*64 + (run) + (level)*64)
72 #define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128*64 + (run)*128 + (level))
73 
74 static const uint8_t wrong_run[102] = {
75  1, 2, 3, 5, 4, 10, 9, 8,
76 11, 15, 17, 16, 23, 22, 21, 20,
77 19, 18, 25, 24, 27, 26, 11, 7,
78  6, 1, 2, 13, 2, 2, 2, 2,
79  6, 12, 3, 9, 1, 3, 4, 3,
80  7, 4, 1, 1, 5, 5, 14, 6,
81  1, 7, 1, 8, 1, 1, 1, 1,
82 10, 1, 1, 5, 9, 17, 25, 24,
83 29, 33, 32, 41, 2, 23, 28, 31,
84  3, 22, 30, 4, 27, 40, 8, 26,
85  6, 39, 7, 38, 16, 37, 15, 10,
86 11, 12, 13, 14, 1, 21, 20, 18,
87 19, 2, 1, 34, 35, 36
88 };
89 
90 /**
91  * Return the 4 bit value that specifies the given aspect ratio.
92  * This may be one of the standard aspect ratios or it specifies
93  * that the aspect will be stored explicitly later.
94  */
96  int i;
97 
98  if(aspect.num==0 || aspect.den==0) aspect= (AVRational){1,1};
99 
100  for(i=1; i<6; i++){
101  if(av_cmp_q(ff_h263_pixel_aspect[i], aspect) == 0){
102  return i;
103  }
104  }
105 
106  return FF_ASPECT_EXTENDED;
107 }
108 
110 {
111  int format, coded_frame_rate, coded_frame_rate_base, i, temp_ref;
112  int best_clock_code=1;
113  int best_divisor=60;
114  int best_error= INT_MAX;
115  int custom_pcf;
116 
117  if(s->h263_plus){
118  for(i=0; i<2; i++){
119  int div, error;
120  div= (s->avctx->time_base.num*1800000LL + 500LL*s->avctx->time_base.den) / ((1000LL+i)*s->avctx->time_base.den);
121  div= av_clip(div, 1, 127);
122  error= FFABS(s->avctx->time_base.num*1800000LL - (1000LL+i)*s->avctx->time_base.den*div);
123  if(error < best_error){
124  best_error= error;
125  best_divisor= div;
126  best_clock_code= i;
127  }
128  }
129  }
130  custom_pcf = best_clock_code != 1 || best_divisor != 60;
131  coded_frame_rate= 1800000;
132  coded_frame_rate_base= (1000+best_clock_code)*best_divisor;
133 
134  align_put_bits(&s->pb);
135 
136  /* Update the pointer to last GOB */
137  s->ptr_lastgob = put_bits_ptr(&s->pb);
138  put_bits(&s->pb, 22, 0x20); /* PSC */
139  temp_ref= s->picture_number * (int64_t)coded_frame_rate * s->avctx->time_base.num / //FIXME use timestamp
140  (coded_frame_rate_base * (int64_t)s->avctx->time_base.den);
141  put_sbits(&s->pb, 8, temp_ref); /* TemporalReference */
142 
143  put_bits(&s->pb, 1, 1); /* marker */
144  put_bits(&s->pb, 1, 0); /* H.263 id */
145  put_bits(&s->pb, 1, 0); /* split screen off */
146  put_bits(&s->pb, 1, 0); /* camera off */
147  put_bits(&s->pb, 1, 0); /* freeze picture release off */
148 
150  if (!s->h263_plus) {
151  /* H.263v1 */
152  put_bits(&s->pb, 3, format);
153  put_bits(&s->pb, 1, (s->pict_type == AV_PICTURE_TYPE_P));
154  /* By now UMV IS DISABLED ON H.263v1, since the restrictions
155  of H.263v1 UMV implies to check the predicted MV after
156  calculation of the current MB to see if we're on the limits */
157  put_bits(&s->pb, 1, 0); /* Unrestricted Motion Vector: off */
158  put_bits(&s->pb, 1, 0); /* SAC: off */
159  put_bits(&s->pb, 1, s->obmc); /* Advanced Prediction */
160  put_bits(&s->pb, 1, 0); /* only I/P-frames, no PB-frame */
161  put_bits(&s->pb, 5, s->qscale);
162  put_bits(&s->pb, 1, 0); /* Continuous Presence Multipoint mode: off */
163  } else {
164  int ufep=1;
165  /* H.263v2 */
166  /* H.263 Plus PTYPE */
167 
168  put_bits(&s->pb, 3, 7);
169  put_bits(&s->pb,3,ufep); /* Update Full Extended PTYPE */
170  if (format == 8)
171  put_bits(&s->pb,3,6); /* Custom Source Format */
172  else
173  put_bits(&s->pb, 3, format);
174 
175  put_bits(&s->pb,1, custom_pcf);
176  put_bits(&s->pb,1, s->umvplus); /* Unrestricted Motion Vector */
177  put_bits(&s->pb,1,0); /* SAC: off */
178  put_bits(&s->pb,1,s->obmc); /* Advanced Prediction Mode */
179  put_bits(&s->pb,1,s->h263_aic); /* Advanced Intra Coding */
180  put_bits(&s->pb,1,s->loop_filter); /* Deblocking Filter */
181  put_bits(&s->pb,1,s->h263_slice_structured); /* Slice Structured */
182  put_bits(&s->pb,1,0); /* Reference Picture Selection: off */
183  put_bits(&s->pb,1,0); /* Independent Segment Decoding: off */
184  put_bits(&s->pb,1,s->alt_inter_vlc); /* Alternative Inter VLC */
185  put_bits(&s->pb,1,s->modified_quant); /* Modified Quantization: */
186  put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */
187  put_bits(&s->pb,3,0); /* Reserved */
188 
189  put_bits(&s->pb, 3, s->pict_type == AV_PICTURE_TYPE_P);
190 
191  put_bits(&s->pb,1,0); /* Reference Picture Resampling: off */
192  put_bits(&s->pb,1,0); /* Reduced-Resolution Update: off */
193  put_bits(&s->pb,1,s->no_rounding); /* Rounding Type */
194  put_bits(&s->pb,2,0); /* Reserved */
195  put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */
196 
197  /* This should be here if PLUSPTYPE */
198  put_bits(&s->pb, 1, 0); /* Continuous Presence Multipoint mode: off */
199 
200  if (format == 8) {
201  /* Custom Picture Format (CPFMT) */
202  unsigned aspect_ratio_info = ff_h263_aspect_to_info(s->avctx->sample_aspect_ratio);
203 
204  put_bits(&s->pb,4, aspect_ratio_info);
205  put_bits(&s->pb,9,(s->width >> 2) - 1);
206  put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */
207  put_bits(&s->pb,9,(s->height >> 2));
208  if (aspect_ratio_info == FF_ASPECT_EXTENDED){
209  put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.num);
210  put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.den);
211  }
212  }
213  if (custom_pcf) {
214  if(ufep){
215  put_bits(&s->pb, 1, best_clock_code);
216  put_bits(&s->pb, 7, best_divisor);
217  }
218  put_sbits(&s->pb, 2, temp_ref>>8);
219  }
220 
221  /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */
222  if (s->umvplus)
223 // put_bits(&s->pb,1,1); /* Limited according tables of Annex D */
224 //FIXME check actual requested range
225  put_bits(&s->pb,2,1); /* unlimited */
226  if(s->h263_slice_structured)
227  put_bits(&s->pb,2,0); /* no weird submodes */
228 
229  put_bits(&s->pb, 5, s->qscale);
230  }
231 
232  put_bits(&s->pb, 1, 0); /* no PEI */
233 
234  if(s->h263_slice_structured){
235  put_bits(&s->pb, 1, 1);
236 
237  av_assert1(s->mb_x == 0 && s->mb_y == 0);
239 
240  put_bits(&s->pb, 1, 1);
241  }
242 }
243 
244 /**
245  * Encode a group of blocks header.
246  */
248 {
249  put_bits(&s->pb, 17, 1); /* GBSC */
250 
251  if(s->h263_slice_structured){
252  put_bits(&s->pb, 1, 1);
253 
255 
256  if(s->mb_num > 1583)
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 */
261  }else{
262  int gob_number= mb_line / s->gob_index;
263 
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 */
267  }
268 }
269 
270 /**
271  * modify qscale so that encoding is actually possible in H.263 (limit difference to -2..2)
272  */
274  int i;
275  int8_t * const qscale_table = s->cur_pic.qscale_table;
276 
278 
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;
282  }
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;
286  }
287 
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];
291 
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;
294  }
295  }
296  }
297 }
298 
299 static const int dquant_code[5]= {1,0,9,2,3};
300 
301 /**
302  * Encode an 8x8 block.
303  * @param block the 8x8 block
304  * @param n block index (0-3 are luma, 4-5 are chroma)
305  */
306 static void h263_encode_block(MpegEncContext * s, int16_t * block, int n)
307 {
308  int level, run, last, i, j, last_index, last_non_zero, sign, slevel, code;
309  const RLTable *rl;
310 
311  rl = &ff_h263_rl_inter;
312  if (s->mb_intra && !s->h263_aic) {
313  /* DC coef */
314  level = block[0];
315  /* 255 cannot be represented, so we clamp */
316  if (level > 254) {
317  level = 254;
318  block[0] = 254;
319  }
320  /* 0 cannot be represented also */
321  else if (level < 1) {
322  level = 1;
323  block[0] = 1;
324  }
325  if (level == 128) //FIXME check rv10
326  put_bits(&s->pb, 8, 0xff);
327  else
328  put_bits(&s->pb, 8, level);
329  i = 1;
330  } else {
331  i = 0;
332  if (s->h263_aic && s->mb_intra)
333  rl = &ff_rl_intra_aic;
334 
335  if(s->alt_inter_vlc && !s->mb_intra){
336  int aic_vlc_bits=0;
337  int inter_vlc_bits=0;
338  int wrong_pos=-1;
339  int aic_code;
340 
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];
345  level = block[j];
346  if (level) {
347  run = i - last_non_zero - 1;
348  last = (i == last_index);
349 
350  if(level<0) level= -level;
351 
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;
356 
357  if (code == rl->n) {
358  inter_vlc_bits += 1+6+8-1;
359  }
360  if (aic_code == ff_rl_intra_aic.n) {
361  aic_vlc_bits += 1+6+8-1;
362  wrong_pos += run + 1;
363  }else
364  wrong_pos += wrong_run[aic_code];
365  last_non_zero = i;
366  }
367  }
368  i = 0;
369  if(aic_vlc_bits < inter_vlc_bits && wrong_pos > 63)
370  rl = &ff_rl_intra_aic;
371  }
372  }
373 
374  /* AC coefs */
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];
379  level = block[j];
380  if (level) {
381  run = i - last_non_zero - 1;
382  last = (i == last_index);
383  sign = 0;
384  slevel = level;
385  if (level < 0) {
386  sign = 1;
387  level = -level;
388  }
389  code = get_rl_index(rl, last, run, level);
390  put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
391  if (code == rl->n) {
392  if(!CONFIG_FLV_ENCODER || s->h263_flv <= 1){
393  put_bits(&s->pb, 1, last);
394  put_bits(&s->pb, 6, run);
395 
396  av_assert2(slevel != 0);
397 
398  if(level < 128)
399  put_sbits(&s->pb, 8, slevel);
400  else{
401  put_bits(&s->pb, 8, 128);
402  put_sbits(&s->pb, 5, slevel);
403  put_sbits(&s->pb, 6, slevel>>5);
404  }
405  }else{
406  ff_flv2_encode_ac_esc(&s->pb, slevel, level, run, last);
407  }
408  } else {
409  put_bits(&s->pb, 1, sign);
410  }
411  last_non_zero = i;
412  }
413  }
414 }
415 
416 /* Encode MV differences on H.263+ with Unrestricted MV mode */
418 {
419  short sval = 0;
420  short i = 0;
421  short n_bits = 0;
422  short temp_val;
423  int code = 0;
424  int tcode;
425 
426  if ( val == 0)
427  put_bits(pb, 1, 1);
428  else if (val == 1)
429  put_bits(pb, 3, 0);
430  else if (val == -1)
431  put_bits(pb, 3, 2);
432  else {
433 
434  sval = ((val < 0) ? (short)(-val):(short)val);
435  temp_val = sval;
436 
437  while (temp_val != 0) {
438  temp_val = temp_val >> 1;
439  n_bits++;
440  }
441 
442  i = n_bits - 1;
443  while (i > 0) {
444  tcode = (sval & (1 << (i-1))) >> (i-1);
445  tcode = (tcode << 1) | 1;
446  code = (code << 2) | tcode;
447  i--;
448  }
449  code = ((code << 1) | (val < 0)) << 1;
450  put_bits(pb, (2*n_bits)+1, code);
451  }
452 }
453 
454 static int h263_pred_dc(MpegEncContext * s, int n, int16_t **dc_val_ptr)
455 {
456  int x, y, wrap, a, c, pred_dc;
457  int16_t *dc_val;
458 
459  /* find prediction */
460  if (n < 4) {
461  x = 2 * s->mb_x + (n & 1);
462  y = 2 * s->mb_y + ((n & 2) >> 1);
463  wrap = s->b8_stride;
464  dc_val = s->dc_val[0];
465  } else {
466  x = s->mb_x;
467  y = s->mb_y;
468  wrap = s->mb_stride;
469  dc_val = s->dc_val[n - 4 + 1];
470  }
471  /* B C
472  * A X
473  */
474  a = dc_val[(x - 1) + (y) * wrap];
475  c = dc_val[(x) + (y - 1) * wrap];
476 
477  /* No prediction outside GOB boundary */
478  if (s->first_slice_line && n != 3) {
479  if (n != 2) c = 1024;
480  if (n != 1 && s->mb_x == s->resync_mb_x) a = 1024;
481  }
482  /* just DC prediction */
483  if (a != 1024 && c != 1024)
484  pred_dc = (a + c) >> 1;
485  else if (a != 1024)
486  pred_dc = a;
487  else
488  pred_dc = c;
489 
490  /* we assume pred is positive */
491  *dc_val_ptr = &dc_val[x + y * wrap];
492  return pred_dc;
493 }
494 
496  int16_t block[6][64],
497  int motion_x, int motion_y)
498 {
499  int cbpc, cbpy, i, cbp, pred_x, pred_y;
500  int16_t pred_dc;
501  int16_t rec_intradc[6];
502  int16_t *dc_ptr[6];
503  const int interleaved_stats = s->avctx->flags & AV_CODEC_FLAG_PASS1;
504 
505  if (!s->mb_intra) {
506  /* compute cbp */
507  cbp= get_p_cbp(s, block, motion_x, motion_y);
508 
509  if ((cbp | motion_x | motion_y | s->dquant | (s->mv_type - MV_TYPE_16X16)) == 0) {
510  /* skip macroblock */
511  put_bits(&s->pb, 1, 1);
512  if(interleaved_stats){
513  s->misc_bits++;
514  s->last_bits++;
515  }
516 
517  return;
518  }
519  put_bits(&s->pb, 1, 0); /* mb coded */
520 
521  cbpc = cbp & 3;
522  cbpy = cbp >> 2;
523  if(s->alt_inter_vlc==0 || cbpc!=3)
524  cbpy ^= 0xF;
525  if(s->dquant) cbpc+= 8;
526  if(s->mv_type==MV_TYPE_16X16){
527  put_bits(&s->pb,
530 
531  put_bits(&s->pb, ff_h263_cbpy_tab[cbpy][1], ff_h263_cbpy_tab[cbpy][0]);
532  if(s->dquant)
533  put_bits(&s->pb, 2, dquant_code[s->dquant+2]);
534 
535  if(interleaved_stats){
536  s->misc_bits+= get_bits_diff(s);
537  }
538 
539  /* motion vectors: 16x16 mode */
540  ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
541 
542  if (!s->umvplus) {
543  ff_h263_encode_motion_vector(s, motion_x - pred_x,
544  motion_y - pred_y, 1);
545  }
546  else {
547  h263p_encode_umotion(&s->pb, motion_x - pred_x);
548  h263p_encode_umotion(&s->pb, motion_y - pred_y);
549  if (((motion_x - pred_x) == 1) && ((motion_y - pred_y) == 1))
550  /* To prevent Start Code emulation */
551  put_bits(&s->pb,1,1);
552  }
553  }else{
554  put_bits(&s->pb,
555  ff_h263_inter_MCBPC_bits[cbpc+16],
556  ff_h263_inter_MCBPC_code[cbpc+16]);
557  put_bits(&s->pb, ff_h263_cbpy_tab[cbpy][1], ff_h263_cbpy_tab[cbpy][0]);
558  if(s->dquant)
559  put_bits(&s->pb, 2, dquant_code[s->dquant+2]);
560 
561  if(interleaved_stats){
562  s->misc_bits+= get_bits_diff(s);
563  }
564 
565  for(i=0; i<4; i++){
566  /* motion vectors: 8x8 mode*/
567  ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y);
568 
569  motion_x = s->cur_pic.motion_val[0][s->block_index[i]][0];
570  motion_y = s->cur_pic.motion_val[0][s->block_index[i]][1];
571  if (!s->umvplus) {
572  ff_h263_encode_motion_vector(s, motion_x - pred_x,
573  motion_y - pred_y, 1);
574  }
575  else {
576  h263p_encode_umotion(&s->pb, motion_x - pred_x);
577  h263p_encode_umotion(&s->pb, motion_y - pred_y);
578  if (((motion_x - pred_x) == 1) && ((motion_y - pred_y) == 1))
579  /* To prevent Start Code emulation */
580  put_bits(&s->pb,1,1);
581  }
582  }
583  }
584 
585  if(interleaved_stats){
586  s->mv_bits+= get_bits_diff(s);
587  }
588  } else {
589  av_assert2(s->mb_intra);
590 
591  cbp = 0;
592  if (s->h263_aic) {
593  /* Predict DC */
594  for(i=0; i<6; i++) {
595  int16_t level = block[i][0];
596  int scale;
597 
598  if(i<4) scale= s->y_dc_scale;
599  else scale= s->c_dc_scale;
600 
601  pred_dc = h263_pred_dc(s, i, &dc_ptr[i]);
602  level -= pred_dc;
603  /* Quant */
604  if (level >= 0)
605  level = (level + (scale>>1))/scale;
606  else
607  level = (level - (scale>>1))/scale;
608 
609  if(!s->modified_quant){
610  if (level < -127)
611  level = -127;
612  else if (level > 127)
613  level = 127;
614  }
615 
616  block[i][0] = level;
617  /* Reconstruction */
618  rec_intradc[i] = scale*level + pred_dc;
619  /* Oddify */
620  rec_intradc[i] |= 1;
621  //if ((rec_intradc[i] % 2) == 0)
622  // rec_intradc[i]++;
623  /* Clipping */
624  if (rec_intradc[i] < 0)
625  rec_intradc[i] = 0;
626  else if (rec_intradc[i] > 2047)
627  rec_intradc[i] = 2047;
628 
629  /* Update AC/DC tables */
630  *dc_ptr[i] = rec_intradc[i];
631  /* AIC can change CBP */
632  if (s->block_last_index[i] > 0 ||
633  (s->block_last_index[i] == 0 && level !=0))
634  cbp |= 1 << (5 - i);
635  }
636  }else{
637  for(i=0; i<6; i++) {
638  /* compute cbp */
639  if (s->block_last_index[i] >= 1)
640  cbp |= 1 << (5 - i);
641  }
642  }
643 
644  cbpc = cbp & 3;
645  if (s->pict_type == AV_PICTURE_TYPE_I) {
646  if(s->dquant) cbpc+=4;
647  put_bits(&s->pb,
650  } else {
651  if(s->dquant) cbpc+=8;
652  put_bits(&s->pb, 1, 0); /* mb coded */
653  put_bits(&s->pb,
654  ff_h263_inter_MCBPC_bits[cbpc + 4],
655  ff_h263_inter_MCBPC_code[cbpc + 4]);
656  }
657  if (s->h263_aic) {
658  /* XXX: currently, we do not try to use ac prediction */
659  put_bits(&s->pb, 1, 0); /* no AC prediction */
660  }
661  cbpy = cbp >> 2;
662  put_bits(&s->pb, ff_h263_cbpy_tab[cbpy][1], ff_h263_cbpy_tab[cbpy][0]);
663  if(s->dquant)
664  put_bits(&s->pb, 2, dquant_code[s->dquant+2]);
665 
666  if(interleaved_stats){
667  s->misc_bits+= get_bits_diff(s);
668  }
669  }
670 
671  for(i=0; i<6; i++) {
672  /* encode each block */
674 
675  /* Update INTRADC for decoding */
676  if (s->h263_aic && s->mb_intra) {
677  block[i][0] = rec_intradc[i];
678 
679  }
680  }
681 
682  if(interleaved_stats){
683  if (!s->mb_intra) {
684  s->p_tex_bits+= get_bits_diff(s);
685  }else{
686  s->i_tex_bits+= get_bits_diff(s);
687  s->i_count++;
688  }
689  }
690 }
691 
693 {
694  const int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
695 
696  if (s->cur_pic.mbskip_table)
697  s->cur_pic.mbskip_table[mb_xy] = s->mb_skipped;
698 
699  if (s->mv_type == MV_TYPE_8X8)
700  s->cur_pic.mb_type[mb_xy] = MB_TYPE_L0 | MB_TYPE_8x8;
701  else if(s->mb_intra)
702  s->cur_pic.mb_type[mb_xy] = MB_TYPE_INTRA;
703  else
704  s->cur_pic.mb_type[mb_xy] = MB_TYPE_L0 | MB_TYPE_16x16;
705 
707 }
708 
709 void ff_h263_encode_motion(PutBitContext *pb, int val, int f_code)
710 {
711  int range, bit_size, sign, code, bits;
712 
713  if (val == 0) {
714  /* zero vector */
715  code = 0;
716  put_bits(pb, ff_mvtab[code][1], ff_mvtab[code][0]);
717  } else {
718  bit_size = f_code - 1;
719  range = 1 << bit_size;
720  /* modulo encoding */
721  val = sign_extend(val, 6 + bit_size);
722  sign = val>>31;
723  val= (val^sign)-sign;
724  sign&=1;
725 
726  val--;
727  code = (val >> bit_size) + 1;
728  bits = val & (range - 1);
729 
730  put_bits(pb, ff_mvtab[code][1] + 1, (ff_mvtab[code][0] << 1) | sign);
731  if (bit_size > 0) {
732  put_bits(pb, bit_size, bits);
733  }
734  }
735 }
736 
738 {
739  int f_code;
740  int mv;
741 
742  for(f_code=1; f_code<=MAX_FCODE; f_code++){
743  for(mv=-MAX_DMV; mv<=MAX_DMV; mv++){
744  int len;
745 
746  if(mv==0) len= ff_mvtab[0][1];
747  else{
748  int val, bit_size, code;
749 
750  bit_size = f_code - 1;
751 
752  val=mv;
753  if (val < 0)
754  val = -val;
755  val--;
756  code = (val >> bit_size) + 1;
757  if(code<33){
758  len= ff_mvtab[code][1] + 1 + bit_size;
759  }else{
760  len= ff_mvtab[32][1] + av_log2(code>>5) + 2 + bit_size;
761  }
762  }
763 
764  mv_penalty[f_code][mv+MAX_DMV]= len;
765  }
766  }
767 
768  for(f_code=MAX_FCODE; f_code>0; f_code--){
769  for(mv=-(16<<f_code); mv<(16<<f_code); mv++){
770  fcode_tab[mv+MAX_MV]= f_code;
771  }
772  }
773 
774  for(mv=0; mv<MAX_MV*2+1; mv++){
775  umv_fcode_tab[mv]= 1;
776  }
777 }
778 
779 static av_cold void init_uni_h263_rl_tab(const RLTable *rl, uint8_t *len_tab)
780 {
781  int slevel, run, last;
782 
783  av_assert0(MAX_LEVEL >= 64);
784  av_assert0(MAX_RUN >= 63);
785 
786  for(slevel=-64; slevel<64; slevel++){
787  if(slevel==0) continue;
788  for(run=0; run<64; run++){
789  for(last=0; last<=1; last++){
790  const int index= UNI_MPEG4_ENC_INDEX(last, run, slevel+64);
791  int level= slevel < 0 ? -slevel : slevel;
792  int sign= slevel < 0 ? 1 : 0;
793  int bits, len, code;
794 
795  len_tab[index]= 100;
796 
797  /* ESC0 */
798  code= get_rl_index(rl, last, run, level);
799  bits= rl->table_vlc[code][0];
800  len= rl->table_vlc[code][1];
801  bits=bits*2+sign; len++;
802 
803  if (code != rl->n && len < len_tab[index])
804  len_tab [index]= len;
805 
806  /* ESC */
807  bits= rl->table_vlc[rl->n][0];
808  len = rl->table_vlc[rl->n][1];
809  bits=bits*2+last; len++;
810  bits=bits*64+run; len+=6;
811  bits=bits*256+(level&0xff); len+=8;
812 
813  if (len < len_tab[index])
814  len_tab [index]= len;
815  }
816  }
817  }
818 }
819 
821 {
822  static uint8_t rl_intra_table[2][2 * MAX_RUN + MAX_LEVEL + 3];
823 
824  ff_rl_init(&ff_rl_intra_aic, rl_intra_table);
826 
829 
831 }
832 
834 {
835  static AVOnce init_static_once = AV_ONCE_INIT;
836 
837  s->me.mv_penalty= mv_penalty; // FIXME exact table for MSMPEG4 & H.263+
838 
839  s->intra_ac_vlc_length =s->inter_ac_vlc_length = uni_h263_inter_rl_len;
840  s->intra_ac_vlc_last_length=s->inter_ac_vlc_last_length= uni_h263_inter_rl_len + 128*64;
841  if(s->h263_aic){
842  s->intra_ac_vlc_length = uni_h263_intra_aic_rl_len;
843  s->intra_ac_vlc_last_length= uni_h263_intra_aic_rl_len + 128*64;
844  }
845  s->ac_esc_length= 7+1+6+8;
846 
847  // use fcodes >1 only for MPEG-4 & H.263 & H.263+ FIXME
848  switch(s->codec_id){
849  case AV_CODEC_ID_MPEG4:
850  s->fcode_tab= fcode_tab;
851  break;
852  case AV_CODEC_ID_H263P:
853  if(s->umvplus)
854  s->fcode_tab= umv_fcode_tab;
855  if(s->modified_quant){
856  s->min_qcoeff= -2047;
857  s->max_qcoeff= 2047;
858  }else{
859  s->min_qcoeff= -127;
860  s->max_qcoeff= 127;
861  }
862  break;
863  // Note for MPEG-4 & H.263 the dc-scale table will be set per frame as needed later
864  case AV_CODEC_ID_FLV1:
865  if (s->h263_flv > 1) {
866  s->min_qcoeff= -1023;
867  s->max_qcoeff= 1023;
868  } else {
869  s->min_qcoeff= -127;
870  s->max_qcoeff= 127;
871  }
872  break;
873  default: //nothing needed - default table already set in mpegvideo.c
874  s->min_qcoeff= -127;
875  s->max_qcoeff= 127;
876  }
877  if(s->h263_aic){
878  s->y_dc_scale_table=
879  s->c_dc_scale_table= ff_aic_dc_scale_table;
880  }else{
881  s->y_dc_scale_table=
882  s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
883  }
884 
885 #if CONFIG_H263_ENCODER // Snow and SVQ1 call this
886  ff_h263dsp_init(&s->h263dsp);
887 #endif
888 
889  ff_thread_once(&init_static_once, h263_encode_init_static);
890 }
891 
893 {
894  int i, mb_pos;
895 
896  for(i=0; i<6; i++){
897  if(s->mb_num-1 <= ff_mba_max[i]) break;
898  }
899  mb_pos= s->mb_x + s->mb_width*s->mb_y;
900  put_bits(&s->pb, ff_mba_length[i], mb_pos);
901 }
902 
903 #define OFFSET(x) offsetof(MpegEncContext, x)
904 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
905 static const AVOption h263_options[] = {
906  { "obmc", "use overlapped block motion compensation.", OFFSET(obmc), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
907  { "mb_info", "emit macroblock info for RFC 2190 packetization, the parameter value is the maximum payload size", OFFSET(mb_info), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
910  { NULL },
911 };
912 
913 static const AVClass h263_class = {
914  .class_name = "H.263 encoder",
915  .item_name = av_default_item_name,
916  .option = h263_options,
917  .version = LIBAVUTIL_VERSION_INT,
918 };
919 
921  .p.name = "h263",
922  CODEC_LONG_NAME("H.263 / H.263-1996"),
923  .p.type = AVMEDIA_TYPE_VIDEO,
924  .p.id = AV_CODEC_ID_H263,
925  .p.pix_fmts = (const enum AVPixelFormat[]){AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE},
926  .p.priv_class = &h263_class,
927  .p.capabilities = AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
928  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
929  .priv_data_size = sizeof(MpegEncContext),
932  .close = ff_mpv_encode_end,
933 };
934 
935 static const AVOption h263p_options[] = {
936  { "umv", "Use unlimited motion vectors.", OFFSET(umvplus), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
937  { "aiv", "Use alternative inter VLC.", OFFSET(alt_inter_vlc), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
938  { "obmc", "use overlapped block motion compensation.", OFFSET(obmc), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
939  { "structured_slices", "Write slice start position at every GOB header instead of just GOB number.", OFFSET(h263_slice_structured), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE},
942  { NULL },
943 };
944 static const AVClass h263p_class = {
945  .class_name = "H.263p encoder",
946  .item_name = av_default_item_name,
947  .option = h263p_options,
948  .version = LIBAVUTIL_VERSION_INT,
949 };
950 
952  .p.name = "h263p",
953  CODEC_LONG_NAME("H.263+ / H.263-1998 / H.263 version 2"),
954  .p.type = AVMEDIA_TYPE_VIDEO,
955  .p.id = AV_CODEC_ID_H263P,
956  .p.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
957  .p.priv_class = &h263p_class,
959  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
960  .priv_data_size = sizeof(MpegEncContext),
963  .close = ff_mpv_encode_end,
964 };
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:32
MB_TYPE_L0
#define MB_TYPE_L0
Definition: mpegutils.h:55
MV_TYPE_16X16
#define MV_TYPE_16X16
1 vector for the whole mb
Definition: mpegvideo.h:266
h263data.h
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
FF_ASPECT_EXTENDED
#define FF_ASPECT_EXTENDED
Definition: h263.h:26
level
uint8_t level
Definition: svq3.c:205
av_clip
#define av_clip
Definition: common.h:100
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:42
get_bits_diff
static int get_bits_diff(MpegEncContext *s)
Definition: mpegvideoenc.h:158
wrong_run
static const uint8_t wrong_run[102]
Definition: ituh263enc.c:74
fcode_tab
static uint8_t fcode_tab[MAX_MV *2+1]
Minimal fcode that a motion vector component would need.
Definition: ituh263enc.c:58
align_put_bits
static void align_put_bits(PutBitContext *s)
Pad the bitstream with zeros up to the next byte boundary.
Definition: put_bits.h:420
uni_h263_inter_rl_len
static uint8_t uni_h263_inter_rl_len[64 *64 *2 *2]
Definition: ituh263enc.c:69
UNI_MPEG4_ENC_INDEX
#define UNI_MPEG4_ENC_INDEX(last, run, level)
Definition: ituh263enc.c:72
h263p_options
static const AVOption h263p_options[]
Definition: ituh263enc.c:935
thread.h
VE
#define VE
Definition: ituh263enc.c:904
mpegvideoenc.h
mv
static const int8_t mv[256][2]
Definition: 4xm.c:81
put_sbits
static void put_sbits(PutBitContext *pb, int n, int32_t value)
Definition: put_bits.h:281
MAX_RUN
#define MAX_RUN
Definition: rl.h:35
h263enc.h
AV_CODEC_ID_MPEG4
@ AV_CODEC_ID_MPEG4
Definition: codec_id.h:64
CANDIDATE_MB_TYPE_INTER
#define CANDIDATE_MB_TYPE_INTER
Definition: mpegvideoenc.h:41
put_bits
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:223
MAX_DMV
#define MAX_DMV
Definition: motion_est.h:37
internal.h
av_const
#define av_const
Definition: attributes.h:84
h263dsp.h
AVOption
AVOption.
Definition: opt.h:357
MB_TYPE_16x16
#define MB_TYPE_16x16
Definition: mpegutils.h:42
OFFSET
#define OFFSET(x)
Definition: ituh263enc.c:903
FFCodec
Definition: codec_internal.h:126
init_uni_h263_rl_tab
static av_cold void init_uni_h263_rl_tab(const RLTable *rl, uint8_t *len_tab)
Definition: ituh263enc.c:779
mpegvideo.h
mpegutils.h
h263_pred_dc
static int h263_pred_dc(MpegEncContext *s, int n, int16_t **dc_val_ptr)
Definition: ituh263enc.c:454
FF_MPV_COMMON_MOTION_EST_OPTS
#define FF_MPV_COMMON_MOTION_EST_OPTS
Definition: mpegvideoenc.h:127
MAX_FCODE
#define MAX_FCODE
Definition: mpegutils.h:36
ff_mpv_encode_picture
int ff_mpv_encode_picture(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pic_arg, int *got_packet)
Definition: mpegvideo_enc.c:1753
FF_MPV_COMMON_OPTS
#define FF_MPV_COMMON_OPTS
Definition: mpegvideoenc.h:84
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:130
h263p_class
static const AVClass h263p_class
Definition: ituh263enc.c:944
ff_match_2uint16
int ff_match_2uint16(const uint16_t(*tab)[2], int size, int a, int b)
Return the index into tab at which {a,b} match elements {[0],[1]} of tab.
Definition: utils.c:831
ff_h263_pred_motion
int16_t * ff_h263_pred_motion(MpegEncContext *s, int block, int dir, int *px, int *py)
Definition: h263.c:179
wrap
#define wrap(func)
Definition: neontest.h:65
ff_h263_pixel_aspect
const AVRational ff_h263_pixel_aspect[16]
Definition: h263data.c:273
RLTable
RLTable.
Definition: rl.h:39
mv_penalty
static uint8_t mv_penalty[MAX_FCODE+1][MAX_DMV *2+1]
Table of number of bits a motion vector component needs.
Definition: ituh263enc.c:53
val
static double val(void *priv, double ch)
Definition: aeval.c:78
ff_h263_encode_motion_vector
static void ff_h263_encode_motion_vector(MpegEncContext *s, int x, int y, int f_code)
Definition: h263enc.h:60
ff_h263_aspect_to_info
av_const int ff_h263_aspect_to_info(AVRational aspect)
Return the 4 bit value that specifies the given aspect ratio.
Definition: ituh263enc.c:95
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:295
ff_h263_update_motion_val
void ff_h263_update_motion_val(MpegEncContext *s)
Definition: h263.c:53
AVRational::num
int num
Numerator.
Definition: rational.h:59
h263_encode_block
static void h263_encode_block(MpegEncContext *s, int16_t *block, int n)
Encode an 8x8 block.
Definition: ituh263enc.c:306
RLTable::n
int n
number of entries of table_vlc minus 1
Definition: rl.h:40
ff_thread_once
static int ff_thread_once(char *control, void(*routine)(void))
Definition: thread.h:205
ff_h263_encode_motion
void ff_h263_encode_motion(PutBitContext *pb, int val, int f_code)
Definition: ituh263enc.c:709
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
MAX_MV
#define MAX_MV
Definition: motion_est.h:35
s
#define s(width, name)
Definition: cbs_vp9.c:198
format
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
get_rl_index
static int get_rl_index(const RLTable *rl, int last, int run, int level)
Definition: rl.h:101
get_p_cbp
static int get_p_cbp(MpegEncContext *s, int16_t block[6][64], int motion_x, int motion_y)
Definition: h263enc.h:73
AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
Definition: codec.h:159
ff_mpeg1_dc_scale_table
static const uint8_t *const ff_mpeg1_dc_scale_table
Definition: mpegvideodata.h:32
bits
uint8_t bits
Definition: vp3data.h:128
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
limits.h
ff_h263p_encoder
const FFCodec ff_h263p_encoder
Definition: ituh263enc.c:951
ff_h263_encode_init
av_cold void ff_h263_encode_init(MpegEncContext *s)
Definition: ituh263enc.c:833
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
PutBitContext
Definition: put_bits.h:50
ff_rl_init
av_cold void ff_rl_init(RLTable *rl, uint8_t static_store[2][2 *MAX_RUN+MAX_LEVEL+3])
Initialize index_run, max_level and max_run from n, last, table_vlc, table_run and table_level.
Definition: rl.c:44
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:271
ff_h263_encode_mb
void ff_h263_encode_mb(MpegEncContext *s, int16_t block[6][64], int motion_x, int motion_y)
Definition: ituh263enc.c:495
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:74
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AV_ONCE_INIT
#define AV_ONCE_INIT
Definition: thread.h:203
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
NULL
#define NULL
Definition: coverity.c:32
init_mv_penalty_and_fcode
static av_cold void init_mv_penalty_and_fcode(void)
Definition: ituh263enc.c:737
run
uint8_t run
Definition: svq3.c:204
RLTable::table_vlc
const uint16_t(* table_vlc)[2]
Definition: rl.h:42
ff_h263_encoder
const FFCodec ff_h263_encoder
Definition: ituh263enc.c:920
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
MB_TYPE_8x8
#define MB_TYPE_8x8
Definition: mpegutils.h:45
uni_h263_intra_aic_rl_len
static uint8_t uni_h263_intra_aic_rl_len[64 *64 *2 *2]
Definition: ituh263enc.c:68
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:279
mathops.h
ff_mba_max
const uint16_t ff_mba_max[6]
Definition: h263data.c:265
ff_mpv_encode_end
av_cold int ff_mpv_encode_end(AVCodecContext *avctx)
Definition: mpegvideo_enc.c:990
ff_init_qscale_tab
void ff_init_qscale_tab(MpegEncContext *s)
init s->cur_pic.qscale_table from s->lambda_table
Definition: mpegvideo_enc.c:240
AVOnce
#define AVOnce
Definition: thread.h:202
index
int index
Definition: gxfenc.c:90
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
MV_TYPE_8X8
#define MV_TYPE_8X8
4 vectors (H.263, MPEG-4 4MV)
Definition: mpegvideo.h:267
MAX_LEVEL
#define MAX_LEVEL
Definition: rl.h:36
ff_clean_h263_qscales
void ff_clean_h263_qscales(MpegEncContext *s)
modify qscale so that encoding is actually possible in H.263 (limit difference to -2....
Definition: ituh263enc.c:273
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:366
ff_h263_rl_inter
RLTable ff_h263_rl_inter
Definition: h263data.c:159
codec_internal.h
AV_CODEC_ID_H263
@ AV_CODEC_ID_H263
Definition: codec_id.h:56
ff_h263_cbpy_tab
const uint8_t ff_h263_cbpy_tab[16][2]
Definition: h263data.c:82
ff_rl_intra_aic
RLTable ff_rl_intra_aic
Definition: h263data.c:228
ff_h263dsp_init
av_cold void ff_h263dsp_init(H263DSPContext *ctx)
Definition: h263dsp.c:117
range
enum AVColorRange range
Definition: mediacodec_wrapper.c:2464
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
AV_CODEC_CAP_SLICE_THREADS
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition: codec.h:114
mpegvideodata.h
attributes.h
ff_h263_inter_MCBPC_bits
const uint8_t ff_h263_inter_MCBPC_bits[28]
Definition: h263data.c:47
pred_dc
static void FUNC() pred_dc(uint8_t *_src, const uint8_t *_top, const uint8_t *_left, ptrdiff_t stride, int log2_size, int c_idx)
Definition: pred_template.c:391
CANDIDATE_MB_TYPE_INTER4V
#define CANDIDATE_MB_TYPE_INTER4V
Definition: mpegvideoenc.h:42
h263_options
static const AVOption h263_options[]
Definition: ituh263enc.c:905
ff_h263_encode_picture_header
void ff_h263_encode_picture_header(MpegEncContext *s)
Definition: ituh263enc.c:109
av_assert2
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:67
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
code
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
Definition: filter_design.txt:178
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:56
ff_h263_format
const uint16_t ff_h263_format[8][2]
Definition: h263data.c:236
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
ff_h263_encode_mba
void ff_h263_encode_mba(MpegEncContext *s)
Definition: ituh263enc.c:892
len
int len
Definition: vorbis_enc_data.h:426
ff_flv2_encode_ac_esc
void ff_flv2_encode_ac_esc(PutBitContext *pb, int slevel, int level, int run, int last)
Definition: flvenc.c:76
avcodec.h
av_cmp_q
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
Definition: rational.h:89
h263_encode_init_static
static av_cold void h263_encode_init_static(void)
Definition: ituh263enc.c:820
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:71
ff_aic_dc_scale_table
const uint8_t ff_aic_dc_scale_table[32]
Definition: h263data.c:245
ff_mvtab
const uint8_t ff_mvtab[33][2]
Definition: h263data.c:88
ff_h263_intra_MCBPC_bits
const uint8_t ff_h263_intra_MCBPC_bits[9]
Definition: h263data.c:33
dquant_code
static const int dquant_code[5]
Definition: ituh263enc.c:299
AV_CODEC_ID_H263P
@ AV_CODEC_ID_H263P
Definition: codec_id.h:71
put_bits_ptr
static uint8_t * put_bits_ptr(PutBitContext *s)
Return the pointer to the byte where the bitstream writer will put the next bit.
Definition: put_bits.h:377
ff_h263_intra_MCBPC_code
const uint8_t ff_h263_intra_MCBPC_code[9]
Definition: h263data.c:32
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
umv_fcode_tab
static uint8_t umv_fcode_tab[MAX_MV *2+1]
Minimal fcode that a motion vector component would need in umv.
Definition: ituh263enc.c:64
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:245
sign_extend
static av_const int sign_extend(int val, unsigned bits)
Definition: mathops.h:133
ff_mba_length
const uint8_t ff_mba_length[7]
Definition: h263data.c:269
flvenc.h
ff_h263_encode_gob_header
void ff_h263_encode_gob_header(MpegEncContext *s, int mb_line)
Encode a group of blocks header.
Definition: ituh263enc.c:247
ff_h263_inter_MCBPC_code
const uint8_t ff_h263_inter_MCBPC_code[28]
Definition: h263data.c:38
AV_PICTURE_TYPE_P
@ AV_PICTURE_TYPE_P
Predicted.
Definition: avutil.h:280
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
ff_mpv_encode_init
av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
Definition: mpegvideo_enc.c:310
scale
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition: intra.c:291
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:261
h263p_encode_umotion
static void h263p_encode_umotion(PutBitContext *pb, int val)
Definition: ituh263enc.c:417
ff_h263_update_mb
void ff_h263_update_mb(MpegEncContext *s)
Definition: ituh263enc.c:692
block
The exact code depends on how similar the blocks are and how related they are to the block
Definition: filter_design.txt:207
ff_h263_init_rl_inter
av_cold void ff_h263_init_rl_inter(void)
Definition: h263.c:47
AV_CODEC_ID_FLV1
@ AV_CODEC_ID_FLV1
Definition: codec_id.h:73
MpegEncContext
MpegEncContext.
Definition: mpegvideo.h:73
h263_class
static const AVClass h263_class
Definition: ituh263enc.c:913
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
mb_info
Definition: cinepakenc.c:87
MB_TYPE_INTRA
#define MB_TYPE_INTRA
Definition: mpegutils.h:61
AV_CODEC_FLAG_PASS1
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
Definition: avcodec.h:310
h263.h