mpeg4videoenc.c
Go to the documentation of this file.
1 /*
2  * MPEG4 encoder.
3  * Copyright (c) 2000,2001 Fabrice Bellard
4  * Copyright (c) 2002-2010 Michael Niedermayer <michaelni@gmx.at>
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include "libavutil/log.h"
24 #include "libavutil/opt.h"
25 #include "mpegvideo.h"
26 #include "h263.h"
27 #include "mpeg4video.h"
28 
29 //The uni_DCtab_* tables below contain unified bits+length tables to encode DC
30 //differences in mpeg4. Unified in the sense that the specification specifies
31 //this encoding in several steps.
34 static uint16_t uni_DCtab_lum_bits[512];
35 static uint16_t uni_DCtab_chrom_bits[512];
36 
37 //unified encoding tables for run length encoding of coefficients
38 //unified in the sense that the specification specifies the encoding in several steps.
39 static uint32_t uni_mpeg4_intra_rl_bits[64*64*2*2];
40 static uint8_t uni_mpeg4_intra_rl_len [64*64*2*2];
41 static uint32_t uni_mpeg4_inter_rl_bits[64*64*2*2];
42 static uint8_t uni_mpeg4_inter_rl_len [64*64*2*2];
43 //#define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128 + (run)*256 + (level))
44 //#define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128*64 + (run) + (level)*64)
45 #define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128*64 + (run)*128 + (level))
46 
47 /* mpeg4
48 inter
49 max level: 24/6
50 max run: 53/63
51 
52 intra
53 max level: 53/16
54 max run: 29/41
55 */
56 
57 
58 /**
59  * Return the number of bits that encoding the 8x8 block in block would need.
60  * @param[in] block_last_index last index in scantable order that refers to a non zero element in block.
61  */
62 static inline int get_block_rate(MpegEncContext * s, int16_t block[64], int block_last_index, uint8_t scantable[64]){
63  int last=0;
64  int j;
65  int rate=0;
66 
67  for(j=1; j<=block_last_index; j++){
68  const int index= scantable[j];
69  int level= block[index];
70  if(level){
71  level+= 64;
72  if((level&(~127)) == 0){
73  if(j<block_last_index) rate+= s->intra_ac_vlc_length [UNI_AC_ENC_INDEX(j-last-1, level)];
74  else rate+= s->intra_ac_vlc_last_length[UNI_AC_ENC_INDEX(j-last-1, level)];
75  }else
76  rate += s->ac_esc_length;
77 
78  last= j;
79  }
80  }
81 
82  return rate;
83 }
84 
85 
86 /**
87  * Restore the ac coefficients in block that have been changed by decide_ac_pred().
88  * This function also restores s->block_last_index.
89  * @param[in,out] block MB coefficients, these will be restored
90  * @param[in] dir ac prediction direction for each 8x8 block
91  * @param[out] st scantable for each 8x8 block
92  * @param[in] zigzag_last_index index referring to the last non zero coefficient in zigzag order
93  */
94 static inline void restore_ac_coeffs(MpegEncContext * s, int16_t block[6][64], const int dir[6], uint8_t *st[6], const int zigzag_last_index[6])
95 {
96  int i, n;
97  memcpy(s->block_last_index, zigzag_last_index, sizeof(int)*6);
98 
99  for(n=0; n<6; n++){
100  int16_t *ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
101 
102  st[n]= s->intra_scantable.permutated;
103  if(dir[n]){
104  /* top prediction */
105  for(i=1; i<8; i++){
106  block[n][s->dsp.idct_permutation[i ]] = ac_val[i+8];
107  }
108  }else{
109  /* left prediction */
110  for(i=1; i<8; i++){
111  block[n][s->dsp.idct_permutation[i<<3]]= ac_val[i ];
112  }
113  }
114  }
115 }
116 
117 /**
118  * Return the optimal value (0 or 1) for the ac_pred element for the given MB in mpeg4.
119  * This function will also update s->block_last_index and s->ac_val.
120  * @param[in,out] block MB coefficients, these will be updated if 1 is returned
121  * @param[in] dir ac prediction direction for each 8x8 block
122  * @param[out] st scantable for each 8x8 block
123  * @param[out] zigzag_last_index index referring to the last non zero coefficient in zigzag order
124  */
125 static inline int decide_ac_pred(MpegEncContext * s, int16_t block[6][64], const int dir[6], uint8_t *st[6], int zigzag_last_index[6])
126 {
127  int score= 0;
128  int i, n;
129  int8_t * const qscale_table = s->current_picture.qscale_table;
130 
131  memcpy(zigzag_last_index, s->block_last_index, sizeof(int)*6);
132 
133  for(n=0; n<6; n++){
134  int16_t *ac_val, *ac_val1;
135 
136  score -= get_block_rate(s, block[n], s->block_last_index[n], s->intra_scantable.permutated);
137 
138  ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
139  ac_val1= ac_val;
140  if(dir[n]){
141  const int xy= s->mb_x + s->mb_y*s->mb_stride - s->mb_stride;
142  /* top prediction */
143  ac_val-= s->block_wrap[n]*16;
144  if(s->mb_y==0 || s->qscale == qscale_table[xy] || n==2 || n==3){
145  /* same qscale */
146  for(i=1; i<8; i++){
147  const int level= block[n][s->dsp.idct_permutation[i ]];
148  block[n][s->dsp.idct_permutation[i ]] = level - ac_val[i+8];
149  ac_val1[i ]= block[n][s->dsp.idct_permutation[i<<3]];
150  ac_val1[i+8]= level;
151  }
152  }else{
153  /* different qscale, we must rescale */
154  for(i=1; i<8; i++){
155  const int level= block[n][s->dsp.idct_permutation[i ]];
156  block[n][s->dsp.idct_permutation[i ]] = level - ROUNDED_DIV(ac_val[i + 8]*qscale_table[xy], s->qscale);
157  ac_val1[i ]= block[n][s->dsp.idct_permutation[i<<3]];
158  ac_val1[i+8]= level;
159  }
160  }
162  }else{
163  const int xy= s->mb_x-1 + s->mb_y*s->mb_stride;
164  /* left prediction */
165  ac_val-= 16;
166  if(s->mb_x==0 || s->qscale == qscale_table[xy] || n==1 || n==3){
167  /* same qscale */
168  for(i=1; i<8; i++){
169  const int level= block[n][s->dsp.idct_permutation[i<<3]];
170  block[n][s->dsp.idct_permutation[i<<3]]= level - ac_val[i];
171  ac_val1[i ]= level;
172  ac_val1[i+8]= block[n][s->dsp.idct_permutation[i ]];
173  }
174  }else{
175  /* different qscale, we must rescale */
176  for(i=1; i<8; i++){
177  const int level= block[n][s->dsp.idct_permutation[i<<3]];
178  block[n][s->dsp.idct_permutation[i<<3]]= level - ROUNDED_DIV(ac_val[i]*qscale_table[xy], s->qscale);
179  ac_val1[i ]= level;
180  ac_val1[i+8]= block[n][s->dsp.idct_permutation[i ]];
181  }
182  }
184  }
185 
186  for(i=63; i>0; i--) //FIXME optimize
187  if(block[n][ st[n][i] ]) break;
188  s->block_last_index[n]= i;
189 
190  score += get_block_rate(s, block[n], s->block_last_index[n], st[n]);
191  }
192 
193  if(score < 0){
194  return 1;
195  }else{
196  restore_ac_coeffs(s, block, dir, st, zigzag_last_index);
197  return 0;
198  }
199 }
200 
201 /**
202  * modify mb_type & qscale so that encoding is actually possible in mpeg4
203  */
205  int i;
206  int8_t * const qscale_table = s->current_picture.qscale_table;
207 
209 
210  if(s->pict_type== AV_PICTURE_TYPE_B){
211  int odd=0;
212  /* ok, come on, this isn't funny anymore, there's more code for handling this mpeg4 mess than for the actual adaptive quantization */
213 
214  for(i=0; i<s->mb_num; i++){
215  int mb_xy= s->mb_index2xy[i];
216  odd += qscale_table[mb_xy]&1;
217  }
218 
219  if(2*odd > s->mb_num) odd=1;
220  else odd=0;
221 
222  for(i=0; i<s->mb_num; i++){
223  int mb_xy= s->mb_index2xy[i];
224  if((qscale_table[mb_xy]&1) != odd)
225  qscale_table[mb_xy]++;
226  if(qscale_table[mb_xy] > 31)
227  qscale_table[mb_xy]= 31;
228  }
229 
230  for(i=1; i<s->mb_num; i++){
231  int mb_xy= s->mb_index2xy[i];
232  if(qscale_table[mb_xy] != qscale_table[s->mb_index2xy[i-1]] && (s->mb_type[mb_xy]&CANDIDATE_MB_TYPE_DIRECT)){
233  s->mb_type[mb_xy]|= CANDIDATE_MB_TYPE_BIDIR;
234  }
235  }
236  }
237 }
238 
239 
240 /**
241  * Encode the dc value.
242  * @param n block index (0-3 are luma, 4-5 are chroma)
243  */
244 static inline void mpeg4_encode_dc(PutBitContext * s, int level, int n)
245 {
246 #if 1
247  /* DC will overflow if level is outside the [-255,255] range. */
248  level+=256;
249  if (n < 4) {
250  /* luminance */
251  put_bits(s, uni_DCtab_lum_len[level], uni_DCtab_lum_bits[level]);
252  } else {
253  /* chrominance */
255  }
256 #else
257  int size, v;
258  /* find number of bits */
259  size = 0;
260  v = abs(level);
261  while (v) {
262  v >>= 1;
263  size++;
264  }
265 
266  if (n < 4) {
267  /* luminance */
268  put_bits(&s->pb, ff_mpeg4_DCtab_lum[size][1], ff_mpeg4_DCtab_lum[size][0]);
269  } else {
270  /* chrominance */
271  put_bits(&s->pb, ff_mpeg4_DCtab_chrom[size][1], ff_mpeg4_DCtab_chrom[size][0]);
272  }
273 
274  /* encode remaining bits */
275  if (size > 0) {
276  if (level < 0)
277  level = (-level) ^ ((1 << size) - 1);
278  put_bits(&s->pb, size, level);
279  if (size > 8)
280  put_bits(&s->pb, 1, 1);
281  }
282 #endif
283 }
284 
285 static inline int mpeg4_get_dc_length(int level, int n){
286  if (n < 4) {
287  return uni_DCtab_lum_len[level + 256];
288  } else {
289  return uni_DCtab_chrom_len[level + 256];
290  }
291 }
292 
293 /**
294  * Encode an 8x8 block.
295  * @param n block index (0-3 are luma, 4-5 are chroma)
296  */
297 static inline void mpeg4_encode_block(MpegEncContext * s, int16_t * block, int n, int intra_dc,
298  uint8_t *scan_table, PutBitContext *dc_pb, PutBitContext *ac_pb)
299 {
300  int i, last_non_zero;
301  uint32_t *bits_tab;
302  uint8_t *len_tab;
303  const int last_index = s->block_last_index[n];
304 
305  if (s->mb_intra) { //Note gcc (3.2.1 at least) will optimize this away
306  /* mpeg4 based DC predictor */
307  mpeg4_encode_dc(dc_pb, intra_dc, n);
308  if(last_index<1) return;
309  i = 1;
310  bits_tab= uni_mpeg4_intra_rl_bits;
311  len_tab = uni_mpeg4_intra_rl_len;
312  } else {
313  if(last_index<0) return;
314  i = 0;
315  bits_tab= uni_mpeg4_inter_rl_bits;
316  len_tab = uni_mpeg4_inter_rl_len;
317  }
318 
319  /* AC coefs */
320  last_non_zero = i - 1;
321  for (; i < last_index; i++) {
322  int level = block[ scan_table[i] ];
323  if (level) {
324  int run = i - last_non_zero - 1;
325  level+=64;
326  if((level&(~127)) == 0){
327  const int index= UNI_MPEG4_ENC_INDEX(0, run, level);
328  put_bits(ac_pb, len_tab[index], bits_tab[index]);
329  }else{ //ESC3
330  put_bits(ac_pb, 7+2+1+6+1+12+1, (3<<23)+(3<<21)+(0<<20)+(run<<14)+(1<<13)+(((level-64)&0xfff)<<1)+1);
331  }
332  last_non_zero = i;
333  }
334  }
335  /*if(i<=last_index)*/{
336  int level = block[ scan_table[i] ];
337  int run = i - last_non_zero - 1;
338  level+=64;
339  if((level&(~127)) == 0){
340  const int index= UNI_MPEG4_ENC_INDEX(1, run, level);
341  put_bits(ac_pb, len_tab[index], bits_tab[index]);
342  }else{ //ESC3
343  put_bits(ac_pb, 7+2+1+6+1+12+1, (3<<23)+(3<<21)+(1<<20)+(run<<14)+(1<<13)+(((level-64)&0xfff)<<1)+1);
344  }
345  }
346 }
347 
348 static int mpeg4_get_block_length(MpegEncContext * s, int16_t * block, int n, int intra_dc,
349  uint8_t *scan_table)
350 {
351  int i, last_non_zero;
352  uint8_t *len_tab;
353  const int last_index = s->block_last_index[n];
354  int len=0;
355 
356  if (s->mb_intra) { //Note gcc (3.2.1 at least) will optimize this away
357  /* mpeg4 based DC predictor */
358  len += mpeg4_get_dc_length(intra_dc, n);
359  if(last_index<1) return len;
360  i = 1;
361  len_tab = uni_mpeg4_intra_rl_len;
362  } else {
363  if(last_index<0) return 0;
364  i = 0;
365  len_tab = uni_mpeg4_inter_rl_len;
366  }
367 
368  /* AC coefs */
369  last_non_zero = i - 1;
370  for (; i < last_index; i++) {
371  int level = block[ scan_table[i] ];
372  if (level) {
373  int run = i - last_non_zero - 1;
374  level+=64;
375  if((level&(~127)) == 0){
376  const int index= UNI_MPEG4_ENC_INDEX(0, run, level);
377  len += len_tab[index];
378  }else{ //ESC3
379  len += 7+2+1+6+1+12+1;
380  }
381  last_non_zero = i;
382  }
383  }
384  /*if(i<=last_index)*/{
385  int level = block[ scan_table[i] ];
386  int run = i - last_non_zero - 1;
387  level+=64;
388  if((level&(~127)) == 0){
389  const int index= UNI_MPEG4_ENC_INDEX(1, run, level);
390  len += len_tab[index];
391  }else{ //ESC3
392  len += 7+2+1+6+1+12+1;
393  }
394  }
395 
396  return len;
397 }
398 
399 static inline void mpeg4_encode_blocks(MpegEncContext * s, int16_t block[6][64], int intra_dc[6],
400  uint8_t **scan_table, PutBitContext *dc_pb, PutBitContext *ac_pb){
401  int i;
402 
403  if(scan_table){
404  if(s->flags2 & CODEC_FLAG2_NO_OUTPUT){
405  for (i = 0; i < 6; i++) {
406  skip_put_bits(&s->pb, mpeg4_get_block_length(s, block[i], i, intra_dc[i], scan_table[i]));
407  }
408  }else{
409  /* encode each block */
410  for (i = 0; i < 6; i++) {
411  mpeg4_encode_block(s, block[i], i, intra_dc[i], scan_table[i], dc_pb, ac_pb);
412  }
413  }
414  }else{
415  if(s->flags2 & CODEC_FLAG2_NO_OUTPUT){
416  for (i = 0; i < 6; i++) {
418  }
419  }else{
420  /* encode each block */
421  for (i = 0; i < 6; i++) {
422  mpeg4_encode_block(s, block[i], i, 0, s->intra_scantable.permutated, dc_pb, ac_pb);
423  }
424  }
425  }
426 }
427 
428 static inline int get_b_cbp(MpegEncContext * s, int16_t block[6][64],
429  int motion_x, int motion_y, int mb_type)
430 {
431  int cbp = 0, i;
432 
433  if (s->mpv_flags & FF_MPV_FLAG_CBP_RD) {
434  int score = 0;
435  const int lambda = s->lambda2 >> (FF_LAMBDA_SHIFT - 6);
436 
437  for (i = 0; i < 6; i++)
438  if (s->coded_score[i] < 0) {
439  score += s->coded_score[i];
440  cbp |= 1 << (5 - i);
441  }
442 
443  if (cbp) {
444  int zero_score = -6;
445  if ((motion_x | motion_y | s->dquant | mb_type) == 0)
446  zero_score -= 4; //2*MV + mb_type + cbp bit
447 
448  zero_score *= lambda;
449  if (zero_score <= score)
450  cbp = 0;
451  }
452 
453  for (i = 0; i < 6; i++) {
454  if (s->block_last_index[i] >= 0 && ((cbp >> (5 - i)) & 1) == 0) {
455  s->block_last_index[i] = -1;
456  s->dsp.clear_block(s->block[i]);
457  }
458  }
459  } else {
460  for (i = 0; i < 6; i++) {
461  if (s->block_last_index[i] >= 0)
462  cbp |= 1 << (5 - i);
463  }
464  }
465  return cbp;
466 }
467 
468 //FIXME this is duplicated to h263.c
469 static const int dquant_code[5]= {1,0,9,2,3};
470 
472  int16_t block[6][64],
473  int motion_x, int motion_y)
474 {
475  int cbpc, cbpy, pred_x, pred_y;
476  PutBitContext * const pb2 = s->data_partitioning ? &s->pb2 : &s->pb;
477  PutBitContext * const tex_pb = s->data_partitioning && s->pict_type!=AV_PICTURE_TYPE_B ? &s->tex_pb : &s->pb;
478  PutBitContext * const dc_pb = s->data_partitioning && s->pict_type!=AV_PICTURE_TYPE_I ? &s->pb2 : &s->pb;
479  const int interleaved_stats= (s->flags&CODEC_FLAG_PASS1) && !s->data_partitioning ? 1 : 0;
480 
481  if (!s->mb_intra) {
482  int i, cbp;
483 
485  static const int mb_type_table[8]= {-1, 3, 2, 1,-1,-1,-1, 0}; /* convert from mv_dir to type */
486  int mb_type= mb_type_table[s->mv_dir];
487 
488  if(s->mb_x==0){
489  for(i=0; i<2; i++){
490  s->last_mv[i][0][0]=
491  s->last_mv[i][0][1]=
492  s->last_mv[i][1][0]=
493  s->last_mv[i][1][1]= 0;
494  }
495  }
496 
497  av_assert2(s->dquant>=-2 && s->dquant<=2);
498  av_assert2((s->dquant&1)==0);
499  av_assert2(mb_type>=0);
500 
501  /* nothing to do if this MB was skipped in the next P Frame */
502  if (s->next_picture.mbskip_table[s->mb_y * s->mb_stride + s->mb_x]) { //FIXME avoid DCT & ...
503  s->skip_count++;
504  s->mv[0][0][0]=
505  s->mv[0][0][1]=
506  s->mv[1][0][0]=
507  s->mv[1][0][1]= 0;
508  s->mv_dir= MV_DIR_FORWARD; //doesn't matter
509  s->qscale -= s->dquant;
510 // s->mb_skipped=1;
511 
512  return;
513  }
514 
515  cbp= get_b_cbp(s, block, motion_x, motion_y, mb_type);
516 
517  if ((cbp | motion_x | motion_y | mb_type) ==0) {
518  /* direct MB with MV={0,0} */
519  av_assert2(s->dquant==0);
520 
521  put_bits(&s->pb, 1, 1); /* mb not coded modb1=1 */
522 
523  if(interleaved_stats){
524  s->misc_bits++;
525  s->last_bits++;
526  }
527  s->skip_count++;
528  return;
529  }
530 
531  put_bits(&s->pb, 1, 0); /* mb coded modb1=0 */
532  put_bits(&s->pb, 1, cbp ? 0 : 1); /* modb2 */ //FIXME merge
533  put_bits(&s->pb, mb_type+1, 1); // this table is so simple that we don't need it :)
534  if(cbp) put_bits(&s->pb, 6, cbp);
535 
536  if(cbp && mb_type){
537  if(s->dquant)
538  put_bits(&s->pb, 2, (s->dquant>>2)+3);
539  else
540  put_bits(&s->pb, 1, 0);
541  }else
542  s->qscale -= s->dquant;
543 
544  if(!s->progressive_sequence){
545  if(cbp)
546  put_bits(&s->pb, 1, s->interlaced_dct);
547  if(mb_type) // not direct mode
548  put_bits(&s->pb, 1, s->mv_type == MV_TYPE_FIELD);
549  }
550 
551  if(interleaved_stats){
552  s->misc_bits+= get_bits_diff(s);
553  }
554 
555  if(mb_type == 0){
557  ff_h263_encode_motion_vector(s, motion_x, motion_y, 1);
558  s->b_count++;
559  s->f_count++;
560  }else{
561  av_assert2(mb_type > 0 && mb_type < 4);
562  if(s->mv_type != MV_TYPE_FIELD){
563  if(s->mv_dir & MV_DIR_FORWARD){
564  ff_h263_encode_motion_vector(s, s->mv[0][0][0] - s->last_mv[0][0][0],
565  s->mv[0][0][1] - s->last_mv[0][0][1], s->f_code);
566  s->last_mv[0][0][0]= s->last_mv[0][1][0]= s->mv[0][0][0];
567  s->last_mv[0][0][1]= s->last_mv[0][1][1]= s->mv[0][0][1];
568  s->f_count++;
569  }
570  if(s->mv_dir & MV_DIR_BACKWARD){
571  ff_h263_encode_motion_vector(s, s->mv[1][0][0] - s->last_mv[1][0][0],
572  s->mv[1][0][1] - s->last_mv[1][0][1], s->b_code);
573  s->last_mv[1][0][0]= s->last_mv[1][1][0]= s->mv[1][0][0];
574  s->last_mv[1][0][1]= s->last_mv[1][1][1]= s->mv[1][0][1];
575  s->b_count++;
576  }
577  }else{
578  if(s->mv_dir & MV_DIR_FORWARD){
579  put_bits(&s->pb, 1, s->field_select[0][0]);
580  put_bits(&s->pb, 1, s->field_select[0][1]);
581  }
582  if(s->mv_dir & MV_DIR_BACKWARD){
583  put_bits(&s->pb, 1, s->field_select[1][0]);
584  put_bits(&s->pb, 1, s->field_select[1][1]);
585  }
586  if(s->mv_dir & MV_DIR_FORWARD){
587  for(i=0; i<2; i++){
588  ff_h263_encode_motion_vector(s, s->mv[0][i][0] - s->last_mv[0][i][0] ,
589  s->mv[0][i][1] - s->last_mv[0][i][1]/2, s->f_code);
590  s->last_mv[0][i][0]= s->mv[0][i][0];
591  s->last_mv[0][i][1]= s->mv[0][i][1]*2;
592  }
593  s->f_count++;
594  }
595  if(s->mv_dir & MV_DIR_BACKWARD){
596  for(i=0; i<2; i++){
597  ff_h263_encode_motion_vector(s, s->mv[1][i][0] - s->last_mv[1][i][0] ,
598  s->mv[1][i][1] - s->last_mv[1][i][1]/2, s->b_code);
599  s->last_mv[1][i][0]= s->mv[1][i][0];
600  s->last_mv[1][i][1]= s->mv[1][i][1]*2;
601  }
602  s->b_count++;
603  }
604  }
605  }
606 
607  if(interleaved_stats){
608  s->mv_bits+= get_bits_diff(s);
609  }
610 
611  mpeg4_encode_blocks(s, block, NULL, NULL, NULL, &s->pb);
612 
613  if(interleaved_stats){
614  s->p_tex_bits+= get_bits_diff(s);
615  }
616 
617  }else{ /* s->pict_type==AV_PICTURE_TYPE_B */
618  cbp= get_p_cbp(s, block, motion_x, motion_y);
619 
620  if ((cbp | motion_x | motion_y | s->dquant) == 0 && s->mv_type==MV_TYPE_16X16) {
621  /* check if the B frames can skip it too, as we must skip it if we skip here
622  why didn't they just compress the skip-mb bits instead of reusing them ?! */
623  if(s->max_b_frames>0){
624  int i;
625  int x,y, offset;
626  uint8_t *p_pic;
627 
628  x= s->mb_x*16;
629  y= s->mb_y*16;
630 
631  offset= x + y*s->linesize;
632  p_pic = s->new_picture.f.data[0] + offset;
633 
634  s->mb_skipped=1;
635  for(i=0; i<s->max_b_frames; i++){
636  uint8_t *b_pic;
637  int diff;
638  Picture *pic= s->reordered_input_picture[i+1];
639 
640  if (pic == NULL || pic->f.pict_type != AV_PICTURE_TYPE_B)
641  break;
642 
643  b_pic = pic->f.data[0] + offset;
644  if (!pic->shared)
645  b_pic+= INPLACE_OFFSET;
646 
647  if(x+16 > s->width || y+16 > s->height){
648  int x1,y1;
649  int xe= FFMIN(16, s->width - x);
650  int ye= FFMIN(16, s->height- y);
651  diff=0;
652  for(y1=0; y1<ye; y1++){
653  for(x1=0; x1<xe; x1++){
654  diff+= FFABS(p_pic[x1+y1*s->linesize] - b_pic[x1+y1*s->linesize]);
655  }
656  }
657  diff= diff*256/(xe*ye);
658  }else{
659  diff= s->dsp.sad[0](NULL, p_pic, b_pic, s->linesize, 16);
660  }
661  if(diff>s->qscale*70){ //FIXME check that 70 is optimal
662  s->mb_skipped=0;
663  break;
664  }
665  }
666  }else
667  s->mb_skipped=1;
668 
669  if(s->mb_skipped==1){
670  /* skip macroblock */
671  put_bits(&s->pb, 1, 1);
672 
673  if(interleaved_stats){
674  s->misc_bits++;
675  s->last_bits++;
676  }
677  s->skip_count++;
678 
679  return;
680  }
681  }
682 
683  put_bits(&s->pb, 1, 0); /* mb coded */
684  cbpc = cbp & 3;
685  cbpy = cbp >> 2;
686  cbpy ^= 0xf;
687  if(s->mv_type==MV_TYPE_16X16){
688  if(s->dquant) cbpc+= 8;
689  put_bits(&s->pb,
692 
693  put_bits(pb2, ff_h263_cbpy_tab[cbpy][1], ff_h263_cbpy_tab[cbpy][0]);
694  if(s->dquant)
695  put_bits(pb2, 2, dquant_code[s->dquant+2]);
696 
697  if(!s->progressive_sequence){
698  if(cbp)
699  put_bits(pb2, 1, s->interlaced_dct);
700  put_bits(pb2, 1, 0);
701  }
702 
703  if(interleaved_stats){
704  s->misc_bits+= get_bits_diff(s);
705  }
706 
707  /* motion vectors: 16x16 mode */
708  ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
709 
710  ff_h263_encode_motion_vector(s, motion_x - pred_x,
711  motion_y - pred_y, s->f_code);
712  }else if(s->mv_type==MV_TYPE_FIELD){
713  if(s->dquant) cbpc+= 8;
714  put_bits(&s->pb,
717 
718  put_bits(pb2, ff_h263_cbpy_tab[cbpy][1], ff_h263_cbpy_tab[cbpy][0]);
719  if(s->dquant)
720  put_bits(pb2, 2, dquant_code[s->dquant+2]);
721 
723  if(cbp)
724  put_bits(pb2, 1, s->interlaced_dct);
725  put_bits(pb2, 1, 1);
726 
727  if(interleaved_stats){
728  s->misc_bits+= get_bits_diff(s);
729  }
730 
731  /* motion vectors: 16x8 interlaced mode */
732  ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
733  pred_y /=2;
734 
735  put_bits(&s->pb, 1, s->field_select[0][0]);
736  put_bits(&s->pb, 1, s->field_select[0][1]);
737 
738  ff_h263_encode_motion_vector(s, s->mv[0][0][0] - pred_x,
739  s->mv[0][0][1] - pred_y, s->f_code);
740  ff_h263_encode_motion_vector(s, s->mv[0][1][0] - pred_x,
741  s->mv[0][1][1] - pred_y, s->f_code);
742  }else{
744  put_bits(&s->pb,
745  ff_h263_inter_MCBPC_bits[cbpc+16],
746  ff_h263_inter_MCBPC_code[cbpc+16]);
747  put_bits(pb2, ff_h263_cbpy_tab[cbpy][1], ff_h263_cbpy_tab[cbpy][0]);
748 
749  if(!s->progressive_sequence){
750  if(cbp)
751  put_bits(pb2, 1, s->interlaced_dct);
752  }
753 
754  if(interleaved_stats){
755  s->misc_bits+= get_bits_diff(s);
756  }
757 
758  for(i=0; i<4; i++){
759  /* motion vectors: 8x8 mode*/
760  ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y);
761 
763  s->current_picture.motion_val[0][ s->block_index[i] ][1] - pred_y, s->f_code);
764  }
765  }
766 
767  if(interleaved_stats){
768  s->mv_bits+= get_bits_diff(s);
769  }
770 
771  mpeg4_encode_blocks(s, block, NULL, NULL, NULL, tex_pb);
772 
773  if(interleaved_stats){
774  s->p_tex_bits+= get_bits_diff(s);
775  }
776  s->f_count++;
777  }
778  } else {
779  int cbp;
780  int dc_diff[6]; //dc values with the dc prediction subtracted
781  int dir[6]; //prediction direction
782  int zigzag_last_index[6];
783  uint8_t *scan_table[6];
784  int i;
785 
786  for(i=0; i<6; i++){
787  dc_diff[i]= ff_mpeg4_pred_dc(s, i, block[i][0], &dir[i], 1);
788  }
789 
790  if(s->flags & CODEC_FLAG_AC_PRED){
791  s->ac_pred= decide_ac_pred(s, block, dir, scan_table, zigzag_last_index);
792  }else{
793  for(i=0; i<6; i++)
794  scan_table[i]= s->intra_scantable.permutated;
795  }
796 
797  /* compute cbp */
798  cbp = 0;
799  for (i = 0; i < 6; i++) {
800  if (s->block_last_index[i] >= 1)
801  cbp |= 1 << (5 - i);
802  }
803 
804  cbpc = cbp & 3;
805  if (s->pict_type == AV_PICTURE_TYPE_I) {
806  if(s->dquant) cbpc+=4;
807  put_bits(&s->pb,
810  } else {
811  if(s->dquant) cbpc+=8;
812  put_bits(&s->pb, 1, 0); /* mb coded */
813  put_bits(&s->pb,
814  ff_h263_inter_MCBPC_bits[cbpc + 4],
815  ff_h263_inter_MCBPC_code[cbpc + 4]);
816  }
817  put_bits(pb2, 1, s->ac_pred);
818  cbpy = cbp >> 2;
819  put_bits(pb2, ff_h263_cbpy_tab[cbpy][1], ff_h263_cbpy_tab[cbpy][0]);
820  if(s->dquant)
821  put_bits(dc_pb, 2, dquant_code[s->dquant+2]);
822 
823  if(!s->progressive_sequence){
824  put_bits(dc_pb, 1, s->interlaced_dct);
825  }
826 
827  if(interleaved_stats){
828  s->misc_bits+= get_bits_diff(s);
829  }
830 
831  mpeg4_encode_blocks(s, block, dc_diff, scan_table, dc_pb, tex_pb);
832 
833  if(interleaved_stats){
834  s->i_tex_bits+= get_bits_diff(s);
835  }
836  s->i_count++;
837 
838  /* restore ac coeffs & last_index stuff if we messed them up with the prediction */
839  if(s->ac_pred)
840  restore_ac_coeffs(s, block, dir, scan_table, zigzag_last_index);
841  }
842 }
843 
844 /**
845  * add mpeg4 stuffing bits (01...1)
846  */
848 {
849  int length;
850  put_bits(pbc, 1, 0);
851  length= (-put_bits_count(pbc))&7;
852  if(length) put_bits(pbc, length, (1<<length)-1);
853 }
854 
855 /* must be called before writing the header */
859  }else{
860  s->last_time_base= s->time_base;
861  s->time_base= FFUDIV(s->time, s->avctx->time_base.den);
862  }
863 }
864 
866  int hours, minutes, seconds;
867  int64_t time;
868 
869  put_bits(&s->pb, 16, 0);
870  put_bits(&s->pb, 16, GOP_STARTCODE);
871 
872  time = s->current_picture_ptr->f.pts;
873  if(s->reordered_input_picture[1])
874  time = FFMIN(time, s->reordered_input_picture[1]->f.pts);
875  time= time*s->avctx->time_base.num;
876  s->last_time_base= FFUDIV(time, s->avctx->time_base.den);
877 
878  seconds= FFUDIV(time, s->avctx->time_base.den);
879  minutes= FFUDIV(seconds, 60); seconds = FFUMOD(seconds, 60);
880  hours = FFUDIV(minutes, 60); minutes = FFUMOD(minutes, 60);
881  hours = FFUMOD(hours , 24);
882 
883  put_bits(&s->pb, 5, hours);
884  put_bits(&s->pb, 6, minutes);
885  put_bits(&s->pb, 1, 1);
886  put_bits(&s->pb, 6, seconds);
887 
888  put_bits(&s->pb, 1, !!(s->flags&CODEC_FLAG_CLOSED_GOP));
889  put_bits(&s->pb, 1, 0); //broken link == NO
890 
891  ff_mpeg4_stuffing(&s->pb);
892 }
893 
895  int profile_and_level_indication;
896  int vo_ver_id;
897 
898  if(s->avctx->profile != FF_PROFILE_UNKNOWN){
899  profile_and_level_indication = s->avctx->profile << 4;
900  }else if(s->max_b_frames || s->quarter_sample){
901  profile_and_level_indication= 0xF0; // adv simple
902  }else{
903  profile_and_level_indication= 0x00; // simple
904  }
905 
906  if(s->avctx->level != FF_LEVEL_UNKNOWN){
907  profile_and_level_indication |= s->avctx->level;
908  }else{
909  profile_and_level_indication |= 1; //level 1
910  }
911 
912  if(profile_and_level_indication>>4 == 0xF){
913  vo_ver_id= 5;
914  }else{
915  vo_ver_id= 1;
916  }
917 
918  //FIXME levels
919 
920  put_bits(&s->pb, 16, 0);
921  put_bits(&s->pb, 16, VOS_STARTCODE);
922 
923  put_bits(&s->pb, 8, profile_and_level_indication);
924 
925  put_bits(&s->pb, 16, 0);
926  put_bits(&s->pb, 16, VISUAL_OBJ_STARTCODE);
927 
928  put_bits(&s->pb, 1, 1);
929  put_bits(&s->pb, 4, vo_ver_id);
930  put_bits(&s->pb, 3, 1); //priority
931 
932  put_bits(&s->pb, 4, 1); //visual obj type== video obj
933 
934  put_bits(&s->pb, 1, 0); //video signal type == no clue //FIXME
935 
936  ff_mpeg4_stuffing(&s->pb);
937 }
938 
939 static void mpeg4_encode_vol_header(MpegEncContext * s, int vo_number, int vol_number)
940 {
941  int vo_ver_id;
942 
943  if (!CONFIG_MPEG4_ENCODER) return;
944 
945  if(s->max_b_frames || s->quarter_sample){
946  vo_ver_id= 5;
948  }else{
949  vo_ver_id= 1;
951  }
952 
953  put_bits(&s->pb, 16, 0);
954  put_bits(&s->pb, 16, 0x100 + vo_number); /* video obj */
955  put_bits(&s->pb, 16, 0);
956  put_bits(&s->pb, 16, 0x120 + vol_number); /* video obj layer */
957 
958  put_bits(&s->pb, 1, 0); /* random access vol */
959  put_bits(&s->pb, 8, s->vo_type); /* video obj type indication */
960  if(s->workaround_bugs & FF_BUG_MS) {
961  put_bits(&s->pb, 1, 0); /* is obj layer id= no */
962  } else {
963  put_bits(&s->pb, 1, 1); /* is obj layer id= yes */
964  put_bits(&s->pb, 4, vo_ver_id); /* is obj layer ver id */
965  put_bits(&s->pb, 3, 1); /* is obj layer priority */
966  }
967 
969 
970  put_bits(&s->pb, 4, s->aspect_ratio_info);/* aspect ratio info */
974  put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.num);
975  put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.den);
976  }
977 
978  if(s->workaround_bugs & FF_BUG_MS) { //
979  put_bits(&s->pb, 1, 0); /* vol control parameters= no @@@ */
980  } else {
981  put_bits(&s->pb, 1, 1); /* vol control parameters= yes */
982  put_bits(&s->pb, 2, 1); /* chroma format YUV 420/YV12 */
983  put_bits(&s->pb, 1, s->low_delay);
984  put_bits(&s->pb, 1, 0); /* vbv parameters= no */
985  }
986 
987  put_bits(&s->pb, 2, RECT_SHAPE); /* vol shape= rectangle */
988  put_bits(&s->pb, 1, 1); /* marker bit */
989 
990  put_bits(&s->pb, 16, s->avctx->time_base.den);
991  if (s->time_increment_bits < 1)
992  s->time_increment_bits = 1;
993  put_bits(&s->pb, 1, 1); /* marker bit */
994  put_bits(&s->pb, 1, 0); /* fixed vop rate=no */
995  put_bits(&s->pb, 1, 1); /* marker bit */
996  put_bits(&s->pb, 13, s->width); /* vol width */
997  put_bits(&s->pb, 1, 1); /* marker bit */
998  put_bits(&s->pb, 13, s->height); /* vol height */
999  put_bits(&s->pb, 1, 1); /* marker bit */
1000  put_bits(&s->pb, 1, s->progressive_sequence ? 0 : 1);
1001  put_bits(&s->pb, 1, 1); /* obmc disable */
1002  if (vo_ver_id == 1) {
1003  put_bits(&s->pb, 1, s->vol_sprite_usage); /* sprite enable */
1004  }else{
1005  put_bits(&s->pb, 2, s->vol_sprite_usage); /* sprite enable */
1006  }
1007 
1008  put_bits(&s->pb, 1, 0); /* not 8 bit == false */
1009  put_bits(&s->pb, 1, s->mpeg_quant); /* quant type= (0=h263 style)*/
1010 
1011  if(s->mpeg_quant){
1014  }
1015 
1016  if (vo_ver_id != 1)
1017  put_bits(&s->pb, 1, s->quarter_sample);
1018  put_bits(&s->pb, 1, 1); /* complexity estimation disable */
1019  s->resync_marker= s->rtp_mode;
1020  put_bits(&s->pb, 1, s->resync_marker ? 0 : 1);/* resync marker disable */
1021  put_bits(&s->pb, 1, s->data_partitioning ? 1 : 0);
1022  if(s->data_partitioning){
1023  put_bits(&s->pb, 1, 0); /* no rvlc */
1024  }
1025 
1026  if (vo_ver_id != 1){
1027  put_bits(&s->pb, 1, 0); /* newpred */
1028  put_bits(&s->pb, 1, 0); /* reduced res vop */
1029  }
1030  put_bits(&s->pb, 1, 0); /* scalability */
1031 
1032  ff_mpeg4_stuffing(&s->pb);
1033 
1034  /* user data */
1035  if(!(s->flags & CODEC_FLAG_BITEXACT)){
1036  put_bits(&s->pb, 16, 0);
1037  put_bits(&s->pb, 16, 0x1B2); /* user_data */
1039  }
1040 }
1041 
1042 /* write mpeg4 VOP header */
1044 {
1045  int time_incr;
1046  int time_div, time_mod;
1047 
1048  if(s->pict_type==AV_PICTURE_TYPE_I){
1049  if(!(s->flags&CODEC_FLAG_GLOBAL_HEADER)){
1050  if(s->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT) //HACK, the reference sw is buggy
1052  if(s->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT || picture_number==0) //HACK, the reference sw is buggy
1053  mpeg4_encode_vol_header(s, 0, 0);
1054  }
1055  if(!(s->workaround_bugs & FF_BUG_MS))
1057  }
1058 
1060 
1061  put_bits(&s->pb, 16, 0); /* vop header */
1062  put_bits(&s->pb, 16, VOP_STARTCODE); /* vop header */
1063  put_bits(&s->pb, 2, s->pict_type - 1); /* pict type: I = 0 , P = 1 */
1064 
1065  time_div= FFUDIV(s->time, s->avctx->time_base.den);
1066  time_mod= FFUMOD(s->time, s->avctx->time_base.den);
1067  time_incr= time_div - s->last_time_base;
1068  av_assert0(time_incr >= 0);
1069  while(time_incr--)
1070  put_bits(&s->pb, 1, 1);
1071 
1072  put_bits(&s->pb, 1, 0);
1073 
1074  put_bits(&s->pb, 1, 1); /* marker */
1075  put_bits(&s->pb, s->time_increment_bits, time_mod); /* time increment */
1076  put_bits(&s->pb, 1, 1); /* marker */
1077  put_bits(&s->pb, 1, 1); /* vop coded */
1078  if ( s->pict_type == AV_PICTURE_TYPE_P
1080  put_bits(&s->pb, 1, s->no_rounding); /* rounding type */
1081  }
1082  put_bits(&s->pb, 3, 0); /* intra dc VLC threshold */
1083  if(!s->progressive_sequence){
1085  put_bits(&s->pb, 1, s->alternate_scan);
1086  }
1087  //FIXME sprite stuff
1088 
1089  put_bits(&s->pb, 5, s->qscale);
1090 
1091  if (s->pict_type != AV_PICTURE_TYPE_I)
1092  put_bits(&s->pb, 3, s->f_code); /* fcode_for */
1093  if (s->pict_type == AV_PICTURE_TYPE_B)
1094  put_bits(&s->pb, 3, s->b_code); /* fcode_back */
1095 }
1096 
1097 
1098 static void init_uni_dc_tab(void)
1099 {
1100  int level, uni_code, uni_len;
1101 
1102  for(level=-256; level<256; level++){
1103  int size, v, l;
1104  /* find number of bits */
1105  size = 0;
1106  v = abs(level);
1107  while (v) {
1108  v >>= 1;
1109  size++;
1110  }
1111 
1112  if (level < 0)
1113  l= (-level) ^ ((1 << size) - 1);
1114  else
1115  l= level;
1116 
1117  /* luminance */
1118  uni_code= ff_mpeg4_DCtab_lum[size][0];
1119  uni_len = ff_mpeg4_DCtab_lum[size][1];
1120 
1121  if (size > 0) {
1122  uni_code<<=size; uni_code|=l;
1123  uni_len+=size;
1124  if (size > 8){
1125  uni_code<<=1; uni_code|=1;
1126  uni_len++;
1127  }
1128  }
1129  uni_DCtab_lum_bits[level+256]= uni_code;
1130  uni_DCtab_lum_len [level+256]= uni_len;
1131 
1132  /* chrominance */
1133  uni_code= ff_mpeg4_DCtab_chrom[size][0];
1134  uni_len = ff_mpeg4_DCtab_chrom[size][1];
1135 
1136  if (size > 0) {
1137  uni_code<<=size; uni_code|=l;
1138  uni_len+=size;
1139  if (size > 8){
1140  uni_code<<=1; uni_code|=1;
1141  uni_len++;
1142  }
1143  }
1144  uni_DCtab_chrom_bits[level+256]= uni_code;
1145  uni_DCtab_chrom_len [level+256]= uni_len;
1146 
1147  }
1148 }
1149 
1150 static void init_uni_mpeg4_rl_tab(RLTable *rl, uint32_t *bits_tab, uint8_t *len_tab){
1151  int slevel, run, last;
1152 
1153  av_assert0(MAX_LEVEL >= 64);
1154  av_assert0(MAX_RUN >= 63);
1155 
1156  for(slevel=-64; slevel<64; slevel++){
1157  if(slevel==0) continue;
1158  for(run=0; run<64; run++){
1159  for(last=0; last<=1; last++){
1160  const int index= UNI_MPEG4_ENC_INDEX(last, run, slevel+64);
1161  int level= slevel < 0 ? -slevel : slevel;
1162  int sign= slevel < 0 ? 1 : 0;
1163  int bits, len, code;
1164  int level1, run1;
1165 
1166  len_tab[index]= 100;
1167 
1168  /* ESC0 */
1169  code= get_rl_index(rl, last, run, level);
1170  bits= rl->table_vlc[code][0];
1171  len= rl->table_vlc[code][1];
1172  bits=bits*2+sign; len++;
1173 
1174  if(code!=rl->n && len < len_tab[index]){
1175  bits_tab[index]= bits;
1176  len_tab [index]= len;
1177  }
1178  /* ESC1 */
1179  bits= rl->table_vlc[rl->n][0];
1180  len= rl->table_vlc[rl->n][1];
1181  bits=bits*2; len++; //esc1
1182  level1= level - rl->max_level[last][run];
1183  if(level1>0){
1184  code= get_rl_index(rl, last, run, level1);
1185  bits<<= rl->table_vlc[code][1];
1186  len += rl->table_vlc[code][1];
1187  bits += rl->table_vlc[code][0];
1188  bits=bits*2+sign; len++;
1189 
1190  if(code!=rl->n && len < len_tab[index]){
1191  bits_tab[index]= bits;
1192  len_tab [index]= len;
1193  }
1194  }
1195  /* ESC2 */
1196  bits= rl->table_vlc[rl->n][0];
1197  len= rl->table_vlc[rl->n][1];
1198  bits=bits*4+2; len+=2; //esc2
1199  run1 = run - rl->max_run[last][level] - 1;
1200  if(run1>=0){
1201  code= get_rl_index(rl, last, run1, level);
1202  bits<<= rl->table_vlc[code][1];
1203  len += rl->table_vlc[code][1];
1204  bits += rl->table_vlc[code][0];
1205  bits=bits*2+sign; len++;
1206 
1207  if(code!=rl->n && len < len_tab[index]){
1208  bits_tab[index]= bits;
1209  len_tab [index]= len;
1210  }
1211  }
1212  /* ESC3 */
1213  bits= rl->table_vlc[rl->n][0];
1214  len = rl->table_vlc[rl->n][1];
1215  bits=bits*4+3; len+=2; //esc3
1216  bits=bits*2+last; len++;
1217  bits=bits*64+run; len+=6;
1218  bits=bits*2+1; len++; //marker
1219  bits=bits*4096+(slevel&0xfff); len+=12;
1220  bits=bits*2+1; len++; //marker
1221 
1222  if(len < len_tab[index]){
1223  bits_tab[index]= bits;
1224  len_tab [index]= len;
1225  }
1226  }
1227  }
1228  }
1229 }
1230 
1232 {
1233  MpegEncContext *s = avctx->priv_data;
1234  int ret;
1235  static int done = 0;
1236 
1237  if (avctx->width >= (1<<13) || avctx->height >= (1<<13)) {
1238  av_log(avctx, AV_LOG_ERROR, "dimensions too large for MPEG-4\n");
1239  return AVERROR(EINVAL);
1240  }
1241 
1242  if((ret=ff_MPV_encode_init(avctx)) < 0)
1243  return ret;
1244 
1245  if (!done) {
1246  done = 1;
1247 
1248  init_uni_dc_tab();
1249 
1251 
1254  }
1255 
1256  s->min_qcoeff= -2048;
1257  s->max_qcoeff= 2047;
1263  s->ac_esc_length= 7+2+1+6+1+12+1;
1266 
1268 
1269  s->avctx->extradata= av_malloc(1024);
1270  init_put_bits(&s->pb, s->avctx->extradata, 1024);
1271 
1272  if(!(s->workaround_bugs & FF_BUG_MS))
1274  mpeg4_encode_vol_header(s, 0, 0);
1275 
1276 // ff_mpeg4_stuffing(&s->pb); ?
1277  flush_put_bits(&s->pb);
1278  s->avctx->extradata_size= (put_bits_count(&s->pb)+7)>>3;
1279  }
1280  return 0;
1281 }
1282 
1284 {
1285  uint8_t *start= put_bits_ptr(&s->pb);
1286  uint8_t *end= s->pb.buf_end;
1287  int size= end - start;
1288  int pb_size = (((intptr_t)start + size/3)&(~3)) - (intptr_t)start;
1289  int tex_size= (size - 2*pb_size)&(~3);
1290 
1291  set_put_bits_buffer_size(&s->pb, pb_size);
1292  init_put_bits(&s->tex_pb, start + pb_size , tex_size);
1293  init_put_bits(&s->pb2 , start + pb_size + tex_size, pb_size);
1294 }
1295 
1297 {
1298  const int pb2_len = put_bits_count(&s->pb2 );
1299  const int tex_pb_len= put_bits_count(&s->tex_pb);
1300  const int bits= put_bits_count(&s->pb);
1301 
1302  if(s->pict_type==AV_PICTURE_TYPE_I){
1303  put_bits(&s->pb, 19, DC_MARKER);
1304  s->misc_bits+=19 + pb2_len + bits - s->last_bits;
1305  s->i_tex_bits+= tex_pb_len;
1306  }else{
1307  put_bits(&s->pb, 17, MOTION_MARKER);
1308  s->misc_bits+=17 + pb2_len;
1309  s->mv_bits+= bits - s->last_bits;
1310  s->p_tex_bits+= tex_pb_len;
1311  }
1312 
1313  flush_put_bits(&s->pb2);
1314  flush_put_bits(&s->tex_pb);
1315 
1316  set_put_bits_buffer_size(&s->pb, s->pb2.buf_end - s->pb.buf);
1317  avpriv_copy_bits(&s->pb, s->pb2.buf , pb2_len);
1318  avpriv_copy_bits(&s->pb, s->tex_pb.buf, tex_pb_len);
1319  s->last_bits= put_bits_count(&s->pb);
1320 }
1321 
1322 
1324 {
1325  int mb_num_bits= av_log2(s->mb_num - 1) + 1;
1326 
1328  put_bits(&s->pb, 1, 1);
1329 
1330  put_bits(&s->pb, mb_num_bits, s->mb_x + s->mb_y*s->mb_width);
1331  put_bits(&s->pb, s->quant_precision, s->qscale);
1332  put_bits(&s->pb, 1, 0); /* no HEC */
1333 }
1334 
1335 #define OFFSET(x) offsetof(MpegEncContext, x)
1336 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1337 static const AVOption options[] = {
1338  { "data_partitioning", "Use data partitioning.", OFFSET(data_partitioning), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
1339  { "alternate_scan", "Enable alternate scantable.", OFFSET(alternate_scan), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
1341  { NULL },
1342 };
1343 
1344 static const AVClass mpeg4enc_class = {
1345  .class_name = "MPEG4 encoder",
1346  .item_name = av_default_item_name,
1347  .option = options,
1348  .version = LIBAVUTIL_VERSION_INT,
1349 };
1350 
1352  .name = "mpeg4",
1353  .type = AVMEDIA_TYPE_VIDEO,
1354  .id = AV_CODEC_ID_MPEG4,
1355  .priv_data_size = sizeof(MpegEncContext),
1356  .init = encode_init,
1357  .encode2 = ff_MPV_encode_picture,
1359  .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
1360  .capabilities = CODEC_CAP_DELAY | CODEC_CAP_SLICE_THREADS,
1361  .long_name = NULL_IF_CONFIG_SMALL("MPEG-4 part 2"),
1362  .priv_class = &mpeg4enc_class,
1363 };
int last_time_base
Definition: mpegvideo.h:556
static void mpeg4_encode_visual_object_header(MpegEncContext *s)
Definition: start.py:1
float v
int aspect_ratio_info
Definition: mpegvideo.h:585
const char * s
Definition: avisynth_c.h:668
ScanTable intra_v_scantable
Definition: mpegvideo.h:298
S(GMC)-VOP MPEG4.
Definition: avutil.h:219
RLTable ff_mpeg4_rl_intra
Definition: mpeg4data.h:109
const uint8_t ff_mpeg4_c_dc_scale_table[32]
Definition: mpeg4data.h:363
int time_increment_bits
number of bits to represent the fractional part of time
Definition: mpegvideo.h:555
struct MpegEncContext MpegEncContext
MpegEncContext.
AVOption.
Definition: opt.h:251
#define MV_TYPE_FIELD
2 vectors, one per field
Definition: mpegvideo.h:424
static uint8_t uni_mpeg4_intra_rl_len[64 *64 *2 *2]
Definition: mpeg4videoenc.c:40
const uint8_t * y_dc_scale_table
qscale -> y_dc_scale table
Definition: mpegvideo.h:351
static void mpeg4_encode_block(MpegEncContext *s, int16_t *block, int n, int intra_dc, uint8_t *scan_table, PutBitContext *dc_pb, PutBitContext *ac_pb)
Encode an 8x8 block.
int last_mv[2][2][2]
last MV, used for MV prediction in MPEG1 & B-frame MPEG4
Definition: mpegvideo.h:433
av_default_item_name
void ff_clean_mpeg4_qscales(MpegEncContext *s)
modify mb_type & qscale so that encoding is actually possible in mpeg4
#define CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
#define CANDIDATE_MB_TYPE_BIDIR
Definition: mpegvideo.h:456
RLTable ff_h263_rl_inter
Definition: h263data.h:162
int16_t(*[3] ac_val)[16]
used for for mpeg4 AC prediction, all 3 arrays must be continuous
Definition: mpegvideo.h:357
static int get_block_rate(MpegEncContext *s, int16_t block[64], int block_last_index, uint8_t scantable[64])
Return the number of bits that encoding the 8x8 block in block would need.
Definition: mpeg4videoenc.c:62
int ff_MPV_encode_end(AVCodecContext *avctx)
const uint8_t ff_h263_intra_MCBPC_code[9]
Definition: h263data.h:36
#define FF_MPV_COMMON_OPTS
Definition: mpegvideo.h:758
const uint8_t ff_h263_cbpy_tab[16][2]
Definition: h263data.h:85
int num
numerator
Definition: rational.h:44
static void skip_put_bits(PutBitContext *s, int n)
Skip the given number of bits.
Definition: put_bits.h:220
void ff_init_rl(RLTable *rl, uint8_t static_store[2][2 *MAX_RUN+MAX_LEVEL+3])
Definition: mpegvideo.c:1304
y1
Definition: lab5.m:33
void avpriv_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
Copy the content of src to the bitstream.
Definition: bitstream.c:61
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
int min_qcoeff
minimum encodable coefficient
Definition: mpegvideo.h:479
x1
Definition: genspecsines3.m:7
int coded_score[12]
Definition: mpegvideo.h:489
mpegvideo header.
static uint32_t uni_mpeg4_intra_rl_bits[64 *64 *2 *2]
Definition: mpeg4videoenc.c:39
#define DC_MARKER
Definition: mpeg4video.h:53
int mpv_flags
flags set by private options
Definition: mpegvideo.h:732
uint8_t permutated[64]
Definition: dsputil.h:116
uint8_t run
Definition: svq3.c:136
uint8_t * intra_ac_vlc_length
Definition: mpegvideo.h:482
#define UNI_AC_ENC_INDEX(run, level)
Definition: mpegvideo.h:487
int mb_num
number of MBs of a picture
Definition: mpegvideo.h:282
#define FF_LAMBDA_SHIFT
Definition: avutil.h:167
void(* clear_block)(int16_t *block)
Definition: dsputil.h:145
int time_base
time in seconds of last I,P,S Frame
Definition: mpegvideo.h:557
RLTable.
Definition: rl.h:38
int qscale
QP.
Definition: mpegvideo.h:369
static void init_uni_dc_tab(void)
int16_t * ff_h263_pred_motion(MpegEncContext *s, int block, int dir, int *px, int *py)
Definition: h263.c:315
void ff_mpeg4_encode_picture_header(MpegEncContext *s, int picture_number)
#define INPLACE_OFFSET
Definition: mpegvideo.h:74
int field_select[2][2]
Definition: mpegvideo.h:432
int block_wrap[6]
Definition: mpegvideo.h:466
int quant_precision
Definition: mpegvideo.h:578
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
#define FF_MPV_FLAG_CBP_RD
Definition: mpegvideo.h:754
initialize output if(nPeaks >3)%at least 3 peaks in spectrum for trying to find f0 nf0peaks
void ff_mpeg4_stuffing(PutBitContext *pbc)
add mpeg4 stuffing bits (01...1)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:55
static uint8_t uni_DCtab_chrom_len[512]
Definition: mpeg4videoenc.c:33
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
int8_t * max_run[2]
encoding & decoding
Definition: rl.h:46
int64_t time
time of current frame
Definition: mpegvideo.h:558
#define MV_DIRECT
bidirectional mode where the difference equals the MV of the last P/S/I-Frame (mpeg4) ...
Definition: mpegvideo.h:419
uint8_t bits
Definition: crc.c:216
uint8_t
#define av_cold
Definition: attributes.h:78
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:63
AVOptions.
PutBitContext pb2
used for data partitioned VOPs
Definition: mpegvideo.h:598
const uint8_t ff_h263_intra_MCBPC_bits[9]
Definition: h263data.h:37
#define VOP_STARTCODE
Definition: mpeg4video.h:59
#define CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
#define FF_COMPLIANCE_VERY_STRICT
Strictly conform to an older more strict version of the spec or reference software.
end end
#define FF_PROFILE_UNKNOWN
static int decide_ac_pred(MpegEncContext *s, int16_t block[6][64], const int dir[6], uint8_t *st[6], int zigzag_last_index[6])
Return the optimal value (0 or 1) for the ac_pred element for the given MB in mpeg4.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:159
int misc_bits
cbp, mb_type
Definition: mpegvideo.h:523
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
int no_rounding
apply no rounding to motion compensation (MPEG4, msmpeg4, ...) for b-frames rounding mode is always 0...
Definition: mpegvideo.h:439
int interlaced_dct
Definition: mpegvideo.h:684
const uint8_t ff_h263_inter_MCBPC_bits[28]
Definition: h263data.h:50
int resync_marker
could this stream contain resync markers
Definition: mpegvideo.h:591
Picture current_picture
copy of the current picture structure.
Definition: mpegvideo.h:343
const uint8_t ff_mpeg4_DCtab_chrom[13][2]
Definition: mpeg4data.h:41
#define RECT_SHAPE
Definition: mpeg4video.h:32
int8_t * max_level[2]
encoding & decoding
Definition: rl.h:45
uint8_t idct_permutation[64]
idct input permutation.
Definition: dsputil.h:249
int flags2
AVCodecContext.flags2.
Definition: mpegvideo.h:261
#define CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
int max_qcoeff
maximum encodable coefficient
Definition: mpegvideo.h:480
#define CODEC_FLAG_AC_PRED
H.263 advanced intra coding / MPEG-4 AC prediction.
static const int dquant_code[5]
#define MAX_LEVEL
Definition: rl.h:35
static uint32_t uni_mpeg4_inter_rl_bits[64 *64 *2 *2]
Definition: mpeg4videoenc.c:41
static int ff_mpeg4_pred_dc(MpegEncContext *s, int n, int level, int *dir_ptr, int encoding)
Predict the dc.
Definition: mpeg4video.h:129
int dquant
qscale difference to prev qscale
Definition: mpegvideo.h:375
#define MOTION_MARKER
Definition: mpeg4video.h:52
#define UNI_MPEG4_ENC_INDEX(last, run, level)
Definition: mpeg4videoenc.c:45
#define ROUNDED_DIV(a, b)
Definition: common.h:50
int ff_MPV_encode_init(AVCodecContext *avctx)
static void mpeg4_encode_gop_header(MpegEncContext *s)
static int get_bits_diff(MpegEncContext *s)
Definition: mpegvideo.h:875
Discrete Time axis x
void ff_mpeg4_init_partitions(MpegEncContext *s)
#define CANDIDATE_MB_TYPE_DIRECT
Definition: mpegvideo.h:453
static uint8_t * put_bits_ptr(PutBitContext *s)
Return the pointer to the byte where the bitstream writer will put the next bit.
Definition: put_bits.h:199
uint8_t * mbskip_table
Definition: mpegvideo.h:111
static void restore_ac_coeffs(MpegEncContext *s, int16_t block[6][64], const int dir[6], uint8_t *st[6], const int zigzag_last_index[6])
Restore the ac coefficients in block that have been changed by decide_ac_pred().
Definition: mpeg4videoenc.c:94
uint8_t * inter_ac_vlc_last_length
Definition: mpegvideo.h:485
void ff_mpeg4_merge_partitions(MpegEncContext *s)
int mb_skipped
MUST BE SET only during DECODING.
Definition: mpegvideo.h:358
#define CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
int strict_std_compliance
strictly follow the std (MPEG4, ...)
Definition: mpegvideo.h:265
int partitioned_frame
is current frame partitioned
Definition: mpegvideo.h:589
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void ff_mpeg4_encode_mb(MpegEncContext *s, int16_t block[6][64], int motion_x, int motion_y)
#define SIMPLE_VO_TYPE
Definition: mpeg4video.h:37
uint8_t * buf
Definition: put_bits.h:44
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
void ff_mpeg4_init_direct_mv(MpegEncContext *s)
Definition: mpeg4video.c:78
const char * name
Name of the codec implementation.
int quarter_sample
1->qpel, 0->half pel ME/MC
Definition: mpegvideo.h:579
uint16_t * mb_type
Table for candidate MB types for encoding.
Definition: mpegvideo.h:446
av_const int ff_h263_aspect_to_info(AVRational aspect)
Return the 4 bit value that specifies the given aspect ratio.
Definition: ituh263enc.c:87
int low_delay
no reordering needed / has no b-frames
Definition: mpegvideo.h:592
int vol_sprite_usage
Definition: mpegvideo.h:565
static const uint8_t offset[127][2]
Definition: vf_spp.c:70
static void put_bits(J2kEncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:160
int size
static int put_bits_count(PutBitContext *s)
Definition: put_bits.h:73
void ff_clean_h263_qscales(MpegEncContext *s)
modify qscale so that encoding is actually possible in h263 (limit difference to -2..2)
Definition: ituh263enc.c:272
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:36
uint8_t * intra_ac_vlc_last_length
Definition: mpegvideo.h:483
#define ADV_SIMPLE_VO_TYPE
Definition: mpeg4video.h:43
const uint8_t ff_mpeg4_DCtab_lum[13][2]
Definition: mpeg4data.h:35
uint8_t ff_mpeg4_static_rl_table_store[3][2][2 *MAX_RUN+MAX_LEVEL+3]
Definition: mpeg4video.c:27
int n
number of entries of table_vlc minus 1
Definition: rl.h:39
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:144
#define FFMIN(a, b)
Definition: common.h:58
const uint8_t ff_mpeg4_y_dc_scale_table[32]
Definition: mpeg4data.h:359
const uint16_t(* table_vlc)[2]
Definition: rl.h:41
Picture new_picture
copy of the source picture structure for encoding.
Definition: mpegvideo.h:337
ret
Definition: avfilter.c:821
static uint8_t uni_mpeg4_inter_rl_len[64 *64 *2 *2]
Definition: mpeg4videoenc.c:42
int width
picture width / height.
int16_t(*[2] motion_val)[2]
Definition: mpegvideo.h:105
Picture * current_picture_ptr
pointer to the current picture
Definition: mpegvideo.h:347
Picture.
Definition: mpegvideo.h:97
static const AVClass mpeg4enc_class
int alternate_scan
Definition: mpegvideo.h:672
static uint16_t uni_DCtab_lum_bits[512]
Definition: mpeg4videoenc.c:34
static uint16_t uni_DCtab_chrom_bits[512]
Definition: mpeg4videoenc.c:35
static int get_b_cbp(MpegEncContext *s, int16_t block[6][64], int motion_x, int motion_y, int mb_type)
static uint8_t uni_DCtab_lum_len[512]
Definition: mpeg4videoenc.c:32
#define FFABS(a)
Definition: common.h:53
int block_last_index[12]
last non zero coefficient in block
Definition: mpegvideo.h:291
#define diff(a, as, b, bs)
Definition: vf_phase.c:80
FIXME Range Coding of cr are level
Definition: snow.txt:367
const uint8_t ff_h263_inter_MCBPC_code[28]
Definition: h263data.h:41
int ac_esc_length
num of bits needed to encode the longest esc
Definition: mpegvideo.h:481
LIBAVUTIL_VERSION_INT
Definition: eval.c:55
static void set_put_bits_buffer_size(PutBitContext *s, int size)
Change the end of the buffer.
Definition: put_bits.h:232
void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix)
int block_index[6]
index to current MB in block based arrays with edges
Definition: mpegvideo.h:465
int * mb_index2xy
mb_index -> mb_x + mb_y*mb_stride
Definition: mpegvideo.h:469
#define VE
#define MV_TYPE_16X16
1 vector for the whole mb
Definition: mpegvideo.h:421
NULL
Definition: eval.c:55
or the Software in violation of any applicable export control laws in any jurisdiction Except as provided by mandatorily applicable UPF has no obligation to provide you with source code to the Software In the event Software contains any source code
#define MV_DIR_BACKWARD
Definition: mpegvideo.h:418
#define FFUDIV(a, b)
Definition: common.h:51
uint8_t * luma_dc_vlc_length
Definition: mpegvideo.h:486
static void init_uni_mpeg4_rl_tab(RLTable *rl, uint32_t *bits_tab, uint8_t *len_tab)
unsigned int lambda2
(lambda*lambda) >> FF_LAMBDA_SHIFT
Definition: mpegvideo.h:372
main external API structure.
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:375
ScanTable intra_scantable
Definition: mpegvideo.h:296
int height
picture size. must be a multiple of 16
Definition: mpegvideo.h:245
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
uint8_t * buf_end
Definition: put_bits.h:44
int data_partitioning
data partitioning flag from header
Definition: mpegvideo.h:588
uint8_t * inter_ac_vlc_length
Definition: mpegvideo.h:484
int progressive_sequence
Definition: mpegvideo.h:658
uint16_t * intra_matrix
custom intra quantization matrix
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:73
Describe the class of an AVClass context structure.
Definition: log.h:50
ScanTable intra_h_scantable
Definition: mpegvideo.h:297
int index
Definition: gxfenc.c:89
synthesis window for stochastic i
static av_cold int encode_init(AVCodecContext *avctx)
static int mpeg4_get_block_length(MpegEncContext *s, int16_t *block, int n, int intra_dc, uint8_t *scan_table)
static void ff_h263_encode_motion_vector(MpegEncContext *s, int x, int y, int f_code)
Definition: h263.h:137
DSPContext dsp
pointers for accelerated dsp functions
Definition: mpegvideo.h:391
int f_code
forward MV resolution
Definition: mpegvideo.h:395
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Buffer references ownership and permissions
#define CODEC_FLAG_CLOSED_GOP
uint16_t * inter_matrix
custom inter quantization matrix
#define MV_DIR_FORWARD
Definition: mpegvideo.h:417
int max_b_frames
max number of b-frames for encoding
Definition: mpegvideo.h:262
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
Definition: mpegvideo.h:377
int ff_mpeg4_get_video_packet_prefix_length(MpegEncContext *s)
Definition: mpeg4video.c:29
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:87
const uint8_t * c_dc_scale_table
qscale -> c_dc_scale table
Definition: mpegvideo.h:352
#define FF_ASPECT_EXTENDED
int mv[2][4][2]
motion vectors for a macroblock first coordinate : 0 = forward 1 = backward second " : depend...
Definition: mpegvideo.h:431
MpegEncContext.
Definition: mpegvideo.h:241
int8_t * qscale_table
Definition: mpegvideo.h:102
#define MAX_RUN
Definition: rl.h:34
struct AVCodecContext * avctx
Definition: mpegvideo.h:243
PutBitContext pb
bit output
Definition: mpegvideo.h:314
#define VISUAL_OBJ_STARTCODE
Definition: mpeg4video.h:58
#define CONFIG_MPEG4_ENCODER
Definition: config.h:1049
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:68
#define CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
int mb_stride
mb_width+1 used for some arrays to allow simple addressing of left & top MBs without sig11 ...
Definition: mpegvideo.h:278
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:81
#define CODEC_FLAG2_NO_OUTPUT
Skip bitstream encoding.
int shared
Definition: mpegvideo.h:179
Bi-dir predicted.
Definition: avutil.h:218
me_cmp_func sad[6]
Definition: dsputil.h:151
static const AVOption options[]
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
Definition: put_bits.h:54
int den
denominator
Definition: rational.h:45
function y
Definition: D.m:1
static int get_rl_index(const RLTable *rl, int last, int run, int level)
Definition: rl.h:75
void ff_mpeg4_encode_video_packet_header(MpegEncContext *s)
int last_bits
temp var used for calculating the above vars
Definition: mpegvideo.h:524
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:275
int len
#define av_log2
Definition: intmath.h:89
#define FFUMOD(a, b)
Definition: common.h:52
int16_t(* block)[64]
points to one of the following blocks
Definition: mpegvideo.h:700
PutBitContext tex_pb
used for data partitioned VOPs
Definition: mpegvideo.h:597
Picture next_picture
copy of the next picture structure.
Definition: mpegvideo.h:331
int linesize
line size, in bytes, may be different from width
Definition: mpegvideo.h:283
static int get_p_cbp(MpegEncContext *s, int16_t block[6][64], int motion_x, int motion_y)
Definition: h263.h:148
Picture ** reordered_input_picture
pointer to the next pictures in codedorder for encoding
Definition: mpegvideo.h:287
#define LIBAVCODEC_IDENT
struct AVFrame f
Definition: mpegvideo.h:98
void avpriv_put_string(PutBitContext *pb, const char *string, int terminate_string)
Put the string string in the bitstream.
Definition: bitstream.c:51
int flags
AVCodecContext.flags (HQ, MV4, ...)
Definition: mpegvideo.h:260
void INT64 start
Definition: avisynth_c.h:594
int workaround_bugs
workaround bugs in encoders which cannot be detected automatically
Definition: mpegvideo.h:266
static int mpeg4_get_dc_length(int level, int n)
void ff_set_mpeg4_time(MpegEncContext *s)
const char int length
Definition: avisynth_c.h:668
static void mpeg4_encode_blocks(MpegEncContext *s, int16_t block[6][64], int intra_dc[6], uint8_t **scan_table, PutBitContext *dc_pb, PutBitContext *ac_pb)
#define MV_TYPE_8X8
4 vectors (h263, mpeg4 4MV)
Definition: mpegvideo.h:422
int b_code
backward MV resolution for B Frames (mpeg4)
Definition: mpegvideo.h:396
static void mpeg4_encode_dc(PutBitContext *s, int level, int n)
Encode the dc value.
AVPixelFormat
Pixel format.
Definition: pixfmt.h:66
static void mpeg4_encode_vol_header(MpegEncContext *s, int vo_number, int vol_number)
int ff_MPV_encode_picture(AVCodecContext *avctx, AVPacket *pkt, AVFrame *frame, int *got_packet)
#define OFFSET(x)
AVCodec ff_mpeg4_encoder
#define FF_BUG_MS
Work around various bugs in Microsoft&#39;s broken decoders.
Predicted.
Definition: avutil.h:217
#define GOP_STARTCODE
Definition: mpeg4video.h:57
#define VOS_STARTCODE
Definition: mpeg4video.h:55
#define FF_LEVEL_UNKNOWN
#define GMC_SPRITE
Definition: mpeg4video.h:50