FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vaapi_encode_mpeg2.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include <va/va.h>
20 #include <va/va_enc_mpeg2.h>
21 
22 #include "libavutil/avassert.h"
23 
24 #include "avcodec.h"
25 #include "cbs.h"
26 #include "cbs_mpeg2.h"
27 #include "mpeg12.h"
28 #include "vaapi_encode.h"
29 
30 typedef struct VAAPIEncodeMPEG2Context {
32 
33  // User options.
34  int profile;
35  int level;
36 
37  // Derived settings.
38  int quant_i;
39  int quant_p;
40  int quant_b;
41 
42  unsigned int bit_rate;
43  unsigned int vbv_buffer_size;
44 
46 
47  unsigned int f_code_horizontal;
48  unsigned int f_code_vertical;
49 
50  // Stream state.
51  int64_t last_i_frame;
52 
53  // Writer structures.
60 
64 
65 
67  char *data, size_t *data_len,
69 {
70  VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
71  int err;
72 
73  err = ff_cbs_write_fragment_data(priv->cbc, frag);
74  if (err < 0) {
75  av_log(avctx, AV_LOG_ERROR, "Failed to write packed header.\n");
76  return err;
77  }
78 
79  if (*data_len < 8 * frag->data_size - frag->data_bit_padding) {
80  av_log(avctx, AV_LOG_ERROR, "Access unit too large: "
81  "%zu < %zu.\n", *data_len,
82  8 * frag->data_size - frag->data_bit_padding);
83  return AVERROR(ENOSPC);
84  }
85 
86  memcpy(data, frag->data, frag->data_size);
87  *data_len = 8 * frag->data_size - frag->data_bit_padding;
88 
89  return 0;
90 }
91 
94  int type, void *header)
95 {
96  VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
97  int err;
98 
99  err = ff_cbs_insert_unit_content(priv->cbc, frag, -1, type, header, NULL);
100  if (err < 0) {
101  av_log(avctx, AV_LOG_ERROR, "Failed to add header: "
102  "type = %d.\n", type);
103  return err;
104  }
105 
106  return 0;
107 }
108 
110  char *data, size_t *data_len)
111 {
112  VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
114  int err;
115 
117  &priv->sequence_header);
118  if (err < 0)
119  goto fail;
120 
122  &priv->sequence_extension);
123  if (err < 0)
124  goto fail;
125 
128  if (err < 0)
129  goto fail;
130 
132  &priv->gop_header);
133  if (err < 0)
134  goto fail;
135 
136  err = vaapi_encode_mpeg2_write_fragment(avctx, data, data_len, frag);
137 fail:
138  ff_cbs_fragment_uninit(priv->cbc, frag);
139  return 0;
140 }
141 
143  VAAPIEncodePicture *pic,
144  char *data, size_t *data_len)
145 {
146  VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
148  int err;
149 
151  &priv->picture_header);
152  if (err < 0)
153  goto fail;
154 
156  &priv->picture_coding_extension);
157  if (err < 0)
158  goto fail;
159 
160  err = vaapi_encode_mpeg2_write_fragment(avctx, data, data_len, frag);
161 fail:
162  ff_cbs_fragment_uninit(priv->cbc, frag);
163  return 0;
164 }
165 
167 {
168  VAAPIEncodeContext *ctx = avctx->priv_data;
169  VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
176  VAEncSequenceParameterBufferMPEG2 *vseq = ctx->codec_sequence_params;
177  VAEncPictureParameterBufferMPEG2 *vpic = ctx->codec_picture_params;
178  int code, ext_n, ext_d;
179 
180  memset(sh, 0, sizeof(*sh));
181  memset(se, 0, sizeof(*se));
182  memset(sde, 0, sizeof(*sde));
183  memset(goph, 0, sizeof(*goph));
184  memset(ph, 0, sizeof(*ph));
185  memset(pce, 0, sizeof(*pce));
186 
187 
188  if (ctx->va_bit_rate > 0) {
189  priv->bit_rate = (ctx->va_bit_rate + 399) / 400;
190  } else {
191  // Unknown (not a bitrate-targetting mode), so just use the
192  // highest value.
193  priv->bit_rate = 0x3fffffff;
194  }
195  if (avctx->rc_buffer_size > 0) {
196  priv->vbv_buffer_size = (avctx->rc_buffer_size + (1 << 14) - 1) >> 14;
197  } else {
198  // Unknown, so guess a value from the bitrate.
199  priv->vbv_buffer_size = priv->bit_rate >> 14;
200  }
201 
202  switch (avctx->level) {
203  case 4: // High.
204  case 6: // High 1440.
205  priv->f_code_horizontal = 9;
206  priv->f_code_vertical = 5;
207  break;
208  case 8: // Main.
209  priv->f_code_horizontal = 8;
210  priv->f_code_vertical = 5;
211  break;
212  case 10: // Low.
213  default:
214  priv->f_code_horizontal = 7;
215  priv->f_code_vertical = 4;
216  break;
217  }
218 
219 
220  // Sequence header
221 
223 
224  sh->horizontal_size_value = avctx->width & 0xfff;
225  sh->vertical_size_value = avctx->height & 0xfff;
226 
227  if (avctx->sample_aspect_ratio.num != 0 &&
228  avctx->sample_aspect_ratio.den != 0) {
230  (AVRational) { avctx->width, avctx->height });
231 
232  if (av_cmp_q(avctx->sample_aspect_ratio, (AVRational) { 1, 1 }) == 0) {
233  sh->aspect_ratio_information = 1;
234  } else if (av_cmp_q(dar, (AVRational) { 3, 4 }) == 0) {
235  sh->aspect_ratio_information = 2;
236  } else if (av_cmp_q(dar, (AVRational) { 9, 16 }) == 0) {
237  sh->aspect_ratio_information = 3;
238  } else if (av_cmp_q(dar, (AVRational) { 100, 221 }) == 0) {
239  sh->aspect_ratio_information = 4;
240  } else {
241  av_log(avctx, AV_LOG_WARNING, "Sample aspect ratio %d:%d is not "
242  "representable, signalling square pixels instead.\n",
243  avctx->sample_aspect_ratio.num,
244  avctx->sample_aspect_ratio.den);
245  sh->aspect_ratio_information = 1;
246  }
247  } else {
248  // Unknown - assume square pixels.
249  sh->aspect_ratio_information = 1;
250  }
251 
252  if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
253  priv->frame_rate = avctx->framerate;
254  else
255  priv->frame_rate = av_inv_q(avctx->time_base);
256  ff_mpeg12_find_best_frame_rate(priv->frame_rate,
257  &code, &ext_n, &ext_d, 0);
258  sh->frame_rate_code = code;
259 
260  sh->bit_rate_value = priv->bit_rate & 0x3ffff;
261  sh->vbv_buffer_size_value = priv->vbv_buffer_size & 0x3ff;
262 
263  sh->constrained_parameters_flag = 0;
264  sh->load_intra_quantiser_matrix = 0;
265  sh->load_non_intra_quantiser_matrix = 0;
266 
267 
268  // Sequence extension
269 
270  priv->sequence_extension.extension_start_code = MPEG2_START_EXTENSION;
271  priv->sequence_extension.extension_start_code_identifier =
273 
274  se->profile_and_level_indication = avctx->profile << 4 | avctx->level;
275  se->progressive_sequence = 1;
276  se->chroma_format = 1;
277 
278  se->horizontal_size_extension = avctx->width >> 12;
279  se->vertical_size_extension = avctx->height >> 12;
280 
281  se->bit_rate_extension = priv->bit_rate >> 18;
282  se->vbv_buffer_size_extension = priv->vbv_buffer_size >> 10;
283  se->low_delay = ctx->b_per_p == 0;
284 
285  se->frame_rate_extension_n = ext_n;
286  se->frame_rate_extension_d = ext_d;
287 
288 
289  // Sequence display extension
290 
291  priv->sequence_display_extension.extension_start_code =
293  priv->sequence_display_extension.extension_start_code_identifier =
295 
296  sde->video_format = 5;
297  if (avctx->color_primaries != AVCOL_PRI_UNSPECIFIED ||
298  avctx->color_trc != AVCOL_TRC_UNSPECIFIED ||
299  avctx->colorspace != AVCOL_SPC_UNSPECIFIED) {
300  sde->colour_description = 1;
301  sde->colour_primaries = avctx->color_primaries;
302  sde->transfer_characteristics = avctx->color_trc;
303  sde->matrix_coefficients = avctx->colorspace;
304  } else {
305  sde->colour_description = 0;
306  }
307 
308  sde->display_horizontal_size = avctx->width;
309  sde->display_vertical_size = avctx->height;
310 
311 
312  // GOP header
313 
314  goph->group_start_code = MPEG2_START_GROUP;
315 
316  goph->time_code = 0;
317  goph->closed_gop = 1;
318  goph->broken_link = 0;
319 
320 
321  // Defaults for picture header
322 
323  ph->picture_start_code = MPEG2_START_PICTURE;
324 
325  ph->vbv_delay = 0xffff; // Not currently calculated.
326 
327  ph->full_pel_forward_vector = 0;
328  ph->forward_f_code = 7;
329  ph->full_pel_backward_vector = 0;
330  ph->forward_f_code = 7;
331 
332 
333  // Defaults for picture coding extension
334 
335  priv->picture_coding_extension.extension_start_code =
337  priv->picture_coding_extension.extension_start_code_identifier =
339 
340  pce->intra_dc_precision = 0;
341  pce->picture_structure = 3;
342  pce->top_field_first = 0;
343  pce->frame_pred_frame_dct = 1;
344  pce->concealment_motion_vectors = 0;
345  pce->q_scale_type = 0;
346  pce->intra_vlc_format = 0;
347  pce->alternate_scan = 0;
348  pce->repeat_first_field = 0;
349  pce->progressive_frame = 1;
350  pce->composite_display_flag = 0;
351 
352 
353 
354  *vseq = (VAEncSequenceParameterBufferMPEG2) {
355  .intra_period = ctx->gop_size,
356  .ip_period = ctx->b_per_p + 1,
357 
358  .picture_width = avctx->width,
359  .picture_height = avctx->height,
360 
361  .bits_per_second = ctx->va_bit_rate,
362  .frame_rate = av_q2d(priv->frame_rate),
363  .aspect_ratio_information = sh->aspect_ratio_information,
364  .vbv_buffer_size = priv->vbv_buffer_size,
365 
366  .sequence_extension.bits = {
367  .profile_and_level_indication = se->profile_and_level_indication,
368  .progressive_sequence = se->progressive_sequence,
369  .chroma_format = se->chroma_format,
370  .low_delay = se->low_delay,
371  .frame_rate_extension_n = se->frame_rate_extension_n,
372  .frame_rate_extension_d = se->frame_rate_extension_d,
373  },
374 
375  .new_gop_header = 1,
376  .gop_header.bits = {
377  .time_code = goph->time_code,
378  .closed_gop = goph->closed_gop,
379  .broken_link = goph->broken_link,
380  },
381  };
382 
383  *vpic = (VAEncPictureParameterBufferMPEG2) {
384  .forward_reference_picture = VA_INVALID_ID,
385  .backward_reference_picture = VA_INVALID_ID,
386  .reconstructed_picture = VA_INVALID_ID,
387  .coded_buf = VA_INVALID_ID,
388 
389  .vbv_delay = 0xffff,
390  .f_code = { { 15, 15 }, { 15, 15 } },
391 
392  .picture_coding_extension.bits = {
393  .intra_dc_precision = pce->intra_dc_precision,
394  .picture_structure = pce->picture_structure,
395  .top_field_first = pce->top_field_first,
396  .frame_pred_frame_dct = pce->frame_pred_frame_dct,
397  .concealment_motion_vectors = pce->concealment_motion_vectors,
398  .q_scale_type = pce->q_scale_type,
399  .intra_vlc_format = pce->intra_vlc_format,
400  .alternate_scan = pce->alternate_scan,
401  .repeat_first_field = pce->repeat_first_field,
402  .progressive_frame = pce->progressive_frame,
403  .composite_display_flag = pce->composite_display_flag,
404  },
405 
406  .composite_display.bits = {
407  .v_axis = pce->v_axis,
408  .field_sequence = pce->field_sequence,
409  .sub_carrier = pce->sub_carrier,
410  .burst_amplitude = pce->burst_amplitude,
411  .sub_carrier_phase = pce->sub_carrier_phase,
412  },
413  };
414 
415  return 0;
416 }
417 
419  VAAPIEncodePicture *pic)
420 {
421  VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
424  VAEncPictureParameterBufferMPEG2 *vpic = pic->codec_picture_params;
425 
426  if (pic->type == PICTURE_TYPE_IDR || pic->type == PICTURE_TYPE_I) {
427  ph->temporal_reference = 0;
428  ph->picture_coding_type = 1;
429  priv->last_i_frame = pic->display_order;
430  } else {
431  ph->temporal_reference = pic->display_order - priv->last_i_frame;
432  ph->picture_coding_type = pic->type == PICTURE_TYPE_B ? 3 : 2;
433  }
434 
435  if (pic->type == PICTURE_TYPE_P || pic->type == PICTURE_TYPE_B) {
436  pce->f_code[0][0] = priv->f_code_horizontal;
437  pce->f_code[0][1] = priv->f_code_vertical;
438  } else {
439  pce->f_code[0][0] = 15;
440  pce->f_code[0][1] = 15;
441  }
442  if (pic->type == PICTURE_TYPE_B) {
443  pce->f_code[1][0] = priv->f_code_horizontal;
444  pce->f_code[1][1] = priv->f_code_vertical;
445  } else {
446  pce->f_code[1][0] = 15;
447  pce->f_code[1][1] = 15;
448  }
449 
450  vpic->reconstructed_picture = pic->recon_surface;
451  vpic->coded_buf = pic->output_buffer;
452 
453  switch (pic->type) {
454  case PICTURE_TYPE_IDR:
455  case PICTURE_TYPE_I:
456  vpic->picture_type = VAEncPictureTypeIntra;
457  break;
458  case PICTURE_TYPE_P:
459  vpic->picture_type = VAEncPictureTypePredictive;
460  vpic->forward_reference_picture = pic->refs[0]->recon_surface;
461  break;
462  case PICTURE_TYPE_B:
463  vpic->picture_type = VAEncPictureTypeBidirectional;
464  vpic->forward_reference_picture = pic->refs[0]->recon_surface;
465  vpic->backward_reference_picture = pic->refs[1]->recon_surface;
466  break;
467  default:
468  av_assert0(0 && "invalid picture type");
469  }
470 
471  vpic->temporal_reference = ph->temporal_reference;
472  vpic->f_code[0][0] = pce->f_code[0][0];
473  vpic->f_code[0][1] = pce->f_code[0][1];
474  vpic->f_code[1][0] = pce->f_code[1][0];
475  vpic->f_code[1][1] = pce->f_code[1][1];
476 
477  return 0;
478 }
479 
481  VAAPIEncodePicture *pic,
482  VAAPIEncodeSlice *slice)
483 {
484  VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
485  VAEncSliceParameterBufferMPEG2 *vslice = slice->codec_slice_params;
486  int qp;
487 
488  vslice->macroblock_address = slice->block_start;
489  vslice->num_macroblocks = slice->block_size;
490 
491  switch (pic->type) {
492  case PICTURE_TYPE_IDR:
493  case PICTURE_TYPE_I:
494  qp = priv->quant_i;
495  break;
496  case PICTURE_TYPE_P:
497  qp = priv->quant_p;
498  break;
499  case PICTURE_TYPE_B:
500  qp = priv->quant_b;
501  break;
502  default:
503  av_assert0(0 && "invalid picture type");
504  }
505 
506  vslice->quantiser_scale_code = qp;
507  vslice->is_intra_slice = (pic->type == PICTURE_TYPE_IDR ||
508  pic->type == PICTURE_TYPE_I);
509 
510  return 0;
511 }
512 
514 {
515  VAAPIEncodeContext *ctx = avctx->priv_data;
516  VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
517  int err;
518 
519  err = ff_cbs_init(&priv->cbc, AV_CODEC_ID_MPEG2VIDEO, avctx);
520  if (err < 0)
521  return err;
522 
523  if (ctx->va_rc_mode == VA_RC_CQP) {
524  priv->quant_p = av_clip(avctx->global_quality, 1, 31);
525  if (avctx->i_quant_factor > 0.0)
526  priv->quant_i = av_clip((avctx->global_quality *
527  avctx->i_quant_factor +
528  avctx->i_quant_offset) + 0.5,
529  1, 31);
530  else
531  priv->quant_i = priv->quant_p;
532  if (avctx->b_quant_factor > 0.0)
533  priv->quant_b = av_clip((avctx->global_quality *
534  avctx->b_quant_factor +
535  avctx->b_quant_offset) + 0.5,
536  1, 31);
537  else
538  priv->quant_b = priv->quant_p;
539 
540  av_log(avctx, AV_LOG_DEBUG, "Using fixed quantiser "
541  "%d / %d / %d for I- / P- / B-frames.\n",
542  priv->quant_i, priv->quant_p, priv->quant_b);
543 
544  } else {
545  av_assert0(0 && "Invalid RC mode.");
546  }
547 
548  ctx->slice_block_rows = FFALIGN(avctx->height, 16) / 16;
549  ctx->slice_block_cols = FFALIGN(avctx->width, 16) / 16;
550 
551  ctx->nb_slices = ctx->slice_block_rows;
552  ctx->slice_size = 1;
553 
554  return 0;
555 }
556 
558  { FF_PROFILE_MPEG2_MAIN, 8, 3, 1, 1, VAProfileMPEG2Main },
559  { FF_PROFILE_MPEG2_SIMPLE, 8, 3, 1, 1, VAProfileMPEG2Simple },
561 };
562 
565 
566  .configure = &vaapi_encode_mpeg2_configure,
567 
568  .sequence_params_size = sizeof(VAEncSequenceParameterBufferMPEG2),
569  .init_sequence_params = &vaapi_encode_mpeg2_init_sequence_params,
570 
571  .picture_params_size = sizeof(VAEncPictureParameterBufferMPEG2),
572  .init_picture_params = &vaapi_encode_mpeg2_init_picture_params,
573 
574  .slice_params_size = sizeof(VAEncSliceParameterBufferMPEG2),
575  .init_slice_params = &vaapi_encode_mpeg2_init_slice_params,
576 
577  .sequence_header_type = VAEncPackedHeaderSequence,
578  .write_sequence_header = &vaapi_encode_mpeg2_write_sequence_header,
579 
580  .picture_header_type = VAEncPackedHeaderPicture,
581  .write_picture_header = &vaapi_encode_mpeg2_write_picture_header,
582 };
583 
585 {
586  VAAPIEncodeContext *ctx = avctx->priv_data;
587  VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
588 
590 
591  if (avctx->profile == FF_PROFILE_UNKNOWN)
592  avctx->profile = priv->profile;
593  if (avctx->level == FF_LEVEL_UNKNOWN)
594  avctx->level = priv->level;
595 
596  // Reject unknown levels (these are required to set f_code for
597  // motion vector encoding).
598  switch (avctx->level) {
599  case 4: // High
600  case 6: // High 1440
601  case 8: // Main
602  case 10: // Low
603  break;
604  default:
605  av_log(avctx, AV_LOG_ERROR, "Unknown MPEG-2 level %d.\n",
606  avctx->level);
607  return AVERROR(EINVAL);
608  }
609 
610  if (avctx->height % 4096 == 0 || avctx->width % 4096 == 0) {
611  av_log(avctx, AV_LOG_ERROR, "MPEG-2 does not support picture "
612  "height or width divisible by 4096.\n");
613  return AVERROR(EINVAL);
614  }
615 
616  ctx->desired_packed_headers = VA_ENC_PACKED_HEADER_SEQUENCE |
617  VA_ENC_PACKED_HEADER_PICTURE;
618 
619  ctx->surface_width = FFALIGN(avctx->width, 16);
620  ctx->surface_height = FFALIGN(avctx->height, 16);
621 
622  return ff_vaapi_encode_init(avctx);
623 }
624 
626 {
627  VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
628 
629  ff_cbs_close(&priv->cbc);
630 
631  return ff_vaapi_encode_close(avctx);
632 }
633 
634 #define OFFSET(x) offsetof(VAAPIEncodeMPEG2Context, x)
635 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
638 
639  { "profile", "Set profile (in profile_and_level_indication)",
641  { .i64 = FF_PROFILE_UNKNOWN }, FF_PROFILE_UNKNOWN, 7, FLAGS, "profile" },
642 
643 #define PROFILE(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
644  { .i64 = value }, 0, 0, FLAGS, "profile"
645  { PROFILE("simple", FF_PROFILE_MPEG2_SIMPLE) },
646  { PROFILE("main", FF_PROFILE_MPEG2_MAIN) },
647 #undef PROFILE
648 
649  { "level", "Set level (in profile_and_level_indication)",
651  { .i64 = 4 }, 0, 15, FLAGS, "level" },
652 
653 #define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
654  { .i64 = value }, 0, 0, FLAGS, "level"
655  { LEVEL("low", 10) },
656  { LEVEL("main", 8) },
657  { LEVEL("high_1440", 6) },
658  { LEVEL("high", 4) },
659 #undef LEVEL
660 
661  { NULL },
662 };
663 
665  { "b", "0" },
666  { "bf", "1" },
667  { "g", "120" },
668  { "i_qfactor", "1" },
669  { "i_qoffset", "0" },
670  { "b_qfactor", "6/5" },
671  { "b_qoffset", "0" },
672  { "global_quality", "10" },
673  { "qmin", "-1" },
674  { "qmax", "-1" },
675  { NULL },
676 };
677 
679  .class_name = "mpeg2_vaapi",
680  .item_name = av_default_item_name,
681  .option = vaapi_encode_mpeg2_options,
682  .version = LIBAVUTIL_VERSION_INT,
683 };
684 
686  .name = "mpeg2_vaapi",
687  .long_name = NULL_IF_CONFIG_SMALL("MPEG-2 (VAAPI)"),
688  .type = AVMEDIA_TYPE_VIDEO,
690  .priv_data_size = sizeof(VAAPIEncodeMPEG2Context),
692  .encode2 = &ff_vaapi_encode2,
693  .close = &vaapi_encode_mpeg2_close,
694  .priv_class = &vaapi_encode_mpeg2_class,
695  .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE,
696  .defaults = vaapi_encode_mpeg2_defaults,
697  .pix_fmts = (const enum AVPixelFormat[]) {
700  },
701  .wrapper_name = "vaapi",
702 };
static av_cold int vaapi_encode_mpeg2_configure(AVCodecContext *avctx)
MPEG2RawExtensionData sequence_extension
#define NULL
Definition: coverity.c:32
#define FF_PROFILE_MPEG2_MAIN
Definition: avcodec.h:2892
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
Definition: rational.c:88
#define se(name, range_min, range_max)
Definition: cbs_h2645.c:258
AVOption.
Definition: opt.h:246
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
static const VAAPIEncodeProfile vaapi_encode_mpeg2_profiles[]
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
MPEG2RawSequenceExtension sequence
Definition: cbs_mpeg2.h:176
#define AV_CODEC_CAP_HARDWARE
Codec is backed by a hardware implementation.
Definition: avcodec.h:1065
int ff_cbs_init(CodedBitstreamContext **ctx_ptr, enum AVCodecID codec_id, void *log_ctx)
Create and initialise a new context for the given codec.
Definition: cbs.c:74
int num
Numerator.
Definition: rational.h:59
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:191
int ff_cbs_insert_unit_content(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int position, CodedBitstreamUnitType type, void *content, AVBufferRef *content_buf)
Insert a new unit into a fragment with the given content.
Definition: cbs.c:570
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
Definition: avcodec.h:1912
MPEG2RawExtensionData sequence_display_extension
void * codec_sequence_params
Definition: vaapi_encode.h:202
static av_cold int vaapi_encode_mpeg2_init(AVCodecContext *avctx)
int profile
profile
Definition: avcodec.h:2859
AVCodec.
Definition: avcodec.h:3424
float i_quant_offset
qscale offset between P and I-frames
Definition: avcodec.h:1845
#define FLAGS
#define FF_LEVEL_UNKNOWN
Definition: avcodec.h:2970
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:72
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: avcodec.h:993
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
uint16_t vertical_size_value
Definition: cbs_mpeg2.h:63
static int vaapi_encode_mpeg2_write_picture_header(AVCodecContext *avctx, VAAPIEncodePicture *pic, char *data, size_t *data_len)
#define av_cold
Definition: attributes.h:82
static int vaapi_encode_mpeg2_add_header(AVCodecContext *avctx, CodedBitstreamFragment *frag, int type, void *header)
static const AVClass vaapi_encode_mpeg2_class
float b_quant_factor
qscale factor between IP and B-frames If > 0 then the last P-frame quantizer will be used (q= lastp_q...
Definition: avcodec.h:1802
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
VASurfaceID recon_surface
Definition: vaapi_encode.h:79
static const uint8_t header[24]
Definition: sdr2.c:67
MPEG2RawSequenceHeader sequence_header
static int vaapi_encode_mpeg2_write_fragment(AVCodecContext *avctx, char *data, size_t *data_len, CodedBitstreamFragment *frag)
#define FFALIGN(x, a)
Definition: macros.h:48
#define av_log(a,...)
MPEG2RawPictureCodingExtension picture_coding
Definition: cbs_mpeg2.h:179
size_t data_size
The number of bytes in the bitstream.
Definition: cbs.h:129
unsigned int va_rc_mode
Definition: vaapi_encode.h:147
AVCodec ff_mpeg2_vaapi_encoder
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
void ff_cbs_fragment_uninit(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Free all allocated memory in a fragment.
Definition: cbs.c:139
#define AVERROR(e)
Definition: error.h:43
static int vaapi_encode_mpeg2_init_picture_params(AVCodecContext *avctx, VAAPIEncodePicture *pic)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
static const AVCodecDefault vaapi_encode_mpeg2_defaults[]
MPEG2RawPictureHeader picture_header
simple assert() macros that are a bit more flexible than ISO C assert().
const char * name
Name of the codec implementation.
Definition: avcodec.h:3431
float i_quant_factor
qscale factor between P- and I-frames If > 0 then the last P-frame quantizer will be used (q = lastp_...
Definition: avcodec.h:1838
static const AVCodecDefault defaults[]
Definition: amfenc_h264.c:361
unsigned int va_bit_rate
Definition: vaapi_encode.h:149
void ff_mpeg12_find_best_frame_rate(AVRational frame_rate, int *code, int *ext_n, int *ext_d, int nonstandard)
void * codec_picture_params
Definition: vaapi_encode.h:88
size_t data_bit_padding
The number of bits which should be ignored in the final byte.
Definition: cbs.h:133
#define fail()
Definition: checkasm.h:117
int rc_buffer_size
decoder bitstream buffer size
Definition: avcodec.h:2392
CodedBitstreamContext * cbc
#define PROFILE(name, value)
static av_cold int vaapi_encode_mpeg2_close(AVCodecContext *avctx)
static int vaapi_encode_mpeg2_init_sequence_params(AVCodecContext *avctx)
int width
picture width / height.
Definition: avcodec.h:1706
#define FF_PROFILE_UNKNOWN
Definition: avcodec.h:2860
const VAAPIEncodeProfile * profiles
Definition: vaapi_encode.h:261
av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
AVFormatContext * ctx
Definition: movenc.c:48
int level
level
Definition: avcodec.h:2969
VAAPIEncodeContext common
void * codec_picture_params
Definition: vaapi_encode.h:206
preferred ID for MPEG-1/2 video decoding
Definition: avcodec.h:220
uint8_t * data
Pointer to the bitstream form of this fragment.
Definition: cbs.h:122
int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Write the content of the fragment to its own internal buffer.
Definition: cbs.c:282
struct VAAPIEncodePicture * refs[MAX_PICTURE_REFERENCES]
Definition: vaapi_encode.h:91
static int vaapi_encode_mpeg2_init_slice_params(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice)
const struct VAAPIEncodeType * codec
Definition: vaapi_encode.h:116
Libavcodec external API header.
MPEG2RawSequenceDisplayExtension sequence_display
Definition: cbs_mpeg2.h:177
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:116
main external API structure.
Definition: avcodec.h:1533
uint8_t sequence_header_code
Definition: cbs_mpeg2.h:60
static const AVOption vaapi_encode_mpeg2_options[]
GLint GLenum type
Definition: opengl_enc.c:105
CodedBitstreamFragment current_fragment
Describe the class of an AVClass context structure.
Definition: log.h:67
Context structure for coded bitstream operations.
Definition: cbs.h:159
#define LEVEL(name, value)
Rational number (pair of numerator and denominator).
Definition: rational.h:58
MPEG2RawExtensionData picture_coding_extension
static const VAAPIEncodeType vaapi_encode_type_mpeg2
uint16_t horizontal_size_value
Definition: cbs_mpeg2.h:62
void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
Definition: cbs.c:113
uint16_t temporal_reference
Definition: cbs_mpeg2.h:120
float b_quant_offset
qscale offset between IP and B-frames
Definition: avcodec.h:1815
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:266
uint8_t picture_coding_type
Definition: cbs_mpeg2.h:121
mfxU16 profile
Definition: qsvenc.c:44
int global_quality
Global quality for codecs which cannot change it per frame.
Definition: avcodec.h:1599
#define VAAPI_ENCODE_COMMON_OPTIONS
Definition: vaapi_encode.h:330
uint8_t level
Definition: svq3.c:207
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
Definition: rational.h:89
int ff_vaapi_encode2(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *input_image, int *got_packet)
Definition: vaapi_encode.c:895
int den
Denominator.
Definition: rational.h:60
void * priv_data
Definition: avcodec.h:1560
#define OFFSET(x)
#define FF_PROFILE_MPEG2_SIMPLE
Definition: avcodec.h:2893
void * codec_slice_params
Definition: vaapi_encode.h:60
MPEG2RawGroupOfPicturesHeader gop_header
unsigned int desired_packed_headers
Definition: vaapi_encode.h:124
static int vaapi_encode_mpeg2_write_sequence_header(AVCodecContext *avctx, char *data, size_t *data_len)
VABufferID output_buffer
Definition: vaapi_encode.h:85
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
av_cold int ff_vaapi_encode_close(AVCodecContext *avctx)
union MPEG2RawExtensionData::@61 data