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