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