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;
284 
285  if (s->avctx->framerate.num > 0 && s->avctx->framerate.den > 0)
286  fps = s->avctx->framerate.num / s->avctx->framerate.den;
287  else {
289  fps = s->avctx->time_base.den / s->avctx->time_base.num
290 #if FF_API_TICKS_PER_FRAME
291  / FFMAX(s->avctx->ticks_per_frame, 1)
292 #endif
293  ;
295  }
296 
297  put_bits(&s->pb, 5, FFMIN(fps, 31)); //yes 29.97 -> 29
298 
299  put_bits(&s->pb, 11, FFMIN(s->bit_rate / 1024, 2047));
300 
301  if (s->msmpeg4_version >= 3)
302  put_bits(&s->pb, 1, s->flipflop_rounding);
303  else
304  av_assert0(!s->flipflop_rounding);
305 }
306 
308  int mx, int my)
309 {
310  int code;
311  MVTable *mv;
312 
313  /* modulo encoding */
314  /* WARNING : you cannot reach all the MVs even with the modulo
315  encoding. This is a somewhat strange compromise they took !!! */
316  if (mx <= -64)
317  mx += 64;
318  else if (mx >= 64)
319  mx -= 64;
320  if (my <= -64)
321  my += 64;
322  else if (my >= 64)
323  my -= 64;
324 
325  mx += 32;
326  my += 32;
327  mv = &ff_mv_tables[s->mv_table_index];
328 
329  code = mv->table_mv_index[(mx << 6) | my];
330  put_bits(&s->pb,
331  mv->table_mv_bits[code],
332  mv->table_mv_code[code]);
334  /* escape : code literally */
335  put_bits(&s->pb, 6, mx);
336  put_bits(&s->pb, 6, my);
337  }
338 }
339 
341  if (s->mb_x == 0) {
342  if (s->slice_height && (s->mb_y % s->slice_height) == 0) {
343  if(s->msmpeg4_version < 4){
345  }
346  s->first_slice_line = 1;
347  } else {
348  s->first_slice_line = 0;
349  }
350  }
351 }
352 
354 {
355  int range, bit_size, sign, code, bits;
356 
357  if (val == 0) {
358  /* zero vector */
359  code = 0;
360  put_bits(&s->pb, ff_mvtab[code][1], ff_mvtab[code][0]);
361  } else {
362  bit_size = s->f_code - 1;
363  range = 1 << bit_size;
364  if (val <= -64)
365  val += 64;
366  else if (val >= 64)
367  val -= 64;
368 
369  if (val >= 0) {
370  sign = 0;
371  } else {
372  val = -val;
373  sign = 1;
374  }
375  val--;
376  code = (val >> bit_size) + 1;
377  bits = val & (range - 1);
378 
379  put_bits(&s->pb, ff_mvtab[code][1] + 1, (ff_mvtab[code][0] << 1) | sign);
380  if (bit_size > 0) {
381  put_bits(&s->pb, bit_size, bits);
382  }
383  }
384 }
385 
387  int16_t block[6][64],
388  int motion_x, int motion_y)
389 {
390  int cbp, coded_cbp, i;
391  int pred_x, pred_y;
392  uint8_t *coded_block;
393 
395 
396  if (!s->mb_intra) {
397  /* compute cbp */
398  cbp = 0;
399  for (i = 0; i < 6; i++) {
400  if (s->block_last_index[i] >= 0)
401  cbp |= 1 << (5 - i);
402  }
403  if (s->use_skip_mb_code && (cbp | motion_x | motion_y) == 0) {
404  /* skip macroblock */
405  put_bits(&s->pb, 1, 1);
406  s->last_bits++;
407  s->misc_bits++;
408  s->skip_count++;
409 
410  return;
411  }
412  if (s->use_skip_mb_code)
413  put_bits(&s->pb, 1, 0); /* mb coded */
414 
415  if(s->msmpeg4_version<=2){
416  put_bits(&s->pb,
417  ff_v2_mb_type[cbp&3][1],
418  ff_v2_mb_type[cbp&3][0]);
419  if((cbp&3) != 3) coded_cbp= cbp ^ 0x3C;
420  else coded_cbp= cbp;
421 
422  put_bits(&s->pb,
423  ff_h263_cbpy_tab[coded_cbp>>2][1],
424  ff_h263_cbpy_tab[coded_cbp>>2][0]);
425 
426  s->misc_bits += get_bits_diff(s);
427 
428  ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
429  msmpeg4v2_encode_motion(s, motion_x - pred_x);
430  msmpeg4v2_encode_motion(s, motion_y - pred_y);
431  }else{
432  put_bits(&s->pb,
433  ff_table_mb_non_intra[cbp + 64][1],
434  ff_table_mb_non_intra[cbp + 64][0]);
435 
436  s->misc_bits += get_bits_diff(s);
437 
438  /* motion vector */
439  ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
440  ff_msmpeg4_encode_motion(s, motion_x - pred_x,
441  motion_y - pred_y);
442  }
443 
444  s->mv_bits += get_bits_diff(s);
445 
446  for (i = 0; i < 6; i++) {
448  }
449  s->p_tex_bits += get_bits_diff(s);
450  } else {
451  /* compute cbp */
452  cbp = 0;
453  coded_cbp = 0;
454  for (i = 0; i < 6; i++) {
455  int val, pred;
456  val = (s->block_last_index[i] >= 1);
457  cbp |= val << (5 - i);
458  if (i < 4) {
459  /* predict value for close blocks only for luma */
460  pred = ff_msmpeg4_coded_block_pred(s, i, &coded_block);
461  *coded_block = val;
462  val = val ^ pred;
463  }
464  coded_cbp |= val << (5 - i);
465  }
466 
467  if(s->msmpeg4_version<=2){
468  if (s->pict_type == AV_PICTURE_TYPE_I) {
469  put_bits(&s->pb,
470  ff_v2_intra_cbpc[cbp&3][1], ff_v2_intra_cbpc[cbp&3][0]);
471  } else {
472  if (s->use_skip_mb_code)
473  put_bits(&s->pb, 1, 0); /* mb coded */
474  put_bits(&s->pb,
475  ff_v2_mb_type[(cbp&3) + 4][1],
476  ff_v2_mb_type[(cbp&3) + 4][0]);
477  }
478  put_bits(&s->pb, 1, 0); /* no AC prediction yet */
479  put_bits(&s->pb,
480  ff_h263_cbpy_tab[cbp>>2][1],
481  ff_h263_cbpy_tab[cbp>>2][0]);
482  }else{
483  if (s->pict_type == AV_PICTURE_TYPE_I) {
484  put_bits(&s->pb,
485  ff_msmp4_mb_i_table[coded_cbp][1], ff_msmp4_mb_i_table[coded_cbp][0]);
486  } else {
487  if (s->use_skip_mb_code)
488  put_bits(&s->pb, 1, 0); /* mb coded */
489  put_bits(&s->pb,
490  ff_table_mb_non_intra[cbp][1],
491  ff_table_mb_non_intra[cbp][0]);
492  }
493  put_bits(&s->pb, 1, 0); /* no AC prediction yet */
494  if(s->inter_intra_pred){
495  s->h263_aic_dir=0;
496  put_bits(&s->pb, ff_table_inter_intra[s->h263_aic_dir][1], ff_table_inter_intra[s->h263_aic_dir][0]);
497  }
498  }
499  s->misc_bits += get_bits_diff(s);
500 
501  for (i = 0; i < 6; i++) {
503  }
504  s->i_tex_bits += get_bits_diff(s);
505  s->i_count++;
506  }
507 }
508 
509 static void msmpeg4_encode_dc(MpegEncContext * s, int level, int n, int *dir_ptr)
510 {
511  int sign, code;
512  int pred;
513 
514  int16_t *dc_val;
515  pred = ff_msmpeg4_pred_dc(s, n, &dc_val, dir_ptr);
516 
517  /* update predictor */
518  if (n < 4) {
519  *dc_val = level * s->y_dc_scale;
520  } else {
521  *dc_val = level * s->c_dc_scale;
522  }
523 
524  /* do the prediction */
525  level -= pred;
526 
527  if(s->msmpeg4_version<=2){
528  if (n < 4) {
529  put_bits(&s->pb,
530  ff_v2_dc_lum_table[level + 256][1],
531  ff_v2_dc_lum_table[level + 256][0]);
532  }else{
533  put_bits(&s->pb,
534  ff_v2_dc_chroma_table[level + 256][1],
535  ff_v2_dc_chroma_table[level + 256][0]);
536  }
537  }else{
538  sign = 0;
539  if (level < 0) {
540  level = -level;
541  sign = 1;
542  }
543  code = level;
544  if (code > DC_MAX)
545  code = DC_MAX;
546 
547  if (s->dc_table_index == 0) {
548  if (n < 4) {
550  } else {
552  }
553  } else {
554  if (n < 4) {
556  } else {
558  }
559  }
560 
561  if (code == DC_MAX)
562  put_bits(&s->pb, 8, level);
563 
564  if (level != 0) {
565  put_bits(&s->pb, 1, sign);
566  }
567  }
568 }
569 
570 /* Encoding of a block; very similar to MPEG-4 except for a different
571  * escape coding (same as H.263) and more VLC tables. */
573 {
574  MSMPEG4EncContext *const ms = (MSMPEG4EncContext*)s;
575  int level, run, last, i, j, last_index;
576  int last_non_zero, sign, slevel;
577  int code, run_diff, dc_pred_dir;
578  const RLTable *rl;
579  const uint8_t *scantable;
580 
581  if (s->mb_intra) {
582  msmpeg4_encode_dc(s, block[0], n, &dc_pred_dir);
583  i = 1;
584  if (n < 4) {
585  rl = &ff_rl_table[s->rl_table_index];
586  } else {
587  rl = &ff_rl_table[3 + s->rl_chroma_table_index];
588  }
589  run_diff = s->msmpeg4_version>=4;
590  scantable= s->intra_scantable.permutated;
591  } else {
592  i = 0;
593  rl = &ff_rl_table[3 + s->rl_table_index];
594  if(s->msmpeg4_version<=2)
595  run_diff = 0;
596  else
597  run_diff = 1;
598  scantable= s->inter_scantable.permutated;
599  }
600 
601  /* recalculate block_last_index for M$ wmv1 */
602  if (s->msmpeg4_version >= 4 && s->block_last_index[n] > 0) {
603  for(last_index=63; last_index>=0; last_index--){
604  if(block[scantable[last_index]]) break;
605  }
606  s->block_last_index[n]= last_index;
607  }else
608  last_index = s->block_last_index[n];
609  /* AC coefs */
610  last_non_zero = i - 1;
611  for (; i <= last_index; i++) {
612  j = scantable[i];
613  level = block[j];
614  if (level) {
615  run = i - last_non_zero - 1;
616  last = (i == last_index);
617  sign = 0;
618  slevel = level;
619  if (level < 0) {
620  sign = 1;
621  level = -level;
622  }
623 
624  if(level<=MAX_LEVEL && run<=MAX_RUN){
625  ms->ac_stats[s->mb_intra][n>3][level][run][last]++;
626  }
627 
628  ms->ac_stats[s->mb_intra][n > 3][40][63][0]++; //esc3 like
629 
630  code = get_rl_index(rl, last, run, level);
631  put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
632  if (code == rl->n) {
633  int level1, run1;
634 
635  level1 = level - rl->max_level[last][run];
636  if (level1 < 1)
637  goto esc2;
638  code = get_rl_index(rl, last, run, level1);
639  if (code == rl->n) {
640  esc2:
641  put_bits(&s->pb, 1, 0);
642  if (level > MAX_LEVEL)
643  goto esc3;
644  run1 = run - rl->max_run[last][level] - run_diff;
645  if (run1 < 0)
646  goto esc3;
647  code = get_rl_index(rl, last, run1+1, level);
648  if (s->msmpeg4_version == 4 && code == rl->n)
649  goto esc3;
650  code = get_rl_index(rl, last, run1, level);
651  if (code == rl->n) {
652  esc3:
653  /* third escape */
654  put_bits(&s->pb, 1, 0);
655  put_bits(&s->pb, 1, last);
656  if(s->msmpeg4_version>=4){
657  if(s->esc3_level_length==0){
658  s->esc3_level_length=8;
659  s->esc3_run_length= 6;
660  //ESCLVLSZ + ESCRUNSZ
661  if(s->qscale<8)
662  put_bits(&s->pb, 6, 3);
663  else
664  put_bits(&s->pb, 8, 3);
665  }
666  put_bits(&s->pb, s->esc3_run_length, run);
667  put_bits(&s->pb, 1, sign);
668  put_bits(&s->pb, s->esc3_level_length, level);
669  }else{
670  put_bits(&s->pb, 6, run);
671  put_sbits(&s->pb, 8, slevel);
672  }
673  } else {
674  /* second escape */
675  put_bits(&s->pb, 1, 1);
676  put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
677  put_bits(&s->pb, 1, sign);
678  }
679  } else {
680  /* first escape */
681  put_bits(&s->pb, 1, 1);
682  put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
683  put_bits(&s->pb, 1, sign);
684  }
685  } else {
686  put_bits(&s->pb, 1, sign);
687  }
688  last_non_zero = i;
689  }
690  }
691 }
692 
694  .p.name = "msmpeg4v2",
695  CODEC_LONG_NAME("MPEG-4 part 2 Microsoft variant version 2"),
696  .p.type = AVMEDIA_TYPE_VIDEO,
697  .p.id = AV_CODEC_ID_MSMPEG4V2,
698  .p.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
699  .p.priv_class = &ff_mpv_enc_class,
700  .p.capabilities = AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
701  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
702  .priv_data_size = sizeof(MSMPEG4EncContext),
705  .close = ff_mpv_encode_end,
706 };
707 
709  .p.name = "msmpeg4",
710  CODEC_LONG_NAME("MPEG-4 part 2 Microsoft variant version 3"),
711  .p.type = AVMEDIA_TYPE_VIDEO,
712  .p.id = AV_CODEC_ID_MSMPEG4V3,
713  .p.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
714  .p.priv_class = &ff_mpv_enc_class,
715  .p.capabilities = AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
716  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
717  .priv_data_size = sizeof(MSMPEG4EncContext),
720  .close = ff_mpv_encode_end,
721 };
722 
724  .p.name = "wmv1",
725  CODEC_LONG_NAME("Windows Media Video 7"),
726  .p.type = AVMEDIA_TYPE_VIDEO,
727  .p.id = AV_CODEC_ID_WMV1,
728  .p.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
729  .p.priv_class = &ff_mpv_enc_class,
730  .p.capabilities = AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
731  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
732  .priv_data_size = sizeof(MSMPEG4EncContext),
735  .close = ff_mpv_encode_end,
736 };
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:73
h263data.h
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
ff_mpv_enc_class
const AVClass ff_mpv_enc_class
Definition: mpegvideo_enc.c:100
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:340
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:708
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:222
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:386
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:1754
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
tab
static const struct twinvq_data tab
Definition: twinvq_data.h:10345
ff_wmv1_encoder
const FFCodec ff_wmv1_encoder
Definition: msmpeg4enc.c:723
val
static double val(void *priv, double ch)
Definition: aeval.c:78
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:203
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:198
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:159
bits
uint8_t bits
Definition: vp3data.h:128
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
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:307
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
AV_ONCE_INIT
#define AV_ONCE_INIT
Definition: thread.h:201
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:279
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:987
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:693
AVOnce
#define AVOnce
Definition: thread.h:200
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
range
enum AVColorRange range
Definition: mediacodec_wrapper.c:2646
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:509
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:255
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:194
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:572
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
FF_DISABLE_DEPRECATION_WARNINGS
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:72
msmpeg4v2_encode_motion
static void msmpeg4v2_encode_motion(MpegEncContext *s, int val)
Definition: msmpeg4enc.c:353
AV_PICTURE_TYPE_P
@ AV_PICTURE_TYPE_P
Predicted.
Definition: avutil.h:280
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:310
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