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, 2, 2 | (n >= 2));
75  }
76 }
77 
78 static int get_size_of_code(const RLTable *rl, int last, int run,
79  int level, int intra)
80 {
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 uint16_t mv_index_tables[2][4096];
124  init_mv_table(&ff_mv_tables[0], mv_index_tables[0]);
125  init_mv_table(&ff_mv_tables[1], mv_index_tables[1]);
126 
127  for (int i = 0; i < NB_RL_TABLES; i++) {
128  for (int level = 1; level <= MAX_LEVEL; level++) {
129  for (int run = 0; run <= MAX_RUN; run++) {
130  for (int last = 0; last < 2; last++) {
131  rl_length[i][level][run][last] = get_size_of_code(&ff_rl_table[i], last, run, level, 0);
132  }
133  }
134  }
135  }
136 }
137 
139 {
140  static AVOnce init_static_once = AV_ONCE_INIT;
141 
143  if (s->msmpeg4_version >= MSMP4_WMV1) {
144  s->min_qcoeff = -255;
145  s->max_qcoeff = 255;
146  }
147 
148  /* init various encoding tables */
149  ff_thread_once(&init_static_once, msmpeg4_encode_init_static);
150 }
151 
153 {
154  MpegEncContext *const s = &ms->s;
155  int i;
156  int best = 0, best_size = INT_MAX;
157  int chroma_best = 0, best_chroma_size = INT_MAX;
158 
159  for(i=0; i<3; i++){
160  int level;
161  int chroma_size=0;
162  int size=0;
163 
164  if(i>0){// ;)
165  size++;
166  chroma_size++;
167  }
168  for(level=0; level<=MAX_LEVEL; level++){
169  int run;
170  for(run=0; run<=MAX_RUN; run++){
171  int last;
172  const int last_size= size + chroma_size;
173  for(last=0; last<2; last++){
174  int inter_count = ms->ac_stats[0][0][level][run][last] + ms->ac_stats[0][1][level][run][last];
175  int intra_luma_count = ms->ac_stats[1][0][level][run][last];
176  int intra_chroma_count= ms->ac_stats[1][1][level][run][last];
177 
178  if(s->pict_type==AV_PICTURE_TYPE_I){
179  size += intra_luma_count *rl_length[i ][level][run][last];
180  chroma_size+= intra_chroma_count*rl_length[i+3][level][run][last];
181  }else{
182  size+= intra_luma_count *rl_length[i ][level][run][last]
183  +intra_chroma_count*rl_length[i+3][level][run][last]
184  +inter_count *rl_length[i+3][level][run][last];
185  }
186  }
187  if(last_size == size+chroma_size) break;
188  }
189  }
190  if(size<best_size){
191  best_size= size;
192  best= i;
193  }
194  if(chroma_size<best_chroma_size){
195  best_chroma_size= chroma_size;
196  chroma_best= i;
197  }
198  }
199 
200  if(s->pict_type==AV_PICTURE_TYPE_P) chroma_best= best;
201 
202  memset(ms->ac_stats, 0, sizeof(ms->ac_stats));
203 
204  s->rl_table_index = best;
205  s->rl_chroma_table_index= chroma_best;
206 
207  if(s->pict_type != s->last_non_b_pict_type){
208  s->rl_table_index= 2;
209  if(s->pict_type==AV_PICTURE_TYPE_I)
210  s->rl_chroma_table_index= 1;
211  else
212  s->rl_chroma_table_index= 2;
213  }
214 
215 }
216 
217 /* write MSMPEG4 compatible frame header */
219 {
220  MSMPEG4EncContext *const ms = (MSMPEG4EncContext*)s;
221 
222  find_best_tables(ms);
223 
224  align_put_bits(&s->pb);
225  put_bits(&s->pb, 2, s->pict_type - 1);
226 
227  put_bits(&s->pb, 5, s->qscale);
228  if (s->msmpeg4_version <= MSMP4_V2) {
229  s->rl_table_index = 2;
230  s->rl_chroma_table_index = 2;
231  }
232 
233  s->dc_table_index = 1;
234  s->mv_table_index = 1; /* only if P-frame */
235  s->use_skip_mb_code = 1; /* only if P-frame */
236  s->per_mb_rl_table = 0;
237  if (s->msmpeg4_version == MSMP4_WMV1)
238  s->inter_intra_pred= (s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE && s->pict_type==AV_PICTURE_TYPE_P);
239  ff_dlog(s, "%d %"PRId64" %d %d %d\n", s->pict_type, s->bit_rate,
240  s->inter_intra_pred, s->width, s->height);
241 
242  if (s->pict_type == AV_PICTURE_TYPE_I) {
243  s->slice_height= s->mb_height/1;
244  put_bits(&s->pb, 5, 0x16 + s->mb_height/s->slice_height);
245 
246  if (s->msmpeg4_version == MSMP4_WMV1) {
248  if(s->bit_rate>MBAC_BITRATE)
249  put_bits(&s->pb, 1, s->per_mb_rl_table);
250  }
251 
252  if (s->msmpeg4_version > MSMP4_V2) {
253  if(!s->per_mb_rl_table){
254  ff_msmpeg4_code012(&s->pb, s->rl_chroma_table_index);
255  ff_msmpeg4_code012(&s->pb, s->rl_table_index);
256  }
257 
258  put_bits(&s->pb, 1, s->dc_table_index);
259  }
260  } else {
261  put_bits(&s->pb, 1, s->use_skip_mb_code);
262 
263  if (s->msmpeg4_version == MSMP4_WMV1 && s->bit_rate > MBAC_BITRATE)
264  put_bits(&s->pb, 1, s->per_mb_rl_table);
265 
266  if (s->msmpeg4_version > MSMP4_V2) {
267  if(!s->per_mb_rl_table)
268  ff_msmpeg4_code012(&s->pb, s->rl_table_index);
269 
270  put_bits(&s->pb, 1, s->dc_table_index);
271 
272  put_bits(&s->pb, 1, s->mv_table_index);
273  }
274  }
275 
276  s->esc3_level_length= 0;
277  s->esc3_run_length= 0;
278 }
279 
281 {
282  unsigned fps;
283 
284  if (s->avctx->framerate.num > 0 && s->avctx->framerate.den > 0)
285  fps = s->avctx->framerate.num / s->avctx->framerate.den;
286  else {
288  fps = s->avctx->time_base.den / s->avctx->time_base.num
289 #if FF_API_TICKS_PER_FRAME
290  / FFMAX(s->avctx->ticks_per_frame, 1)
291 #endif
292  ;
294  }
295 
296  put_bits(&s->pb, 5, FFMIN(fps, 31)); //yes 29.97 -> 29
297 
298  put_bits(&s->pb, 11, FFMIN(s->bit_rate / 1024, 2047));
299 
300  if (s->msmpeg4_version >= MSMP4_V3)
301  put_bits(&s->pb, 1, s->flipflop_rounding);
302  else
303  av_assert0(!s->flipflop_rounding);
304 }
305 
307  int mx, int my)
308 {
309  int code;
310  MVTable *mv;
311 
312  /* modulo encoding */
313  /* WARNING : you cannot reach all the MVs even with the modulo
314  encoding. This is a somewhat strange compromise they took !!! */
315  if (mx <= -64)
316  mx += 64;
317  else if (mx >= 64)
318  mx -= 64;
319  if (my <= -64)
320  my += 64;
321  else if (my >= 64)
322  my -= 64;
323 
324  mx += 32;
325  my += 32;
326  mv = &ff_mv_tables[s->mv_table_index];
327 
328  code = mv->table_mv_index[(mx << 6) | my];
329  put_bits(&s->pb,
330  mv->table_mv_bits[code],
331  mv->table_mv_code[code]);
333  /* escape : code literally */
334  put_bits(&s->pb, 6, mx);
335  put_bits(&s->pb, 6, my);
336  }
337 }
338 
340  if (s->mb_x == 0) {
341  if (s->slice_height && (s->mb_y % s->slice_height) == 0) {
342  if (s->msmpeg4_version < MSMP4_WMV1) {
344  }
345  s->first_slice_line = 1;
346  } else {
347  s->first_slice_line = 0;
348  }
349  }
350 }
351 
353 {
354  int range, bit_size, sign, code, bits;
355 
356  if (val == 0) {
357  /* zero vector */
358  code = 0;
359  put_bits(&s->pb, ff_mvtab[code][1], ff_mvtab[code][0]);
360  } else {
361  bit_size = s->f_code - 1;
362  range = 1 << bit_size;
363  if (val <= -64)
364  val += 64;
365  else if (val >= 64)
366  val -= 64;
367 
368  if (val >= 0) {
369  sign = 0;
370  } else {
371  val = -val;
372  sign = 1;
373  }
374  val--;
375  code = (val >> bit_size) + 1;
376  bits = val & (range - 1);
377 
378  put_bits(&s->pb, ff_mvtab[code][1] + 1, (ff_mvtab[code][0] << 1) | sign);
379  if (bit_size > 0) {
380  put_bits(&s->pb, bit_size, bits);
381  }
382  }
383 }
384 
386  int16_t block[6][64],
387  int motion_x, int motion_y)
388 {
389  int cbp, coded_cbp, i;
390  int pred_x, pred_y;
391 
393 
394  if (!s->mb_intra) {
395  /* compute cbp */
396  cbp = 0;
397  for (i = 0; i < 6; i++) {
398  if (s->block_last_index[i] >= 0)
399  cbp |= 1 << (5 - i);
400  }
401  if (s->use_skip_mb_code && (cbp | motion_x | motion_y) == 0) {
402  /* skip macroblock */
403  put_bits(&s->pb, 1, 1);
404  s->last_bits++;
405  s->misc_bits++;
406 
407  return;
408  }
409  if (s->use_skip_mb_code)
410  put_bits(&s->pb, 1, 0); /* mb coded */
411 
412  if (s->msmpeg4_version <= MSMP4_V2) {
413  put_bits(&s->pb,
414  ff_v2_mb_type[cbp&3][1],
415  ff_v2_mb_type[cbp&3][0]);
416  if((cbp&3) != 3) coded_cbp= cbp ^ 0x3C;
417  else coded_cbp= cbp;
418 
419  put_bits(&s->pb,
420  ff_h263_cbpy_tab[coded_cbp>>2][1],
421  ff_h263_cbpy_tab[coded_cbp>>2][0]);
422 
423  s->misc_bits += get_bits_diff(s);
424 
425  ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
426  msmpeg4v2_encode_motion(s, motion_x - pred_x);
427  msmpeg4v2_encode_motion(s, motion_y - pred_y);
428  }else{
429  put_bits(&s->pb,
430  ff_table_mb_non_intra[cbp + 64][1],
431  ff_table_mb_non_intra[cbp + 64][0]);
432 
433  s->misc_bits += get_bits_diff(s);
434 
435  /* motion vector */
436  ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
437  ff_msmpeg4_encode_motion(s, motion_x - pred_x,
438  motion_y - pred_y);
439  }
440 
441  s->mv_bits += get_bits_diff(s);
442 
443  for (i = 0; i < 6; i++) {
445  }
446  s->p_tex_bits += get_bits_diff(s);
447  } else {
448  /* compute cbp */
449  cbp = 0;
450  for (int i = 0; i < 6; i++) {
451  int val = (s->block_last_index[i] >= 1);
452  cbp |= val << (5 - i);
453  }
454  if (s->msmpeg4_version <= MSMP4_V2) {
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  /* compute coded_cbp; the 0x3 corresponds to chroma cbp;
472  * luma coded_cbp are set in the loop below */
473  coded_cbp = cbp & 0x3;
474  for (int i = 0; i < 4; i++) {
475  uint8_t *coded_block;
476  int pred = ff_msmpeg4_coded_block_pred(s, i, &coded_block);
477  int val = (s->block_last_index[i] >= 1);
478  *coded_block = val;
479  val ^= pred;
480  coded_cbp |= val << (5 - i);
481  }
482 
483  put_bits(&s->pb,
484  ff_msmp4_mb_i_table[coded_cbp][1], ff_msmp4_mb_i_table[coded_cbp][0]);
485  } else {
486  if (s->use_skip_mb_code)
487  put_bits(&s->pb, 1, 0); /* mb coded */
488  put_bits(&s->pb,
489  ff_table_mb_non_intra[cbp][1],
490  ff_table_mb_non_intra[cbp][0]);
491  }
492  put_bits(&s->pb, 1, 0); /* no AC prediction yet */
493  if(s->inter_intra_pred){
494  s->h263_aic_dir=0;
495  put_bits(&s->pb, ff_table_inter_intra[s->h263_aic_dir][1], ff_table_inter_intra[s->h263_aic_dir][0]);
496  }
497  }
498  s->misc_bits += get_bits_diff(s);
499 
500  for (i = 0; i < 6; i++) {
502  }
503  s->i_tex_bits += get_bits_diff(s);
504  s->i_count++;
505  }
506 }
507 
508 static void msmpeg4_encode_dc(MpegEncContext * s, int level, int n, int *dir_ptr)
509 {
510  int sign, code;
511  int pred;
512 
513  int16_t *dc_val;
514  pred = ff_msmpeg4_pred_dc(s, n, &dc_val, dir_ptr);
515 
516  /* update predictor */
517  if (n < 4) {
518  *dc_val = level * s->y_dc_scale;
519  } else {
520  *dc_val = level * s->c_dc_scale;
521  }
522 
523  /* do the prediction */
524  level -= pred;
525 
526  if (s->msmpeg4_version <= MSMP4_V2) {
527  if (n < 4) {
528  put_bits(&s->pb,
529  ff_v2_dc_lum_table[level + 256][1],
530  ff_v2_dc_lum_table[level + 256][0]);
531  }else{
532  put_bits(&s->pb,
533  ff_v2_dc_chroma_table[level + 256][1],
534  ff_v2_dc_chroma_table[level + 256][0]);
535  }
536  }else{
537  sign = 0;
538  if (level < 0) {
539  level = -level;
540  sign = 1;
541  }
542  code = level;
543  if (code > DC_MAX)
544  code = DC_MAX;
545 
546  put_bits(&s->pb, ff_msmp4_dc_tables[s->dc_table_index][n >= 4][code][1],
547  ff_msmp4_dc_tables[s->dc_table_index][n >= 4][code][0]);
548 
549  if (code == DC_MAX)
550  put_bits(&s->pb, 8, level);
551 
552  if (level != 0) {
553  put_bits(&s->pb, 1, sign);
554  }
555  }
556 }
557 
558 /* Encoding of a block; very similar to MPEG-4 except for a different
559  * escape coding (same as H.263) and more VLC tables. */
561 {
562  MSMPEG4EncContext *const ms = (MSMPEG4EncContext*)s;
563  int level, run, last, i, j, last_index;
564  int last_non_zero, sign, slevel;
565  int code, run_diff, dc_pred_dir;
566  const RLTable *rl;
567  const uint8_t *scantable;
568 
569  if (s->mb_intra) {
570  msmpeg4_encode_dc(s, block[0], n, &dc_pred_dir);
571  i = 1;
572  if (n < 4) {
573  rl = &ff_rl_table[s->rl_table_index];
574  } else {
575  rl = &ff_rl_table[3 + s->rl_chroma_table_index];
576  }
577  run_diff = s->msmpeg4_version >= MSMP4_WMV1;
578  scantable= s->intra_scantable.permutated;
579  } else {
580  i = 0;
581  rl = &ff_rl_table[3 + s->rl_table_index];
582  run_diff = s->msmpeg4_version > MSMP4_V2;
583  scantable= s->inter_scantable.permutated;
584  }
585 
586  /* recalculate block_last_index for M$ wmv1 */
587  if (s->msmpeg4_version >= MSMP4_WMV1 && s->block_last_index[n] > 0) {
588  for(last_index=63; last_index>=0; last_index--){
589  if(block[scantable[last_index]]) break;
590  }
591  s->block_last_index[n]= last_index;
592  }else
593  last_index = s->block_last_index[n];
594  /* AC coefs */
595  last_non_zero = i - 1;
596  for (; i <= last_index; i++) {
597  j = scantable[i];
598  level = block[j];
599  if (level) {
600  run = i - last_non_zero - 1;
601  last = (i == last_index);
602  sign = 0;
603  slevel = level;
604  if (level < 0) {
605  sign = 1;
606  level = -level;
607  }
608 
609  if(level<=MAX_LEVEL && run<=MAX_RUN){
610  ms->ac_stats[s->mb_intra][n>3][level][run][last]++;
611  }
612 
613  ms->ac_stats[s->mb_intra][n > 3][40][63][0]++; //esc3 like
614 
615  code = get_rl_index(rl, last, run, level);
616  put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
617  if (code == rl->n) {
618  int level1, run1;
619 
620  level1 = level - rl->max_level[last][run];
621  if (level1 < 1)
622  goto esc2;
623  code = get_rl_index(rl, last, run, level1);
624  if (code == rl->n) {
625  esc2:
626  put_bits(&s->pb, 1, 0);
627  if (level > MAX_LEVEL)
628  goto esc3;
629  run1 = run - rl->max_run[last][level] - run_diff;
630  if (run1 < 0)
631  goto esc3;
632  code = get_rl_index(rl, last, run1+1, level);
633  if (s->msmpeg4_version == MSMP4_WMV1 && code == rl->n)
634  goto esc3;
635  code = get_rl_index(rl, last, run1, level);
636  if (code == rl->n) {
637  esc3:
638  /* third escape */
639  put_bits(&s->pb, 1, 0);
640  put_bits(&s->pb, 1, last);
641  if (s->msmpeg4_version >= MSMP4_WMV1) {
642  if(s->esc3_level_length==0){
643  s->esc3_level_length=8;
644  s->esc3_run_length= 6;
645  //ESCLVLSZ + ESCRUNSZ
646  if(s->qscale<8)
647  put_bits(&s->pb, 6, 3);
648  else
649  put_bits(&s->pb, 8, 3);
650  }
651  put_bits(&s->pb, s->esc3_run_length, run);
652  put_bits(&s->pb, 1, sign);
653  put_bits(&s->pb, s->esc3_level_length, level);
654  }else{
655  put_bits(&s->pb, 6, run);
656  put_sbits(&s->pb, 8, slevel);
657  }
658  } else {
659  /* second escape */
660  put_bits(&s->pb, 1, 1);
661  put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
662  put_bits(&s->pb, 1, sign);
663  }
664  } else {
665  /* first escape */
666  put_bits(&s->pb, 1, 1);
667  put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
668  put_bits(&s->pb, 1, sign);
669  }
670  } else {
671  put_bits(&s->pb, 1, sign);
672  }
673  last_non_zero = i;
674  }
675  }
676 }
677 
679  .p.name = "msmpeg4v2",
680  CODEC_LONG_NAME("MPEG-4 part 2 Microsoft variant version 2"),
681  .p.type = AVMEDIA_TYPE_VIDEO,
682  .p.id = AV_CODEC_ID_MSMPEG4V2,
683  .p.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
684  .color_ranges = AVCOL_RANGE_MPEG,
685  .p.priv_class = &ff_mpv_enc_class,
686  .p.capabilities = AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
687  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
688  .priv_data_size = sizeof(MSMPEG4EncContext),
691  .close = ff_mpv_encode_end,
692 };
693 
695  .p.name = "msmpeg4",
696  CODEC_LONG_NAME("MPEG-4 part 2 Microsoft variant version 3"),
697  .p.type = AVMEDIA_TYPE_VIDEO,
698  .p.id = AV_CODEC_ID_MSMPEG4V3,
699  .p.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
700  .color_ranges = AVCOL_RANGE_MPEG,
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  .color_ranges = AVCOL_RANGE_MPEG,
717  .p.priv_class = &ff_mpv_enc_class,
718  .p.capabilities = AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
719  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
720  .priv_data_size = sizeof(MSMPEG4EncContext),
723  .close = ff_mpv_encode_end,
724 };
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:73
ff_msmp4_dc_tables
const uint32_t ff_msmp4_dc_tables[2][2][120][2]
Definition: msmpeg4_vc1_data.c:83
h263data.h
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
ff_mpv_enc_class
const AVClass ff_mpv_enc_class
Definition: mpegvideo_enc.c:105
level
uint8_t level
Definition: svq3.c:205
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:43
get_bits_diff
static int get_bits_diff(MpegEncContext *s)
Definition: mpegvideoenc.h:158
ff_msmpeg4_handle_slices
void ff_msmpeg4_handle_slices(MpegEncContext *s)
Definition: msmpeg4enc.c:339
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_msmpeg4v3_encoder
const FFCodec ff_msmpeg4v3_encoder
Definition: msmpeg4enc.c:694
thread.h
mpegvideoenc.h
mv
static const int8_t mv[256][2]
Definition: 4xm.c:81
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:223
ff_msmpeg4_common_init
av_cold void ff_msmpeg4_common_init(MpegEncContext *s)
Definition: msmpeg4.c:117
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:385
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:1793
mx
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t mx
Definition: dsp.h:53
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:179
ff_msmpeg4_encode_init
av_cold void ff_msmpeg4_encode_init(MpegEncContext *s)
Definition: msmpeg4enc.c:138
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: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:320
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:205
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
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:152
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:73
PutBitContext
Definition: put_bits.h:50
ff_msmpeg4_encode_motion
void ff_msmpeg4_encode_motion(MpegEncContext *s, int mx, int my)
Definition: msmpeg4enc.c:306
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:296
my
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t my
Definition: dsp.h:53
AV_ONCE_INIT
#define AV_ONCE_INIT
Definition: thread.h:203
run
uint8_t run
Definition: svq3.c:204
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:63
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:1028
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:678
AVOnce
#define AVOnce
Definition: thread.h:202
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
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
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:280
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:2464
ff_msmpeg4_pred_dc
int ff_msmpeg4_pred_dc(MpegEncContext *s, int n, int16_t **dc_val_ptr, int *dir_ptr)
Definition: msmpeg4.c:196
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:508
ff_msmpeg4_encode_picture_header
void ff_msmpeg4_encode_picture_header(MpegEncContext *s)
Definition: msmpeg4enc.c:218
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
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:78
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
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:700
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:121
ff_msmpeg4_encode_block
void ff_msmpeg4_encode_block(MpegEncContext *s, int16_t *block, int n)
Definition: msmpeg4enc.c:560
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:72
MVTable
Definition: msmpeg4data.h:41
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:352
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:351
rl.h
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:73
ff_msmpeg4_coded_block_pred
int ff_msmpeg4_coded_block_pred(MpegEncContext *s, int n, uint8_t **coded_block_ptr)
Definition: msmpeg4.c:156
h263.h