FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
msmpeg4enc.c
Go to the documentation of this file.
1 /*
2  * MSMPEG4 encoder backend
3  * Copyright (c) 2001 Fabrice Bellard
4  * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5  *
6  * msmpeg4v1 & v2 stuff by 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  * MSMPEG4 encoder backend
28  */
29 
30 #include <stdint.h>
31 #include <string.h>
32 
33 #include "libavutil/attributes.h"
34 #include "libavutil/avutil.h"
35 #include "libavutil/mem.h"
36 #include "mpegvideo.h"
37 #include "h263.h"
38 #include "internal.h"
39 #include "mpeg4video.h"
40 #include "msmpeg4.h"
41 #include "msmpeg4data.h"
42 #include "put_bits.h"
43 #include "rl.h"
44 #include "vc1data.h"
45 
47 
48 /* build the table which associate a (x,y) motion vector to a vlc */
50 {
51  int i, x, y;
52 
53  tab->table_mv_index = av_malloc(sizeof(uint16_t) * 4096);
54  if (!tab->table_mv_index)
55  return AVERROR(ENOMEM);
56 
57  /* mark all entries as not used */
58  for(i=0;i<4096;i++)
59  tab->table_mv_index[i] = tab->n;
60 
61  for(i=0;i<tab->n;i++) {
62  x = tab->table_mvx[i];
63  y = tab->table_mvy[i];
64  tab->table_mv_index[(x << 6) | y] = i;
65  }
66 
67  return 0;
68 }
69 
71 {
72  if (n == 0) {
73  put_bits(pb, 1, 0);
74  } else {
75  put_bits(pb, 1, 1);
76  put_bits(pb, 1, (n >= 2));
77  }
78 }
79 
80 static int get_size_of_code(MpegEncContext * s, RLTable *rl, int last, int run, int level, int intra){
81  int size=0;
82  int code;
83  int run_diff= intra ? 0 : 1;
84 
85  code = get_rl_index(rl, last, run, level);
86  size+= rl->table_vlc[code][1];
87  if (code == rl->n) {
88  int level1, run1;
89 
90  level1 = level - rl->max_level[last][run];
91  if (level1 < 1)
92  goto esc2;
93  code = get_rl_index(rl, last, run, level1);
94  if (code == rl->n) {
95  esc2:
96  size++;
97  if (level > MAX_LEVEL)
98  goto esc3;
99  run1 = run - rl->max_run[last][level] - run_diff;
100  if (run1 < 0)
101  goto esc3;
102  code = get_rl_index(rl, last, run1, level);
103  if (code == rl->n) {
104  esc3:
105  /* third escape */
106  size+=1+1+6+8;
107  } else {
108  /* second escape */
109  size+= 1+1+ rl->table_vlc[code][1];
110  }
111  } else {
112  /* first escape */
113  size+= 1+1+ rl->table_vlc[code][1];
114  }
115  } else {
116  size++;
117  }
118  return size;
119 }
120 
122 {
123  static int init_done=0;
124  int i, ret;
125 
127  if(s->msmpeg4_version>=4){
128  s->min_qcoeff= -255;
129  s->max_qcoeff= 255;
130  }
131 
132  if (!init_done) {
133  /* init various encoding tables */
134  init_done = 1;
135  if ((ret = init_mv_table(&ff_mv_tables[0])) < 0)
136  return ret;
137  if ((ret = init_mv_table(&ff_mv_tables[1])) < 0)
138  return ret;
139  for(i=0;i<NB_RL_TABLES;i++)
141 
142  for(i=0; i<NB_RL_TABLES; i++){
143  int level;
144  for (level = 1; level <= MAX_LEVEL; level++) {
145  int run;
146  for(run=0; run<=MAX_RUN; run++){
147  int last;
148  for(last=0; last<2; last++){
149  rl_length[i][level][run][last]= get_size_of_code(s, &ff_rl_table[ i], last, run, level, 0);
150  }
151  }
152  }
153  }
154  }
155 
156  return 0;
157 }
158 
160 {
161  int i;
162  int best = 0, best_size = INT_MAX;
163  int chroma_best = 0, best_chroma_size = INT_MAX;
164 
165  for(i=0; i<3; i++){
166  int level;
167  int chroma_size=0;
168  int size=0;
169 
170  if(i>0){// ;)
171  size++;
172  chroma_size++;
173  }
174  for(level=0; level<=MAX_LEVEL; level++){
175  int run;
176  for(run=0; run<=MAX_RUN; run++){
177  int last;
178  const int last_size= size + chroma_size;
179  for(last=0; last<2; last++){
180  int inter_count = s->ac_stats[0][0][level][run][last] + s->ac_stats[0][1][level][run][last];
181  int intra_luma_count = s->ac_stats[1][0][level][run][last];
182  int intra_chroma_count= s->ac_stats[1][1][level][run][last];
183 
185  size += intra_luma_count *rl_length[i ][level][run][last];
186  chroma_size+= intra_chroma_count*rl_length[i+3][level][run][last];
187  }else{
188  size+= intra_luma_count *rl_length[i ][level][run][last]
189  +intra_chroma_count*rl_length[i+3][level][run][last]
190  +inter_count *rl_length[i+3][level][run][last];
191  }
192  }
193  if(last_size == size+chroma_size) break;
194  }
195  }
196  if(size<best_size){
197  best_size= size;
198  best= i;
199  }
200  if(chroma_size<best_chroma_size){
201  best_chroma_size= chroma_size;
202  chroma_best= i;
203  }
204  }
205 
206  if(s->pict_type==AV_PICTURE_TYPE_P) chroma_best= best;
207 
208  memset(s->ac_stats, 0, sizeof(int)*(MAX_LEVEL+1)*(MAX_RUN+1)*2*2*2);
209 
210  s->rl_table_index = best;
211  s->rl_chroma_table_index= chroma_best;
212 
213  if(s->pict_type != s->last_non_b_pict_type){
214  s->rl_table_index= 2;
216  s->rl_chroma_table_index= 1;
217  else
218  s->rl_chroma_table_index= 2;
219  }
220 
221 }
222 
223 /* write MSMPEG4 compatible frame header */
225 {
226  find_best_tables(s);
227 
229  put_bits(&s->pb, 2, s->pict_type - 1);
230 
231  put_bits(&s->pb, 5, s->qscale);
232  if(s->msmpeg4_version<=2){
233  s->rl_table_index = 2;
234  s->rl_chroma_table_index = 2;
235  }
236 
237  s->dc_table_index = 1;
238  s->mv_table_index = 1; /* only if P-frame */
239  s->use_skip_mb_code = 1; /* only if P-frame */
240  s->per_mb_rl_table = 0;
241  if(s->msmpeg4_version==4)
242  s->inter_intra_pred= (s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE && s->pict_type==AV_PICTURE_TYPE_P);
243  ff_dlog(s, "%d %"PRId64" %d %d %d\n", s->pict_type, s->bit_rate,
244  s->inter_intra_pred, s->width, s->height);
245 
246  if (s->pict_type == AV_PICTURE_TYPE_I) {
247  s->slice_height= s->mb_height/1;
248  put_bits(&s->pb, 5, 0x16 + s->mb_height/s->slice_height);
249 
250  if(s->msmpeg4_version==4){
252  if(s->bit_rate>MBAC_BITRATE)
253  put_bits(&s->pb, 1, s->per_mb_rl_table);
254  }
255 
256  if(s->msmpeg4_version>2){
257  if(!s->per_mb_rl_table){
260  }
261 
262  put_bits(&s->pb, 1, s->dc_table_index);
263  }
264  } else {
265  put_bits(&s->pb, 1, s->use_skip_mb_code);
266 
267  if(s->msmpeg4_version==4 && s->bit_rate>MBAC_BITRATE)
268  put_bits(&s->pb, 1, s->per_mb_rl_table);
269 
270  if(s->msmpeg4_version>2){
271  if(!s->per_mb_rl_table)
273 
274  put_bits(&s->pb, 1, s->dc_table_index);
275 
276  put_bits(&s->pb, 1, s->mv_table_index);
277  }
278  }
279 
280  s->esc3_level_length= 0;
281  s->esc3_run_length= 0;
282 }
283 
285 {
286  unsigned fps = s->avctx->time_base.den / s->avctx->time_base.num / FFMAX(s->avctx->ticks_per_frame, 1);
287  put_bits(&s->pb, 5, FFMIN(fps, 31)); //yes 29.97 -> 29
288 
289  put_bits(&s->pb, 11, FFMIN(s->bit_rate/1024, 2047));
290 
291  if(s->msmpeg4_version>=3)
292  put_bits(&s->pb, 1, s->flipflop_rounding);
293  else
295 }
296 
298  int mx, int my)
299 {
300  int code;
301  MVTable *mv;
302 
303  /* modulo encoding */
304  /* WARNING : you cannot reach all the MVs even with the modulo
305  encoding. This is a somewhat strange compromise they took !!! */
306  if (mx <= -64)
307  mx += 64;
308  else if (mx >= 64)
309  mx -= 64;
310  if (my <= -64)
311  my += 64;
312  else if (my >= 64)
313  my -= 64;
314 
315  mx += 32;
316  my += 32;
317  mv = &ff_mv_tables[s->mv_table_index];
318 
319  code = mv->table_mv_index[(mx << 6) | my];
320  put_bits(&s->pb,
321  mv->table_mv_bits[code],
322  mv->table_mv_code[code]);
323  if (code == mv->n) {
324  /* escape : code literally */
325  put_bits(&s->pb, 6, mx);
326  put_bits(&s->pb, 6, my);
327  }
328 }
329 
331  if (s->mb_x == 0) {
332  if (s->slice_height && (s->mb_y % s->slice_height) == 0) {
333  if(s->msmpeg4_version < 4){
335  }
336  s->first_slice_line = 1;
337  } else {
338  s->first_slice_line = 0;
339  }
340  }
341 }
342 
344 {
345  int range, bit_size, sign, code, bits;
346 
347  if (val == 0) {
348  /* zero vector */
349  code = 0;
350  put_bits(&s->pb, ff_mvtab[code][1], ff_mvtab[code][0]);
351  } else {
352  bit_size = s->f_code - 1;
353  range = 1 << bit_size;
354  if (val <= -64)
355  val += 64;
356  else if (val >= 64)
357  val -= 64;
358 
359  if (val >= 0) {
360  sign = 0;
361  } else {
362  val = -val;
363  sign = 1;
364  }
365  val--;
366  code = (val >> bit_size) + 1;
367  bits = val & (range - 1);
368 
369  put_bits(&s->pb, ff_mvtab[code][1] + 1, (ff_mvtab[code][0] << 1) | sign);
370  if (bit_size > 0) {
371  put_bits(&s->pb, bit_size, bits);
372  }
373  }
374 }
375 
377  int16_t block[6][64],
378  int motion_x, int motion_y)
379 {
380  int cbp, coded_cbp, i;
381  int pred_x, pred_y;
382  uint8_t *coded_block;
383 
385 
386  if (!s->mb_intra) {
387  /* compute cbp */
388  cbp = 0;
389  for (i = 0; i < 6; i++) {
390  if (s->block_last_index[i] >= 0)
391  cbp |= 1 << (5 - i);
392  }
393  if (s->use_skip_mb_code && (cbp | motion_x | motion_y) == 0) {
394  /* skip macroblock */
395  put_bits(&s->pb, 1, 1);
396  s->last_bits++;
397  s->misc_bits++;
398  s->skip_count++;
399 
400  return;
401  }
402  if (s->use_skip_mb_code)
403  put_bits(&s->pb, 1, 0); /* mb coded */
404 
405  if(s->msmpeg4_version<=2){
406  put_bits(&s->pb,
407  ff_v2_mb_type[cbp&3][1],
408  ff_v2_mb_type[cbp&3][0]);
409  if((cbp&3) != 3) coded_cbp= cbp ^ 0x3C;
410  else coded_cbp= cbp;
411 
412  put_bits(&s->pb,
413  ff_h263_cbpy_tab[coded_cbp>>2][1],
414  ff_h263_cbpy_tab[coded_cbp>>2][0]);
415 
416  s->misc_bits += get_bits_diff(s);
417 
418  ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
419  msmpeg4v2_encode_motion(s, motion_x - pred_x);
420  msmpeg4v2_encode_motion(s, motion_y - pred_y);
421  }else{
422  put_bits(&s->pb,
423  ff_table_mb_non_intra[cbp + 64][1],
424  ff_table_mb_non_intra[cbp + 64][0]);
425 
426  s->misc_bits += get_bits_diff(s);
427 
428  /* motion vector */
429  ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
430  ff_msmpeg4_encode_motion(s, motion_x - pred_x,
431  motion_y - pred_y);
432  }
433 
434  s->mv_bits += get_bits_diff(s);
435 
436  for (i = 0; i < 6; i++) {
437  ff_msmpeg4_encode_block(s, block[i], i);
438  }
439  s->p_tex_bits += get_bits_diff(s);
440  } else {
441  /* compute cbp */
442  cbp = 0;
443  coded_cbp = 0;
444  for (i = 0; i < 6; i++) {
445  int val, pred;
446  val = (s->block_last_index[i] >= 1);
447  cbp |= val << (5 - i);
448  if (i < 4) {
449  /* predict value for close blocks only for luma */
450  pred = ff_msmpeg4_coded_block_pred(s, i, &coded_block);
451  *coded_block = val;
452  val = val ^ pred;
453  }
454  coded_cbp |= val << (5 - i);
455  }
456 
457  if(s->msmpeg4_version<=2){
458  if (s->pict_type == AV_PICTURE_TYPE_I) {
459  put_bits(&s->pb,
460  ff_v2_intra_cbpc[cbp&3][1], ff_v2_intra_cbpc[cbp&3][0]);
461  } else {
462  if (s->use_skip_mb_code)
463  put_bits(&s->pb, 1, 0); /* mb coded */
464  put_bits(&s->pb,
465  ff_v2_mb_type[(cbp&3) + 4][1],
466  ff_v2_mb_type[(cbp&3) + 4][0]);
467  }
468  put_bits(&s->pb, 1, 0); /* no AC prediction yet */
469  put_bits(&s->pb,
470  ff_h263_cbpy_tab[cbp>>2][1],
471  ff_h263_cbpy_tab[cbp>>2][0]);
472  }else{
473  if (s->pict_type == AV_PICTURE_TYPE_I) {
474  put_bits(&s->pb,
475  ff_msmp4_mb_i_table[coded_cbp][1], ff_msmp4_mb_i_table[coded_cbp][0]);
476  } else {
477  if (s->use_skip_mb_code)
478  put_bits(&s->pb, 1, 0); /* mb coded */
479  put_bits(&s->pb,
480  ff_table_mb_non_intra[cbp][1],
481  ff_table_mb_non_intra[cbp][0]);
482  }
483  put_bits(&s->pb, 1, 0); /* no AC prediction yet */
484  if(s->inter_intra_pred){
485  s->h263_aic_dir=0;
487  }
488  }
489  s->misc_bits += get_bits_diff(s);
490 
491  for (i = 0; i < 6; i++) {
492  ff_msmpeg4_encode_block(s, block[i], i);
493  }
494  s->i_tex_bits += get_bits_diff(s);
495  s->i_count++;
496  }
497 }
498 
499 static void msmpeg4_encode_dc(MpegEncContext * s, int level, int n, int *dir_ptr)
500 {
501  int sign, code;
502  int pred, av_uninit(extquant);
503  int extrabits = 0;
504 
505  int16_t *dc_val;
506  pred = ff_msmpeg4_pred_dc(s, n, &dc_val, dir_ptr);
507 
508  /* update predictor */
509  if (n < 4) {
510  *dc_val = level * s->y_dc_scale;
511  } else {
512  *dc_val = level * s->c_dc_scale;
513  }
514 
515  /* do the prediction */
516  level -= pred;
517 
518  if(s->msmpeg4_version<=2){
519  if (n < 4) {
520  put_bits(&s->pb,
521  ff_v2_dc_lum_table[level + 256][1],
522  ff_v2_dc_lum_table[level + 256][0]);
523  }else{
524  put_bits(&s->pb,
525  ff_v2_dc_chroma_table[level + 256][1],
526  ff_v2_dc_chroma_table[level + 256][0]);
527  }
528  }else{
529  sign = 0;
530  if (level < 0) {
531  level = -level;
532  sign = 1;
533  }
534  code = level;
535  if (code > DC_MAX)
536  code = DC_MAX;
537  else if( s->msmpeg4_version>=6 ) {
538  if( s->qscale == 1 ) {
539  extquant = (level + 3) & 0x3;
540  code = ((level+3)>>2);
541  } else if( s->qscale == 2 ) {
542  extquant = (level + 1) & 0x1;
543  code = ((level+1)>>1);
544  }
545  }
546 
547  if (s->dc_table_index == 0) {
548  if (n < 4) {
549  put_bits(&s->pb, ff_table0_dc_lum[code][1], ff_table0_dc_lum[code][0]);
550  } else {
551  put_bits(&s->pb, ff_table0_dc_chroma[code][1], ff_table0_dc_chroma[code][0]);
552  }
553  } else {
554  if (n < 4) {
555  put_bits(&s->pb, ff_table1_dc_lum[code][1], ff_table1_dc_lum[code][0]);
556  } else {
557  put_bits(&s->pb, ff_table1_dc_chroma[code][1], ff_table1_dc_chroma[code][0]);
558  }
559  }
560 
561  if(s->msmpeg4_version>=6 && s->qscale<=2)
562  extrabits = 3 - s->qscale;
563 
564  if (code == DC_MAX)
565  put_bits(&s->pb, 8 + extrabits, level);
566  else if(extrabits > 0)//== VC1 && s->qscale<=2
567  put_bits(&s->pb, extrabits, extquant);
568 
569  if (level != 0) {
570  put_bits(&s->pb, 1, sign);
571  }
572  }
573 }
574 
575 /* Encoding of a block; very similar to MPEG-4 except for a different
576  * escape coding (same as H.263) and more VLC tables. */
578 {
579  int level, run, last, i, j, last_index;
580  int last_non_zero, sign, slevel;
581  int code, run_diff, dc_pred_dir;
582  const RLTable *rl;
583  const uint8_t *scantable;
584 
585  if (s->mb_intra) {
586  msmpeg4_encode_dc(s, block[0], n, &dc_pred_dir);
587  i = 1;
588  if (n < 4) {
589  rl = &ff_rl_table[s->rl_table_index];
590  } else {
591  rl = &ff_rl_table[3 + s->rl_chroma_table_index];
592  }
593  run_diff = s->msmpeg4_version>=4;
594  scantable= s->intra_scantable.permutated;
595  } else {
596  i = 0;
597  rl = &ff_rl_table[3 + s->rl_table_index];
598  if(s->msmpeg4_version<=2)
599  run_diff = 0;
600  else
601  run_diff = 1;
602  scantable= s->inter_scantable.permutated;
603  }
604 
605  /* recalculate block_last_index for M$ wmv1 */
606  if(s->msmpeg4_version>=4 && s->msmpeg4_version<6 && s->block_last_index[n]>0){
607  for(last_index=63; last_index>=0; last_index--){
608  if(block[scantable[last_index]]) break;
609  }
610  s->block_last_index[n]= last_index;
611  }else
612  last_index = s->block_last_index[n];
613  /* AC coefs */
614  last_non_zero = i - 1;
615  for (; i <= last_index; i++) {
616  j = scantable[i];
617  level = block[j];
618  if (level) {
619  run = i - last_non_zero - 1;
620  last = (i == last_index);
621  sign = 0;
622  slevel = level;
623  if (level < 0) {
624  sign = 1;
625  level = -level;
626  }
627 
628  if(level<=MAX_LEVEL && run<=MAX_RUN){
629  s->ac_stats[s->mb_intra][n>3][level][run][last]++;
630  }
631 
632  s->ac_stats[s->mb_intra][n > 3][40][63][0]++; //esc3 like
633 
634  code = get_rl_index(rl, last, run, level);
635  put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
636  if (code == rl->n) {
637  int level1, run1;
638 
639  level1 = level - rl->max_level[last][run];
640  if (level1 < 1)
641  goto esc2;
642  code = get_rl_index(rl, last, run, level1);
643  if (code == rl->n) {
644  esc2:
645  put_bits(&s->pb, 1, 0);
646  if (level > MAX_LEVEL)
647  goto esc3;
648  run1 = run - rl->max_run[last][level] - run_diff;
649  if (run1 < 0)
650  goto esc3;
651  code = get_rl_index(rl, last, run1+1, level);
652  if (s->msmpeg4_version == 4 && code == rl->n)
653  goto esc3;
654  code = get_rl_index(rl, last, run1, level);
655  if (code == rl->n) {
656  esc3:
657  /* third escape */
658  put_bits(&s->pb, 1, 0);
659  put_bits(&s->pb, 1, last);
660  if(s->msmpeg4_version>=4){
661  if(s->esc3_level_length==0){
662  s->esc3_level_length=8;
663  s->esc3_run_length= 6;
664  //ESCLVLSZ + ESCRUNSZ
665  if(s->qscale<8)
666  put_bits(&s->pb, 6 + (s->msmpeg4_version>=6), 3);
667  else
668  put_bits(&s->pb, 8, 3);
669  }
670  put_bits(&s->pb, s->esc3_run_length, run);
671  put_bits(&s->pb, 1, sign);
672  put_bits(&s->pb, s->esc3_level_length, level);
673  }else{
674  put_bits(&s->pb, 6, run);
675  put_sbits(&s->pb, 8, slevel);
676  }
677  } else {
678  /* second escape */
679  put_bits(&s->pb, 1, 1);
680  put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
681  put_bits(&s->pb, 1, sign);
682  }
683  } else {
684  /* first escape */
685  put_bits(&s->pb, 1, 1);
686  put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
687  put_bits(&s->pb, 1, sign);
688  }
689  } else {
690  put_bits(&s->pb, 1, sign);
691  }
692  last_non_zero = i;
693  }
694  }
695 }
int inter_intra_pred
Definition: mpegvideo.h:442
const char const char void * val
Definition: avisynth_c.h:771
const char * s
Definition: avisynth_c.h:768
int esc3_level_length
Definition: mpegvideo.h:438
uint32_t ff_v2_dc_lum_table[512][2]
Definition: msmpeg4data.c:34
const uint32_t ff_table_mb_non_intra[128][2]
Definition: msmpeg4data.c:63
static void put_sbits(PutBitContext *pb, int n, int32_t value)
Definition: put_bits.h:240
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:206
const uint32_t ff_table0_dc_lum[120][2]
Definition: msmpeg4data.c:100
Memory handling functions.
uint32_t ff_v2_dc_chroma_table[512][2]
Definition: msmpeg4data.c:35
int msmpeg4_version
0=not msmpeg4, 1=mp41, 2=mp42, 3=mp43/divx3 4=wmv1/7 5=wmv2/8
Definition: mpegvideo.h:436
int num
Numerator.
Definition: rational.h:59
void avpriv_align_put_bits(PutBitContext *s)
Pad the bitstream with zeros up to the next byte boundary.
Definition: bitstream.c:48
Convenience header that includes libavutil's core.
int min_qcoeff
minimum encodable coefficient
Definition: mpegvideo.h:308
mpegvideo header.
#define NB_RL_TABLES
Definition: msmpeg4data.h:60
uint8_t permutated[64]
Definition: idctdsp.h:33
uint8_t run
Definition: svq3.c:206
static uint8_t rl_length[NB_RL_TABLES][MAX_LEVEL+1][MAX_RUN+1][2]
Definition: msmpeg4enc.c:46
int qscale
QP.
Definition: mpegvideo.h:201
RLTable.
Definition: rl.h:39
av_cold void ff_msmpeg4_common_init(MpegEncContext *s)
Definition: msmpeg4.c:109
int16_t * ff_h263_pred_motion(MpegEncContext *s, int block, int dir, int *px, int *py)
Definition: h263.c:307
Macro definitions for various function/variable attributes.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:1898
static int16_t block[64]
Definition: dct.c:115
void ff_mpeg4_clean_buffers(MpegEncContext *s)
Definition: mpeg4video.c:45
void ff_msmpeg4_encode_picture_header(MpegEncContext *s, int picture_number)
Definition: msmpeg4enc.c:224
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
int esc3_run_length
Definition: mpegvideo.h:439
int8_t * max_run[2]
encoding & decoding
Definition: rl.h:47
VC-1 tables.
uint8_t bits
Definition: crc.c:296
static av_cold int init_mv_table(MVTable *tab)
Definition: msmpeg4enc.c:49
const uint8_t ff_v2_intra_cbpc[4][2]
Definition: msmpeg4data.c:1791
uint8_t
#define av_cold
Definition: attributes.h:82
#define av_malloc(s)
uint8_t ff_static_rl_table_store[NB_RL_TABLES][2][2 *MAX_RUN+MAX_LEVEL+3]
Definition: msmpeg4data.c:36
int misc_bits
cbp, mb_type
Definition: mpegvideo.h:352
#define MBAC_BITRATE
Definition: msmpeg4.h:38
MSMPEG4 data tables.
int8_t * max_level[2]
encoding & decoding
Definition: rl.h:46
#define ff_dlog(a,...)
const uint32_t ff_table0_dc_chroma[120][2]
Definition: msmpeg4data.c:133
int mb_height
number of MBs horizontally & vertically
Definition: mpegvideo.h:126
ptrdiff_t size
Definition: opengl_enc.c:101
int max_qcoeff
maximum encodable coefficient
Definition: mpegvideo.h:309
static void msmpeg4_encode_dc(MpegEncContext *s, int level, int n, int *dir_ptr)
Definition: msmpeg4enc.c:499
#define MAX_LEVEL
Definition: rl.h:36
int flipflop_rounding
Definition: mpegvideo.h:435
static void find_best_tables(MpegEncContext *s)
Definition: msmpeg4enc.c:159
static int get_bits_diff(MpegEncContext *s)
Definition: mpegvideo.h:745
int last_non_b_pict_type
used for MPEG-4 gmc B-frames & ratecontrol
Definition: mpegvideo.h:212
const uint16_t ff_msmp4_mb_i_table[64][2]
Definition: msmpeg4data.c:43
void ff_msmpeg4_encode_mb(MpegEncContext *s, int16_t block[6][64], int motion_x, int motion_y)
Definition: msmpeg4enc.c:376
int rl_chroma_table_index
Definition: mpegvideo.h:430
#define AVERROR(e)
Definition: error.h:43
int per_mb_rl_table
Definition: mpegvideo.h:437
rl header.
#define FFMAX(a, b)
Definition: common.h:94
int n
number of entries of table_vlc minus 1
Definition: rl.h:40
const uint8_t ff_v2_mb_type[8][2]
Definition: msmpeg4data.c:1786
int ff_msmpeg4_pred_dc(MpegEncContext *s, int n, int16_t **dc_val_ptr, int *dir_ptr)
Definition: msmpeg4.c:193
#define FFMIN(a, b)
Definition: common.h:96
const uint8_t * table_mvx
Definition: msmpeg4data.h:43
const uint16_t(* table_vlc)[2]
Definition: rl.h:42
const uint8_t * table_mv_bits
Definition: msmpeg4data.h:42
int(* ac_stats)[2][MAX_LEVEL+1][MAX_RUN+1][2]
[mb_intra][isChroma][level][run][last]
Definition: mpegvideo.h:441
av_cold int ff_msmpeg4_encode_init(MpegEncContext *s)
Definition: msmpeg4enc.c:121
int block_last_index[12]
last non zero coefficient in block
Definition: mpegvideo.h:83
int n
Definition: avisynth_c.h:684
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
Definition: avcodec.h:1907
const uint32_t ff_table1_dc_chroma[120][2]
Definition: msmpeg4data.c:201
uint16_t * table_mv_index
Definition: msmpeg4data.h:45
static const float pred[4]
Definition: siprdata.h:259
static const int8_t mv[256][2]
Definition: 4xm.c:77
int first_slice_line
used in MPEG-4 too to handle resync markers
Definition: mpegvideo.h:434
void ff_msmpeg4_encode_block(MpegEncContext *s, int16_t *block, int n)
Definition: msmpeg4enc.c:577
ScanTable intra_scantable
Definition: mpegvideo.h:88
int height
picture size. must be a multiple of 16
Definition: mpegvideo.h:97
void ff_msmpeg4_encode_ext_header(MpegEncContext *s)
Definition: msmpeg4enc.c:284
const uint16_t * table_mv_code
Definition: msmpeg4data.h:41
av_cold int ff_rl_init(RLTable *rl, uint8_t static_store[2][2 *MAX_RUN+MAX_LEVEL+3])
Definition: rl.c:39
#define DC_MAX
Definition: msmpeg4.h:40
const uint32_t ff_table1_dc_lum[120][2]
Definition: msmpeg4data.c:168
static void msmpeg4v2_encode_motion(MpegEncContext *s, int val)
Definition: msmpeg4enc.c:343
int slice_height
in macroblocks
Definition: mpegvideo.h:433
int use_skip_mb_code
Definition: mpegvideo.h:432
MVTable ff_mv_tables[2]
Definition: msmpeg4data.c:1773
int f_code
forward MV resolution
Definition: mpegvideo.h:235
const uint8_t ff_h263_cbpy_tab[16][2]
Definition: h263data.c:84
void ff_msmpeg4_code012(PutBitContext *pb, int n)
Definition: msmpeg4enc.c:70
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
Definition: mpegvideo.h:209
#define II_BITRATE
Definition: msmpeg4.h:37
RLTable ff_rl_table[NB_RL_TABLES]
Definition: msmpeg4data.c:601
uint8_t level
Definition: svq3.c:207
MpegEncContext.
Definition: mpegvideo.h:78
#define MAX_RUN
Definition: rl.h:35
struct AVCodecContext * avctx
Definition: mpegvideo.h:95
PutBitContext pb
bit output
Definition: mpegvideo.h:148
void ff_msmpeg4_handle_slices(MpegEncContext *s)
Definition: msmpeg4enc.c:330
void ff_msmpeg4_encode_motion(MpegEncContext *s, int mx, int my)
Definition: msmpeg4enc.c:297
common internal api header.
int den
Denominator.
Definition: rational.h:60
static int get_rl_index(const RLTable *rl, int last, int run, int level)
Definition: rl.h:76
int last_bits
temp var used for calculating the above vars
Definition: mpegvideo.h:353
int64_t bit_rate
wanted bit rate
Definition: mpegvideo.h:100
int rl_table_index
Definition: mpegvideo.h:429
static const struct twinvq_data tab
#define av_uninit(x)
Definition: attributes.h:148
const uint8_t * table_mvy
Definition: msmpeg4data.h:44
ScanTable inter_scantable
if inter == intra then intra should be used to reduce the cache usage
Definition: mpegvideo.h:87
int ff_msmpeg4_coded_block_pred(MpegEncContext *s, int n, uint8_t **coded_block_ptr)
Definition: msmpeg4.c:153
static int get_size_of_code(MpegEncContext *s, RLTable *rl, int last, int run, int level, int intra)
Definition: msmpeg4enc.c:80
int mv_table_index
Definition: mpegvideo.h:428
int h263_aic_dir
AIC direction: 0 = left, 1 = top.
Definition: mpegvideo.h:376
const uint8_t ff_table_inter_intra[4][2]
Definition: msmpeg4data.c:1844
int dc_table_index
Definition: mpegvideo.h:431
Predicted.
Definition: avutil.h:275
const uint8_t ff_mvtab[33][2]
Definition: h263data.c:90
bitstream writer API