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 #if 0
318  if ((unsigned)mx >= 64 ||
319  (unsigned)my >= 64)
320  av_log(s->avctx, AV_LOG_ERROR, "error mx=%d my=%d\n", mx, my);
321 #endif
322  mv = &ff_mv_tables[s->mv_table_index];
323 
324  code = mv->table_mv_index[(mx << 6) | my];
325  put_bits(&s->pb,
326  mv->table_mv_bits[code],
327  mv->table_mv_code[code]);
328  if (code == mv->n) {
329  /* escape : code literally */
330  put_bits(&s->pb, 6, mx);
331  put_bits(&s->pb, 6, my);
332  }
333 }
334 
336  if (s->mb_x == 0) {
337  if (s->slice_height && (s->mb_y % s->slice_height) == 0) {
338  if(s->msmpeg4_version < 4){
340  }
341  s->first_slice_line = 1;
342  } else {
343  s->first_slice_line = 0;
344  }
345  }
346 }
347 
349 {
350  int range, bit_size, sign, code, bits;
351 
352  if (val == 0) {
353  /* zero vector */
354  code = 0;
355  put_bits(&s->pb, ff_mvtab[code][1], ff_mvtab[code][0]);
356  } else {
357  bit_size = s->f_code - 1;
358  range = 1 << bit_size;
359  if (val <= -64)
360  val += 64;
361  else if (val >= 64)
362  val -= 64;
363 
364  if (val >= 0) {
365  sign = 0;
366  } else {
367  val = -val;
368  sign = 1;
369  }
370  val--;
371  code = (val >> bit_size) + 1;
372  bits = val & (range - 1);
373 
374  put_bits(&s->pb, ff_mvtab[code][1] + 1, (ff_mvtab[code][0] << 1) | sign);
375  if (bit_size > 0) {
376  put_bits(&s->pb, bit_size, bits);
377  }
378  }
379 }
380 
382  int16_t block[6][64],
383  int motion_x, int motion_y)
384 {
385  int cbp, coded_cbp, i;
386  int pred_x, pred_y;
387  uint8_t *coded_block;
388 
390 
391  if (!s->mb_intra) {
392  /* compute cbp */
393  cbp = 0;
394  for (i = 0; i < 6; i++) {
395  if (s->block_last_index[i] >= 0)
396  cbp |= 1 << (5 - i);
397  }
398  if (s->use_skip_mb_code && (cbp | motion_x | motion_y) == 0) {
399  /* skip macroblock */
400  put_bits(&s->pb, 1, 1);
401  s->last_bits++;
402  s->misc_bits++;
403  s->skip_count++;
404 
405  return;
406  }
407  if (s->use_skip_mb_code)
408  put_bits(&s->pb, 1, 0); /* mb coded */
409 
410  if(s->msmpeg4_version<=2){
411  put_bits(&s->pb,
412  ff_v2_mb_type[cbp&3][1],
413  ff_v2_mb_type[cbp&3][0]);
414  if((cbp&3) != 3) coded_cbp= cbp ^ 0x3C;
415  else coded_cbp= cbp;
416 
417  put_bits(&s->pb,
418  ff_h263_cbpy_tab[coded_cbp>>2][1],
419  ff_h263_cbpy_tab[coded_cbp>>2][0]);
420 
421  s->misc_bits += get_bits_diff(s);
422 
423  ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
424  msmpeg4v2_encode_motion(s, motion_x - pred_x);
425  msmpeg4v2_encode_motion(s, motion_y - pred_y);
426  }else{
427  put_bits(&s->pb,
428  ff_table_mb_non_intra[cbp + 64][1],
429  ff_table_mb_non_intra[cbp + 64][0]);
430 
431  s->misc_bits += get_bits_diff(s);
432 
433  /* motion vector */
434  ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
435  ff_msmpeg4_encode_motion(s, motion_x - pred_x,
436  motion_y - pred_y);
437  }
438 
439  s->mv_bits += get_bits_diff(s);
440 
441  for (i = 0; i < 6; i++) {
442  ff_msmpeg4_encode_block(s, block[i], i);
443  }
444  s->p_tex_bits += get_bits_diff(s);
445  } else {
446  /* compute cbp */
447  cbp = 0;
448  coded_cbp = 0;
449  for (i = 0; i < 6; i++) {
450  int val, pred;
451  val = (s->block_last_index[i] >= 1);
452  cbp |= val << (5 - i);
453  if (i < 4) {
454  /* predict value for close blocks only for luma */
455  pred = ff_msmpeg4_coded_block_pred(s, i, &coded_block);
456  *coded_block = val;
457  val = val ^ pred;
458  }
459  coded_cbp |= val << (5 - i);
460  }
461 
462  if(s->msmpeg4_version<=2){
463  if (s->pict_type == AV_PICTURE_TYPE_I) {
464  put_bits(&s->pb,
465  ff_v2_intra_cbpc[cbp&3][1], ff_v2_intra_cbpc[cbp&3][0]);
466  } else {
467  if (s->use_skip_mb_code)
468  put_bits(&s->pb, 1, 0); /* mb coded */
469  put_bits(&s->pb,
470  ff_v2_mb_type[(cbp&3) + 4][1],
471  ff_v2_mb_type[(cbp&3) + 4][0]);
472  }
473  put_bits(&s->pb, 1, 0); /* no AC prediction yet */
474  put_bits(&s->pb,
475  ff_h263_cbpy_tab[cbp>>2][1],
476  ff_h263_cbpy_tab[cbp>>2][0]);
477  }else{
478  if (s->pict_type == AV_PICTURE_TYPE_I) {
479  put_bits(&s->pb,
480  ff_msmp4_mb_i_table[coded_cbp][1], ff_msmp4_mb_i_table[coded_cbp][0]);
481  } else {
482  if (s->use_skip_mb_code)
483  put_bits(&s->pb, 1, 0); /* mb coded */
484  put_bits(&s->pb,
485  ff_table_mb_non_intra[cbp][1],
486  ff_table_mb_non_intra[cbp][0]);
487  }
488  put_bits(&s->pb, 1, 0); /* no AC prediction yet */
489  if(s->inter_intra_pred){
490  s->h263_aic_dir=0;
492  }
493  }
494  s->misc_bits += get_bits_diff(s);
495 
496  for (i = 0; i < 6; i++) {
497  ff_msmpeg4_encode_block(s, block[i], i);
498  }
499  s->i_tex_bits += get_bits_diff(s);
500  s->i_count++;
501  }
502 }
503 
504 static void msmpeg4_encode_dc(MpegEncContext * s, int level, int n, int *dir_ptr)
505 {
506  int sign, code;
507  int pred, av_uninit(extquant);
508  int extrabits = 0;
509 
510  int16_t *dc_val;
511  pred = ff_msmpeg4_pred_dc(s, n, &dc_val, dir_ptr);
512 
513  /* update predictor */
514  if (n < 4) {
515  *dc_val = level * s->y_dc_scale;
516  } else {
517  *dc_val = level * s->c_dc_scale;
518  }
519 
520  /* do the prediction */
521  level -= pred;
522 
523  if(s->msmpeg4_version<=2){
524  if (n < 4) {
525  put_bits(&s->pb,
526  ff_v2_dc_lum_table[level + 256][1],
527  ff_v2_dc_lum_table[level + 256][0]);
528  }else{
529  put_bits(&s->pb,
530  ff_v2_dc_chroma_table[level + 256][1],
531  ff_v2_dc_chroma_table[level + 256][0]);
532  }
533  }else{
534  sign = 0;
535  if (level < 0) {
536  level = -level;
537  sign = 1;
538  }
539  code = level;
540  if (code > DC_MAX)
541  code = DC_MAX;
542  else if( s->msmpeg4_version>=6 ) {
543  if( s->qscale == 1 ) {
544  extquant = (level + 3) & 0x3;
545  code = ((level+3)>>2);
546  } else if( s->qscale == 2 ) {
547  extquant = (level + 1) & 0x1;
548  code = ((level+1)>>1);
549  }
550  }
551 
552  if (s->dc_table_index == 0) {
553  if (n < 4) {
554  put_bits(&s->pb, ff_table0_dc_lum[code][1], ff_table0_dc_lum[code][0]);
555  } else {
556  put_bits(&s->pb, ff_table0_dc_chroma[code][1], ff_table0_dc_chroma[code][0]);
557  }
558  } else {
559  if (n < 4) {
560  put_bits(&s->pb, ff_table1_dc_lum[code][1], ff_table1_dc_lum[code][0]);
561  } else {
562  put_bits(&s->pb, ff_table1_dc_chroma[code][1], ff_table1_dc_chroma[code][0]);
563  }
564  }
565 
566  if(s->msmpeg4_version>=6 && s->qscale<=2)
567  extrabits = 3 - s->qscale;
568 
569  if (code == DC_MAX)
570  put_bits(&s->pb, 8 + extrabits, level);
571  else if(extrabits > 0)//== VC1 && s->qscale<=2
572  put_bits(&s->pb, extrabits, extquant);
573 
574  if (level != 0) {
575  put_bits(&s->pb, 1, sign);
576  }
577  }
578 }
579 
580 /* Encoding of a block; very similar to MPEG-4 except for a different
581  * escape coding (same as H.263) and more VLC tables. */
583 {
584  int level, run, last, i, j, last_index;
585  int last_non_zero, sign, slevel;
586  int code, run_diff, dc_pred_dir;
587  const RLTable *rl;
588  const uint8_t *scantable;
589 
590  if (s->mb_intra) {
591  msmpeg4_encode_dc(s, block[0], n, &dc_pred_dir);
592  i = 1;
593  if (n < 4) {
594  rl = &ff_rl_table[s->rl_table_index];
595  } else {
596  rl = &ff_rl_table[3 + s->rl_chroma_table_index];
597  }
598  run_diff = s->msmpeg4_version>=4;
599  scantable= s->intra_scantable.permutated;
600  } else {
601  i = 0;
602  rl = &ff_rl_table[3 + s->rl_table_index];
603  if(s->msmpeg4_version<=2)
604  run_diff = 0;
605  else
606  run_diff = 1;
607  scantable= s->inter_scantable.permutated;
608  }
609 
610  /* recalculate block_last_index for M$ wmv1 */
611  if(s->msmpeg4_version>=4 && s->msmpeg4_version<6 && s->block_last_index[n]>0){
612  for(last_index=63; last_index>=0; last_index--){
613  if(block[scantable[last_index]]) break;
614  }
615  s->block_last_index[n]= last_index;
616  }else
617  last_index = s->block_last_index[n];
618  /* AC coefs */
619  last_non_zero = i - 1;
620  for (; i <= last_index; i++) {
621  j = scantable[i];
622  level = block[j];
623  if (level) {
624  run = i - last_non_zero - 1;
625  last = (i == last_index);
626  sign = 0;
627  slevel = level;
628  if (level < 0) {
629  sign = 1;
630  level = -level;
631  }
632 
633  if(level<=MAX_LEVEL && run<=MAX_RUN){
634  s->ac_stats[s->mb_intra][n>3][level][run][last]++;
635  }
636 
637  s->ac_stats[s->mb_intra][n > 3][40][63][0]++; //esc3 like
638 
639  code = get_rl_index(rl, last, run, level);
640  put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
641  if (code == rl->n) {
642  int level1, run1;
643 
644  level1 = level - rl->max_level[last][run];
645  if (level1 < 1)
646  goto esc2;
647  code = get_rl_index(rl, last, run, level1);
648  if (code == rl->n) {
649  esc2:
650  put_bits(&s->pb, 1, 0);
651  if (level > MAX_LEVEL)
652  goto esc3;
653  run1 = run - rl->max_run[last][level] - run_diff;
654  if (run1 < 0)
655  goto esc3;
656  code = get_rl_index(rl, last, run1+1, level);
657  if (s->msmpeg4_version == 4 && code == rl->n)
658  goto esc3;
659  code = get_rl_index(rl, last, run1, level);
660  if (code == rl->n) {
661  esc3:
662  /* third escape */
663  put_bits(&s->pb, 1, 0);
664  put_bits(&s->pb, 1, last);
665  if(s->msmpeg4_version>=4){
666  if(s->esc3_level_length==0){
667  s->esc3_level_length=8;
668  s->esc3_run_length= 6;
669  //ESCLVLSZ + ESCRUNSZ
670  if(s->qscale<8)
671  put_bits(&s->pb, 6 + (s->msmpeg4_version>=6), 3);
672  else
673  put_bits(&s->pb, 8, 3);
674  }
675  put_bits(&s->pb, s->esc3_run_length, run);
676  put_bits(&s->pb, 1, sign);
677  put_bits(&s->pb, s->esc3_level_length, level);
678  }else{
679  put_bits(&s->pb, 6, run);
680  put_sbits(&s->pb, 8, slevel);
681  }
682  } else {
683  /* second escape */
684  put_bits(&s->pb, 1, 1);
685  put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
686  put_bits(&s->pb, 1, sign);
687  }
688  } else {
689  /* first escape */
690  put_bits(&s->pb, 1, 1);
691  put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
692  put_bits(&s->pb, 1, sign);
693  }
694  } else {
695  put_bits(&s->pb, 1, sign);
696  }
697  last_non_zero = i;
698  }
699  }
700 }
int inter_intra_pred
Definition: mpegvideo.h:441
const char const char void * val
Definition: avisynth_c.h:634
const char * s
Definition: avisynth_c.h:631
int esc3_level_length
Definition: mpegvideo.h:437
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:200
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:435
int num
numerator
Definition: rational.h:44
void avpriv_align_put_bits(PutBitContext *s)
Pad the bitstream with zeros up to the next byte boundary.
Definition: bitstream.c:49
external API header
int min_qcoeff
minimum encodable coefficient
Definition: mpegvideo.h:308
mpegvideo header.
#define NB_RL_TABLES
Definition: msmpeg4data.h:59
uint8_t permutated[64]
Definition: idctdsp.h:31
uint8_t run
Definition: svq3.c:192
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:310
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:1785
static int16_t block[64]
Definition: dct.c:113
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:438
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:504
#define MAX_LEVEL
Definition: rl.h:36
int flipflop_rounding
Definition: mpegvideo.h:434
#define av_log(a,...)
static void find_best_tables(MpegEncContext *s)
Definition: msmpeg4enc.c:159
static int get_bits_diff(MpegEncContext *s)
Definition: mpegvideo.h:743
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
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
void ff_msmpeg4_encode_mb(MpegEncContext *s, int16_t block[6][64], int motion_x, int motion_y)
Definition: msmpeg4enc.c:381
int rl_chroma_table_index
Definition: mpegvideo.h:429
#define AVERROR(e)
Definition: error.h:43
int per_mb_rl_table
Definition: mpegvideo.h:436
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:42
const uint16_t(* table_vlc)[2]
Definition: rl.h:42
const uint8_t * table_mv_bits
Definition: msmpeg4data.h:41
int(* ac_stats)[2][MAX_LEVEL+1][MAX_RUN+1][2]
[mb_intra][isChroma][level][run][last]
Definition: mpegvideo.h:440
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:547
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
Definition: avcodec.h:1794
const uint32_t ff_table1_dc_chroma[120][2]
Definition: msmpeg4data.c:201
uint16_t * table_mv_index
Definition: msmpeg4data.h:44
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:433
void ff_msmpeg4_encode_block(MpegEncContext *s, int16_t *block, int n)
Definition: msmpeg4enc.c:582
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:40
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:348
int slice_height
in macroblocks
Definition: mpegvideo.h:432
int use_skip_mb_code
Definition: mpegvideo.h:431
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:193
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:335
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:45
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:428
static const struct twinvq_data tab
#define av_uninit(x)
Definition: attributes.h:149
const uint8_t * table_mvy
Definition: msmpeg4data.h:43
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:427
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:430
Predicted.
Definition: avutil.h:267
const uint8_t ff_mvtab[33][2]
Definition: h263data.c:90
bitstream writer API