FFmpeg
vaapi_encode_h265.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 <string.h>
20 
21 #include <va/va.h>
22 #include <va/va_enc_hevc.h>
23 
24 #include "libavutil/avassert.h"
25 #include "libavutil/common.h"
26 #include "libavutil/mem.h"
27 #include "libavutil/pixdesc.h"
28 #include "libavutil/opt.h"
30 
31 #include "atsc_a53.h"
32 #include "avcodec.h"
33 #include "cbs.h"
34 #include "cbs_h265.h"
35 #include "hw_base_encode_h265.h"
36 #include "codec_internal.h"
37 #include "h2645data.h"
38 #include "h265_profile_level.h"
39 #include "vaapi_encode.h"
40 
41 #include "hevc/hevc.h"
42 
43 enum {
46  SEI_A53_CC = 0x20,
47 };
48 
49 typedef struct VAAPIEncodeH265Picture {
51 
53 
56  int pic_type;
58 
59 typedef struct VAAPIEncodeH265Context {
61 
62  // Encoder features.
63  uint32_t va_features;
64  // Block size info.
65  uint32_t va_bs;
66  uint32_t ctu_size;
67  uint32_t min_cb_size;
68 
69  // User options.
70  int qp;
71  int aud;
72  int profile;
73  int level;
74  int sei;
75 
76  // Derived settings.
79 
80  // Writer structures.
85 
90 
96 
97 
99  char *data, size_t *data_len,
101 {
102  VAAPIEncodeH265Context *priv = avctx->priv_data;
103  int err;
104 
105  err = ff_cbs_write_fragment_data(priv->cbc, au);
106  if (err < 0) {
107  av_log(avctx, AV_LOG_ERROR, "Failed to write packed header.\n");
108  return err;
109  }
110 
111  if (*data_len < 8 * au->data_size - au->data_bit_padding) {
112  av_log(avctx, AV_LOG_ERROR, "Access unit too large: "
113  "%zu < %zu.\n", *data_len,
114  8 * au->data_size - au->data_bit_padding);
115  return AVERROR(ENOSPC);
116  }
117 
118  memcpy(data, au->data, au->data_size);
119  *data_len = 8 * au->data_size - au->data_bit_padding;
120 
121  return 0;
122 }
123 
126  void *nal_unit)
127 {
128  H265RawNALUnitHeader *header = nal_unit;
129  int err;
130 
131  err = ff_cbs_insert_unit_content(au, -1,
132  header->nal_unit_type, nal_unit, NULL);
133  if (err < 0) {
134  av_log(avctx, AV_LOG_ERROR, "Failed to add NAL unit: "
135  "type = %d.\n", header->nal_unit_type);
136  return err;
137  }
138 
139  return 0;
140 }
141 
143  char *data, size_t *data_len)
144 {
145  VAAPIEncodeH265Context *priv = avctx->priv_data;
147  int err;
148 
149  if (priv->aud_needed) {
150  err = vaapi_encode_h265_add_nal(avctx, au, &priv->raw_aud);
151  if (err < 0)
152  goto fail;
153  priv->aud_needed = 0;
154  }
155 
156  err = vaapi_encode_h265_add_nal(avctx, au, &priv->units.raw_vps);
157  if (err < 0)
158  goto fail;
159 
160  err = vaapi_encode_h265_add_nal(avctx, au, &priv->units.raw_sps);
161  if (err < 0)
162  goto fail;
163 
164  err = vaapi_encode_h265_add_nal(avctx, au, &priv->units.raw_pps);
165  if (err < 0)
166  goto fail;
167 
168  err = vaapi_encode_h265_write_access_unit(avctx, data, data_len, au);
169 fail:
171  return err;
172 }
173 
175  VAAPIEncodePicture *pic,
176  VAAPIEncodeSlice *slice,
177  char *data, size_t *data_len)
178 {
179  VAAPIEncodeH265Context *priv = avctx->priv_data;
181  int err;
182 
183  if (priv->aud_needed) {
184  err = vaapi_encode_h265_add_nal(avctx, au, &priv->raw_aud);
185  if (err < 0)
186  goto fail;
187  priv->aud_needed = 0;
188  }
189 
190  err = vaapi_encode_h265_add_nal(avctx, au, &priv->raw_slice);
191  if (err < 0)
192  goto fail;
193 
194  err = vaapi_encode_h265_write_access_unit(avctx, data, data_len, au);
195 fail:
197  return err;
198 }
199 
202  int index, int *type,
203  char *data, size_t *data_len)
204 {
205  VAAPIEncodeH265Context *priv = avctx->priv_data;
207  int err;
208 
209  if (priv->sei_needed) {
210  if (priv->aud_needed) {
211  err = vaapi_encode_h265_add_nal(avctx, au, &priv->aud);
212  if (err < 0)
213  goto fail;
214  priv->aud_needed = 0;
215  }
216 
217  if (priv->sei_needed & SEI_MASTERING_DISPLAY) {
218  err = ff_cbs_sei_add_message(priv->cbc, au, 1,
220  &priv->sei_mastering_display, NULL);
221  if (err < 0)
222  goto fail;
223  }
224 
225  if (priv->sei_needed & SEI_CONTENT_LIGHT_LEVEL) {
226  err = ff_cbs_sei_add_message(priv->cbc, au, 1,
228  &priv->sei_content_light_level, NULL);
229  if (err < 0)
230  goto fail;
231  }
232  if (priv->sei_needed & SEI_A53_CC) {
233  err = ff_cbs_sei_add_message(priv->cbc, au, 1,
235  &priv->sei_a53cc, NULL);
236  if (err < 0)
237  goto fail;
238  }
239 
240  priv->sei_needed = 0;
241 
242  err = vaapi_encode_h265_write_access_unit(avctx, data, data_len, au);
243  if (err < 0)
244  goto fail;
245 
247 
248  *type = VAEncPackedHeaderRawData;
249  return 0;
250  } else {
251  return AVERROR_EOF;
252  }
253 
254 fail:
256  return err;
257 }
258 
260 {
261  FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
262  VAAPIEncodeContext *ctx = avctx->priv_data;
263  VAAPIEncodeH265Context *priv = avctx->priv_data;
264  H265RawVPS *vps = &priv->units.raw_vps;
265  H265RawSPS *sps = &priv->units.raw_sps;
266  H265RawPPS *pps = &priv->units.raw_pps;
267  VAEncSequenceParameterBufferHEVC *vseq = ctx->codec_sequence_params;
268  VAEncPictureParameterBufferHEVC *vpic = ctx->codec_picture_params;
269  int i, err;
270 
271  // priv->unit_opts.tier already set
272  // priv->unit_opts.fixed_qp_idr already set
273  priv->unit_opts.cu_qp_delta_enabled_flag = (ctx->va_rc_mode != VA_RC_CQP);
274  priv->unit_opts.tile_rows = ctx->tile_rows;
275  priv->unit_opts.tile_cols = ctx->tile_cols;
276  priv->unit_opts.nb_slices = ctx->nb_slices;
277  priv->unit_opts.slice_block_rows = ctx->slice_block_rows;
278  priv->unit_opts.slice_block_cols = ctx->slice_block_cols;
279  memcpy(priv->unit_opts.col_width, ctx->col_width,
280  ctx->tile_rows*sizeof(*priv->unit_opts.col_width));
281  memcpy(priv->unit_opts.row_height, ctx->row_height,
282  ctx->tile_cols*sizeof(*priv->unit_opts.row_height));
283 
284  err = ff_hw_base_encode_init_params_h265(base_ctx, avctx,
285  &priv->units, &priv->unit_opts);
286  if (err < 0)
287  return err;
288 
289 #if VA_CHECK_VERSION(1, 13, 0)
290  // update sps setting according to queried result
291  if (priv->va_features) {
292  VAConfigAttribValEncHEVCFeatures features = { .value = priv->va_features };
293 
294  // Enable feature if get queried result is VA_FEATURE_SUPPORTED | VA_FEATURE_REQUIRED
295  sps->amp_enabled_flag =
296  !!features.bits.amp;
297  sps->sample_adaptive_offset_enabled_flag =
298  !!features.bits.sao;
299  sps->sps_temporal_mvp_enabled_flag =
300  !!features.bits.temporal_mvp;
301  sps->pcm_enabled_flag =
302  !!features.bits.pcm;
303  }
304 
305  if (priv->va_bs) {
306  VAConfigAttribValEncHEVCBlockSizes bs = { .value = priv->va_bs };
307  sps->log2_min_luma_coding_block_size_minus3 =
308  ff_ctz(priv->min_cb_size) - 3;
309  sps->log2_diff_max_min_luma_coding_block_size =
310  ff_ctz(priv->ctu_size) - ff_ctz(priv->min_cb_size);
311 
312  sps->log2_min_luma_transform_block_size_minus2 =
313  bs.bits.log2_min_luma_transform_block_size_minus2;
314  sps->log2_diff_max_min_luma_transform_block_size =
315  bs.bits.log2_max_luma_transform_block_size_minus2 -
316  bs.bits.log2_min_luma_transform_block_size_minus2;
317 
318  sps->max_transform_hierarchy_depth_inter =
319  bs.bits.max_max_transform_hierarchy_depth_inter;
320  sps->max_transform_hierarchy_depth_intra =
321  bs.bits.max_max_transform_hierarchy_depth_intra;
322  }
323 
324  // update pps setting according to queried result
325  if (priv->va_features) {
326  VAConfigAttribValEncHEVCFeatures features = { .value = priv->va_features };
327  if (ctx->va_rc_mode != VA_RC_CQP)
328  pps->cu_qp_delta_enabled_flag =
329  !!features.bits.cu_qp_delta;
330 
331  pps->transform_skip_enabled_flag =
332  !!features.bits.transform_skip;
333  // set diff_cu_qp_delta_depth as its max value if cu_qp_delta enabled. Otherwise
334  // 0 will make cu_qp_delta invalid.
335  if (pps->cu_qp_delta_enabled_flag)
336  pps->diff_cu_qp_delta_depth = sps->log2_diff_max_min_luma_coding_block_size;
337  }
338 #endif
339 
340  // Fill VAAPI parameter buffers.
341 
342  *vseq = (VAEncSequenceParameterBufferHEVC) {
343  .general_profile_idc = vps->profile_tier_level.general_profile_idc,
344  .general_level_idc = vps->profile_tier_level.general_level_idc,
345  .general_tier_flag = vps->profile_tier_level.general_tier_flag,
346 
347  .intra_period = base_ctx->gop_size,
348  .intra_idr_period = base_ctx->gop_size,
349  .ip_period = base_ctx->b_per_p + 1,
350  .bits_per_second = ctx->va_bit_rate,
351 
352  .pic_width_in_luma_samples = sps->pic_width_in_luma_samples,
353  .pic_height_in_luma_samples = sps->pic_height_in_luma_samples,
354 
355  .seq_fields.bits = {
356  .chroma_format_idc = sps->chroma_format_idc,
357  .separate_colour_plane_flag = sps->separate_colour_plane_flag,
358  .bit_depth_luma_minus8 = sps->bit_depth_luma_minus8,
359  .bit_depth_chroma_minus8 = sps->bit_depth_chroma_minus8,
360  .scaling_list_enabled_flag = sps->scaling_list_enabled_flag,
361  .strong_intra_smoothing_enabled_flag =
362  sps->strong_intra_smoothing_enabled_flag,
363  .amp_enabled_flag = sps->amp_enabled_flag,
364  .sample_adaptive_offset_enabled_flag =
365  sps->sample_adaptive_offset_enabled_flag,
366  .pcm_enabled_flag = sps->pcm_enabled_flag,
367  .pcm_loop_filter_disabled_flag = sps->pcm_loop_filter_disabled_flag,
368  .sps_temporal_mvp_enabled_flag = sps->sps_temporal_mvp_enabled_flag,
369  },
370 
371  .log2_min_luma_coding_block_size_minus3 =
372  sps->log2_min_luma_coding_block_size_minus3,
373  .log2_diff_max_min_luma_coding_block_size =
374  sps->log2_diff_max_min_luma_coding_block_size,
375  .log2_min_transform_block_size_minus2 =
376  sps->log2_min_luma_transform_block_size_minus2,
377  .log2_diff_max_min_transform_block_size =
378  sps->log2_diff_max_min_luma_transform_block_size,
379  .max_transform_hierarchy_depth_inter =
380  sps->max_transform_hierarchy_depth_inter,
381  .max_transform_hierarchy_depth_intra =
382  sps->max_transform_hierarchy_depth_intra,
383 
384  .pcm_sample_bit_depth_luma_minus1 =
385  sps->pcm_sample_bit_depth_luma_minus1,
386  .pcm_sample_bit_depth_chroma_minus1 =
387  sps->pcm_sample_bit_depth_chroma_minus1,
388  .log2_min_pcm_luma_coding_block_size_minus3 =
389  sps->log2_min_pcm_luma_coding_block_size_minus3,
390  .log2_max_pcm_luma_coding_block_size_minus3 =
391  sps->log2_min_pcm_luma_coding_block_size_minus3 +
392  sps->log2_diff_max_min_pcm_luma_coding_block_size,
393 
394  .vui_parameters_present_flag = 0,
395  };
396 
397  *vpic = (VAEncPictureParameterBufferHEVC) {
398  .decoded_curr_pic = {
399  .picture_id = VA_INVALID_ID,
400  .flags = VA_PICTURE_HEVC_INVALID,
401  },
402 
403  .coded_buf = VA_INVALID_ID,
404 
405  .collocated_ref_pic_index = sps->sps_temporal_mvp_enabled_flag ?
406  0 : 0xff,
407  .last_picture = 0,
408 
409  .pic_init_qp = pps->init_qp_minus26 + 26,
410  .diff_cu_qp_delta_depth = pps->diff_cu_qp_delta_depth,
411  .pps_cb_qp_offset = pps->pps_cb_qp_offset,
412  .pps_cr_qp_offset = pps->pps_cr_qp_offset,
413 
414  .num_tile_columns_minus1 = pps->num_tile_columns_minus1,
415  .num_tile_rows_minus1 = pps->num_tile_rows_minus1,
416 
417  .log2_parallel_merge_level_minus2 = pps->log2_parallel_merge_level_minus2,
418  .ctu_max_bitsize_allowed = 0,
419 
420  .num_ref_idx_l0_default_active_minus1 =
421  pps->num_ref_idx_l0_default_active_minus1,
422  .num_ref_idx_l1_default_active_minus1 =
423  pps->num_ref_idx_l1_default_active_minus1,
424 
425  .slice_pic_parameter_set_id = pps->pps_pic_parameter_set_id,
426 
427  .pic_fields.bits = {
428  .sign_data_hiding_enabled_flag = pps->sign_data_hiding_enabled_flag,
429  .constrained_intra_pred_flag = pps->constrained_intra_pred_flag,
430  .transform_skip_enabled_flag = pps->transform_skip_enabled_flag,
431  .cu_qp_delta_enabled_flag = pps->cu_qp_delta_enabled_flag,
432  .weighted_pred_flag = pps->weighted_pred_flag,
433  .weighted_bipred_flag = pps->weighted_bipred_flag,
434  .transquant_bypass_enabled_flag = pps->transquant_bypass_enabled_flag,
435  .tiles_enabled_flag = pps->tiles_enabled_flag,
436  .entropy_coding_sync_enabled_flag = pps->entropy_coding_sync_enabled_flag,
437  .loop_filter_across_tiles_enabled_flag =
438  pps->loop_filter_across_tiles_enabled_flag,
439  .pps_loop_filter_across_slices_enabled_flag =
440  pps->pps_loop_filter_across_slices_enabled_flag,
441  .scaling_list_data_present_flag = (sps->sps_scaling_list_data_present_flag |
442  pps->pps_scaling_list_data_present_flag),
443  .screen_content_flag = 0,
444  .enable_gpu_weighted_prediction = 0,
445  .no_output_of_prior_pics_flag = 0,
446  },
447  };
448 
449  if (pps->tiles_enabled_flag) {
450  for (i = 0; i <= vpic->num_tile_rows_minus1; i++)
451  vpic->row_height_minus1[i] = pps->row_height_minus1[i];
452  for (i = 0; i <= vpic->num_tile_columns_minus1; i++)
453  vpic->column_width_minus1[i] = pps->column_width_minus1[i];
454  }
455 
456  return 0;
457 }
458 
461 {
462  FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
463  VAAPIEncodeH265Context *priv = avctx->priv_data;
464  VAAPIEncodePicture *vaapi_pic = pic->priv;
465  VAAPIEncodeH265Picture *hpic = pic->codec_priv;
466  FFHWBaseEncodePicture *prev = pic->prev;
467  VAAPIEncodeH265Picture *hprev = prev ? prev->codec_priv : NULL;
468  VAEncPictureParameterBufferHEVC *vpic = vaapi_pic->codec_picture_params;
469  int i, j = 0;
470 
471  if (pic->type == FF_HW_PICTURE_TYPE_IDR) {
472  av_assert0(pic->display_order == pic->encode_order);
473 
474  hpic->last_idr_frame = pic->display_order;
475 
477  hpic->slice_type = HEVC_SLICE_I;
478  hpic->pic_type = 0;
479  } else {
480  av_assert0(prev);
481  hpic->last_idr_frame = hprev->last_idr_frame;
482 
483  if (pic->type == FF_HW_PICTURE_TYPE_I) {
485  hpic->slice_type = HEVC_SLICE_I;
486  hpic->pic_type = 0;
487  } else if (pic->type == FF_HW_PICTURE_TYPE_P) {
488  av_assert0(pic->refs[0]);
490  hpic->slice_type = HEVC_SLICE_P;
491  hpic->pic_type = 1;
492  } else {
493  FFHWBaseEncodePicture *irap_ref;
494  av_assert0(pic->refs[0][0] && pic->refs[1][0]);
495  for (irap_ref = pic; irap_ref; irap_ref = irap_ref->refs[1][0]) {
496  if (irap_ref->type == FF_HW_PICTURE_TYPE_I)
497  break;
498  }
499  if (pic->b_depth == base_ctx->max_b_depth) {
500  hpic->slice_nal_unit = irap_ref ? HEVC_NAL_RASL_N
502  } else {
503  hpic->slice_nal_unit = irap_ref ? HEVC_NAL_RASL_R
505  }
506  hpic->slice_type = HEVC_SLICE_B;
507  hpic->pic_type = 2;
508  }
509  }
510  hpic->pic_order_cnt = pic->display_order - hpic->last_idr_frame;
511 
512  if (priv->aud) {
513  priv->aud_needed = 1;
514  priv->raw_aud = (H265RawAUD) {
515  .nal_unit_header = {
517  .nuh_layer_id = 0,
518  .nuh_temporal_id_plus1 = 1,
519  },
520  .pic_type = hpic->pic_type,
521  };
522  } else {
523  priv->aud_needed = 0;
524  }
525 
526  priv->sei_needed = 0;
527 
528  // Only look for the metadata on I/IDR frame on the output. We
529  // may force an IDR frame on the output where the medadata gets
530  // changed on the input frame.
531  if ((priv->sei & SEI_MASTERING_DISPLAY) &&
532  (pic->type == FF_HW_PICTURE_TYPE_I || pic->type == FF_HW_PICTURE_TYPE_IDR)) {
533  AVFrameSideData *sd =
536 
537  if (sd) {
540 
541  // SEI is needed when both the primaries and luminance are set
542  if (mdm->has_primaries && mdm->has_luminance) {
544  &priv->sei_mastering_display;
545  const int mapping[3] = {1, 2, 0};
546  const int chroma_den = 50000;
547  const int luma_den = 10000;
548 
549  for (i = 0; i < 3; i++) {
550  const int j = mapping[i];
551  mdcv->display_primaries_x[i] =
552  FFMIN(lrint(chroma_den *
553  av_q2d(mdm->display_primaries[j][0])),
554  chroma_den);
555  mdcv->display_primaries_y[i] =
556  FFMIN(lrint(chroma_den *
557  av_q2d(mdm->display_primaries[j][1])),
558  chroma_den);
559  }
560 
561  mdcv->white_point_x =
562  FFMIN(lrint(chroma_den * av_q2d(mdm->white_point[0])),
563  chroma_den);
564  mdcv->white_point_y =
565  FFMIN(lrint(chroma_den * av_q2d(mdm->white_point[1])),
566  chroma_den);
567 
569  lrint(luma_den * av_q2d(mdm->max_luminance));
571  FFMIN(lrint(luma_den * av_q2d(mdm->min_luminance)),
573 
575  }
576  }
577  }
578 
579  if ((priv->sei & SEI_CONTENT_LIGHT_LEVEL) &&
580  (pic->type == FF_HW_PICTURE_TYPE_I || pic->type == FF_HW_PICTURE_TYPE_IDR)) {
581  AVFrameSideData *sd =
584 
585  if (sd) {
590 
591  clli->max_content_light_level = FFMIN(clm->MaxCLL, 65535);
592  clli->max_pic_average_light_level = FFMIN(clm->MaxFALL, 65535);
593 
595  }
596  }
597 
598  if (priv->sei & SEI_A53_CC) {
599  int err;
600  size_t sei_a53cc_len;
601  av_freep(&priv->sei_a53cc_data);
602  err = ff_alloc_a53_sei(pic->input_image, 0, &priv->sei_a53cc_data, &sei_a53cc_len);
603  if (err < 0)
604  return err;
605  if (priv->sei_a53cc_data != NULL) {
606  priv->sei_a53cc.itu_t_t35_country_code = 181;
607  priv->sei_a53cc.data = (uint8_t *)priv->sei_a53cc_data + 1;
608  priv->sei_a53cc.data_length = sei_a53cc_len - 1;
609 
610  priv->sei_needed |= SEI_A53_CC;
611  }
612  }
613 
614  vpic->decoded_curr_pic = (VAPictureHEVC) {
615  .picture_id = vaapi_pic->recon_surface,
616  .pic_order_cnt = hpic->pic_order_cnt,
617  .flags = 0,
618  };
619 
620  for (int k = 0; k < MAX_REFERENCE_LIST_NUM; k++) {
621  for (i = 0; i < pic->nb_refs[k]; i++) {
622  FFHWBaseEncodePicture *ref = pic->refs[k][i];
624 
625  av_assert0(ref && ref->encode_order < pic->encode_order);
626  href = ref->codec_priv;
627 
628  vpic->reference_frames[j++] = (VAPictureHEVC) {
629  .picture_id = ((VAAPIEncodePicture *)ref->priv)->recon_surface,
630  .pic_order_cnt = href->pic_order_cnt,
631  .flags = (ref->display_order < pic->display_order ?
632  VA_PICTURE_HEVC_RPS_ST_CURR_BEFORE : 0) |
633  (ref->display_order > pic->display_order ?
634  VA_PICTURE_HEVC_RPS_ST_CURR_AFTER : 0),
635  };
636  }
637  }
638 
639  for (; j < FF_ARRAY_ELEMS(vpic->reference_frames); j++) {
640  vpic->reference_frames[j] = (VAPictureHEVC) {
641  .picture_id = VA_INVALID_ID,
642  .flags = VA_PICTURE_HEVC_INVALID,
643  };
644  }
645 
646  vpic->coded_buf = vaapi_pic->output_buffer;
647 
648  vpic->nal_unit_type = hpic->slice_nal_unit;
649 
650  vpic->pic_fields.bits.reference_pic_flag = pic->is_reference;
651  switch (pic->type) {
653  vpic->pic_fields.bits.idr_pic_flag = 1;
654  vpic->pic_fields.bits.coding_type = 1;
655  break;
657  vpic->pic_fields.bits.idr_pic_flag = 0;
658  vpic->pic_fields.bits.coding_type = 1;
659  break;
661  vpic->pic_fields.bits.idr_pic_flag = 0;
662  vpic->pic_fields.bits.coding_type = 2;
663  break;
665  vpic->pic_fields.bits.idr_pic_flag = 0;
666  vpic->pic_fields.bits.coding_type = 3;
667  break;
668  default:
669  av_assert0(0 && "invalid picture type");
670  }
671 
672  return 0;
673 }
674 
677  VAAPIEncodeSlice *slice)
678 {
679  FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
680  VAAPIEncodeH265Context *priv = avctx->priv_data;
681  VAAPIEncodePicture *vaapi_pic = pic->priv;
682  VAAPIEncodeH265Picture *hpic = pic->codec_priv;
683  const H265RawSPS *sps = &priv->units.raw_sps;
684  const H265RawPPS *pps = &priv->units.raw_pps;
685  H265RawSliceHeader *sh = &priv->raw_slice.header;
686  VAEncPictureParameterBufferHEVC *vpic = vaapi_pic->codec_picture_params;
687  VAEncSliceParameterBufferHEVC *vslice = slice->codec_slice_params;
688  int i;
689 
691  .nal_unit_type = hpic->slice_nal_unit,
692  .nuh_layer_id = 0,
693  .nuh_temporal_id_plus1 = 1,
694  };
695 
696  sh->slice_pic_parameter_set_id = pps->pps_pic_parameter_set_id;
697 
698  sh->first_slice_segment_in_pic_flag = slice->index == 0;
699  sh->slice_segment_address = slice->block_start;
700 
701  sh->slice_type = hpic->slice_type;
702 
703  if (sh->slice_type == HEVC_SLICE_P && base_ctx->p_to_gpb)
704  sh->slice_type = HEVC_SLICE_B;
705 
707  (1 << (sps->log2_max_pic_order_cnt_lsb_minus4 + 4)) - 1;
708 
709  if (pic->type != FF_HW_PICTURE_TYPE_IDR) {
710  H265RawSTRefPicSet *rps;
711  const VAAPIEncodeH265Picture *strp;
712  int rps_poc[MAX_DPB_SIZE];
713  int rps_used[MAX_DPB_SIZE];
714  int i, j, poc, rps_pics;
715 
717 
718  rps = &sh->short_term_ref_pic_set;
719  memset(rps, 0, sizeof(*rps));
720 
721  rps_pics = 0;
722  for (i = 0; i < MAX_REFERENCE_LIST_NUM; i++) {
723  for (j = 0; j < pic->nb_refs[i]; j++) {
724  strp = pic->refs[i][j]->codec_priv;
725  rps_poc[rps_pics] = strp->pic_order_cnt;
726  rps_used[rps_pics] = 1;
727  ++rps_pics;
728  }
729  }
730 
731  for (i = 0; i < pic->nb_dpb_pics; i++) {
732  if (pic->dpb[i] == pic)
733  continue;
734 
735  for (j = 0; j < pic->nb_refs[0]; j++) {
736  if (pic->dpb[i] == pic->refs[0][j])
737  break;
738  }
739  if (j < pic->nb_refs[0])
740  continue;
741 
742  for (j = 0; j < pic->nb_refs[1]; j++) {
743  if (pic->dpb[i] == pic->refs[1][j])
744  break;
745  }
746  if (j < pic->nb_refs[1])
747  continue;
748 
749  strp = pic->dpb[i]->codec_priv;
750  rps_poc[rps_pics] = strp->pic_order_cnt;
751  rps_used[rps_pics] = 0;
752  ++rps_pics;
753  }
754 
755  for (i = 1; i < rps_pics; i++) {
756  for (j = i; j > 0; j--) {
757  if (rps_poc[j] > rps_poc[j - 1])
758  break;
759  av_assert0(rps_poc[j] != rps_poc[j - 1]);
760  FFSWAP(int, rps_poc[j], rps_poc[j - 1]);
761  FFSWAP(int, rps_used[j], rps_used[j - 1]);
762  }
763  }
764 
765  av_log(avctx, AV_LOG_DEBUG, "RPS for POC %d:",
766  hpic->pic_order_cnt);
767  for (i = 0; i < rps_pics; i++) {
768  av_log(avctx, AV_LOG_DEBUG, " (%d,%d)",
769  rps_poc[i], rps_used[i]);
770  }
771  av_log(avctx, AV_LOG_DEBUG, "\n");
772 
773  for (i = 0; i < rps_pics; i++) {
774  av_assert0(rps_poc[i] != hpic->pic_order_cnt);
775  if (rps_poc[i] > hpic->pic_order_cnt)
776  break;
777  }
778 
779  rps->num_negative_pics = i;
780  poc = hpic->pic_order_cnt;
781  for (j = i - 1; j >= 0; j--) {
782  rps->delta_poc_s0_minus1[i - 1 - j] = poc - rps_poc[j] - 1;
783  rps->used_by_curr_pic_s0_flag[i - 1 - j] = rps_used[j];
784  poc = rps_poc[j];
785  }
786 
787  rps->num_positive_pics = rps_pics - i;
788  poc = hpic->pic_order_cnt;
789  for (j = i; j < rps_pics; j++) {
790  rps->delta_poc_s1_minus1[j - i] = rps_poc[j] - poc - 1;
791  rps->used_by_curr_pic_s1_flag[j - i] = rps_used[j];
792  poc = rps_poc[j];
793  }
794 
795  sh->num_long_term_sps = 0;
796  sh->num_long_term_pics = 0;
797 
798  // when this flag is not present, it is inerred to 1.
799  sh->collocated_from_l0_flag = 1;
801  sps->sps_temporal_mvp_enabled_flag;
803  if (sh->slice_type == HEVC_SLICE_B)
804  sh->collocated_from_l0_flag = 1;
805  sh->collocated_ref_idx = 0;
806  }
807 
809  sh->num_ref_idx_l0_active_minus1 = pps->num_ref_idx_l0_default_active_minus1;
810  sh->num_ref_idx_l1_active_minus1 = pps->num_ref_idx_l1_default_active_minus1;
811  }
812 
814  sps->sample_adaptive_offset_enabled_flag;
815 
816  if (pic->type == FF_HW_PICTURE_TYPE_B)
817  sh->slice_qp_delta = priv->fixed_qp_b - (pps->init_qp_minus26 + 26);
818  else if (pic->type == FF_HW_PICTURE_TYPE_P)
819  sh->slice_qp_delta = priv->fixed_qp_p - (pps->init_qp_minus26 + 26);
820  else
821  sh->slice_qp_delta = priv->unit_opts.fixed_qp_idr - (pps->init_qp_minus26 + 26);
822 
823 
824  *vslice = (VAEncSliceParameterBufferHEVC) {
825  .slice_segment_address = sh->slice_segment_address,
826  .num_ctu_in_slice = slice->block_size,
827 
828  .slice_type = sh->slice_type,
829  .slice_pic_parameter_set_id = sh->slice_pic_parameter_set_id,
830 
831  .num_ref_idx_l0_active_minus1 = sh->num_ref_idx_l0_active_minus1,
832  .num_ref_idx_l1_active_minus1 = sh->num_ref_idx_l1_active_minus1,
833 
834  .luma_log2_weight_denom = sh->luma_log2_weight_denom,
835  .delta_chroma_log2_weight_denom = sh->delta_chroma_log2_weight_denom,
836 
837  .max_num_merge_cand = 5 - sh->five_minus_max_num_merge_cand,
838 
839  .slice_qp_delta = sh->slice_qp_delta,
840  .slice_cb_qp_offset = sh->slice_cb_qp_offset,
841  .slice_cr_qp_offset = sh->slice_cr_qp_offset,
842 
843  .slice_beta_offset_div2 = sh->slice_beta_offset_div2,
844  .slice_tc_offset_div2 = sh->slice_tc_offset_div2,
845 
846  .slice_fields.bits = {
847  .last_slice_of_pic_flag = slice->index == vaapi_pic->nb_slices - 1,
848  .dependent_slice_segment_flag = sh->dependent_slice_segment_flag,
849  .colour_plane_id = sh->colour_plane_id,
850  .slice_temporal_mvp_enabled_flag =
852  .slice_sao_luma_flag = sh->slice_sao_luma_flag,
853  .slice_sao_chroma_flag = sh->slice_sao_chroma_flag,
854  .num_ref_idx_active_override_flag =
856  .mvd_l1_zero_flag = sh->mvd_l1_zero_flag,
857  .cabac_init_flag = sh->cabac_init_flag,
858  .slice_deblocking_filter_disabled_flag =
860  .slice_loop_filter_across_slices_enabled_flag =
862  .collocated_from_l0_flag = sh->collocated_from_l0_flag,
863  },
864  };
865 
866  for (i = 0; i < FF_ARRAY_ELEMS(vslice->ref_pic_list0); i++) {
867  vslice->ref_pic_list0[i].picture_id = VA_INVALID_ID;
868  vslice->ref_pic_list0[i].flags = VA_PICTURE_HEVC_INVALID;
869  vslice->ref_pic_list1[i].picture_id = VA_INVALID_ID;
870  vslice->ref_pic_list1[i].flags = VA_PICTURE_HEVC_INVALID;
871  }
872 
873  if (pic->nb_refs[0]) {
874  // Backward reference for P- or B-frame.
876  pic->type == FF_HW_PICTURE_TYPE_B);
877  vslice->ref_pic_list0[0] = vpic->reference_frames[0];
878  if (base_ctx->p_to_gpb && pic->type == FF_HW_PICTURE_TYPE_P)
879  // Reference for GPB B-frame, L0 == L1
880  vslice->ref_pic_list1[0] = vpic->reference_frames[0];
881  }
882  if (pic->nb_refs[1]) {
883  // Forward reference for B-frame.
885  vslice->ref_pic_list1[0] = vpic->reference_frames[1];
886  }
887 
888  if (pic->type == FF_HW_PICTURE_TYPE_P && base_ctx->p_to_gpb) {
889  vslice->slice_type = HEVC_SLICE_B;
890  for (i = 0; i < FF_ARRAY_ELEMS(vslice->ref_pic_list0); i++) {
891  vslice->ref_pic_list1[i].picture_id = vslice->ref_pic_list0[i].picture_id;
892  vslice->ref_pic_list1[i].flags = vslice->ref_pic_list0[i].flags;
893  }
894  }
895 
896  return 0;
897 }
898 
900 {
901  FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
902  VAAPIEncodeH265Context *priv = avctx->priv_data;
903 
904 #if VA_CHECK_VERSION(1, 13, 0)
905  {
906  VAAPIEncodeContext *ctx = avctx->priv_data;
907  VAConfigAttribValEncHEVCBlockSizes block_size;
908  VAConfigAttrib attr;
909  VAStatus vas;
910 
911  attr.type = VAConfigAttribEncHEVCFeatures;
912  vas = vaGetConfigAttributes(ctx->hwctx->display, ctx->va_profile,
913  ctx->va_entrypoint, &attr, 1);
914  if (vas != VA_STATUS_SUCCESS) {
915  av_log(avctx, AV_LOG_ERROR, "Failed to query encoder "
916  "features, using guessed defaults.\n");
917  return AVERROR_EXTERNAL;
918  } else if (attr.value == VA_ATTRIB_NOT_SUPPORTED) {
919  av_log(avctx, AV_LOG_WARNING, "Driver does not advertise "
920  "encoder features, using guessed defaults.\n");
921  } else {
922  priv->va_features = attr.value;
923  }
924 
925  attr.type = VAConfigAttribEncHEVCBlockSizes;
926  vas = vaGetConfigAttributes(ctx->hwctx->display, ctx->va_profile,
927  ctx->va_entrypoint, &attr, 1);
928  if (vas != VA_STATUS_SUCCESS) {
929  av_log(avctx, AV_LOG_ERROR, "Failed to query encoder "
930  "block size, using guessed defaults.\n");
931  return AVERROR_EXTERNAL;
932  } else if (attr.value == VA_ATTRIB_NOT_SUPPORTED) {
933  av_log(avctx, AV_LOG_WARNING, "Driver does not advertise "
934  "encoder block size, using guessed defaults.\n");
935  } else {
936  priv->va_bs = block_size.value = attr.value;
937 
938  priv->ctu_size =
939  1 << block_size.bits.log2_max_coding_tree_block_size_minus3 + 3;
940  priv->min_cb_size =
941  1 << block_size.bits.log2_min_luma_coding_block_size_minus3 + 3;
942  }
943  }
944 #endif
945 
946  if (!priv->ctu_size) {
947  priv->ctu_size = 32;
948  priv->min_cb_size = 16;
949  }
950  av_log(avctx, AV_LOG_VERBOSE, "Using CTU size %dx%d, "
951  "min CB size %dx%d.\n", priv->ctu_size, priv->ctu_size,
952  priv->min_cb_size, priv->min_cb_size);
953 
954  base_ctx->surface_width = FFALIGN(avctx->width, priv->min_cb_size);
955  base_ctx->surface_height = FFALIGN(avctx->height, priv->min_cb_size);
956 
957  base_ctx->slice_block_width = base_ctx->slice_block_height = priv->ctu_size;
958 
959  return 0;
960 }
961 
963 {
964  VAAPIEncodeContext *ctx = avctx->priv_data;
965  VAAPIEncodeH265Context *priv = avctx->priv_data;
966  int err;
967 
968  err = ff_cbs_init(&priv->cbc, AV_CODEC_ID_HEVC, avctx);
969  if (err < 0)
970  return err;
971 
972  if (ctx->va_rc_mode == VA_RC_CQP) {
973  // Note that VAAPI only supports positive QP values - the range is
974  // therefore always bounded below by 1, even in 10-bit mode where
975  // it should go down to -12.
976 
977  priv->fixed_qp_p = av_clip(ctx->rc_quality, 1, 51);
978  if (avctx->i_quant_factor > 0.0)
979  priv->unit_opts.fixed_qp_idr =
980  av_clip((avctx->i_quant_factor * priv->fixed_qp_p +
981  avctx->i_quant_offset) + 0.5, 1, 51);
982  else
983  priv->unit_opts.fixed_qp_idr = priv->fixed_qp_p;
984  if (avctx->b_quant_factor > 0.0)
985  priv->fixed_qp_b =
986  av_clip((avctx->b_quant_factor * priv->fixed_qp_p +
987  avctx->b_quant_offset) + 0.5, 1, 51);
988  else
989  priv->fixed_qp_b = priv->fixed_qp_p;
990 
991  av_log(avctx, AV_LOG_DEBUG, "Using fixed QP = "
992  "%d / %d / %d for IDR- / P- / B-frames.\n",
993  priv->unit_opts.fixed_qp_idr, priv->fixed_qp_p, priv->fixed_qp_b);
994 
995  } else {
996  // These still need to be set for init_qp/slice_qp_delta.
997  priv->unit_opts.fixed_qp_idr = 30;
998  priv->fixed_qp_p = 30;
999  priv->fixed_qp_b = 30;
1000  }
1001 
1002  ctx->roi_quant_range = 51 + 6 * (ctx->profile->depth - 8);
1003 
1004  return 0;
1005 }
1006 
1008  { AV_PROFILE_HEVC_MAIN, 8, 3, 1, 1, VAProfileHEVCMain },
1009  { AV_PROFILE_HEVC_REXT, 8, 3, 1, 1, VAProfileHEVCMain },
1010 #if VA_CHECK_VERSION(0, 37, 0)
1011  { AV_PROFILE_HEVC_MAIN_10, 10, 3, 1, 1, VAProfileHEVCMain10 },
1012  { AV_PROFILE_HEVC_REXT, 10, 3, 1, 1, VAProfileHEVCMain10 },
1013 #endif
1014 #if VA_CHECK_VERSION(1, 2, 0)
1015  { AV_PROFILE_HEVC_REXT, 12, 3, 1, 1, VAProfileHEVCMain12 },
1016  { AV_PROFILE_HEVC_REXT, 8, 3, 1, 0, VAProfileHEVCMain422_10 },
1017  { AV_PROFILE_HEVC_REXT, 10, 3, 1, 0, VAProfileHEVCMain422_10 },
1018  { AV_PROFILE_HEVC_REXT, 12, 3, 1, 0, VAProfileHEVCMain422_12 },
1019  { AV_PROFILE_HEVC_REXT, 8, 3, 0, 0, VAProfileHEVCMain444 },
1020  { AV_PROFILE_HEVC_REXT, 10, 3, 0, 0, VAProfileHEVCMain444_10 },
1021  { AV_PROFILE_HEVC_REXT, 12, 3, 0, 0, VAProfileHEVCMain444_12 },
1022 #endif
1023  { AV_PROFILE_UNKNOWN }
1024 };
1025 
1028 
1029  .flags = FF_HW_FLAG_SLICE_CONTROL |
1033 
1034  .default_quality = 25,
1035 
1036  .get_encoder_caps = &vaapi_encode_h265_get_encoder_caps,
1037  .configure = &vaapi_encode_h265_configure,
1038 
1039  .picture_priv_data_size = sizeof(VAAPIEncodeH265Picture),
1040 
1041  .sequence_params_size = sizeof(VAEncSequenceParameterBufferHEVC),
1042  .init_sequence_params = &vaapi_encode_h265_init_sequence_params,
1043 
1044  .picture_params_size = sizeof(VAEncPictureParameterBufferHEVC),
1045  .init_picture_params = &vaapi_encode_h265_init_picture_params,
1046 
1047  .slice_params_size = sizeof(VAEncSliceParameterBufferHEVC),
1048  .init_slice_params = &vaapi_encode_h265_init_slice_params,
1049 
1050  .sequence_header_type = VAEncPackedHeaderSequence,
1051  .write_sequence_header = &vaapi_encode_h265_write_sequence_header,
1052 
1053  .slice_header_type = VAEncPackedHeaderHEVC_Slice,
1054  .write_slice_header = &vaapi_encode_h265_write_slice_header,
1055 
1056  .write_extra_header = &vaapi_encode_h265_write_extra_header,
1057 };
1058 
1060 {
1061  VAAPIEncodeContext *ctx = avctx->priv_data;
1062  VAAPIEncodeH265Context *priv = avctx->priv_data;
1063 
1064  ctx->codec = &vaapi_encode_type_h265;
1065 
1066  if (avctx->profile == AV_PROFILE_UNKNOWN)
1067  avctx->profile = priv->profile;
1068  if (avctx->level == AV_LEVEL_UNKNOWN)
1069  avctx->level = priv->level;
1070 
1071  if (avctx->level != AV_LEVEL_UNKNOWN && avctx->level & ~0xff) {
1072  av_log(avctx, AV_LOG_ERROR, "Invalid level %d: must fit "
1073  "in 8-bit unsigned integer.\n", avctx->level);
1074  return AVERROR(EINVAL);
1075  }
1076 
1077  ctx->desired_packed_headers =
1078  VA_ENC_PACKED_HEADER_SEQUENCE | // VPS, SPS and PPS.
1079  VA_ENC_PACKED_HEADER_SLICE | // Slice headers.
1080  VA_ENC_PACKED_HEADER_MISC; // SEI
1081 
1082  if (priv->qp > 0)
1083  ctx->explicit_qp = priv->qp;
1084 
1085  return ff_vaapi_encode_init(avctx);
1086 }
1087 
1089 {
1090  VAAPIEncodeH265Context *priv = avctx->priv_data;
1091 
1093  ff_cbs_close(&priv->cbc);
1094  av_freep(&priv->sei_a53cc_data);
1095 
1096  return ff_vaapi_encode_close(avctx);
1097 }
1098 
1099 #define OFFSET(x) offsetof(VAAPIEncodeH265Context, x)
1100 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
1105 
1106  { "qp", "Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)",
1107  OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 52, FLAGS },
1108 
1109  { "aud", "Include AUD",
1110  OFFSET(aud), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
1111 
1112  { "profile", "Set profile (general_profile_idc)",
1114  { .i64 = AV_PROFILE_UNKNOWN }, AV_PROFILE_UNKNOWN, 0xff, FLAGS, .unit = "profile" },
1115 
1116 #define PROFILE(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
1117  { .i64 = value }, 0, 0, FLAGS, .unit = "profile"
1118  { PROFILE("main", AV_PROFILE_HEVC_MAIN) },
1119  { PROFILE("main10", AV_PROFILE_HEVC_MAIN_10) },
1120  { PROFILE("rext", AV_PROFILE_HEVC_REXT) },
1121 #undef PROFILE
1122 
1123  { "tier", "Set tier (general_tier_flag)",
1124  OFFSET(unit_opts.tier), AV_OPT_TYPE_INT,
1125  { .i64 = 0 }, 0, 1, FLAGS, .unit = "tier" },
1126  { "main", NULL, 0, AV_OPT_TYPE_CONST,
1127  { .i64 = 0 }, 0, 0, FLAGS, .unit = "tier" },
1128  { "high", NULL, 0, AV_OPT_TYPE_CONST,
1129  { .i64 = 1 }, 0, 0, FLAGS, .unit = "tier" },
1130 
1131  { "level", "Set level (general_level_idc)",
1133  { .i64 = AV_LEVEL_UNKNOWN }, AV_LEVEL_UNKNOWN, 0xff, FLAGS, .unit = "level" },
1134 
1135 #define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
1136  { .i64 = value }, 0, 0, FLAGS, .unit = "level"
1137  { LEVEL("1", 30) },
1138  { LEVEL("2", 60) },
1139  { LEVEL("2.1", 63) },
1140  { LEVEL("3", 90) },
1141  { LEVEL("3.1", 93) },
1142  { LEVEL("4", 120) },
1143  { LEVEL("4.1", 123) },
1144  { LEVEL("5", 150) },
1145  { LEVEL("5.1", 153) },
1146  { LEVEL("5.2", 156) },
1147  { LEVEL("6", 180) },
1148  { LEVEL("6.1", 183) },
1149  { LEVEL("6.2", 186) },
1150 #undef LEVEL
1151 
1152  { "sei", "Set SEI to include",
1155  0, INT_MAX, FLAGS, .unit = "sei" },
1156  { "hdr",
1157  "Include HDR metadata for mastering display colour volume "
1158  "and content light level information",
1159  0, AV_OPT_TYPE_CONST,
1161  INT_MIN, INT_MAX, FLAGS, .unit = "sei" },
1162  { "a53_cc",
1163  "Include A/53 caption data",
1164  0, AV_OPT_TYPE_CONST,
1165  { .i64 = SEI_A53_CC },
1166  INT_MIN, INT_MAX, FLAGS, .unit = "sei" },
1167 
1168  { "tiles", "Tile columns x rows",
1169  OFFSET(common.tile_cols), AV_OPT_TYPE_IMAGE_SIZE,
1170  { .str = NULL }, 0, 0, FLAGS },
1171 
1172  { NULL },
1173 };
1174 
1176  { "b", "0" },
1177  { "bf", "2" },
1178  { "g", "120" },
1179  { "i_qfactor", "1" },
1180  { "i_qoffset", "0" },
1181  { "b_qfactor", "6/5" },
1182  { "b_qoffset", "0" },
1183  { "qmin", "-1" },
1184  { "qmax", "-1" },
1185  { NULL },
1186 };
1187 
1189  .class_name = "h265_vaapi",
1190  .item_name = av_default_item_name,
1191  .option = vaapi_encode_h265_options,
1192  .version = LIBAVUTIL_VERSION_INT,
1193 };
1194 
1196  .p.name = "hevc_vaapi",
1197  CODEC_LONG_NAME("H.265/HEVC (VAAPI)"),
1198  .p.type = AVMEDIA_TYPE_VIDEO,
1199  .p.id = AV_CODEC_ID_HEVC,
1200  .priv_data_size = sizeof(VAAPIEncodeH265Context),
1203  .close = &vaapi_encode_h265_close,
1204  .p.priv_class = &vaapi_encode_h265_class,
1205  .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE |
1207  .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE |
1209  .defaults = vaapi_encode_h265_defaults,
1210  .p.pix_fmts = (const enum AVPixelFormat[]) {
1213  },
1214  .color_ranges = AVCOL_RANGE_MPEG | AVCOL_RANGE_JPEG,
1215  .hw_configs = ff_vaapi_encode_hw_configs,
1216  .p.wrapper_name = "vaapi",
1217 };
H265RawSliceHeader::slice_sao_chroma_flag
uint8_t slice_sao_chroma_flag
Definition: cbs_h265.h:526
HEVC_NAL_AUD
@ HEVC_NAL_AUD
Definition: hevc.h:64
AVMasteringDisplayMetadata::has_primaries
int has_primaries
Flag indicating whether the display primaries (and white point) are set.
Definition: mastering_display_metadata.h:62
H265RawSliceHeader::collocated_from_l0_flag
uint8_t collocated_from_l0_flag
Definition: cbs_h265.h:539
SEIRawMasteringDisplayColourVolume::display_primaries_x
uint16_t display_primaries_x[3]
Definition: cbs_sei.h:77
ff_alloc_a53_sei
int ff_alloc_a53_sei(const AVFrame *frame, size_t prefix_len, void **data, size_t *sei_size)
Check AVFrame for A53 side data and allocate and fill SEI message with A53 info.
Definition: atsc_a53.c:26
FFHWBaseEncodePicture::b_depth
int b_depth
Definition: hw_base_encode.h:79
H265RawSliceHeader::colour_plane_id
uint8_t colour_plane_id
Definition: cbs_h265.h:507
VAAPIEncodeH265Context::va_features
uint32_t va_features
Definition: vaapi_encode_h265.c:63
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:215
VAAPIEncodeSlice::codec_slice_params
void * codec_slice_params
Definition: vaapi_encode.h:62
AVMasteringDisplayMetadata::max_luminance
AVRational max_luminance
Max luminance of mastering display (cd/m^2).
Definition: mastering_display_metadata.h:57
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
H265RawSliceHeader::first_slice_segment_in_pic_flag
uint8_t first_slice_segment_in_pic_flag
Definition: cbs_h265.h:496
H265RawSliceHeader::num_ref_idx_l0_active_minus1
uint8_t num_ref_idx_l0_active_minus1
Definition: cbs_h265.h:529
vaapi_encode_h265_init_picture_params
static int vaapi_encode_h265_init_picture_params(AVCodecContext *avctx, FFHWBaseEncodePicture *pic)
Definition: vaapi_encode_h265.c:459
level
uint8_t level
Definition: svq3.c:205
av_clip
#define av_clip
Definition: common.h:100
FF_HW_PICTURE_TYPE_IDR
@ FF_HW_PICTURE_TYPE_IDR
Definition: hw_base_encode.h:39
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:43
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame 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. Frame references ownership and permissions
opt.h
H265RawSliceHeader::num_ref_idx_active_override_flag
uint8_t num_ref_idx_active_override_flag
Definition: cbs_h265.h:528
SEIRawUserDataRegistered
Definition: cbs_sei.h:33
FF_HW_FLAG_B_PICTURE_REFERENCES
@ FF_HW_FLAG_B_PICTURE_REFERENCES
Definition: hw_base_encode.h:55
ff_ctz
#define ff_ctz
Definition: intmath.h:107
av_frame_get_side_data
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:951
FFHWBaseEncodePicture::priv
void * priv
Definition: hw_base_encode.h:63
FFHWBaseEncodePicture::codec_priv
void * codec_priv
Definition: hw_base_encode.h:65
ff_cbs_fragment_free
av_cold void ff_cbs_fragment_free(CodedBitstreamFragment *frag)
Free the units array of a fragment in addition to what ff_cbs_fragment_reset does.
Definition: cbs.c:186
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
AV_CODEC_CAP_HARDWARE
#define AV_CODEC_CAP_HARDWARE
Codec is backed by a hardware implementation.
Definition: codec.h:145
FFHWBaseEncodeH265Opts::tile_cols
int tile_cols
Definition: hw_base_encode_h265.h:39
ff_cbs_sei_add_message
int ff_cbs_sei_add_message(CodedBitstreamContext *ctx, CodedBitstreamFragment *au, int prefix, uint32_t payload_type, void *payload_data, void *payload_ref)
Add an SEI message to an access unit.
Definition: cbs_sei.c:267
AVMasteringDisplayMetadata::display_primaries
AVRational display_primaries[3][2]
CIE 1931 xy chromaticity coords of color primaries (r, g, b order).
Definition: mastering_display_metadata.h:42
AVMasteringDisplayMetadata::has_luminance
int has_luminance
Flag indicating whether the luminance (min_ and max_) have been set.
Definition: mastering_display_metadata.h:67
H265RawSliceHeader::slice_deblocking_filter_disabled_flag
uint8_t slice_deblocking_filter_disabled_flag
Definition: cbs_h265.h:569
VAAPIEncodeH265Context::raw_aud
H265RawAUD raw_aud
Definition: vaapi_encode_h265.c:83
vaapi_encode_h265_write_extra_header
static int vaapi_encode_h265_write_extra_header(AVCodecContext *avctx, FFHWBaseEncodePicture *base, int index, int *type, char *data, size_t *data_len)
Definition: vaapi_encode_h265.c:200
FF_HW_FLAG_B_PICTURES
@ FF_HW_FLAG_B_PICTURES
Definition: hw_base_encode.h:53
ff_cbs_insert_unit_content
int ff_cbs_insert_unit_content(CodedBitstreamFragment *frag, int position, CodedBitstreamUnitType type, void *content, void *content_ref)
Insert a new unit into a fragment with the given content.
Definition: cbs.c:783
int64_t
long long int64_t
Definition: coverity.c:34
H265RawSlice::header
H265RawSliceHeader header
Definition: cbs_h265.h:584
VAAPIEncodeH265Context::cbc
CodedBitstreamContext * cbc
Definition: vaapi_encode_h265.c:91
FFHWBaseEncodeH265::raw_vps
H265RawVPS raw_vps
Definition: hw_base_encode_h265.h:26
AV_PROFILE_HEVC_MAIN
#define AV_PROFILE_HEVC_MAIN
Definition: defs.h:159
AVContentLightMetadata::MaxCLL
unsigned MaxCLL
Max content light level (cd/m^2).
Definition: mastering_display_metadata.h:111
vaapi_encode_h265_add_nal
static int vaapi_encode_h265_add_nal(AVCodecContext *avctx, CodedBitstreamFragment *au, void *nal_unit)
Definition: vaapi_encode_h265.c:124
pixdesc.h
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:717
ff_cbs_fragment_reset
void ff_cbs_fragment_reset(CodedBitstreamFragment *frag)
Free the units contained in a fragment as well as the fragment's own data buffer, but not the units a...
Definition: cbs.c:172
H265RawSTRefPicSet::delta_poc_s1_minus1
uint16_t delta_poc_s1_minus1[HEVC_MAX_REFS]
Definition: cbs_h265.h:234
CodedBitstreamContext
Context structure for coded bitstream operations.
Definition: cbs.h:219
VAAPIEncodeSlice
Definition: vaapi_encode.h:56
AVOption
AVOption.
Definition: opt.h:429
H265RawSTRefPicSet::used_by_curr_pic_s1_flag
uint8_t used_by_curr_pic_s1_flag[HEVC_MAX_REFS]
Definition: cbs_h265.h:235
H265RawSliceHeader::slice_temporal_mvp_enabled_flag
uint8_t slice_temporal_mvp_enabled_flag
Definition: cbs_h265.h:523
data
const char data[16]
Definition: mxf.c:149
VAAPIEncodeH265Context::unit_opts
FFHWBaseEncodeH265Opts unit_opts
Definition: vaapi_encode_h265.c:82
AVCodecContext::b_quant_offset
float b_quant_offset
qscale offset between IP and B-frames
Definition: avcodec.h:817
VAAPIEncodeSlice::block_start
int block_start
Definition: vaapi_encode.h:60
FF_CODEC_CAP_NOT_INIT_THREADSAFE
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
Definition: codec_internal.h:35
FFCodec
Definition: codec_internal.h:127
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:225
base
uint8_t base
Definition: vp3data.h:128
ff_vaapi_encode_close
av_cold int ff_vaapi_encode_close(AVCodecContext *avctx)
Definition: vaapi_encode.c:2275
cbs.h
FFHWBaseEncodeContext::slice_block_width
int slice_block_width
Definition: hw_base_encode.h:144
cbs_h265.h
VAAPIEncodeSlice::index
int index
Definition: vaapi_encode.h:57
HEVC_NAL_IDR_W_RADL
@ HEVC_NAL_IDR_W_RADL
Definition: hevc.h:48
H265RawSliceHeader::num_long_term_sps
uint8_t num_long_term_sps
Definition: cbs_h265.h:515
H265RawSliceHeader::luma_log2_weight_denom
uint8_t luma_log2_weight_denom
Definition: cbs_h265.h:542
FFHWBaseEncodeContext::slice_block_height
int slice_block_height
Definition: hw_base_encode.h:145
VAAPIEncodeH265Context::profile
int profile
Definition: vaapi_encode_h265.c:72
H265RawSliceHeader::five_minus_max_num_merge_cand
uint8_t five_minus_max_num_merge_cand
Definition: cbs_h265.h:557
ff_cbs_close
av_cold void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
Definition: cbs.c:142
H265RawSPS
Definition: cbs_h265.h:245
H265RawVPS
Definition: cbs_h265.h:184
vaapi_encode_h265_close
static av_cold int vaapi_encode_h265_close(AVCodecContext *avctx)
Definition: vaapi_encode_h265.c:1088
AVContentLightMetadata
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
Definition: mastering_display_metadata.h:107
H265RawPPS
Definition: cbs_h265.h:356
FFHWBaseEncodeContext
Definition: hw_base_encode.h:122
SEIRawContentLightLevelInfo
Definition: cbs_sei.h:85
FFHWBaseEncodeH265Opts::slice_block_rows
int slice_block_rows
Definition: hw_base_encode_h265.h:42
AVCodecContext::i_quant_factor
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:826
FFCodecDefault
Definition: codec_internal.h:97
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
H265RawSTRefPicSet::used_by_curr_pic_s0_flag
uint8_t used_by_curr_pic_s0_flag[HEVC_MAX_REFS]
Definition: cbs_h265.h:233
FFHWBaseEncodePicture::type
int type
Definition: hw_base_encode.h:78
H265RawSliceHeader::num_long_term_pics
uint8_t num_long_term_pics
Definition: cbs_h265.h:516
vaapi_encode.h
FFHWBaseEncodePicture::is_reference
int is_reference
Definition: hw_base_encode.h:87
fail
#define fail()
Definition: checkasm.h:188
vaapi_encode_h265_init_sequence_params
static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx)
Definition: vaapi_encode_h265.c:259
H265RawSTRefPicSet::delta_poc_s0_minus1
uint16_t delta_poc_s0_minus1[HEVC_MAX_REFS]
Definition: cbs_h265.h:232
VAAPIEncodePicture
Definition: vaapi_encode.h:65
H265RawSliceHeader::short_term_ref_pic_set
H265RawSTRefPicSet short_term_ref_pic_set
Definition: cbs_h265.h:512
FFHWBaseEncodeH265Opts::slice_block_cols
int slice_block_cols
Definition: hw_base_encode_h265.h:43
FFHWBaseEncodeH265::raw_pps
H265RawPPS raw_pps
Definition: hw_base_encode_h265.h:28
SEIRawMasteringDisplayColourVolume::max_display_mastering_luminance
uint32_t max_display_mastering_luminance
Definition: cbs_sei.h:81
vaapi_encode_h265_class
static const AVClass vaapi_encode_h265_class
Definition: vaapi_encode_h265.c:1188
ff_hw_base_encode_init_params_h265
int ff_hw_base_encode_init_params_h265(FFHWBaseEncodeContext *base_ctx, AVCodecContext *avctx, FFHWBaseEncodeH265 *common, FFHWBaseEncodeH265Opts *opts)
Definition: hw_base_encode_h265.c:26
FFHWBaseEncodeH265Opts::tile_rows
int tile_rows
Definition: hw_base_encode_h265.h:38
FFHWBaseEncodePicture::input_image
AVFrame * input_image
Definition: hw_base_encode.h:83
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
H265RawSliceHeader::mvd_l1_zero_flag
uint8_t mvd_l1_zero_flag
Definition: cbs_h265.h:537
FFHWBaseEncodePicture::prev
struct FFHWBaseEncodePicture * prev
Definition: hw_base_encode.h:101
H265RawSliceHeader::collocated_ref_idx
uint8_t collocated_ref_idx
Definition: cbs_h265.h:540
avassert.h
lrint
#define lrint
Definition: tablegen.h:53
SEIRawUserDataRegistered::itu_t_t35_country_code
uint8_t itu_t_t35_country_code
Definition: cbs_sei.h:34
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
HEVC_SLICE_B
@ HEVC_SLICE_B
Definition: hevc.h:96
H265RawSliceHeader::slice_cb_qp_offset
int8_t slice_cb_qp_offset
Definition: cbs_h265.h:561
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
H265RawSliceHeader::slice_pic_order_cnt_lsb
uint16_t slice_pic_order_cnt_lsb
Definition: cbs_h265.h:509
AV_PROFILE_UNKNOWN
#define AV_PROFILE_UNKNOWN
Definition: defs.h:65
VAAPIEncodePicture::codec_picture_params
void * codec_picture_params
Definition: vaapi_encode.h:83
CodedBitstreamFragment
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:122
AVMasteringDisplayMetadata::white_point
AVRational white_point[2]
CIE 1931 xy chromaticity coords of white point.
Definition: mastering_display_metadata.h:47
SEI_A53_CC
@ SEI_A53_CC
Definition: vaapi_encode_h265.c:46
SEIRawMasteringDisplayColourVolume::white_point_y
uint16_t white_point_y
Definition: cbs_sei.h:80
CodedBitstreamFragment::data_size
size_t data_size
The number of bytes in the bitstream.
Definition: cbs.h:135
FLAGS
#define FLAGS
Definition: vaapi_encode_h265.c:1100
H265RawSliceHeader::slice_sao_luma_flag
uint8_t slice_sao_luma_flag
Definition: cbs_h265.h:525
av_q2d
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
FFHWBaseEncodeContext::max_b_depth
int max_b_depth
Definition: hw_base_encode.h:188
AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
Definition: codec.h:159
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:230
H265RawSliceHeader::num_ref_idx_l1_active_minus1
uint8_t num_ref_idx_l1_active_minus1
Definition: cbs_h265.h:530
H265RawSTRefPicSet::num_positive_pics
uint8_t num_positive_pics
Definition: cbs_h265.h:231
H265RawSliceHeader::slice_pic_parameter_set_id
uint8_t slice_pic_parameter_set_id
Definition: cbs_h265.h:498
FF_HW_PICTURE_TYPE_B
@ FF_HW_PICTURE_TYPE_B
Definition: hw_base_encode.h:42
ctx
AVFormatContext * ctx
Definition: movenc.c:49
VAAPIEncodeH265Context::aud
int aud
Definition: vaapi_encode_h265.c:71
SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35
@ SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35
Definition: sei.h:34
hevc.h
ff_vaapi_encode_receive_packet
int ff_vaapi_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
Definition: vaapi_encode.c:2086
FFHWBaseEncodeH265Opts::row_height
int row_height[22]
Definition: hw_base_encode_h265.h:48
CodedBitstreamFragment::data_bit_padding
size_t data_bit_padding
The number of bits which should be ignored in the final byte.
Definition: cbs.h:139
h2645data.h
VAAPIEncodeType
Definition: vaapi_encode.h:265
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:296
FFHWBaseEncodeContext::b_per_p
int b_per_p
Definition: hw_base_encode.h:189
VAAPIEncodeH265Picture
Definition: vaapi_encode_h265.c:49
VAAPIEncodeContext
Definition: vaapi_encode.h:145
if
if(ret)
Definition: filter_design.txt:179
hw_base_encode_h265.h
FFHWBaseEncodePicture::dpb
struct FFHWBaseEncodePicture * dpb[MAX_DPB_SIZE]
Definition: hw_base_encode.h:93
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
SEIRawMasteringDisplayColourVolume::min_display_mastering_luminance
uint32_t min_display_mastering_luminance
Definition: cbs_sei.h:82
H265RawSliceHeader::slice_segment_address
uint16_t slice_segment_address
Definition: cbs_h265.h:501
NULL
#define NULL
Definition: coverity.c:32
VAAPIEncodeH265Context::units
FFHWBaseEncodeH265 units
Definition: vaapi_encode_h265.c:81
H265RawAUD
Definition: cbs_h265.h:487
FFHWBaseEncodeH265Opts
Definition: hw_base_encode_h265.h:33
PROFILE
#define PROFILE(name, value)
H265RawSliceHeader::slice_tc_offset_div2
int8_t slice_tc_offset_div2
Definition: cbs_h265.h:571
H265RawSliceHeader::short_term_ref_pic_set_sps_flag
uint8_t short_term_ref_pic_set_sps_flag
Definition: cbs_h265.h:511
AV_LEVEL_UNKNOWN
#define AV_LEVEL_UNKNOWN
Definition: defs.h:198
vaapi_encode_h265_write_slice_header
static int vaapi_encode_h265_write_slice_header(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice, char *data, size_t *data_len)
Definition: vaapi_encode_h265.c:174
VAAPIEncodeType::profiles
const VAAPIEncodeProfile * profiles
Definition: vaapi_encode.h:268
VAAPIEncodeH265Context::aud_needed
int aud_needed
Definition: vaapi_encode_h265.c:93
HEVC_SLICE_I
@ HEVC_SLICE_I
Definition: hevc.h:98
SEIRawMasteringDisplayColourVolume
Definition: cbs_sei.h:76
FF_CODEC_RECEIVE_PACKET_CB
#define FF_CODEC_RECEIVE_PACKET_CB(func)
Definition: codec_internal.h:326
AV_OPT_TYPE_IMAGE_SIZE
@ AV_OPT_TYPE_IMAGE_SIZE
Underlying C type is two consecutive integers.
Definition: opt.h:303
OFFSET
#define OFFSET(x)
Definition: vaapi_encode_h265.c:1099
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
AV_FRAME_DATA_MASTERING_DISPLAY_METADATA
@ AV_FRAME_DATA_MASTERING_DISPLAY_METADATA
Mastering display metadata associated with a video frame.
Definition: frame.h:120
vaapi_encode_h265_write_access_unit
static int vaapi_encode_h265_write_access_unit(AVCodecContext *avctx, char *data, size_t *data_len, CodedBitstreamFragment *au)
Definition: vaapi_encode_h265.c:98
vaapi_encode_h265_options
static const AVOption vaapi_encode_h265_options[]
Definition: vaapi_encode_h265.c:1101
vps
static int FUNC() vps(CodedBitstreamContext *ctx, RWContext *rw, H265RawVPS *current)
Definition: cbs_h265_syntax_template.c:423
H265RawSliceHeader::slice_type
uint8_t slice_type
Definition: cbs_h265.h:504
VAAPIEncodeH265Context::sei_content_light_level
SEIRawContentLightLevelInfo sei_content_light_level
Definition: vaapi_encode_h265.c:87
H265RawNALUnitHeader::nal_unit_type
uint8_t nal_unit_type
Definition: cbs_h265.h:31
sei
static int FUNC() sei(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEI *current)
Definition: cbs_h264_syntax_template.c:858
AVCodecContext::level
int level
Encoding level descriptor.
Definition: avcodec.h:1794
H265RawSliceHeader::slice_qp_delta
int8_t slice_qp_delta
Definition: cbs_h265.h:560
AV_PROFILE_HEVC_MAIN_10
#define AV_PROFILE_HEVC_MAIN_10
Definition: defs.h:160
H265RawNALUnitHeader
Definition: cbs_h265.h:30
AV_PROFILE_HEVC_REXT
#define AV_PROFILE_HEVC_REXT
Definition: defs.h:162
index
int index
Definition: gxfenc.c:90
VAAPIEncodeH265Context::va_bs
uint32_t va_bs
Definition: vaapi_encode_h265.c:65
vaapi_encode_h265_init
static av_cold int vaapi_encode_h265_init(AVCodecContext *avctx)
Definition: vaapi_encode_h265.c:1059
VAAPIEncodeH265Context::fixed_qp_b
int fixed_qp_b
Definition: vaapi_encode_h265.c:78
VAAPIEncodeH265Context::ctu_size
uint32_t ctu_size
Definition: vaapi_encode_h265.c:66
HEVC_NAL_RASL_R
@ HEVC_NAL_RASL_R
Definition: hevc.h:38
aud
static int FUNC() aud(CodedBitstreamContext *ctx, RWContext *rw, H264RawAUD *current)
Definition: cbs_h264_syntax_template.c:875
SEI_CONTENT_LIGHT_LEVEL
@ SEI_CONTENT_LIGHT_LEVEL
Definition: vaapi_encode_h265.c:45
VAAPIEncodeH265Picture::slice_type
int slice_type
Definition: vaapi_encode_h265.c:55
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
codec_internal.h
VAAPI_ENCODE_RC_OPTIONS
#define VAAPI_ENCODE_RC_OPTIONS
Definition: vaapi_encode.h:364
H265RawSliceHeader::cabac_init_flag
uint8_t cabac_init_flag
Definition: cbs_h265.h:538
HEVC_NAL_RASL_N
@ HEVC_NAL_RASL_N
Definition: hevc.h:37
FFHWBaseEncodePicture::nb_refs
int nb_refs[MAX_REFERENCE_LIST_NUM]
Definition: hw_base_encode.h:97
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
MAX_DPB_SIZE
#define MAX_DPB_SIZE
Definition: hw_base_encode.h:26
vaapi_encode_h265_get_encoder_caps
static av_cold int vaapi_encode_h265_get_encoder_caps(AVCodecContext *avctx)
Definition: vaapi_encode_h265.c:899
SEIRawUserDataRegistered::data
uint8_t * data
RefStruct reference.
Definition: cbs_sei.h:36
CodedBitstreamFragment::data
uint8_t * data
Pointer to the bitstream form of this fragment.
Definition: cbs.h:128
VAAPIEncodeH265Context::raw_slice
H265RawSlice raw_slice
Definition: vaapi_encode_h265.c:84
FFHWBaseEncodeH265
Definition: hw_base_encode_h265.h:25
AVFrameSideData::data
uint8_t * data
Definition: frame.h:267
h265_profile_level.h
H265RawSliceHeader::dependent_slice_segment_flag
uint8_t dependent_slice_segment_flag
Definition: cbs_h265.h:500
H265RawSliceHeader::slice_cr_qp_offset
int8_t slice_cr_qp_offset
Definition: cbs_h265.h:562
FFHWBaseEncodeContext::p_to_gpb
int p_to_gpb
Definition: hw_base_encode.h:194
header
static const uint8_t header[24]
Definition: sdr2.c:68
H265RawAUD::nal_unit_header
H265RawNALUnitHeader nal_unit_header
Definition: cbs_h265.h:488
FFHWBaseEncodePicture::encode_order
int64_t encode_order
Definition: hw_base_encode.h:70
vaapi_encode_type_h265
static const VAAPIEncodeType vaapi_encode_type_h265
Definition: vaapi_encode_h265.c:1026
FF_HW_FLAG_SLICE_CONTROL
@ FF_HW_FLAG_SLICE_CONTROL
Definition: hw_base_encode.h:47
vaapi_encode_h265_init_slice_params
static int vaapi_encode_h265_init_slice_params(AVCodecContext *avctx, FFHWBaseEncodePicture *pic, VAAPIEncodeSlice *slice)
Definition: vaapi_encode_h265.c:675
vaapi_encode_h265_profiles
static const VAAPIEncodeProfile vaapi_encode_h265_profiles[]
Definition: vaapi_encode_h265.c:1007
VAAPI_ENCODE_COMMON_OPTIONS
#define VAAPI_ENCODE_COMMON_OPTIONS
Definition: vaapi_encode.h:350
SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME
@ SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME
Definition: sei.h:96
VAAPIEncodePicture::recon_surface
VASurfaceID recon_surface
Definition: vaapi_encode.h:74
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:59
VAAPIEncodePicture::output_buffer
VABufferID output_buffer
Definition: vaapi_encode.h:81
FFHWBaseEncodeH265Opts::cu_qp_delta_enabled_flag
int cu_qp_delta_enabled_flag
Definition: hw_base_encode_h265.h:36
vaapi_encode_h265_configure
static av_cold int vaapi_encode_h265_configure(AVCodecContext *avctx)
Definition: vaapi_encode_h265.c:962
SEIRawUserDataRegistered::data_length
size_t data_length
Definition: cbs_sei.h:37
ff_hevc_vaapi_encoder
const FFCodec ff_hevc_vaapi_encoder
Definition: vaapi_encode_h265.c:1195
AV_PIX_FMT_VAAPI
@ AV_PIX_FMT_VAAPI
Hardware acceleration through VA-API, data[3] contains a VASurfaceID.
Definition: pixfmt.h:126
AVCodecContext::b_quant_factor
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:810
H265RawSliceHeader
Definition: cbs_h265.h:493
VAAPIEncodeH265Context::sei_a53cc_data
void * sei_a53cc_data
Definition: vaapi_encode_h265.c:89
AV_FRAME_DATA_CONTENT_LIGHT_LEVEL
@ AV_FRAME_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
Definition: frame.h:137
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
VAAPIEncodeH265Picture::slice_nal_unit
int slice_nal_unit
Definition: vaapi_encode_h265.c:54
FF_HW_PICTURE_TYPE_P
@ FF_HW_PICTURE_TYPE_P
Definition: hw_base_encode.h:41
SEIRawMasteringDisplayColourVolume::white_point_x
uint16_t white_point_x
Definition: cbs_sei.h:79
FFHWBaseEncodeH265Opts::nb_slices
int nb_slices
Definition: hw_base_encode_h265.h:41
VAAPIEncodeH265Context
Definition: vaapi_encode_h265.c:59
common.h
MAX_REFERENCE_LIST_NUM
#define MAX_REFERENCE_LIST_NUM
Definition: hw_base_encode.h:30
AV_CODEC_ID_HEVC
@ AV_CODEC_ID_HEVC
Definition: codec_id.h:228
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
H265RawSliceHeader::nal_unit_header
H265RawNALUnitHeader nal_unit_header
Definition: cbs_h265.h:494
FFHWBaseEncodePicture::refs
struct FFHWBaseEncodePicture * refs[MAX_REFERENCE_LIST_NUM][MAX_PICTURE_REFERENCES]
Definition: hw_base_encode.h:98
H265RawSliceHeader::slice_beta_offset_div2
int8_t slice_beta_offset_div2
Definition: cbs_h265.h:570
H265RawSTRefPicSet
Definition: cbs_h265.h:220
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
AVMasteringDisplayMetadata
Mastering display metadata capable of representing the color volume of the display used to master the...
Definition: mastering_display_metadata.h:38
profile
int profile
Definition: mxfenc.c:2233
VAAPIEncodeH265Context::sei_mastering_display
SEIRawMasteringDisplayColourVolume sei_mastering_display
Definition: vaapi_encode_h265.c:86
AVCodecContext::height
int height
Definition: avcodec.h:624
SEIRawMasteringDisplayColourVolume::display_primaries_y
uint16_t display_primaries_y[3]
Definition: cbs_sei.h:78
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:700
ff_cbs_write_fragment_data
int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Write the content of the fragment to its own internal buffer.
Definition: cbs.c:409
avcodec.h
ff_vaapi_encode_hw_configs
const AVCodecHWConfigInternal *const ff_vaapi_encode_hw_configs[]
Definition: vaapi_encode.c:36
ff_vaapi_encode_init
av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
Definition: vaapi_encode.c:2091
FFHWBaseEncodeContext::gop_size
int gop_size
Definition: hw_base_encode.h:184
FFHWBaseEncodePicture
Definition: hw_base_encode.h:61
FFSWAP
#define FFSWAP(type, a, b)
Definition: macros.h:52
AVClass::class_name
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:80
VAAPIEncodeH265Context::common
VAAPIEncodeContext common
Definition: vaapi_encode_h265.c:60
atsc_a53.h
SEIRawContentLightLevelInfo::max_content_light_level
uint16_t max_content_light_level
Definition: cbs_sei.h:86
sps
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
Definition: cbs_h264_syntax_template.c:260
VAAPIEncodeH265Context::fixed_qp_p
int fixed_qp_p
Definition: vaapi_encode_h265.c:77
LEVEL
#define LEVEL(name, value)
H265RawSliceHeader::slice_loop_filter_across_slices_enabled_flag
uint8_t slice_loop_filter_across_slices_enabled_flag
Definition: cbs_h265.h:572
FFHWBaseEncodeContext::surface_height
int surface_height
Definition: hw_base_encode.h:141
AVCodecContext
main external API structure.
Definition: avcodec.h:451
H265RawSTRefPicSet::num_negative_pics
uint8_t num_negative_pics
Definition: cbs_h265.h:230
FF_HW_FLAG_NON_IDR_KEY_PICTURES
@ FF_HW_FLAG_NON_IDR_KEY_PICTURES
Definition: hw_base_encode.h:58
HEVC_NAL_CRA_NUT
@ HEVC_NAL_CRA_NUT
Definition: hevc.h:50
vaapi_encode_h265_write_sequence_header
static int vaapi_encode_h265_write_sequence_header(AVCodecContext *avctx, char *data, size_t *data_len)
Definition: vaapi_encode_h265.c:142
FF_HW_PICTURE_TYPE_I
@ FF_HW_PICTURE_TYPE_I
Definition: hw_base_encode.h:40
FFHWBaseEncodeH265Opts::fixed_qp_idr
int fixed_qp_idr
Definition: hw_base_encode_h265.h:35
FFHWBaseEncodeH265::raw_sps
H265RawSPS raw_sps
Definition: hw_base_encode_h265.h:27
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
AVCodecContext::profile
int profile
profile
Definition: avcodec.h:1650
VAAPIEncodeH265Context::qp
int qp
Definition: vaapi_encode_h265.c:70
AVCodecContext::i_quant_offset
float i_quant_offset
qscale offset between P and I-frames
Definition: avcodec.h:833
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:117
pps
uint64_t pps
Definition: dovi_rpuenc.c:35
AV_CODEC_CAP_DELAY
#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: codec.h:76
FFHWBaseEncodeH265Opts::col_width
int col_width[22]
Definition: hw_base_encode_h265.h:46
AVMasteringDisplayMetadata::min_luminance
AVRational min_luminance
Min luminance of mastering display (cd/m^2).
Definition: mastering_display_metadata.h:52
VAAPIEncodeH265Picture::pic_type
int pic_type
Definition: vaapi_encode_h265.c:56
FFHWBaseEncodeContext::surface_width
int surface_width
Definition: hw_base_encode.h:140
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
mem.h
mastering_display_metadata.h
VAAPIEncodeSlice::block_size
int block_size
Definition: vaapi_encode.h:61
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:265
VAAPIEncodeH265Picture::last_idr_frame
int64_t last_idr_frame
Definition: vaapi_encode_h265.c:52
ff_cbs_init
av_cold 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:90
VAAPIEncodeH265Context::sei
int sei
Definition: vaapi_encode_h265.c:74
HEVC_NAL_TRAIL_R
@ HEVC_NAL_TRAIL_R
Definition: hevc.h:30
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
AVContentLightMetadata::MaxFALL
unsigned MaxFALL
Max average light level per frame (cd/m^2).
Definition: mastering_display_metadata.h:116
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:478
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:327
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
VAAPIEncodeH265Context::current_access_unit
CodedBitstreamFragment current_access_unit
Definition: vaapi_encode_h265.c:92
VAAPIEncodeH265Context::sei_a53cc
SEIRawUserDataRegistered sei_a53cc
Definition: vaapi_encode_h265.c:88
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:624
AV_OPT_TYPE_FLAGS
@ AV_OPT_TYPE_FLAGS
Underlying C type is unsigned int.
Definition: opt.h:255
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO
@ SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO
Definition: sei.h:103
HW_BASE_ENCODE_COMMON_OPTIONS
#define HW_BASE_ENCODE_COMMON_OPTIONS
Definition: hw_base_encode.h:239
VAAPIEncodeH265Context::level
int level
Definition: vaapi_encode_h265.c:73
SEI_MASTERING_DISPLAY
@ SEI_MASTERING_DISPLAY
Definition: vaapi_encode_h265.c:44
FFHWBaseEncodePicture::display_order
int64_t display_order
Definition: hw_base_encode.h:69
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
H265RawSliceHeader::delta_chroma_log2_weight_denom
int8_t delta_chroma_log2_weight_denom
Definition: cbs_h265.h:543
VAAPIEncodeH265Context::min_cb_size
uint32_t min_cb_size
Definition: vaapi_encode_h265.c:67
VAAPIEncodeProfile
Definition: vaapi_encode.h:100
FFHWBaseEncodePicture::nb_dpb_pics
int nb_dpb_pics
Definition: hw_base_encode.h:92
HEVC_NAL_TRAIL_N
@ HEVC_NAL_TRAIL_N
Definition: hevc.h:29
H265RawSlice
Definition: cbs_h265.h:583
HEVC_SLICE_P
@ HEVC_SLICE_P
Definition: hevc.h:97
VAAPIEncodePicture::nb_slices
int nb_slices
Definition: vaapi_encode.h:85
vaapi_encode_h265_defaults
static const FFCodecDefault vaapi_encode_h265_defaults[]
Definition: vaapi_encode_h265.c:1175
VAAPIEncodeH265Context::sei_needed
int sei_needed
Definition: vaapi_encode_h265.c:94
VAAPIEncodeH265Picture::pic_order_cnt
int pic_order_cnt
Definition: vaapi_encode_h265.c:50