mpeg12enc.c
Go to the documentation of this file.
1 /*
2  * MPEG1/2 encoder
3  * Copyright (c) 2000,2001 Fabrice Bellard
4  * Copyright (c) 2002-2004 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 /**
24  * @file
25  * MPEG1/2 encoder
26  */
27 
28 #include "avcodec.h"
29 #include "mathops.h"
30 #include "mpegvideo.h"
31 
32 #include "mpeg12.h"
33 #include "mpeg12data.h"
34 #include "bytestream.h"
35 #include "libavutil/log.h"
36 #include "libavutil/opt.h"
37 #include "libavutil/avassert.h"
38 #include "libavutil/timecode.h"
39 
40 static const uint8_t inv_non_linear_qscale[13] = {
41  0, 2, 4, 6, 8,
42  9,10,11,12,13,14,15,16,
43 };
44 
46  0x10, 0x0E,
47  0x00, 0x80, 0x81,
48  0x00, 0x80, 0x81,
49  0xff, 0xff, 0xff,
50  0xff, 0xff, 0xff,
51 };
52 
54  int16_t *block,
55  int component);
56 static void mpeg1_encode_motion(MpegEncContext *s, int val, int f_or_b_code); // RAL: f_code parameter added
57 
59 static uint8_t fcode_tab[MAX_MV*2+1];
60 
61 static uint8_t uni_mpeg1_ac_vlc_len [64*64*2];
62 static uint8_t uni_mpeg2_ac_vlc_len [64*64*2];
63 
64 /* simple include everything table for dc, first byte is bits number next 3 are code*/
65 static uint32_t mpeg1_lum_dc_uni[512];
66 static uint32_t mpeg1_chr_dc_uni[512];
67 
68 static uint8_t mpeg1_index_run[2][64];
69 static int8_t mpeg1_max_level[2][64];
70 
71 static void init_uni_ac_vlc(RLTable *rl, uint8_t *uni_ac_vlc_len){
72  int i;
73 
74  for(i=0; i<128; i++){
75  int level= i-64;
76  int run;
77  if (!level)
78  continue;
79  for(run=0; run<64; run++){
80  int len, code;
81 
82  int alevel= FFABS(level);
83 
84  if (alevel > rl->max_level[0][run])
85  code= 111; /*rl->n*/
86  else
87  code= rl->index_run[0][run] + alevel - 1;
88 
89  if (code < 111 /* rl->n */) {
90  /* length of vlc and sign */
91  len= rl->table_vlc[code][1]+1;
92  } else {
93  len= rl->table_vlc[111/*rl->n*/][1]+6;
94 
95  if (alevel < 128) {
96  len += 8;
97  } else {
98  len += 16;
99  }
100  }
101 
102  uni_ac_vlc_len [UNI_AC_ENC_INDEX(run, i)]= len;
103  }
104  }
105 }
106 
107 
109  int i;
110  AVRational bestq= (AVRational){0, 0};
111  AVRational ext;
112  AVRational target = av_inv_q(s->avctx->time_base);
113 
114  for(i=1;i<14;i++) {
115  if(s->avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL && i>=9) break;
116 
117  for (ext.num=1; ext.num <= 4; ext.num++) {
118  for (ext.den=1; ext.den <= 32; ext.den++) {
120 
121  if(s->codec_id != AV_CODEC_ID_MPEG2VIDEO && (ext.den!=1 || ext.num!=1))
122  continue;
123  if(av_gcd(ext.den, ext.num) != 1)
124  continue;
125 
126  if( bestq.num==0
127  || av_nearer_q(target, bestq, q) < 0
128  || ext.num==1 && ext.den==1 && av_nearer_q(target, bestq, q) == 0){
129  bestq = q;
130  s->frame_rate_index= i;
131  s->mpeg2_frame_rate_ext.num = ext.num;
132  s->mpeg2_frame_rate_ext.den = ext.den;
133  }
134  }
135  }
136  }
137  if(av_cmp_q(target, bestq))
138  return -1;
139  else
140  return 0;
141 }
142 
144 {
145  MpegEncContext *s = avctx->priv_data;
146 
147  if (avctx->codec_id == AV_CODEC_ID_MPEG1VIDEO && avctx->height > 2800)
148  avctx->thread_count = 1;
149 
150  if(ff_MPV_encode_init(avctx) < 0)
151  return -1;
152 
153  if(find_frame_rate_index(s) < 0){
155  av_log(avctx, AV_LOG_ERROR, "MPEG1/2 does not support %d/%d fps\n", avctx->time_base.den, avctx->time_base.num);
156  return -1;
157  }else{
158  av_log(avctx, AV_LOG_INFO, "MPEG1/2 does not support %d/%d fps, there may be AV sync issues\n", avctx->time_base.den, avctx->time_base.num);
159  }
160  }
161 
162  if(avctx->profile == FF_PROFILE_UNKNOWN){
163  if(avctx->level != FF_LEVEL_UNKNOWN){
164  av_log(avctx, AV_LOG_ERROR, "Set profile and level\n");
165  return -1;
166  }
167  avctx->profile = s->chroma_format == CHROMA_420 ? 4 : 0; /* Main or 4:2:2 */
168  }
169 
170  if(avctx->level == FF_LEVEL_UNKNOWN){
171  if(avctx->profile == 0){ /* 4:2:2 */
172  if(avctx->width <= 720 && avctx->height <= 608) avctx->level = 5; /* Main */
173  else avctx->level = 2; /* High */
174  }else{
175  if(avctx->profile != 1 && s->chroma_format != CHROMA_420){
176  av_log(avctx, AV_LOG_ERROR, "Only High(1) and 4:2:2(0) profiles support 4:2:2 color sampling\n");
177  return -1;
178  }
179  if(avctx->width <= 720 && avctx->height <= 576) avctx->level = 8; /* Main */
180  else if(avctx->width <= 1440) avctx->level = 6; /* High 1440 */
181  else avctx->level = 4; /* High */
182  }
183  }
184 
185  if ((avctx->width & 0xFFF) == 0 && (avctx->height & 0xFFF) == 1) {
186  av_log(avctx, AV_LOG_ERROR, "Width / Height is invalid for MPEG2\n");
187  return AVERROR(EINVAL);
188  }
189 
191  if ((avctx->width & 0xFFF) == 0 || (avctx->height & 0xFFF) == 0) {
192  av_log(avctx, AV_LOG_ERROR, "Width or Height are not allowed to be multiplies of 4096\n"
193  "add '-strict %d' if you want to use them anyway.\n", FF_COMPLIANCE_UNOFFICIAL);
194  return AVERROR(EINVAL);
195  }
196  }
197 
199  if (s->drop_frame_timecode)
201  if (s->drop_frame_timecode && s->frame_rate_index != 4) {
202  av_log(avctx, AV_LOG_ERROR, "Drop frame time code only allowed with 1001/30000 fps\n");
203  return -1;
204  }
205 
206  if (s->tc_opt_str) {
208  int ret = av_timecode_init_from_string(&s->tc, rate, s->tc_opt_str, s);
209  if (ret < 0)
210  return ret;
213  } else {
214  s->avctx->timecode_frame_start = 0; // default is -1
215  }
216  return 0;
217 }
218 
219 static void put_header(MpegEncContext *s, int header)
220 {
222  put_bits(&s->pb, 16, header>>16);
223  put_sbits(&s->pb, 16, header);
224 }
225 
226 /* put sequence header if needed */
228 {
229  unsigned int vbv_buffer_size;
230  unsigned int fps, v;
231  int i;
232  uint64_t time_code;
233  float best_aspect_error= 1E10;
234  float aspect_ratio= av_q2d(s->avctx->sample_aspect_ratio);
235  int constraint_parameter_flag;
236 
237  if(aspect_ratio==0.0) aspect_ratio= 1.0; //pixel aspect 1:1 (VGA)
238 
239  if (s->current_picture.f.key_frame) {
241 
242  /* mpeg1 header repeated every gop */
244 
245  put_sbits(&s->pb, 12, s->width & 0xFFF);
246  put_sbits(&s->pb, 12, s->height & 0xFFF);
247 
248  for(i=1; i<15; i++){
249  float error= aspect_ratio;
250  if(s->codec_id == AV_CODEC_ID_MPEG1VIDEO || i <=1)
251  error-= 1.0/ff_mpeg1_aspect[i];
252  else
253  error-= av_q2d(ff_mpeg2_aspect[i])*s->height/s->width;
254 
255  error= FFABS(error);
256 
257  if(error < best_aspect_error){
258  best_aspect_error= error;
259  s->aspect_ratio_info= i;
260  }
261  }
262 
263  put_bits(&s->pb, 4, s->aspect_ratio_info);
264  put_bits(&s->pb, 4, s->frame_rate_index);
265 
266  if(s->avctx->rc_max_rate){
267  v = (s->avctx->rc_max_rate + 399) / 400;
268  if (v > 0x3ffff && s->codec_id == AV_CODEC_ID_MPEG1VIDEO)
269  v = 0x3ffff;
270  }else{
271  v= 0x3FFFF;
272  }
273 
274  if(s->avctx->rc_buffer_size)
275  vbv_buffer_size = s->avctx->rc_buffer_size;
276  else
277  /* VBV calculation: Scaled so that a VCD has the proper VBV size of 40 kilobytes */
278  vbv_buffer_size = (( 20 * s->bit_rate) / (1151929 / 2)) * 8 * 1024;
279  vbv_buffer_size= (vbv_buffer_size + 16383) / 16384;
280 
281  put_sbits(&s->pb, 18, v);
282  put_bits(&s->pb, 1, 1); /* marker */
283  put_sbits(&s->pb, 10, vbv_buffer_size);
284 
285  constraint_parameter_flag=
286  s->width <= 768 && s->height <= 576 &&
287  s->mb_width * s->mb_height <= 396 &&
288  s->mb_width * s->mb_height * framerate.num <= framerate.den*396*25 &&
289  framerate.num <= framerate.den*30 &&
290  s->avctx->me_range && s->avctx->me_range < 128 &&
291  vbv_buffer_size <= 20 &&
292  v <= 1856000/400 &&
294 
295  put_bits(&s->pb, 1, constraint_parameter_flag);
296 
299 
302  put_bits(&s->pb, 4, 1); //seq ext
303 
304  put_bits(&s->pb, 1, s->avctx->profile == 0); //escx 1 for 4:2:2 profile */
305 
306  put_bits(&s->pb, 3, s->avctx->profile); //profile
307  put_bits(&s->pb, 4, s->avctx->level); //level
308 
309  put_bits(&s->pb, 1, s->progressive_sequence);
310  put_bits(&s->pb, 2, s->chroma_format);
311  put_bits(&s->pb, 2, s->width >>12);
312  put_bits(&s->pb, 2, s->height>>12);
313  put_bits(&s->pb, 12, v>>18); //bitrate ext
314  put_bits(&s->pb, 1, 1); //marker
315  put_bits(&s->pb, 8, vbv_buffer_size >>10); //vbv buffer ext
316  put_bits(&s->pb, 1, s->low_delay);
317  put_bits(&s->pb, 2, s->mpeg2_frame_rate_ext.num-1); // frame_rate_ext_n
318  put_bits(&s->pb, 5, s->mpeg2_frame_rate_ext.den-1); // frame_rate_ext_d
319  }
320 
322  put_bits(&s->pb, 1, s->drop_frame_timecode); /* drop frame flag */
323  /* time code : we must convert from the real frame rate to a
324  fake mpeg frame rate in case of low frame rate */
325  fps = (framerate.num + framerate.den/2)/ framerate.den;
327 
330  if (s->drop_frame_timecode)
331  time_code = av_timecode_adjust_ntsc_framenum2(time_code, fps);
332  put_bits(&s->pb, 5, (uint32_t)((time_code / (fps * 3600)) % 24));
333  put_bits(&s->pb, 6, (uint32_t)((time_code / (fps * 60)) % 60));
334  put_bits(&s->pb, 1, 1);
335  put_bits(&s->pb, 6, (uint32_t)((time_code / fps) % 60));
336  put_bits(&s->pb, 6, (uint32_t)((time_code % fps)));
337  put_bits(&s->pb, 1, !!(s->flags & CODEC_FLAG_CLOSED_GOP));
338  put_bits(&s->pb, 1, 0); /* broken link */
339  }
340 }
341 
342 static inline void encode_mb_skip_run(MpegEncContext *s, int run){
343  while (run >= 33) {
344  put_bits(&s->pb, 11, 0x008);
345  run -= 33;
346  }
348  ff_mpeg12_mbAddrIncrTable[run][0]);
349 }
350 
352 {
353  if(s->q_scale_type){
354  av_assert2(s->qscale>=1 && s->qscale <=12);
356  }else{
357  put_bits(&s->pb, 5, s->qscale);
358  }
359 }
360 
362  if (s->codec_id == AV_CODEC_ID_MPEG2VIDEO && s->height > 2800) {
363  put_header(s, SLICE_MIN_START_CODE + (s->mb_y & 127));
364  put_bits(&s->pb, 3, s->mb_y >> 7); /* slice_vertical_position_extension */
365  } else {
367  }
368  put_qscale(s);
369  put_bits(&s->pb, 1, 0); /* slice extra information */
370 }
371 
372 void ff_mpeg1_encode_picture_header(MpegEncContext *s, int picture_number)
373 {
375 
376  /* mpeg1 picture header */
378  /* temporal reference */
379 
380  // RAL: s->picture_number instead of s->fake_picture_number
381  put_bits(&s->pb, 10, (s->picture_number -
382  s->gop_picture_number) & 0x3ff);
383  put_bits(&s->pb, 3, s->pict_type);
384 
385  s->vbv_delay_ptr= s->pb.buf + put_bits_count(&s->pb)/8;
386  put_bits(&s->pb, 16, 0xFFFF); /* vbv_delay */
387 
388  // RAL: Forward f_code also needed for B frames
390  put_bits(&s->pb, 1, 0); /* half pel coordinates */
392  put_bits(&s->pb, 3, s->f_code); /* forward_f_code */
393  else
394  put_bits(&s->pb, 3, 7); /* forward_f_code */
395  }
396 
397  // RAL: Backward f_code necessary for B frames
398  if (s->pict_type == AV_PICTURE_TYPE_B) {
399  put_bits(&s->pb, 1, 0); /* half pel coordinates */
401  put_bits(&s->pb, 3, s->b_code); /* backward_f_code */
402  else
403  put_bits(&s->pb, 3, 7); /* backward_f_code */
404  }
405 
406  put_bits(&s->pb, 1, 0); /* extra bit picture */
407 
408  s->frame_pred_frame_dct = 1;
411  put_bits(&s->pb, 4, 8); //pic ext
413  put_bits(&s->pb, 4, s->f_code);
414  put_bits(&s->pb, 4, s->f_code);
415  }else{
416  put_bits(&s->pb, 8, 255);
417  }
418  if (s->pict_type == AV_PICTURE_TYPE_B) {
419  put_bits(&s->pb, 4, s->b_code);
420  put_bits(&s->pb, 4, s->b_code);
421  }else{
422  put_bits(&s->pb, 8, 255);
423  }
424  put_bits(&s->pb, 2, s->intra_dc_precision);
425 
427  put_bits(&s->pb, 2, s->picture_structure);
428  if (s->progressive_sequence) {
429  put_bits(&s->pb, 1, 0); /* no repeat */
430  } else {
432  }
433  /* XXX: optimize the generation of this flag with entropy
434  measures */
436 
437  put_bits(&s->pb, 1, s->frame_pred_frame_dct);
439  put_bits(&s->pb, 1, s->q_scale_type);
440  put_bits(&s->pb, 1, s->intra_vlc_format);
441  put_bits(&s->pb, 1, s->alternate_scan);
442  put_bits(&s->pb, 1, s->repeat_first_field);
444  put_bits(&s->pb, 1, s->chroma_format == CHROMA_420 ? s->progressive_frame : 0); /* chroma_420_type */
445  put_bits(&s->pb, 1, s->progressive_frame);
446  put_bits(&s->pb, 1, 0); //composite_display_flag
447  }
448  if (s->scan_offset) {
449  int i;
450 
452  for(i=0; i<sizeof(svcd_scan_offset_placeholder); i++){
454  }
455  }
456 
457  s->mb_y=0;
459 }
460 
461 static inline void put_mb_modes(MpegEncContext *s, int n, int bits,
462  int has_mv, int field_motion)
463 {
464  put_bits(&s->pb, n, bits);
465  if (!s->frame_pred_frame_dct) {
466  if (has_mv)
467  put_bits(&s->pb, 2, 2 - field_motion); /* motion_type: frame/field */
468  put_bits(&s->pb, 1, s->interlaced_dct);
469  }
470 }
471 
473  int16_t block[6][64],
474  int motion_x, int motion_y,
475  int mb_block_count)
476 {
477  int i, cbp;
478  const int mb_x = s->mb_x;
479  const int mb_y = s->mb_y;
480  const int first_mb= mb_x == s->resync_mb_x && mb_y == s->resync_mb_y;
481 
482  /* compute cbp */
483  cbp = 0;
484  for(i=0;i<mb_block_count;i++) {
485  if (s->block_last_index[i] >= 0)
486  cbp |= 1 << (mb_block_count - 1 - i);
487  }
488 
489  if (cbp == 0 && !first_mb && s->mv_type == MV_TYPE_16X16 &&
490  (mb_x != s->mb_width - 1 || (mb_y != s->end_mb_y - 1 && s->codec_id == AV_CODEC_ID_MPEG1VIDEO)) &&
491  ((s->pict_type == AV_PICTURE_TYPE_P && (motion_x | motion_y) == 0) ||
492  (s->pict_type == AV_PICTURE_TYPE_B && s->mv_dir == s->last_mv_dir && (((s->mv_dir & MV_DIR_FORWARD) ? ((s->mv[0][0][0] - s->last_mv[0][0][0])|(s->mv[0][0][1] - s->last_mv[0][0][1])) : 0) |
493  ((s->mv_dir & MV_DIR_BACKWARD) ? ((s->mv[1][0][0] - s->last_mv[1][0][0])|(s->mv[1][0][1] - s->last_mv[1][0][1])) : 0)) == 0))) {
494  s->mb_skip_run++;
495  s->qscale -= s->dquant;
496  s->skip_count++;
497  s->misc_bits++;
498  s->last_bits++;
499  if(s->pict_type == AV_PICTURE_TYPE_P){
500  s->last_mv[0][1][0]= s->last_mv[0][0][0]=
501  s->last_mv[0][1][1]= s->last_mv[0][0][1]= 0;
502  }
503  } else {
504  if(first_mb){
505  av_assert0(s->mb_skip_run == 0);
506  encode_mb_skip_run(s, s->mb_x);
507  }else{
509  }
510 
511  if (s->pict_type == AV_PICTURE_TYPE_I) {
512  if(s->dquant && cbp){
513  put_mb_modes(s, 2, 1, 0, 0); /* macroblock_type : macroblock_quant = 1 */
514  put_qscale(s);
515  }else{
516  put_mb_modes(s, 1, 1, 0, 0); /* macroblock_type : macroblock_quant = 0 */
517  s->qscale -= s->dquant;
518  }
519  s->misc_bits+= get_bits_diff(s);
520  s->i_count++;
521  } else if (s->mb_intra) {
522  if(s->dquant && cbp){
523  put_mb_modes(s, 6, 0x01, 0, 0);
524  put_qscale(s);
525  }else{
526  put_mb_modes(s, 5, 0x03, 0, 0);
527  s->qscale -= s->dquant;
528  }
529  s->misc_bits+= get_bits_diff(s);
530  s->i_count++;
531  memset(s->last_mv, 0, sizeof(s->last_mv));
532  } else if (s->pict_type == AV_PICTURE_TYPE_P) {
533  if(s->mv_type == MV_TYPE_16X16){
534  if (cbp != 0) {
535  if ((motion_x|motion_y) == 0) {
536  if(s->dquant){
537  put_mb_modes(s, 5, 1, 0, 0); /* macroblock_pattern & quant */
538  put_qscale(s);
539  }else{
540  put_mb_modes(s, 2, 1, 0, 0); /* macroblock_pattern only */
541  }
542  s->misc_bits+= get_bits_diff(s);
543  } else {
544  if(s->dquant){
545  put_mb_modes(s, 5, 2, 1, 0); /* motion + cbp */
546  put_qscale(s);
547  }else{
548  put_mb_modes(s, 1, 1, 1, 0); /* motion + cbp */
549  }
550  s->misc_bits+= get_bits_diff(s);
551  mpeg1_encode_motion(s, motion_x - s->last_mv[0][0][0], s->f_code); // RAL: f_code parameter added
552  mpeg1_encode_motion(s, motion_y - s->last_mv[0][0][1], s->f_code); // RAL: f_code parameter added
553  s->mv_bits+= get_bits_diff(s);
554  }
555  } else {
556  put_bits(&s->pb, 3, 1); /* motion only */
557  if (!s->frame_pred_frame_dct)
558  put_bits(&s->pb, 2, 2); /* motion_type: frame */
559  s->misc_bits+= get_bits_diff(s);
560  mpeg1_encode_motion(s, motion_x - s->last_mv[0][0][0], s->f_code); // RAL: f_code parameter added
561  mpeg1_encode_motion(s, motion_y - s->last_mv[0][0][1], s->f_code); // RAL: f_code parameter added
562  s->qscale -= s->dquant;
563  s->mv_bits+= get_bits_diff(s);
564  }
565  s->last_mv[0][1][0]= s->last_mv[0][0][0]= motion_x;
566  s->last_mv[0][1][1]= s->last_mv[0][0][1]= motion_y;
567  }else{
569 
570  if (cbp) {
571  if(s->dquant){
572  put_mb_modes(s, 5, 2, 1, 1); /* motion + cbp */
573  put_qscale(s);
574  }else{
575  put_mb_modes(s, 1, 1, 1, 1); /* motion + cbp */
576  }
577  } else {
578  put_bits(&s->pb, 3, 1); /* motion only */
579  put_bits(&s->pb, 2, 1); /* motion_type: field */
580  s->qscale -= s->dquant;
581  }
582  s->misc_bits+= get_bits_diff(s);
583  for(i=0; i<2; i++){
584  put_bits(&s->pb, 1, s->field_select[0][i]);
585  mpeg1_encode_motion(s, s->mv[0][i][0] - s->last_mv[0][i][0] , s->f_code);
586  mpeg1_encode_motion(s, s->mv[0][i][1] - (s->last_mv[0][i][1]>>1), s->f_code);
587  s->last_mv[0][i][0]= s->mv[0][i][0];
588  s->last_mv[0][i][1]= 2*s->mv[0][i][1];
589  }
590  s->mv_bits+= get_bits_diff(s);
591  }
592  if(cbp) {
593  if (s->chroma_y_shift) {
594  put_bits(&s->pb, ff_mpeg12_mbPatTable[cbp][1], ff_mpeg12_mbPatTable[cbp][0]);
595  } else {
596  put_bits(&s->pb, ff_mpeg12_mbPatTable[cbp>>2][1], ff_mpeg12_mbPatTable[cbp>>2][0]);
597  put_sbits(&s->pb, 2, cbp);
598  }
599  }
600  s->f_count++;
601  } else{
602  if(s->mv_type == MV_TYPE_16X16){
603  if (cbp){ // With coded bloc pattern
604  if (s->dquant) {
605  if(s->mv_dir == MV_DIR_FORWARD)
606  put_mb_modes(s, 6, 3, 1, 0);
607  else
608  put_mb_modes(s, 8-s->mv_dir, 2, 1, 0);
609  put_qscale(s);
610  } else {
611  put_mb_modes(s, 5-s->mv_dir, 3, 1, 0);
612  }
613  }else{ // No coded bloc pattern
614  put_bits(&s->pb, 5-s->mv_dir, 2);
615  if (!s->frame_pred_frame_dct)
616  put_bits(&s->pb, 2, 2); /* motion_type: frame */
617  s->qscale -= s->dquant;
618  }
619  s->misc_bits += get_bits_diff(s);
620  if (s->mv_dir&MV_DIR_FORWARD){
621  mpeg1_encode_motion(s, s->mv[0][0][0] - s->last_mv[0][0][0], s->f_code);
622  mpeg1_encode_motion(s, s->mv[0][0][1] - s->last_mv[0][0][1], s->f_code);
623  s->last_mv[0][0][0]=s->last_mv[0][1][0]= s->mv[0][0][0];
624  s->last_mv[0][0][1]=s->last_mv[0][1][1]= s->mv[0][0][1];
625  s->f_count++;
626  }
627  if (s->mv_dir&MV_DIR_BACKWARD){
628  mpeg1_encode_motion(s, s->mv[1][0][0] - s->last_mv[1][0][0], s->b_code);
629  mpeg1_encode_motion(s, s->mv[1][0][1] - s->last_mv[1][0][1], s->b_code);
630  s->last_mv[1][0][0]=s->last_mv[1][1][0]= s->mv[1][0][0];
631  s->last_mv[1][0][1]=s->last_mv[1][1][1]= s->mv[1][0][1];
632  s->b_count++;
633  }
634  }else{
637  if (cbp){ // With coded bloc pattern
638  if (s->dquant) {
639  if(s->mv_dir == MV_DIR_FORWARD)
640  put_mb_modes(s, 6, 3, 1, 1);
641  else
642  put_mb_modes(s, 8-s->mv_dir, 2, 1, 1);
643  put_qscale(s);
644  } else {
645  put_mb_modes(s, 5-s->mv_dir, 3, 1, 1);
646  }
647  }else{ // No coded bloc pattern
648  put_bits(&s->pb, 5-s->mv_dir, 2);
649  put_bits(&s->pb, 2, 1); /* motion_type: field */
650  s->qscale -= s->dquant;
651  }
652  s->misc_bits += get_bits_diff(s);
653  if (s->mv_dir&MV_DIR_FORWARD){
654  for(i=0; i<2; i++){
655  put_bits(&s->pb, 1, s->field_select[0][i]);
656  mpeg1_encode_motion(s, s->mv[0][i][0] - s->last_mv[0][i][0] , s->f_code);
657  mpeg1_encode_motion(s, s->mv[0][i][1] - (s->last_mv[0][i][1]>>1), s->f_code);
658  s->last_mv[0][i][0]= s->mv[0][i][0];
659  s->last_mv[0][i][1]= 2*s->mv[0][i][1];
660  }
661  s->f_count++;
662  }
663  if (s->mv_dir&MV_DIR_BACKWARD){
664  for(i=0; i<2; i++){
665  put_bits(&s->pb, 1, s->field_select[1][i]);
666  mpeg1_encode_motion(s, s->mv[1][i][0] - s->last_mv[1][i][0] , s->b_code);
667  mpeg1_encode_motion(s, s->mv[1][i][1] - (s->last_mv[1][i][1]>>1), s->b_code);
668  s->last_mv[1][i][0]= s->mv[1][i][0];
669  s->last_mv[1][i][1]= 2*s->mv[1][i][1];
670  }
671  s->b_count++;
672  }
673  }
674  s->mv_bits += get_bits_diff(s);
675  if(cbp) {
676  if (s->chroma_y_shift) {
677  put_bits(&s->pb, ff_mpeg12_mbPatTable[cbp][1], ff_mpeg12_mbPatTable[cbp][0]);
678  } else {
679  put_bits(&s->pb, ff_mpeg12_mbPatTable[cbp>>2][1], ff_mpeg12_mbPatTable[cbp>>2][0]);
680  put_sbits(&s->pb, 2, cbp);
681  }
682  }
683  }
684  for(i=0;i<mb_block_count;i++) {
685  if (cbp & (1 << (mb_block_count - 1 - i))) {
686  mpeg1_encode_block(s, block[i], i);
687  }
688  }
689  s->mb_skip_run = 0;
690  if(s->mb_intra)
691  s->i_tex_bits+= get_bits_diff(s);
692  else
693  s->p_tex_bits+= get_bits_diff(s);
694  }
695 }
696 
697 void ff_mpeg1_encode_mb(MpegEncContext *s, int16_t block[6][64], int motion_x, int motion_y)
698 {
699  if (s->chroma_format == CHROMA_420) mpeg1_encode_mb_internal(s, block, motion_x, motion_y, 6);
700  else mpeg1_encode_mb_internal(s, block, motion_x, motion_y, 8);
701 }
702 
703 // RAL: Parameter added: f_or_b_code
704 static void mpeg1_encode_motion(MpegEncContext *s, int val, int f_or_b_code)
705 {
706  if (val == 0) {
707  /* zero vector */
708  put_bits(&s->pb,
711  } else {
712  int code, sign, bits;
713  int bit_size = f_or_b_code - 1;
714  int range = 1 << bit_size;
715  /* modulo encoding */
716  val = sign_extend(val, 5 + bit_size);
717 
718  if (val >= 0) {
719  val--;
720  code = (val >> bit_size) + 1;
721  bits = val & (range - 1);
722  sign = 0;
723  } else {
724  val = -val;
725  val--;
726  code = (val >> bit_size) + 1;
727  bits = val & (range - 1);
728  sign = 1;
729  }
730 
731  av_assert2(code > 0 && code <= 16);
732 
733  put_bits(&s->pb,
736 
737  put_bits(&s->pb, 1, sign);
738  if (bit_size > 0) {
739  put_bits(&s->pb, bit_size, bits);
740  }
741  }
742 }
743 
745 {
746  static int done=0;
747 
749 
750  if(!done){
751  int f_code;
752  int mv;
753  int i;
754 
755  done=1;
758 
759  for(i=0; i<64; i++)
760  {
763  }
764 
766  if(s->intra_vlc_format)
768 
769  /* build unified dc encoding tables */
770  for(i=-255; i<256; i++)
771  {
772  int adiff, index;
773  int bits, code;
774  int diff=i;
775 
776  adiff = FFABS(diff);
777  if(diff<0) diff--;
778  index = av_log2(2*adiff);
779 
781  code= (ff_mpeg12_vlc_dc_lum_code[index]<<index) + (diff & ((1 << index) - 1));
782  mpeg1_lum_dc_uni[i+255]= bits + (code<<8);
783 
785  code= (ff_mpeg12_vlc_dc_chroma_code[index]<<index) + (diff & ((1 << index) - 1));
786  mpeg1_chr_dc_uni[i+255]= bits + (code<<8);
787  }
788 
789  for(f_code=1; f_code<=MAX_FCODE; f_code++){
790  for(mv=-MAX_MV; mv<=MAX_MV; mv++){
791  int len;
792 
793  if(mv==0) len= ff_mpeg12_mbMotionVectorTable[0][1];
794  else{
795  int val, bit_size, code;
796 
797  bit_size = f_code - 1;
798 
799  val=mv;
800  if (val < 0)
801  val = -val;
802  val--;
803  code = (val >> bit_size) + 1;
804  if(code<17){
805  len= ff_mpeg12_mbMotionVectorTable[code][1] + 1 + bit_size;
806  }else{
807  len= ff_mpeg12_mbMotionVectorTable[16][1] + 2 + bit_size;
808  }
809  }
810 
811  mv_penalty[f_code][mv+MAX_MV]= len;
812  }
813  }
814 
815 
816  for(f_code=MAX_FCODE; f_code>0; f_code--){
817  for(mv=-(8<<f_code); mv<(8<<f_code); mv++){
818  fcode_tab[mv+MAX_MV]= f_code;
819  }
820  }
821  }
823  s->fcode_tab= fcode_tab;
825  s->min_qcoeff=-255;
826  s->max_qcoeff= 255;
827  }else{
828  s->min_qcoeff=-2047;
829  s->max_qcoeff= 2047;
830  }
831  if (s->intra_vlc_format) {
834  } else {
837  }
840 }
841 
842 static inline void encode_dc(MpegEncContext *s, int diff, int component)
843 {
844  if(((unsigned) (diff+255)) >= 511){
845  int index;
846 
847  if(diff<0){
848  index= av_log2_16bit(-2*diff);
849  diff--;
850  }else{
851  index= av_log2_16bit(2*diff);
852  }
853  if (component == 0) {
854  put_bits(
855  &s->pb,
856  ff_mpeg12_vlc_dc_lum_bits[index] + index,
857  (ff_mpeg12_vlc_dc_lum_code[index]<<index) + (diff & ((1 << index) - 1)));
858  }else{
859  put_bits(
860  &s->pb,
861  ff_mpeg12_vlc_dc_chroma_bits[index] + index,
862  (ff_mpeg12_vlc_dc_chroma_code[index]<<index) + (diff & ((1 << index) - 1)));
863  }
864  }else{
865  if (component == 0) {
866  put_bits(
867  &s->pb,
868  mpeg1_lum_dc_uni[diff+255]&0xFF,
869  mpeg1_lum_dc_uni[diff+255]>>8);
870  } else {
871  put_bits(
872  &s->pb,
873  mpeg1_chr_dc_uni[diff+255]&0xFF,
874  mpeg1_chr_dc_uni[diff+255]>>8);
875  }
876  }
877 }
878 
880  int16_t *block,
881  int n)
882 {
883  int alevel, level, last_non_zero, dc, diff, i, j, run, last_index, sign;
884  int code, component;
885  const uint16_t (*table_vlc)[2] = ff_rl_mpeg1.table_vlc;
886 
887  last_index = s->block_last_index[n];
888 
889  /* DC coef */
890  if (s->mb_intra) {
891  component = (n <= 3 ? 0 : (n&1) + 1);
892  dc = block[0]; /* overflow is impossible */
893  diff = dc - s->last_dc[component];
894  encode_dc(s, diff, component);
895  s->last_dc[component] = dc;
896  i = 1;
897  if (s->intra_vlc_format)
898  table_vlc = ff_rl_mpeg2.table_vlc;
899  } else {
900  /* encode the first coefficient : needs to be done here because
901  it is handled slightly differently */
902  level = block[0];
903  if (abs(level) == 1) {
904  code = ((uint32_t)level >> 31); /* the sign bit */
905  put_bits(&s->pb, 2, code | 0x02);
906  i = 1;
907  } else {
908  i = 0;
909  last_non_zero = -1;
910  goto next_coef;
911  }
912  }
913 
914  /* now quantify & encode AC coefs */
915  last_non_zero = i - 1;
916 
917  for(;i<=last_index;i++) {
918  j = s->intra_scantable.permutated[i];
919  level = block[j];
920  next_coef:
921  /* encode using VLC */
922  if (level != 0) {
923  run = i - last_non_zero - 1;
924 
925  alevel= level;
926  MASK_ABS(sign, alevel);
927  sign&=1;
928 
929  if (alevel <= mpeg1_max_level[0][run]){
930  code= mpeg1_index_run[0][run] + alevel - 1;
931  /* store the vlc & sign at once */
932  put_bits(&s->pb, table_vlc[code][1]+1, (table_vlc[code][0]<<1) + sign);
933  } else {
934  /* escape seems to be pretty rare <5% so I do not optimize it */
935  put_bits(&s->pb, table_vlc[111][1], table_vlc[111][0]);
936  /* escape: only clip in this case */
937  put_bits(&s->pb, 6, run);
939  if (alevel < 128) {
940  put_sbits(&s->pb, 8, level);
941  } else {
942  if (level < 0) {
943  put_bits(&s->pb, 16, 0x8001 + level + 255);
944  } else {
945  put_sbits(&s->pb, 16, level);
946  }
947  }
948  }else{
949  put_sbits(&s->pb, 12, level);
950  }
951  }
952  last_non_zero = i;
953  }
954  }
955  /* end of block */
956  put_bits(&s->pb, table_vlc[112][1], table_vlc[112][0]);
957 }
958 
959 #define OFFSET(x) offsetof(MpegEncContext, x)
960 #define VE AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
961 #define COMMON_OPTS\
962  { "gop_timecode", "MPEG GOP Timecode in hh:mm:ss[:;.]ff format", OFFSET(tc_opt_str), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, VE },\
963  { "intra_vlc", "Use MPEG-2 intra VLC table.", OFFSET(intra_vlc_format), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },\
964  { "drop_frame_timecode", "Timecode is in drop frame format.", OFFSET(drop_frame_timecode), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE}, \
965  { "scan_offset", "Reserve space for SVCD scan offset user data.", OFFSET(scan_offset), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
966 
967 static const AVOption mpeg1_options[] = {
970  { NULL },
971 };
972 
973 static const AVOption mpeg2_options[] = {
975  { "non_linear_quant", "Use nonlinear quantizer.", OFFSET(q_scale_type), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
976  { "alternate_scan", "Enable alternate scantable.", OFFSET(alternate_scan), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE },
978  { NULL },
979 };
980 
981 #define mpeg12_class(x)\
982 static const AVClass mpeg## x ##_class = {\
983  .class_name = "mpeg" #x "video encoder",\
984  .item_name = av_default_item_name,\
985  .option = mpeg## x ##_options,\
986  .version = LIBAVUTIL_VERSION_INT,\
987 };
988 
990 mpeg12_class(2)
991 
992 AVCodec ff_mpeg1video_encoder = {
993  .name = "mpeg1video",
994  .type = AVMEDIA_TYPE_VIDEO,
996  .priv_data_size = sizeof(MpegEncContext),
997  .init = encode_init,
998  .encode2 = ff_MPV_encode_picture,
1000  .supported_framerates = ff_mpeg12_frame_rate_tab + 1,
1001  .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P,
1002  AV_PIX_FMT_NONE },
1003  .capabilities = CODEC_CAP_DELAY | CODEC_CAP_SLICE_THREADS,
1004  .long_name = NULL_IF_CONFIG_SMALL("MPEG-1 video"),
1005  .priv_class = &mpeg1_class,
1006 };
1007 
1009  .name = "mpeg2video",
1010  .type = AVMEDIA_TYPE_VIDEO,
1011  .id = AV_CODEC_ID_MPEG2VIDEO,
1012  .priv_data_size = sizeof(MpegEncContext),
1013  .init = encode_init,
1014  .encode2 = ff_MPV_encode_picture,
1016  .supported_framerates = ff_mpeg2_frame_rate_tab,
1017  .pix_fmts = (const enum AVPixelFormat[]){
1019  },
1020  .capabilities = CODEC_CAP_DELAY | CODEC_CAP_SLICE_THREADS,
1021  .long_name = NULL_IF_CONFIG_SMALL("MPEG-2 video"),
1022  .priv_class = &mpeg2_class,
1023 };
static uint8_t uni_mpeg1_ac_vlc_len[64 *64 *2]
Definition: mpeg12enc.c:61
#define MASK_ABS(mask, level)
Definition: mathops.h:148
AVCodec ff_mpeg2video_encoder
Definition: mpeg12enc.c:1008
float v
int aspect_ratio_info
Definition: mpegvideo.h:585
int picture_number
Definition: mpegvideo.h:275
const char * s
Definition: avisynth_c.h:668
const AVRational ff_mpeg2_frame_rate_tab[]
Definition: mpeg12data.c:328
struct MpegEncContext MpegEncContext
MpegEncContext.
AVOption.
Definition: opt.h:251
uint8_t * fcode_tab
smallest fcode needed for each MV
Definition: mpegvideo.h:434
#define MV_TYPE_FIELD
2 vectors, one per field
Definition: mpegvideo.h:424
int last_mv[2][2][2]
last MV, used for MV prediction in MPEG1 & B-frame MPEG4
Definition: mpegvideo.h:433
static const uint8_t inv_non_linear_qscale[13]
Definition: mpeg12enc.c:40
static int find_frame_rate_index(MpegEncContext *s)
Definition: mpeg12enc.c:108
static void put_sbits(PutBitContext *pb, int n, int32_t value)
Definition: put_bits.h:172
int end_mb_y
end mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y) ...
Definition: mpegvideo.h:317
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
int ff_MPV_encode_end(AVCodecContext *avctx)
#define FF_MPV_COMMON_OPTS
Definition: mpegvideo.h:758
int num
numerator
Definition: rational.h:44
const unsigned char ff_mpeg12_vlc_dc_lum_bits[12]
Definition: mpeg12data.c:55
enum AVCodecID codec_id
Definition: mpegvideo.h:257
void ff_init_rl(RLTable *rl, uint8_t static_store[2][2 *MAX_RUN+MAX_LEVEL+3])
Definition: mpegvideo.c:1304
location of range
int av_timecode_init_from_string(AVTimecode *tc, AVRational rate, const char *str, void *log_ctx)
Parse timecode representation (hh:mm:ss[:;.
void avpriv_align_put_bits(PutBitContext *s)
Pad the bitstream with zeros up to the next byte boundary.
Definition: bitstream.c:46
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 scan_offset
reserve space for SVCD scan offset user data.
Definition: mpegvideo.h:688
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
Definition: rational.h:55
int min_qcoeff
minimum encodable coefficient
Definition: mpegvideo.h:479
mpegvideo header.
#define CODEC_FLAG2_DROP_FRAME_TIMECODE
timecode is in drop frame format. DEPRECATED!!!!
uint8_t permutated[64]
Definition: dsputil.h:116
const uint16_t ff_mpeg12_vlc_dc_lum_code[12]
Definition: mpeg12data.c:52
Timecode helpers header.
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
#define SLICE_MIN_START_CODE
Definition: mpegvideo.h:81
static void init_uni_ac_vlc(RLTable *rl, uint8_t *uni_ac_vlc_len)
Definition: mpeg12enc.c:71
int qscale
QP.
Definition: mpegvideo.h:369
RLTable.
Definition: rl.h:38
int field_select[2][2]
Definition: mpegvideo.h:432
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
AVRational mpeg2_frame_rate_ext
Definition: mpegvideo.h:383
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
static uint32_t mpeg1_lum_dc_uni[512]
Definition: mpeg12enc.c:65
#define PICT_FRAME
Definition: mpegvideo.h:664
AVOptions.
static void encode_mb_skip_run(MpegEncContext *s, int run)
Definition: mpeg12enc.c:342
RLTable ff_rl_mpeg2
Definition: mpeg12data.c:174
int me_range
maximum motion estimation search range in subpel units If 0 then no limit.
const float ff_mpeg1_aspect[16]
Definition: mpeg12data.c:394
#define FF_PROFILE_UNKNOWN
int misc_bits
cbp, mb_type
Definition: mpegvideo.h:523
static const AVOption mpeg1_options[]
Definition: mpeg12enc.c:967
int interlaced_dct
Definition: mpegvideo.h:684
Picture current_picture
copy of the current picture structure.
Definition: mpegvideo.h:343
#define CHROMA_420
Definition: mpegvideo.h:676
int intra_dc_precision
Definition: mpegvideo.h:666
int repeat_first_field
Definition: mpegvideo.h:673
static double av_q2d(AVRational a)
Convert rational to double.
Definition: rational.h:69
uint8_t(* mv_penalty)[MAX_MV *2+1]
amount of bits needed to encode a MV
Definition: mpegvideo.h:230
static uint8_t mv_penalty[MAX_FCODE+1][MAX_MV *2+1]
Definition: mpeg12enc.c:58
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition: rational.c:80
static int8_t mpeg1_max_level[2][64]
Definition: mpeg12enc.c:69
int start
timecode frame start (first base frame number)
int8_t * max_level[2]
encoding & decoding
Definition: rl.h:45
int mb_height
number of MBs horizontally & vertically
Definition: mpegvideo.h:277
int max_qcoeff
maximum encodable coefficient
Definition: mpegvideo.h:480
int dquant
qscale difference to prev qscale
Definition: mpegvideo.h:375
int gop_picture_number
index of the first picture of a GOP based on fake_pic_num & mpeg1 specific
Definition: mpegvideo.h:652
int ff_MPV_encode_init(AVCodecContext *avctx)
static int get_bits_diff(MpegEncContext *s)
Definition: mpegvideo.h:875
int last_dc[3]
last DC values for MPEG1
Definition: mpegvideo.h:348
static void put_mb_modes(MpegEncContext *s, int n, int bits, int has_mv, int field_motion)
Definition: mpeg12enc.c:461
uint8_t * inter_ac_vlc_last_length
Definition: mpegvideo.h:485
#define CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
int chroma_y_shift
Definition: mpegvideo.h:680
int strict_std_compliance
strictly follow the std (MPEG4, ...)
Definition: mpegvideo.h:265
static void mpeg1_encode_block(MpegEncContext *s, int16_t *block, int component)
Definition: mpeg12enc.c:879
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
int av_nearer_q(AVRational q, AVRational q1, AVRational q2)
Definition: rational.c:123
const uint16_t ff_mpeg12_vlc_dc_chroma_code[12]
Definition: mpeg12data.c:59
static void encode_dc(MpegEncContext *s, int diff, int component)
Definition: mpeg12enc.c:842
uint8_t * buf
Definition: put_bits.h:44
int rc_max_rate
maximum bitrate
simple assert() macros that are a bit more flexible than ISO C assert().
int64_t av_gcd(int64_t a, int64_t b)
Return the greatest common divisor of a and b.
Definition: mathematics.c:55
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
const char * name
Name of the codec implementation.
int low_delay
no reordering needed / has no b-frames
Definition: mpegvideo.h:592
static void put_bits(J2kEncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:160
external API header
static void mpeg1_encode_sequence_header(MpegEncContext *s)
Definition: mpeg12enc.c:227
static void mpeg1_encode_motion(MpegEncContext *s, int val, int f_or_b_code)
Definition: mpeg12enc.c:704
static int put_bits_count(PutBitContext *s)
Definition: put_bits.h:73
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:72
int resync_mb_x
x position of last resync marker
Definition: mpegvideo.h:527
int rc_buffer_size
decoder bitstream buffer size
uint8_t * intra_ac_vlc_last_length
Definition: mpegvideo.h:483
#define mpeg12_class(x)
Definition: mpeg12enc.c:981
int intra_vlc_format
Definition: mpegvideo.h:671
struct AVRational AVRational
rational number numerator/denominator
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
int64_t timecode_frame_start
GOP timecode frame start number.
int progressive_frame
Definition: mpegvideo.h:682
uint8_t * vbv_delay_ptr
pointer to vbv_delay in the bitstream
Definition: mpegvideo.h:655
const uint16_t(* table_vlc)[2]
Definition: rl.h:41
static uint8_t fcode_tab[MAX_MV *2+1]
Definition: mpeg12enc.c:59
ret
Definition: avfilter.c:821
int width
picture width / height.
const unsigned char ff_mpeg12_vlc_dc_chroma_bits[12]
Definition: mpeg12data.c:62
Picture * current_picture_ptr
pointer to the current picture
Definition: mpegvideo.h:347
RLTable ff_rl_mpeg1
Definition: mpeg12data.c:166
int alternate_scan
Definition: mpegvideo.h:672
#define GOP_START_CODE
Definition: mpegvideo.h:79
static uint8_t uni_mpeg2_ac_vlc_len[64 *64 *2]
Definition: mpeg12enc.c:62
#define FFABS(a)
Definition: common.h:53
#define VE
Definition: mpeg12enc.c:960
int block_last_index[12]
last non zero coefficient in block
Definition: mpegvideo.h:291
MotionEstContext me
Definition: mpegvideo.h:437
#define diff(a, as, b, bs)
Definition: vf_phase.c:80
#define EXT_START_CODE
Definition: cavs.h:32
FIXME Range Coding of cr are level
Definition: snow.txt:367
static void put_header(MpegEncContext *s, int header)
Definition: mpeg12enc.c:219
preferred ID for MPEG-1/2 video decoding
int av_timecode_adjust_ntsc_framenum2(int framenum, int fps)
Adjust frame number for NTSC drop frame time code.
void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix)
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
static const int8_t mv[256][2]
#define MV_TYPE_16X16
1 vector for the whole mb
Definition: mpegvideo.h:421
int frame_pred_frame_dct
Definition: mpegvideo.h:667
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 FF_COMPLIANCE_UNOFFICIAL
Allow unofficial extensions.
int coded_picture_number
picture number in bitstream order
Definition: frame.h:176
int concealment_motion_vectors
Definition: mpegvideo.h:669
char * tc_opt_str
timecode option string
Definition: mpegvideo.h:693
enum AVCodecID codec_id
main external API structure.
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:375
FIXME Range Coding of cr are mx and my are Motion Vector top and top right vectors is used as motion vector prediction the used motion vector is the sum of the predictor and(mvx_diff, mvy_diff)*mv_scale Intra DC Predicton block[y][x] dc[1]
Definition: snow.txt:392
ScanTable intra_scantable
Definition: mpegvideo.h:296
#define USER_START_CODE
Definition: cavs.h:33
int height
picture size. must be a multiple of 16
Definition: mpegvideo.h:245
MPEG1/2 tables.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
uint8_t * inter_ac_vlc_length
Definition: mpegvideo.h:484
static uint8_t mpeg1_index_run[2][64]
Definition: mpeg12enc.c:68
int progressive_sequence
Definition: mpegvideo.h:658
uint16_t * intra_matrix
custom intra quantization matrix
int index
Definition: gxfenc.c:89
synthesis window for stochastic i
rational number numerator/denominator
Definition: rational.h:43
#define COMMON_OPTS
Definition: mpeg12enc.c:961
uint8_t * index_run[2]
encoding only
Definition: rl.h:44
#define OFFSET(x)
Definition: mpeg12enc.c:959
static av_always_inline void mpeg1_encode_mb_internal(MpegEncContext *s, int16_t block[6][64], int motion_x, int motion_y, int mb_block_count)
Definition: mpeg12enc.c:472
#define MAX_MV
Definition: mpegvideo.h:63
void ff_mpeg1_encode_picture_header(MpegEncContext *s, int picture_number)
Definition: mpeg12enc.c:372
int f_code
forward MV resolution
Definition: mpegvideo.h:395
#define MAX_FCODE
Definition: mpegvideo.h:62
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
#define MV_DIR_FORWARD
Definition: mpegvideo.h:417
uint16_t * inter_matrix
custom inter quantization matrix
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
Definition: mpegvideo.h:377
int bit_rate
wanted bit rate
Definition: mpegvideo.h:248
static av_const int sign_extend(int val, unsigned bits)
Definition: mathops.h:123
int last_mv_dir
last mv_dir, used for b frame encoding
Definition: mpegvideo.h:653
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:122
int mv[2][4][2]
motion vectors for a macroblock first coordinate : 0 = forward 1 = backward second " : depend...
Definition: mpegvideo.h:431
static av_cold int encode_init(AVCodecContext *avctx)
Definition: mpeg12enc.c:143
MpegEncContext.
Definition: mpegvideo.h:241
struct AVCodecContext * avctx
Definition: mpegvideo.h:243
PutBitContext pb
bit output
Definition: mpegvideo.h:314
const AVRational ff_mpeg2_aspect[16]
Definition: mpeg12data.c:415
void ff_mpeg1_encode_mb(MpegEncContext *s, int16_t block[6][64], int motion_x, int motion_y)
Definition: mpeg12enc.c:697
static av_always_inline void put_qscale(MpegEncContext *s)
Definition: mpeg12enc.c:351
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.
static uint32_t mpeg1_chr_dc_uni[512]
Definition: mpeg12enc.c:66
static const AVOption mpeg2_options[]
Definition: mpeg12enc.c:973
uint8_t ff_mpeg12_static_rl_table_store[2][2][2 *MAX_RUN+MAX_LEVEL+3]
Definition: mpeg12.c:48
Bi-dir predicted.
Definition: avutil.h:218
const uint8_t ff_mpeg12_mbPatTable[64][2]
Definition: mpeg12data.c:221
int den
denominator
Definition: rational.h:45
void ff_mpeg1_encode_slice_header(MpegEncContext *s)
Definition: mpeg12enc.c:361
int last_bits
temp var used for calculating the above vars
Definition: mpegvideo.h:524
int frame_rate_index
Definition: mpegvideo.h:382
void ff_mpeg12_common_init(MpegEncContext *s)
Definition: mpeg12.c:94
int picture_structure
Definition: mpegvideo.h:660
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:275
int len
#define av_log2_16bit
Definition: intmath.h:90
#define SEQ_START_CODE
Definition: mpegvideo.h:78
int drop_frame_timecode
timecode is in drop frame format.
Definition: mpegvideo.h:687
#define av_log2
Definition: intmath.h:89
int resync_mb_y
y position of last resync marker
Definition: mpegvideo.h:528
static const uint8_t svcd_scan_offset_placeholder[14]
Definition: mpeg12enc.c:45
const uint8_t ff_mpeg12_mbAddrIncrTable[36][2]
Definition: mpeg12data.c:182
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:139
int flags2
CODEC_FLAG2_*.
void ff_mpeg1_encode_init(MpegEncContext *s)
Definition: mpeg12enc.c:744
struct AVFrame f
Definition: mpegvideo.h:98
int flags
AVCodecContext.flags (HQ, MV4, ...)
Definition: mpegvideo.h:260
#define AV_LOG_INFO
Definition: log.h:156
const uint8_t ff_mpeg12_mbMotionVectorTable[17][2]
Definition: mpeg12data.c:288
#define PICTURE_START_CODE
Definition: mpegvideo.h:80
#define av_always_inline
Definition: attributes.h:41
int b_code
backward MV resolution for B Frames (mpeg4)
Definition: mpegvideo.h:396
AVTimecode tc
timecode context
Definition: mpegvideo.h:694
uint32_t flags
flags such as drop frame, +24 hours support, ...
AVPixelFormat
Pixel format.
Definition: pixfmt.h:66
const AVRational ff_mpeg12_frame_rate_tab[16]
Definition: mpeg12data.c:308
int strict_std_compliance
strictly follow the standard (MPEG4, ...).
int ff_MPV_encode_picture(AVCodecContext *avctx, AVPacket *pkt, AVFrame *frame, int *got_packet)
Predicted.
Definition: avutil.h:217
timecode is drop frame
#define FF_LEVEL_UNKNOWN