FFmpeg  4.0
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 {
31  int mb_width;
32  int mb_height;
33 
34  int quant_i;
35  int quant_p;
36  int quant_b;
37 
44 
45  int64_t last_i_frame;
46 
47  unsigned int bit_rate;
48  unsigned int vbv_buffer_size;
49 
51 
52  unsigned int f_code_horizontal;
53  unsigned int f_code_vertical;
54 
58 
59 
61  char *data, size_t *data_len,
63 {
66  int err;
67 
68  err = ff_cbs_write_fragment_data(priv->cbc, frag);
69  if (err < 0) {
70  av_log(avctx, AV_LOG_ERROR, "Failed to write packed header.\n");
71  return err;
72  }
73 
74  if (*data_len < 8 * frag->data_size - frag->data_bit_padding) {
75  av_log(avctx, AV_LOG_ERROR, "Access unit too large: "
76  "%zu < %zu.\n", *data_len,
77  8 * frag->data_size - frag->data_bit_padding);
78  return AVERROR(ENOSPC);
79  }
80 
81  memcpy(data, frag->data, frag->data_size);
82  *data_len = 8 * frag->data_size - frag->data_bit_padding;
83 
84  return 0;
85 }
86 
89  int type, void *header)
90 {
93  int err;
94 
95  err = ff_cbs_insert_unit_content(priv->cbc, frag, -1, type, header, NULL);
96  if (err < 0) {
97  av_log(avctx, AV_LOG_ERROR, "Failed to add header: "
98  "type = %d.\n", type);
99  return err;
100  }
101 
102  return 0;
103 }
104 
106  char *data, size_t *data_len)
107 {
108  VAAPIEncodeContext *ctx = avctx->priv_data;
109  VAAPIEncodeMPEG2Context *priv = ctx->priv_data;
111  int err;
112 
114  &priv->sequence_header);
115  if (err < 0)
116  goto fail;
117 
119  &priv->sequence_extension);
120  if (err < 0)
121  goto fail;
122 
125  if (err < 0)
126  goto fail;
127 
129  &priv->gop_header);
130  if (err < 0)
131  goto fail;
132 
133  err = vaapi_encode_mpeg2_write_fragment(avctx, data, data_len, frag);
134 fail:
135  ff_cbs_fragment_uninit(priv->cbc, frag);
136  return 0;
137 }
138 
140  VAAPIEncodePicture *pic,
141  char *data, size_t *data_len)
142 {
143  VAAPIEncodeContext *ctx = avctx->priv_data;
144  VAAPIEncodeMPEG2Context *priv = ctx->priv_data;
146  int err;
147 
149  &priv->picture_header);
150  if (err < 0)
151  goto fail;
152 
154  &priv->picture_coding_extension);
155  if (err < 0)
156  goto fail;
157 
158  err = vaapi_encode_mpeg2_write_fragment(avctx, data, data_len, frag);
159 fail:
160  ff_cbs_fragment_uninit(priv->cbc, frag);
161  return 0;
162 }
163 
165 {
166  VAAPIEncodeContext *ctx = avctx->priv_data;
167  VAAPIEncodeMPEG2Context *priv = ctx->priv_data;
174  VAEncSequenceParameterBufferMPEG2 *vseq = ctx->codec_sequence_params;
175  VAEncPictureParameterBufferMPEG2 *vpic = ctx->codec_picture_params;
176  int code, ext_n, ext_d;
177 
178  memset(sh, 0, sizeof(*sh));
179  memset(se, 0, sizeof(*se));
180  memset(sde, 0, sizeof(*sde));
181  memset(goph, 0, sizeof(*goph));
182  memset(ph, 0, sizeof(*ph));
183  memset(pce, 0, sizeof(*pce));
184 
185 
186  if (avctx->bit_rate > 0) {
187  priv->bit_rate = (avctx->bit_rate + 399) / 400;
188  } else {
189  // Unknown (not a bitrate-targetting mode), so just use the
190  // highest value.
191  priv->bit_rate = 0x3fffffff;
192  }
193  if (avctx->rc_buffer_size > 0) {
194  priv->vbv_buffer_size = (avctx->rc_buffer_size + (1 << 14) - 1) >> 14;
195  } else {
196  // Unknown, so guess a value from the bitrate.
197  priv->vbv_buffer_size = priv->bit_rate >> 14;
198  }
199 
200  switch (avctx->level) {
201  case 4: // High.
202  case 6: // High 1440.
203  priv->f_code_horizontal = 9;
204  priv->f_code_vertical = 5;
205  break;
206  case 8: // Main.
207  priv->f_code_horizontal = 8;
208  priv->f_code_vertical = 5;
209  break;
210  case 10: // Low.
211  default:
212  priv->f_code_horizontal = 7;
213  priv->f_code_vertical = 4;
214  break;
215  }
216 
217 
218  // Sequence header
219 
221 
222  sh->horizontal_size_value = avctx->width & 0xfff;
223  sh->vertical_size_value = avctx->height & 0xfff;
224 
225  if (avctx->sample_aspect_ratio.num != 0 &&
226  avctx->sample_aspect_ratio.den != 0) {
228  (AVRational) { avctx->width, avctx->height });
229 
230  if (av_cmp_q(avctx->sample_aspect_ratio, (AVRational) { 1, 1 }) == 0) {
231  sh->aspect_ratio_information = 1;
232  } else if (av_cmp_q(dar, (AVRational) { 3, 4 }) == 0) {
233  sh->aspect_ratio_information = 2;
234  } else if (av_cmp_q(dar, (AVRational) { 9, 16 }) == 0) {
235  sh->aspect_ratio_information = 3;
236  } else if (av_cmp_q(dar, (AVRational) { 100, 221 }) == 0) {
237  sh->aspect_ratio_information = 4;
238  } else {
239  av_log(avctx, AV_LOG_WARNING, "Sample aspect ratio %d:%d is not "
240  "representable, signalling square pixels instead.\n",
241  avctx->sample_aspect_ratio.num,
242  avctx->sample_aspect_ratio.den);
243  sh->aspect_ratio_information = 1;
244  }
245  } else {
246  // Unknown - assume square pixels.
247  sh->aspect_ratio_information = 1;
248  }
249 
250  if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
251  priv->frame_rate = avctx->framerate;
252  else
253  priv->frame_rate = av_inv_q(avctx->time_base);
255  &code, &ext_n, &ext_d, 0);
256  sh->frame_rate_code = code;
257 
258  sh->bit_rate_value = priv->bit_rate & 0x3ffff;
259  sh->vbv_buffer_size_value = priv->vbv_buffer_size & 0x3ff;
260 
264 
265 
266  // Sequence extension
267 
271 
272  se->profile_and_level_indication = avctx->profile << 4 | avctx->level;
273  se->progressive_sequence = 1;
274  se->chroma_format = 1;
275 
276  se->horizontal_size_extension = avctx->width >> 12;
277  se->vertical_size_extension = avctx->height >> 12;
278 
279  se->bit_rate_extension = priv->bit_rate >> 18;
280  se->vbv_buffer_size_extension = priv->vbv_buffer_size >> 10;
281  se->low_delay = ctx->b_per_p == 0;
282 
283  se->frame_rate_extension_n = ext_n;
284  se->frame_rate_extension_d = ext_d;
285 
286 
287  // Sequence display extension
288 
293 
294  sde->video_format = 5;
295  if (avctx->color_primaries != AVCOL_PRI_UNSPECIFIED ||
296  avctx->color_trc != AVCOL_TRC_UNSPECIFIED ||
297  avctx->colorspace != AVCOL_SPC_UNSPECIFIED) {
298  sde->colour_description = 1;
299  sde->colour_primaries = avctx->color_primaries;
300  sde->transfer_characteristics = avctx->color_trc;
301  sde->matrix_coefficients = avctx->colorspace;
302  } else {
303  sde->colour_description = 0;
304  }
305 
306  sde->display_horizontal_size = avctx->width;
307  sde->display_vertical_size = avctx->height;
308 
309 
310  // GOP header
311 
313 
314  goph->time_code = 0;
315  goph->closed_gop = 1;
316  goph->broken_link = 0;
317 
318 
319  // Defaults for picture header
320 
322 
323  ph->vbv_delay = 0xffff; // Not currently calculated.
324 
325  ph->full_pel_forward_vector = 0;
326  ph->forward_f_code = 7;
327  ph->full_pel_backward_vector = 0;
328  ph->forward_f_code = 7;
329 
330 
331  // Defaults for picture coding extension
332 
337 
338  pce->intra_dc_precision = 0;
339  pce->picture_structure = 3;
340  pce->top_field_first = 0;
341  pce->frame_pred_frame_dct = 1;
343  pce->q_scale_type = 0;
344  pce->intra_vlc_format = 0;
345  pce->alternate_scan = 0;
346  pce->repeat_first_field = 0;
347  pce->progressive_frame = 1;
348  pce->composite_display_flag = 0;
349 
350 
351 
352  *vseq = (VAEncSequenceParameterBufferMPEG2) {
353  .intra_period = avctx->gop_size,
354  .ip_period = ctx->b_per_p + 1,
355 
356  .picture_width = avctx->width,
357  .picture_height = avctx->height,
358 
359  .bits_per_second = avctx->bit_rate,
360  .frame_rate = av_q2d(priv->frame_rate),
361  .aspect_ratio_information = sh->aspect_ratio_information,
362  .vbv_buffer_size = priv->vbv_buffer_size,
363 
364  .sequence_extension.bits = {
365  .profile_and_level_indication = se->profile_and_level_indication,
366  .progressive_sequence = se->progressive_sequence,
367  .chroma_format = se->chroma_format,
368  .low_delay = se->low_delay,
369  .frame_rate_extension_n = se->frame_rate_extension_n,
370  .frame_rate_extension_d = se->frame_rate_extension_d,
371  },
372 
373  .new_gop_header = 1,
374  .gop_header.bits = {
375  .time_code = goph->time_code,
376  .closed_gop = goph->closed_gop,
377  .broken_link = goph->broken_link,
378  },
379  };
380 
381  *vpic = (VAEncPictureParameterBufferMPEG2) {
382  .forward_reference_picture = VA_INVALID_ID,
383  .backward_reference_picture = VA_INVALID_ID,
384  .reconstructed_picture = VA_INVALID_ID,
385  .coded_buf = VA_INVALID_ID,
386 
387  .vbv_delay = 0xffff,
388  .f_code = { { 15, 15 }, { 15, 15 } },
389 
390  .picture_coding_extension.bits = {
391  .intra_dc_precision = pce->intra_dc_precision,
392  .picture_structure = pce->picture_structure,
393  .top_field_first = pce->top_field_first,
394  .frame_pred_frame_dct = pce->frame_pred_frame_dct,
395  .concealment_motion_vectors = pce->concealment_motion_vectors,
396  .q_scale_type = pce->q_scale_type,
397  .intra_vlc_format = pce->intra_vlc_format,
398  .alternate_scan = pce->alternate_scan,
399  .repeat_first_field = pce->repeat_first_field,
400  .progressive_frame = pce->progressive_frame,
401  .composite_display_flag = pce->composite_display_flag,
402  },
403 
404  .composite_display.bits = {
405  .v_axis = pce->v_axis,
406  .field_sequence = pce->field_sequence,
407  .sub_carrier = pce->sub_carrier,
408  .burst_amplitude = pce->burst_amplitude,
409  .sub_carrier_phase = pce->sub_carrier_phase,
410  },
411  };
412 
413  return 0;
414 }
415 
417  VAAPIEncodePicture *pic)
418 {
419  VAAPIEncodeContext *ctx = avctx->priv_data;
420  VAAPIEncodeMPEG2Context *priv = ctx->priv_data;
423  VAEncPictureParameterBufferMPEG2 *vpic = pic->codec_picture_params;
424 
425  if (pic->type == PICTURE_TYPE_IDR || pic->type == PICTURE_TYPE_I) {
426  ph->temporal_reference = 0;
427  ph->picture_coding_type = 1;
428  priv->last_i_frame = pic->display_order;
429  } else {
430  ph->temporal_reference = pic->display_order - priv->last_i_frame;
431  ph->picture_coding_type = pic->type == PICTURE_TYPE_B ? 3 : 2;
432  }
433 
434  if (pic->type == PICTURE_TYPE_P || pic->type == PICTURE_TYPE_B) {
435  pce->f_code[0][0] = priv->f_code_horizontal;
436  pce->f_code[0][1] = priv->f_code_vertical;
437  } else {
438  pce->f_code[0][0] = 15;
439  pce->f_code[0][1] = 15;
440  }
441  if (pic->type == PICTURE_TYPE_B) {
442  pce->f_code[1][0] = priv->f_code_horizontal;
443  pce->f_code[1][1] = priv->f_code_vertical;
444  } else {
445  pce->f_code[1][0] = 15;
446  pce->f_code[1][1] = 15;
447  }
448 
449  vpic->reconstructed_picture = pic->recon_surface;
450  vpic->coded_buf = pic->output_buffer;
451 
452  switch (pic->type) {
453  case PICTURE_TYPE_IDR:
454  case PICTURE_TYPE_I:
455  vpic->picture_type = VAEncPictureTypeIntra;
456  break;
457  case PICTURE_TYPE_P:
458  vpic->picture_type = VAEncPictureTypePredictive;
459  vpic->forward_reference_picture = pic->refs[0]->recon_surface;
460  break;
461  case PICTURE_TYPE_B:
462  vpic->picture_type = VAEncPictureTypeBidirectional;
463  vpic->forward_reference_picture = pic->refs[0]->recon_surface;
464  vpic->backward_reference_picture = pic->refs[1]->recon_surface;
465  break;
466  default:
467  av_assert0(0 && "invalid picture type");
468  }
469 
470  vpic->temporal_reference = ph->temporal_reference;
471  vpic->f_code[0][0] = pce->f_code[0][0];
472  vpic->f_code[0][1] = pce->f_code[0][1];
473  vpic->f_code[1][0] = pce->f_code[1][0];
474  vpic->f_code[1][1] = pce->f_code[1][1];
475 
476  pic->nb_slices = priv->mb_height;
477 
478  return 0;
479 }
480 
482  VAAPIEncodePicture *pic,
483  VAAPIEncodeSlice *slice)
484 {
485  VAAPIEncodeContext *ctx = avctx->priv_data;
486  VAEncSliceParameterBufferMPEG2 *vslice = slice->codec_slice_params;
487  VAAPIEncodeMPEG2Context *priv = ctx->priv_data;
488  int qp;
489 
490  vslice->macroblock_address = priv->mb_width * slice->index;
491  vslice->num_macroblocks = priv->mb_width;
492 
493  switch (pic->type) {
494  case PICTURE_TYPE_IDR:
495  case PICTURE_TYPE_I:
496  qp = priv->quant_i;
497  break;
498  case PICTURE_TYPE_P:
499  qp = priv->quant_p;
500  break;
501  case PICTURE_TYPE_B:
502  qp = priv->quant_b;
503  break;
504  default:
505  av_assert0(0 && "invalid picture type");
506  }
507 
508  vslice->quantiser_scale_code = qp;
509  vslice->is_intra_slice = (pic->type == PICTURE_TYPE_IDR ||
510  pic->type == PICTURE_TYPE_I);
511 
512  return 0;
513 }
514 
516 {
517  VAAPIEncodeContext *ctx = avctx->priv_data;
518  VAAPIEncodeMPEG2Context *priv = ctx->priv_data;
519  int err;
520 
521  err = ff_cbs_init(&priv->cbc, AV_CODEC_ID_MPEG2VIDEO, avctx);
522  if (err < 0)
523  return err;
524 
525  priv->mb_width = FFALIGN(avctx->width, 16) / 16;
526  priv->mb_height = FFALIGN(avctx->height, 16) / 16;
527 
528  if (ctx->va_rc_mode == VA_RC_CQP) {
529  priv->quant_p = av_clip(avctx->global_quality, 1, 31);
530  if (avctx->i_quant_factor > 0.0)
531  priv->quant_i = av_clip((avctx->global_quality *
532  avctx->i_quant_factor +
533  avctx->i_quant_offset) + 0.5,
534  1, 31);
535  else
536  priv->quant_i = priv->quant_p;
537  if (avctx->b_quant_factor > 0.0)
538  priv->quant_b = av_clip((avctx->global_quality *
539  avctx->b_quant_factor +
540  avctx->b_quant_offset) + 0.5,
541  1, 31);
542  else
543  priv->quant_b = priv->quant_p;
544 
545  av_log(avctx, AV_LOG_DEBUG, "Using fixed quantiser "
546  "%d / %d / %d for I- / P- / B-frames.\n",
547  priv->quant_i, priv->quant_p, priv->quant_b);
548 
549  } else {
550  av_assert0(0 && "Invalid RC mode.");
551  }
552 
553  return 0;
554 }
555 
558 
559  .configure = &vaapi_encode_mpeg2_configure,
560 
561  .sequence_params_size = sizeof(VAEncSequenceParameterBufferMPEG2),
562  .init_sequence_params = &vaapi_encode_mpeg2_init_sequence_params,
563 
564  .picture_params_size = sizeof(VAEncPictureParameterBufferMPEG2),
565  .init_picture_params = &vaapi_encode_mpeg2_init_picture_params,
566 
567  .slice_params_size = sizeof(VAEncSliceParameterBufferMPEG2),
568  .init_slice_params = &vaapi_encode_mpeg2_init_slice_params,
569 
570  .sequence_header_type = VAEncPackedHeaderSequence,
571  .write_sequence_header = &vaapi_encode_mpeg2_write_sequence_header,
572 
573  .picture_header_type = VAEncPackedHeaderPicture,
574  .write_picture_header = &vaapi_encode_mpeg2_write_picture_header,
575 };
576 
578 {
579  VAAPIEncodeContext *ctx = avctx->priv_data;
580 
582 
583  switch (avctx->profile) {
585  ctx->va_profile = VAProfileMPEG2Simple;
586  break;
588  ctx->va_profile = VAProfileMPEG2Main;
589  break;
591  av_log(avctx, AV_LOG_ERROR, "MPEG-2 4:2:2 profile "
592  "is not supported.\n");
593  return AVERROR_PATCHWELCOME;
595  av_log(avctx, AV_LOG_ERROR, "MPEG-2 high profile "
596  "is not supported.\n");
597  return AVERROR_PATCHWELCOME;
598  case FF_PROFILE_MPEG2_SS:
600  av_log(avctx, AV_LOG_ERROR, "MPEG-2 scalable profiles "
601  "are not supported.\n");
602  return AVERROR_PATCHWELCOME;
603  default:
604  av_log(avctx, AV_LOG_ERROR, "Unknown MPEG-2 profile %d.\n",
605  avctx->profile);
606  return AVERROR(EINVAL);
607  }
608  switch (avctx->level) {
609  case 4: // High
610  case 6: // High 1440
611  case 8: // Main
612  case 10: // Low
613  break;
614  default:
615  av_log(avctx, AV_LOG_ERROR, "Unknown MPEG-2 level %d.\n",
616  avctx->level);
617  return AVERROR(EINVAL);
618  }
619 
620  if (avctx->height % 4096 == 0 || avctx->width % 4096 == 0) {
621  av_log(avctx, AV_LOG_ERROR, "MPEG-2 does not support picture "
622  "height or width divisible by 4096.\n");
623  return AVERROR(EINVAL);
624  }
625 
626  ctx->va_entrypoint = VAEntrypointEncSlice;
627  ctx->va_rt_format = VA_RT_FORMAT_YUV420;
628  ctx->va_rc_mode = VA_RC_CQP;
629 
630  ctx->va_packed_headers = VA_ENC_PACKED_HEADER_SEQUENCE |
631  VA_ENC_PACKED_HEADER_PICTURE;
632 
633  ctx->surface_width = FFALIGN(avctx->width, 16);
634  ctx->surface_height = FFALIGN(avctx->height, 16);
635 
636  return ff_vaapi_encode_init(avctx);
637 }
638 
640 {
641  VAAPIEncodeContext *ctx = avctx->priv_data;
642  VAAPIEncodeMPEG2Context *priv = ctx->priv_data;
643 
644  if (priv)
645  ff_cbs_close(&priv->cbc);
646 
647  return ff_vaapi_encode_close(avctx);
648 }
649 
651  { "profile", "4" },
652  { "level", "4" },
653  { "bf", "1" },
654  { "g", "120" },
655  { "i_qfactor", "1" },
656  { "i_qoffset", "0" },
657  { "b_qfactor", "6/5" },
658  { "b_qoffset", "0" },
659  { "global_quality", "10" },
660  { NULL },
661 };
662 
664  .name = "mpeg2_vaapi",
665  .long_name = NULL_IF_CONFIG_SMALL("MPEG-2 (VAAPI)"),
666  .type = AVMEDIA_TYPE_VIDEO,
668  .priv_data_size = sizeof(VAAPIEncodeContext),
670  .encode2 = &ff_vaapi_encode2,
671  .close = &vaapi_encode_mpeg2_close,
672  .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE,
673  .defaults = vaapi_encode_mpeg2_defaults,
674  .pix_fmts = (const enum AVPixelFormat[]) {
677  },
678  .wrapper_name = "vaapi",
679 };
static av_cold int vaapi_encode_mpeg2_configure(AVCodecContext *avctx)
MPEG2RawExtensionData sequence_extension
uint8_t full_pel_backward_vector
Definition: cbs_mpeg2.h:126
#define NULL
Definition: coverity.c:32
AVRational framerate
Definition: avcodec.h:3040
uint8_t load_non_intra_quantiser_matrix
Definition: cbs_mpeg2.h:72
uint8_t picture_start_code
Definition: cbs_mpeg2.h:118
uint8_t extension_start_code_identifier
Definition: cbs_mpeg2.h:173
VAProfile va_profile
Definition: vaapi_encode.h:96
#define FF_PROFILE_MPEG2_MAIN
Definition: avcodec.h:2876
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:349
VAEntrypoint va_entrypoint
Definition: vaapi_encode.h:98
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
int64_t bit_rate
the average bitrate
Definition: avcodec.h:1568
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:1056
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:56
int num
Numerator.
Definition: rational.h:59
size_t priv_data_size
Definition: vaapi_encode.h:218
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:518
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:1896
MPEG2RawExtensionData sequence_display_extension
union MPEG2RawExtensionData::@48 data
void * codec_sequence_params
Definition: vaapi_encode.h:168
static av_cold int vaapi_encode_mpeg2_init(AVCodecContext *avctx)
int profile
profile
Definition: avcodec.h:2843
AVCodec.
Definition: avcodec.h:3408
float i_quant_offset
qscale offset between P and I-frames
Definition: avcodec.h:1829
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:1640
unsigned int va_packed_headers
Definition: vaapi_encode.h:105
#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:984
#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)
uint8_t load_intra_quantiser_matrix
Definition: cbs_mpeg2.h:70
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:1786
const char data[16]
Definition: mxf.c:90
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
VASurfaceID recon_surface
Definition: vaapi_encode.h:71
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,...)
uint8_t constrained_parameters_flag
Definition: cbs_mpeg2.h:68
MPEG2RawPictureCodingExtension picture_coding
Definition: cbs_mpeg2.h:179
size_t data_size
The number of bytes in the bitstream.
Definition: cbs.h:127
unsigned int va_rc_mode
Definition: vaapi_encode.h:102
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:121
#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:3415
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:1822
static const AVCodecDefault defaults[]
Definition: amfenc_h264.c:361
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:80
size_t data_bit_padding
The number of bits which should be ignored in the final byte.
Definition: cbs.h:131
#define fail()
Definition: checkasm.h:116
#define FF_PROFILE_MPEG2_SNR_SCALABLE
Definition: avcodec.h:2875
int rc_buffer_size
decoder bitstream buffer size
Definition: avcodec.h:2376
CodedBitstreamContext * cbc
#define FF_PROFILE_MPEG2_HIGH
Definition: avcodec.h:2873
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:1690
av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
AVFormatContext * ctx
Definition: movenc.c:48
#define FF_PROFILE_MPEG2_422
Definition: avcodec.h:2872
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:2127
unsigned int va_rt_format
Definition: vaapi_encode.h:100
int level
level
Definition: avcodec.h:2953
void * codec_picture_params
Definition: vaapi_encode.h:172
uint8_t horizontal_size_extension
Definition: cbs_mpeg2.h:88
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:120
int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Write the content of the fragment to its own internal buffer.
Definition: cbs.c:261
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
struct VAAPIEncodePicture * refs[MAX_PICTURE_REFERENCES]
Definition: vaapi_encode.h:83
static int vaapi_encode_mpeg2_init_slice_params(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice)
const struct VAAPIEncodeType * codec
Definition: vaapi_encode.h:93
Libavcodec external API header.
MPEG2RawSequenceDisplayExtension sequence_display
Definition: cbs_mpeg2.h:177
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:114
main external API structure.
Definition: avcodec.h:1518
uint8_t full_pel_forward_vector
Definition: cbs_mpeg2.h:124
uint8_t frame_rate_extension_n
Definition: cbs_mpeg2.h:93
uint8_t vbv_buffer_size_extension
Definition: cbs_mpeg2.h:91
uint8_t sequence_header_code
Definition: cbs_mpeg2.h:60
uint8_t frame_rate_extension_d
Definition: cbs_mpeg2.h:94
CodedBitstreamFragment current_fragment
Context structure for coded bitstream operations.
Definition: cbs.h:156
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:2141
Rational number (pair of numerator and denominator).
Definition: rational.h:58
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:2134
MPEG2RawExtensionData picture_coding_extension
static const VAAPIEncodeType vaapi_encode_type_mpeg2
uint8_t extension_start_code
Definition: cbs_mpeg2.h:172
uint16_t horizontal_size_value
Definition: cbs_mpeg2.h:62
cl_device_type type
void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
Definition: cbs.c:95
uint16_t temporal_reference
Definition: cbs_mpeg2.h:120
float b_quant_offset
qscale offset between IP and B-frames
Definition: avcodec.h:1799
uint8_t aspect_ratio_information
Definition: cbs_mpeg2.h:64
#define FF_PROFILE_MPEG2_SS
Definition: avcodec.h:2874
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:266
uint8_t picture_coding_type
Definition: cbs_mpeg2.h:121
int global_quality
Global quality for codecs which cannot change it per frame.
Definition: avcodec.h:1584
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
Definition: avcodec.h:1712
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
Definition: rational.h:89
uint16_t vbv_buffer_size_value
Definition: cbs_mpeg2.h:67
uint32_t bit_rate_value
Definition: cbs_mpeg2.h:66
int ff_vaapi_encode2(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *input_image, int *got_packet)
Definition: vaapi_encode.c:853
int den
Denominator.
Definition: rational.h:60
void * priv_data
Definition: avcodec.h:1545
uint8_t profile_and_level_indication
Definition: cbs_mpeg2.h:85
uint8_t vertical_size_extension
Definition: cbs_mpeg2.h:89
#define FF_PROFILE_MPEG2_SIMPLE
Definition: avcodec.h:2877
void * codec_slice_params
Definition: vaapi_encode.h:52
MPEG2RawGroupOfPicturesHeader gop_header
static int vaapi_encode_mpeg2_write_sequence_header(AVCodecContext *avctx, char *data, size_t *data_len)
VABufferID output_buffer
Definition: vaapi_encode.h:77
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60
av_cold int ff_vaapi_encode_close(AVCodecContext *avctx)