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/pixdesc.h"
27 #include "libavutil/opt.h"
29 
30 #include "atsc_a53.h"
31 #include "avcodec.h"
32 #include "cbs.h"
33 #include "cbs_h265.h"
34 #include "codec_internal.h"
35 #include "h2645data.h"
36 #include "h265_profile_level.h"
37 #include "hevc.h"
38 #include "hevc_sei.h"
39 #include "put_bits.h"
40 #include "vaapi_encode.h"
41 
42 enum {
45  SEI_A53_CC = 0x20,
46 };
47 
48 typedef struct VAAPIEncodeH265Picture {
50 
51  int64_t last_idr_frame;
52 
55  int pic_type;
57 
58 typedef struct VAAPIEncodeH265Context {
60 
61  // Encoder features.
62  uint32_t va_features;
63  // Block size info.
64  uint32_t va_bs;
65  uint32_t ctu_size;
66  uint32_t min_cb_size;
67 
68  // User options.
69  int qp;
70  int aud;
71  int profile;
72  int tier;
73  int level;
74  int sei;
75 
76  // Derived settings.
80 
81  // Writer structures.
87 
92 
98 
99 
101  char *data, size_t *data_len,
103 {
104  VAAPIEncodeH265Context *priv = avctx->priv_data;
105  int err;
106 
107  err = ff_cbs_write_fragment_data(priv->cbc, au);
108  if (err < 0) {
109  av_log(avctx, AV_LOG_ERROR, "Failed to write packed header.\n");
110  return err;
111  }
112 
113  if (*data_len < 8 * au->data_size - au->data_bit_padding) {
114  av_log(avctx, AV_LOG_ERROR, "Access unit too large: "
115  "%zu < %zu.\n", *data_len,
116  8 * au->data_size - au->data_bit_padding);
117  return AVERROR(ENOSPC);
118  }
119 
120  memcpy(data, au->data, au->data_size);
121  *data_len = 8 * au->data_size - au->data_bit_padding;
122 
123  return 0;
124 }
125 
128  void *nal_unit)
129 {
130  H265RawNALUnitHeader *header = nal_unit;
131  int err;
132 
133  err = ff_cbs_insert_unit_content(au, -1,
134  header->nal_unit_type, nal_unit, NULL);
135  if (err < 0) {
136  av_log(avctx, AV_LOG_ERROR, "Failed to add NAL unit: "
137  "type = %d.\n", header->nal_unit_type);
138  return err;
139  }
140 
141  return 0;
142 }
143 
145  char *data, size_t *data_len)
146 {
147  VAAPIEncodeH265Context *priv = avctx->priv_data;
149  int err;
150 
151  if (priv->aud_needed) {
152  err = vaapi_encode_h265_add_nal(avctx, au, &priv->raw_aud);
153  if (err < 0)
154  goto fail;
155  priv->aud_needed = 0;
156  }
157 
158  err = vaapi_encode_h265_add_nal(avctx, au, &priv->raw_vps);
159  if (err < 0)
160  goto fail;
161 
162  err = vaapi_encode_h265_add_nal(avctx, au, &priv->raw_sps);
163  if (err < 0)
164  goto fail;
165 
166  err = vaapi_encode_h265_add_nal(avctx, au, &priv->raw_pps);
167  if (err < 0)
168  goto fail;
169 
170  err = vaapi_encode_h265_write_access_unit(avctx, data, data_len, au);
171 fail:
173  return err;
174 }
175 
177  VAAPIEncodePicture *pic,
178  VAAPIEncodeSlice *slice,
179  char *data, size_t *data_len)
180 {
181  VAAPIEncodeH265Context *priv = avctx->priv_data;
183  int err;
184 
185  if (priv->aud_needed) {
186  err = vaapi_encode_h265_add_nal(avctx, au, &priv->raw_aud);
187  if (err < 0)
188  goto fail;
189  priv->aud_needed = 0;
190  }
191 
192  err = vaapi_encode_h265_add_nal(avctx, au, &priv->raw_slice);
193  if (err < 0)
194  goto fail;
195 
196  err = vaapi_encode_h265_write_access_unit(avctx, data, data_len, au);
197 fail:
199  return err;
200 }
201 
203  VAAPIEncodePicture *pic,
204  int index, int *type,
205  char *data, size_t *data_len)
206 {
207  VAAPIEncodeH265Context *priv = avctx->priv_data;
209  int err;
210 
211  if (priv->sei_needed) {
212  if (priv->aud_needed) {
213  err = vaapi_encode_h265_add_nal(avctx, au, &priv->aud);
214  if (err < 0)
215  goto fail;
216  priv->aud_needed = 0;
217  }
218 
219  if (priv->sei_needed & SEI_MASTERING_DISPLAY) {
220  err = ff_cbs_sei_add_message(priv->cbc, au, 1,
222  &priv->sei_mastering_display, NULL);
223  if (err < 0)
224  goto fail;
225  }
226 
227  if (priv->sei_needed & SEI_CONTENT_LIGHT_LEVEL) {
228  err = ff_cbs_sei_add_message(priv->cbc, au, 1,
230  &priv->sei_content_light_level, NULL);
231  if (err < 0)
232  goto fail;
233  }
234  if (priv->sei_needed & SEI_A53_CC) {
235  err = ff_cbs_sei_add_message(priv->cbc, au, 1,
237  &priv->sei_a53cc, NULL);
238  if (err < 0)
239  goto fail;
240  }
241 
242  priv->sei_needed = 0;
243 
244  err = vaapi_encode_h265_write_access_unit(avctx, data, data_len, au);
245  if (err < 0)
246  goto fail;
247 
249 
250  *type = VAEncPackedHeaderRawData;
251  return 0;
252  } else {
253  return AVERROR_EOF;
254  }
255 
256 fail:
258  return err;
259 }
260 
262 {
263  VAAPIEncodeContext *ctx = avctx->priv_data;
264  VAAPIEncodeH265Context *priv = avctx->priv_data;
265  H265RawVPS *vps = &priv->raw_vps;
266  H265RawSPS *sps = &priv->raw_sps;
267  H265RawPPS *pps = &priv->raw_pps;
268  H265RawProfileTierLevel *ptl = &vps->profile_tier_level;
269  H265RawVUI *vui = &sps->vui;
270  VAEncSequenceParameterBufferHEVC *vseq = ctx->codec_sequence_params;
271  VAEncPictureParameterBufferHEVC *vpic = ctx->codec_picture_params;
272  const AVPixFmtDescriptor *desc;
273  int chroma_format, bit_depth;
274  int i;
275 
276  memset(vps, 0, sizeof(*vps));
277  memset(sps, 0, sizeof(*sps));
278  memset(pps, 0, sizeof(*pps));
279 
280 
282  av_assert0(desc);
283  if (desc->nb_components == 1) {
284  chroma_format = 0;
285  } else {
286  if (desc->log2_chroma_w == 1 && desc->log2_chroma_h == 1) {
287  chroma_format = 1;
288  } else if (desc->log2_chroma_w == 1 && desc->log2_chroma_h == 0) {
289  chroma_format = 2;
290  } else if (desc->log2_chroma_w == 0 && desc->log2_chroma_h == 0) {
291  chroma_format = 3;
292  } else {
293  av_log(avctx, AV_LOG_ERROR, "Chroma format of input pixel format "
294  "%s is not supported.\n", desc->name);
295  return AVERROR(EINVAL);
296  }
297  }
298  bit_depth = desc->comp[0].depth;
299 
300 
301  // VPS
302 
303  vps->nal_unit_header = (H265RawNALUnitHeader) {
304  .nal_unit_type = HEVC_NAL_VPS,
305  .nuh_layer_id = 0,
306  .nuh_temporal_id_plus1 = 1,
307  };
308 
309  vps->vps_video_parameter_set_id = 0;
310 
311  vps->vps_base_layer_internal_flag = 1;
312  vps->vps_base_layer_available_flag = 1;
313  vps->vps_max_layers_minus1 = 0;
314  vps->vps_max_sub_layers_minus1 = 0;
315  vps->vps_temporal_id_nesting_flag = 1;
316 
318  ptl->general_profile_idc = avctx->profile;
319  ptl->general_tier_flag = priv->tier;
320 
322 
328  }
329 
334 
339 
340  ptl->general_max_422chroma_constraint_flag = chroma_format <= 2;
341  ptl->general_max_420chroma_constraint_flag = chroma_format <= 1;
342  ptl->general_max_monochrome_constraint_flag = chroma_format == 0;
343 
344  ptl->general_intra_constraint_flag = ctx->gop_size == 1;
346 
348 
349  if (avctx->level != AV_LEVEL_UNKNOWN) {
350  ptl->general_level_idc = avctx->level;
351  } else {
352  const H265LevelDescriptor *level;
353 
355  ctx->surface_width, ctx->surface_height,
356  ctx->nb_slices, ctx->tile_rows, ctx->tile_cols,
357  (ctx->b_per_p > 0) + 1);
358  if (level) {
359  av_log(avctx, AV_LOG_VERBOSE, "Using level %s.\n", level->name);
360  ptl->general_level_idc = level->level_idc;
361  } else {
362  av_log(avctx, AV_LOG_VERBOSE, "Stream will not conform to "
363  "any normal level; using level 8.5.\n");
364  ptl->general_level_idc = 255;
365  // The tier flag must be set in level 8.5.
366  ptl->general_tier_flag = 1;
367  }
368  }
369 
370  vps->vps_sub_layer_ordering_info_present_flag = 0;
371  vps->vps_max_dec_pic_buffering_minus1[0] = ctx->max_b_depth + 1;
372  vps->vps_max_num_reorder_pics[0] = ctx->max_b_depth;
373  vps->vps_max_latency_increase_plus1[0] = 0;
374 
375  vps->vps_max_layer_id = 0;
376  vps->vps_num_layer_sets_minus1 = 0;
377  vps->layer_id_included_flag[0][0] = 1;
378 
379  vps->vps_timing_info_present_flag = 1;
380  if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
381  vps->vps_num_units_in_tick = avctx->framerate.den;
382  vps->vps_time_scale = avctx->framerate.num;
383  vps->vps_poc_proportional_to_timing_flag = 1;
384  vps->vps_num_ticks_poc_diff_one_minus1 = 0;
385  } else {
386  vps->vps_num_units_in_tick = avctx->time_base.num;
387  vps->vps_time_scale = avctx->time_base.den;
388  vps->vps_poc_proportional_to_timing_flag = 0;
389  }
390  vps->vps_num_hrd_parameters = 0;
391 
392 
393  // SPS
394 
395  sps->nal_unit_header = (H265RawNALUnitHeader) {
396  .nal_unit_type = HEVC_NAL_SPS,
397  .nuh_layer_id = 0,
398  .nuh_temporal_id_plus1 = 1,
399  };
400 
401  sps->sps_video_parameter_set_id = vps->vps_video_parameter_set_id;
402 
403  sps->sps_max_sub_layers_minus1 = vps->vps_max_sub_layers_minus1;
404  sps->sps_temporal_id_nesting_flag = vps->vps_temporal_id_nesting_flag;
405 
406  sps->profile_tier_level = vps->profile_tier_level;
407 
408  sps->sps_seq_parameter_set_id = 0;
409 
410  sps->chroma_format_idc = chroma_format;
411  sps->separate_colour_plane_flag = 0;
412 
413  sps->pic_width_in_luma_samples = ctx->surface_width;
414  sps->pic_height_in_luma_samples = ctx->surface_height;
415 
416  if (avctx->width != ctx->surface_width ||
417  avctx->height != ctx->surface_height) {
418  sps->conformance_window_flag = 1;
419  sps->conf_win_left_offset = 0;
420  sps->conf_win_right_offset =
421  (ctx->surface_width - avctx->width) >> desc->log2_chroma_w;
422  sps->conf_win_top_offset = 0;
423  sps->conf_win_bottom_offset =
424  (ctx->surface_height - avctx->height) >> desc->log2_chroma_h;
425  } else {
426  sps->conformance_window_flag = 0;
427  }
428 
429  sps->bit_depth_luma_minus8 = bit_depth - 8;
430  sps->bit_depth_chroma_minus8 = bit_depth - 8;
431 
432  sps->log2_max_pic_order_cnt_lsb_minus4 = 8;
433 
434  sps->sps_sub_layer_ordering_info_present_flag =
435  vps->vps_sub_layer_ordering_info_present_flag;
436  for (i = 0; i <= sps->sps_max_sub_layers_minus1; i++) {
437  sps->sps_max_dec_pic_buffering_minus1[i] =
438  vps->vps_max_dec_pic_buffering_minus1[i];
439  sps->sps_max_num_reorder_pics[i] =
440  vps->vps_max_num_reorder_pics[i];
441  sps->sps_max_latency_increase_plus1[i] =
442  vps->vps_max_latency_increase_plus1[i];
443  }
444 
445  // These values come from the capabilities of the first encoder
446  // implementation in the i965 driver on Intel Skylake. They may
447  // fail badly with other platforms or drivers.
448  // CTB size from 8x8 to 32x32.
449  sps->log2_min_luma_coding_block_size_minus3 = 0;
450  sps->log2_diff_max_min_luma_coding_block_size = 2;
451  // Transform size from 4x4 to 32x32.
452  sps->log2_min_luma_transform_block_size_minus2 = 0;
453  sps->log2_diff_max_min_luma_transform_block_size = 3;
454  // Full transform hierarchy allowed (2-5).
455  sps->max_transform_hierarchy_depth_inter = 3;
456  sps->max_transform_hierarchy_depth_intra = 3;
457  // AMP works.
458  sps->amp_enabled_flag = 1;
459  // SAO and temporal MVP do not work.
460  sps->sample_adaptive_offset_enabled_flag = 0;
461  sps->sps_temporal_mvp_enabled_flag = 0;
462 
463  sps->pcm_enabled_flag = 0;
464 
465 // update sps setting according to queried result
466 #if VA_CHECK_VERSION(1, 13, 0)
467  if (priv->va_features) {
468  VAConfigAttribValEncHEVCFeatures features = { .value = priv->va_features };
469 
470  // Enable feature if get queried result is VA_FEATURE_SUPPORTED | VA_FEATURE_REQUIRED
471  sps->amp_enabled_flag =
472  !!features.bits.amp;
473  sps->sample_adaptive_offset_enabled_flag =
474  !!features.bits.sao;
475  sps->sps_temporal_mvp_enabled_flag =
476  !!features.bits.temporal_mvp;
477  sps->pcm_enabled_flag =
478  !!features.bits.pcm;
479  }
480 
481  if (priv->va_bs) {
482  VAConfigAttribValEncHEVCBlockSizes bs = { .value = priv->va_bs };
483  sps->log2_min_luma_coding_block_size_minus3 =
484  ff_ctz(priv->min_cb_size) - 3;
485  sps->log2_diff_max_min_luma_coding_block_size =
486  ff_ctz(priv->ctu_size) - ff_ctz(priv->min_cb_size);
487 
488  sps->log2_min_luma_transform_block_size_minus2 =
489  bs.bits.log2_min_luma_transform_block_size_minus2;
490  sps->log2_diff_max_min_luma_transform_block_size =
491  bs.bits.log2_max_luma_transform_block_size_minus2 -
492  bs.bits.log2_min_luma_transform_block_size_minus2;
493 
494  sps->max_transform_hierarchy_depth_inter =
495  bs.bits.max_max_transform_hierarchy_depth_inter;
496  sps->max_transform_hierarchy_depth_intra =
497  bs.bits.max_max_transform_hierarchy_depth_intra;
498  }
499 #endif
500 
501  // STRPSs should ideally be here rather than defined individually in
502  // each slice, but the structure isn't completely fixed so for now
503  // don't bother.
504  sps->num_short_term_ref_pic_sets = 0;
505  sps->long_term_ref_pics_present_flag = 0;
506 
507  sps->vui_parameters_present_flag = 1;
508 
509  if (avctx->sample_aspect_ratio.num != 0 &&
510  avctx->sample_aspect_ratio.den != 0) {
511  int num, den, i;
512  av_reduce(&num, &den, avctx->sample_aspect_ratio.num,
513  avctx->sample_aspect_ratio.den, 65535);
514  for (i = 0; i < FF_ARRAY_ELEMS(ff_h2645_pixel_aspect); i++) {
515  if (num == ff_h2645_pixel_aspect[i].num &&
516  den == ff_h2645_pixel_aspect[i].den) {
517  vui->aspect_ratio_idc = i;
518  break;
519  }
520  }
522  vui->aspect_ratio_idc = 255;
523  vui->sar_width = num;
524  vui->sar_height = den;
525  }
527  }
528 
529  // Unspecified video format, from table E-2.
530  vui->video_format = 5;
531  vui->video_full_range_flag =
532  avctx->color_range == AVCOL_RANGE_JPEG;
533  vui->colour_primaries = avctx->color_primaries;
534  vui->transfer_characteristics = avctx->color_trc;
535  vui->matrix_coefficients = avctx->colorspace;
536  if (avctx->color_primaries != AVCOL_PRI_UNSPECIFIED ||
537  avctx->color_trc != AVCOL_TRC_UNSPECIFIED ||
540  if (avctx->color_range != AVCOL_RANGE_UNSPECIFIED ||
543 
548  avctx->chroma_sample_location - 1;
549  }
550 
552  vui->vui_num_units_in_tick = vps->vps_num_units_in_tick;
553  vui->vui_time_scale = vps->vps_time_scale;
554  vui->vui_poc_proportional_to_timing_flag = vps->vps_poc_proportional_to_timing_flag;
555  vui->vui_num_ticks_poc_diff_one_minus1 = vps->vps_num_ticks_poc_diff_one_minus1;
557 
561  vui->max_bytes_per_pic_denom = 0;
562  vui->max_bits_per_min_cu_denom = 0;
564  vui->log2_max_mv_length_vertical = 15;
565 
566 
567  // PPS
568 
569  pps->nal_unit_header = (H265RawNALUnitHeader) {
570  .nal_unit_type = HEVC_NAL_PPS,
571  .nuh_layer_id = 0,
572  .nuh_temporal_id_plus1 = 1,
573  };
574 
575  pps->pps_pic_parameter_set_id = 0;
576  pps->pps_seq_parameter_set_id = sps->sps_seq_parameter_set_id;
577 
578  pps->num_ref_idx_l0_default_active_minus1 = 0;
579  pps->num_ref_idx_l1_default_active_minus1 = 0;
580 
581  pps->init_qp_minus26 = priv->fixed_qp_idr - 26;
582 
583  pps->cu_qp_delta_enabled_flag = (ctx->va_rc_mode != VA_RC_CQP);
584  pps->diff_cu_qp_delta_depth = 0;
585 
586 // update pps setting according to queried result
587 #if VA_CHECK_VERSION(1, 13, 0)
588  if (priv->va_features) {
589  VAConfigAttribValEncHEVCFeatures features = { .value = priv->va_features };
590  if (ctx->va_rc_mode != VA_RC_CQP)
591  pps->cu_qp_delta_enabled_flag =
592  !!features.bits.cu_qp_delta;
593 
594  pps->transform_skip_enabled_flag =
595  !!features.bits.transform_skip;
596  // set diff_cu_qp_delta_depth as its max value if cu_qp_delta enabled. Otherwise
597  // 0 will make cu_qp_delta invalid.
598  if (pps->cu_qp_delta_enabled_flag)
599  pps->diff_cu_qp_delta_depth = sps->log2_diff_max_min_luma_coding_block_size;
600  }
601 #endif
602 
603  if (ctx->tile_rows && ctx->tile_cols) {
604  int uniform_spacing;
605 
606  pps->tiles_enabled_flag = 1;
607  pps->num_tile_columns_minus1 = ctx->tile_cols - 1;
608  pps->num_tile_rows_minus1 = ctx->tile_rows - 1;
609 
610  // Test whether the spacing provided matches the H.265 uniform
611  // spacing, and set the flag if it does.
612  uniform_spacing = 1;
613  for (i = 0; i <= pps->num_tile_columns_minus1 &&
614  uniform_spacing; i++) {
615  if (ctx->col_width[i] !=
616  (i + 1) * ctx->slice_block_cols / ctx->tile_cols -
617  i * ctx->slice_block_cols / ctx->tile_cols)
618  uniform_spacing = 0;
619  }
620  for (i = 0; i <= pps->num_tile_rows_minus1 &&
621  uniform_spacing; i++) {
622  if (ctx->row_height[i] !=
623  (i + 1) * ctx->slice_block_rows / ctx->tile_rows -
624  i * ctx->slice_block_rows / ctx->tile_rows)
625  uniform_spacing = 0;
626  }
627  pps->uniform_spacing_flag = uniform_spacing;
628 
629  for (i = 0; i <= pps->num_tile_columns_minus1; i++)
630  pps->column_width_minus1[i] = ctx->col_width[i] - 1;
631  for (i = 0; i <= pps->num_tile_rows_minus1; i++)
632  pps->row_height_minus1[i] = ctx->row_height[i] - 1;
633 
634  pps->loop_filter_across_tiles_enabled_flag = 1;
635  }
636 
637  pps->pps_loop_filter_across_slices_enabled_flag = 1;
638 
639  // Fill VAAPI parameter buffers.
640 
641  *vseq = (VAEncSequenceParameterBufferHEVC) {
642  .general_profile_idc = vps->profile_tier_level.general_profile_idc,
643  .general_level_idc = vps->profile_tier_level.general_level_idc,
644  .general_tier_flag = vps->profile_tier_level.general_tier_flag,
645 
646  .intra_period = ctx->gop_size,
647  .intra_idr_period = ctx->gop_size,
648  .ip_period = ctx->b_per_p + 1,
649  .bits_per_second = ctx->va_bit_rate,
650 
651  .pic_width_in_luma_samples = sps->pic_width_in_luma_samples,
652  .pic_height_in_luma_samples = sps->pic_height_in_luma_samples,
653 
654  .seq_fields.bits = {
655  .chroma_format_idc = sps->chroma_format_idc,
656  .separate_colour_plane_flag = sps->separate_colour_plane_flag,
657  .bit_depth_luma_minus8 = sps->bit_depth_luma_minus8,
658  .bit_depth_chroma_minus8 = sps->bit_depth_chroma_minus8,
659  .scaling_list_enabled_flag = sps->scaling_list_enabled_flag,
660  .strong_intra_smoothing_enabled_flag =
661  sps->strong_intra_smoothing_enabled_flag,
662  .amp_enabled_flag = sps->amp_enabled_flag,
663  .sample_adaptive_offset_enabled_flag =
664  sps->sample_adaptive_offset_enabled_flag,
665  .pcm_enabled_flag = sps->pcm_enabled_flag,
666  .pcm_loop_filter_disabled_flag = sps->pcm_loop_filter_disabled_flag,
667  .sps_temporal_mvp_enabled_flag = sps->sps_temporal_mvp_enabled_flag,
668  },
669 
670  .log2_min_luma_coding_block_size_minus3 =
671  sps->log2_min_luma_coding_block_size_minus3,
672  .log2_diff_max_min_luma_coding_block_size =
673  sps->log2_diff_max_min_luma_coding_block_size,
674  .log2_min_transform_block_size_minus2 =
675  sps->log2_min_luma_transform_block_size_minus2,
676  .log2_diff_max_min_transform_block_size =
677  sps->log2_diff_max_min_luma_transform_block_size,
678  .max_transform_hierarchy_depth_inter =
679  sps->max_transform_hierarchy_depth_inter,
680  .max_transform_hierarchy_depth_intra =
681  sps->max_transform_hierarchy_depth_intra,
682 
683  .pcm_sample_bit_depth_luma_minus1 =
684  sps->pcm_sample_bit_depth_luma_minus1,
685  .pcm_sample_bit_depth_chroma_minus1 =
686  sps->pcm_sample_bit_depth_chroma_minus1,
687  .log2_min_pcm_luma_coding_block_size_minus3 =
688  sps->log2_min_pcm_luma_coding_block_size_minus3,
689  .log2_max_pcm_luma_coding_block_size_minus3 =
690  sps->log2_min_pcm_luma_coding_block_size_minus3 +
691  sps->log2_diff_max_min_pcm_luma_coding_block_size,
692 
693  .vui_parameters_present_flag = 0,
694  };
695 
696  *vpic = (VAEncPictureParameterBufferHEVC) {
697  .decoded_curr_pic = {
698  .picture_id = VA_INVALID_ID,
699  .flags = VA_PICTURE_HEVC_INVALID,
700  },
701 
702  .coded_buf = VA_INVALID_ID,
703 
704  .collocated_ref_pic_index = sps->sps_temporal_mvp_enabled_flag ?
705  0 : 0xff,
706  .last_picture = 0,
707 
708  .pic_init_qp = pps->init_qp_minus26 + 26,
709  .diff_cu_qp_delta_depth = pps->diff_cu_qp_delta_depth,
710  .pps_cb_qp_offset = pps->pps_cb_qp_offset,
711  .pps_cr_qp_offset = pps->pps_cr_qp_offset,
712 
713  .num_tile_columns_minus1 = pps->num_tile_columns_minus1,
714  .num_tile_rows_minus1 = pps->num_tile_rows_minus1,
715 
716  .log2_parallel_merge_level_minus2 = pps->log2_parallel_merge_level_minus2,
717  .ctu_max_bitsize_allowed = 0,
718 
719  .num_ref_idx_l0_default_active_minus1 =
720  pps->num_ref_idx_l0_default_active_minus1,
721  .num_ref_idx_l1_default_active_minus1 =
722  pps->num_ref_idx_l1_default_active_minus1,
723 
724  .slice_pic_parameter_set_id = pps->pps_pic_parameter_set_id,
725 
726  .pic_fields.bits = {
727  .sign_data_hiding_enabled_flag = pps->sign_data_hiding_enabled_flag,
728  .constrained_intra_pred_flag = pps->constrained_intra_pred_flag,
729  .transform_skip_enabled_flag = pps->transform_skip_enabled_flag,
730  .cu_qp_delta_enabled_flag = pps->cu_qp_delta_enabled_flag,
731  .weighted_pred_flag = pps->weighted_pred_flag,
732  .weighted_bipred_flag = pps->weighted_bipred_flag,
733  .transquant_bypass_enabled_flag = pps->transquant_bypass_enabled_flag,
734  .tiles_enabled_flag = pps->tiles_enabled_flag,
735  .entropy_coding_sync_enabled_flag = pps->entropy_coding_sync_enabled_flag,
736  .loop_filter_across_tiles_enabled_flag =
737  pps->loop_filter_across_tiles_enabled_flag,
738  .pps_loop_filter_across_slices_enabled_flag =
739  pps->pps_loop_filter_across_slices_enabled_flag,
740  .scaling_list_data_present_flag = (sps->sps_scaling_list_data_present_flag |
741  pps->pps_scaling_list_data_present_flag),
742  .screen_content_flag = 0,
743  .enable_gpu_weighted_prediction = 0,
744  .no_output_of_prior_pics_flag = 0,
745  },
746  };
747 
748  if (pps->tiles_enabled_flag) {
749  for (i = 0; i <= vpic->num_tile_rows_minus1; i++)
750  vpic->row_height_minus1[i] = pps->row_height_minus1[i];
751  for (i = 0; i <= vpic->num_tile_columns_minus1; i++)
752  vpic->column_width_minus1[i] = pps->column_width_minus1[i];
753  }
754 
755  return 0;
756 }
757 
759  VAAPIEncodePicture *pic)
760 {
761  VAAPIEncodeContext *ctx = avctx->priv_data;
762  VAAPIEncodeH265Context *priv = avctx->priv_data;
763  VAAPIEncodeH265Picture *hpic = pic->priv_data;
764  VAAPIEncodePicture *prev = pic->prev;
765  VAAPIEncodeH265Picture *hprev = prev ? prev->priv_data : NULL;
766  VAEncPictureParameterBufferHEVC *vpic = pic->codec_picture_params;
767  int i, j = 0;
768 
769  if (pic->type == PICTURE_TYPE_IDR) {
770  av_assert0(pic->display_order == pic->encode_order);
771 
772  hpic->last_idr_frame = pic->display_order;
773 
775  hpic->slice_type = HEVC_SLICE_I;
776  hpic->pic_type = 0;
777  } else {
778  av_assert0(prev);
779  hpic->last_idr_frame = hprev->last_idr_frame;
780 
781  if (pic->type == PICTURE_TYPE_I) {
783  hpic->slice_type = HEVC_SLICE_I;
784  hpic->pic_type = 0;
785  } else if (pic->type == PICTURE_TYPE_P) {
786  av_assert0(pic->refs[0]);
788  hpic->slice_type = HEVC_SLICE_P;
789  hpic->pic_type = 1;
790  } else {
791  VAAPIEncodePicture *irap_ref;
792  av_assert0(pic->refs[0][0] && pic->refs[1][0]);
793  for (irap_ref = pic; irap_ref; irap_ref = irap_ref->refs[1][0]) {
794  if (irap_ref->type == PICTURE_TYPE_I)
795  break;
796  }
797  if (pic->b_depth == ctx->max_b_depth) {
798  hpic->slice_nal_unit = irap_ref ? HEVC_NAL_RASL_N
800  } else {
801  hpic->slice_nal_unit = irap_ref ? HEVC_NAL_RASL_R
803  }
804  hpic->slice_type = HEVC_SLICE_B;
805  hpic->pic_type = 2;
806  }
807  }
808  hpic->pic_order_cnt = pic->display_order - hpic->last_idr_frame;
809 
810  if (priv->aud) {
811  priv->aud_needed = 1;
812  priv->raw_aud = (H265RawAUD) {
813  .nal_unit_header = {
815  .nuh_layer_id = 0,
816  .nuh_temporal_id_plus1 = 1,
817  },
818  .pic_type = hpic->pic_type,
819  };
820  } else {
821  priv->aud_needed = 0;
822  }
823 
824  priv->sei_needed = 0;
825 
826  // Only look for the metadata on I/IDR frame on the output. We
827  // may force an IDR frame on the output where the medadata gets
828  // changed on the input frame.
829  if ((priv->sei & SEI_MASTERING_DISPLAY) &&
830  (pic->type == PICTURE_TYPE_I || pic->type == PICTURE_TYPE_IDR)) {
831  AVFrameSideData *sd =
834 
835  if (sd) {
838 
839  // SEI is needed when both the primaries and luminance are set
840  if (mdm->has_primaries && mdm->has_luminance) {
842  &priv->sei_mastering_display;
843  const int mapping[3] = {1, 2, 0};
844  const int chroma_den = 50000;
845  const int luma_den = 10000;
846 
847  for (i = 0; i < 3; i++) {
848  const int j = mapping[i];
849  mdcv->display_primaries_x[i] =
850  FFMIN(lrint(chroma_den *
851  av_q2d(mdm->display_primaries[j][0])),
852  chroma_den);
853  mdcv->display_primaries_y[i] =
854  FFMIN(lrint(chroma_den *
855  av_q2d(mdm->display_primaries[j][1])),
856  chroma_den);
857  }
858 
859  mdcv->white_point_x =
860  FFMIN(lrint(chroma_den * av_q2d(mdm->white_point[0])),
861  chroma_den);
862  mdcv->white_point_y =
863  FFMIN(lrint(chroma_den * av_q2d(mdm->white_point[1])),
864  chroma_den);
865 
867  lrint(luma_den * av_q2d(mdm->max_luminance));
869  FFMIN(lrint(luma_den * av_q2d(mdm->min_luminance)),
871 
873  }
874  }
875  }
876 
877  if ((priv->sei & SEI_CONTENT_LIGHT_LEVEL) &&
878  (pic->type == PICTURE_TYPE_I || pic->type == PICTURE_TYPE_IDR)) {
879  AVFrameSideData *sd =
882 
883  if (sd) {
888 
889  clli->max_content_light_level = FFMIN(clm->MaxCLL, 65535);
890  clli->max_pic_average_light_level = FFMIN(clm->MaxFALL, 65535);
891 
893  }
894  }
895 
896  if (priv->sei & SEI_A53_CC) {
897  int err;
898  size_t sei_a53cc_len;
899  av_freep(&priv->sei_a53cc_data);
900  err = ff_alloc_a53_sei(pic->input_image, 0, &priv->sei_a53cc_data, &sei_a53cc_len);
901  if (err < 0)
902  return err;
903  if (priv->sei_a53cc_data != NULL) {
904  priv->sei_a53cc.itu_t_t35_country_code = 181;
905  priv->sei_a53cc.data = (uint8_t *)priv->sei_a53cc_data + 1;
906  priv->sei_a53cc.data_length = sei_a53cc_len - 1;
907 
908  priv->sei_needed |= SEI_A53_CC;
909  }
910  }
911 
912  vpic->decoded_curr_pic = (VAPictureHEVC) {
913  .picture_id = pic->recon_surface,
914  .pic_order_cnt = hpic->pic_order_cnt,
915  .flags = 0,
916  };
917 
918  for (int k = 0; k < MAX_REFERENCE_LIST_NUM; k++) {
919  for (i = 0; i < pic->nb_refs[k]; i++) {
920  VAAPIEncodePicture *ref = pic->refs[k][i];
922 
923  av_assert0(ref && ref->encode_order < pic->encode_order);
924  href = ref->priv_data;
925 
926  vpic->reference_frames[j++] = (VAPictureHEVC) {
927  .picture_id = ref->recon_surface,
928  .pic_order_cnt = href->pic_order_cnt,
929  .flags = (ref->display_order < pic->display_order ?
930  VA_PICTURE_HEVC_RPS_ST_CURR_BEFORE : 0) |
931  (ref->display_order > pic->display_order ?
932  VA_PICTURE_HEVC_RPS_ST_CURR_AFTER : 0),
933  };
934  }
935  }
936 
937  for (; j < FF_ARRAY_ELEMS(vpic->reference_frames); j++) {
938  vpic->reference_frames[j] = (VAPictureHEVC) {
939  .picture_id = VA_INVALID_ID,
940  .flags = VA_PICTURE_HEVC_INVALID,
941  };
942  }
943 
944  vpic->coded_buf = pic->output_buffer;
945 
946  vpic->nal_unit_type = hpic->slice_nal_unit;
947 
948  switch (pic->type) {
949  case PICTURE_TYPE_IDR:
950  vpic->pic_fields.bits.idr_pic_flag = 1;
951  vpic->pic_fields.bits.coding_type = 1;
952  vpic->pic_fields.bits.reference_pic_flag = 1;
953  break;
954  case PICTURE_TYPE_I:
955  vpic->pic_fields.bits.idr_pic_flag = 0;
956  vpic->pic_fields.bits.coding_type = 1;
957  vpic->pic_fields.bits.reference_pic_flag = 1;
958  break;
959  case PICTURE_TYPE_P:
960  vpic->pic_fields.bits.idr_pic_flag = 0;
961  vpic->pic_fields.bits.coding_type = 2;
962  vpic->pic_fields.bits.reference_pic_flag = 1;
963  break;
964  case PICTURE_TYPE_B:
965  vpic->pic_fields.bits.idr_pic_flag = 0;
966  vpic->pic_fields.bits.coding_type = 3;
967  vpic->pic_fields.bits.reference_pic_flag = 0;
968  break;
969  default:
970  av_assert0(0 && "invalid picture type");
971  }
972 
973  return 0;
974 }
975 
977  VAAPIEncodePicture *pic,
978  VAAPIEncodeSlice *slice)
979 {
980  VAAPIEncodeContext *ctx = avctx->priv_data;
981  VAAPIEncodeH265Context *priv = avctx->priv_data;
982  VAAPIEncodeH265Picture *hpic = pic->priv_data;
983  const H265RawSPS *sps = &priv->raw_sps;
984  const H265RawPPS *pps = &priv->raw_pps;
985  H265RawSliceHeader *sh = &priv->raw_slice.header;
986  VAEncPictureParameterBufferHEVC *vpic = pic->codec_picture_params;
987  VAEncSliceParameterBufferHEVC *vslice = slice->codec_slice_params;
988  int i;
989 
991  .nal_unit_type = hpic->slice_nal_unit,
992  .nuh_layer_id = 0,
993  .nuh_temporal_id_plus1 = 1,
994  };
995 
996  sh->slice_pic_parameter_set_id = pps->pps_pic_parameter_set_id;
997 
998  sh->first_slice_segment_in_pic_flag = slice->index == 0;
999  sh->slice_segment_address = slice->block_start;
1000 
1001  sh->slice_type = hpic->slice_type;
1002 
1003  if (sh->slice_type == HEVC_SLICE_P && ctx->p_to_gpb)
1004  sh->slice_type = HEVC_SLICE_B;
1005 
1007  (1 << (sps->log2_max_pic_order_cnt_lsb_minus4 + 4)) - 1;
1008 
1009  if (pic->type != PICTURE_TYPE_IDR) {
1010  H265RawSTRefPicSet *rps;
1011  const VAAPIEncodeH265Picture *strp;
1012  int rps_poc[MAX_DPB_SIZE];
1013  int rps_used[MAX_DPB_SIZE];
1014  int i, j, poc, rps_pics;
1015 
1017 
1018  rps = &sh->short_term_ref_pic_set;
1019  memset(rps, 0, sizeof(*rps));
1020 
1021  rps_pics = 0;
1022  for (i = 0; i < MAX_REFERENCE_LIST_NUM; i++) {
1023  for (j = 0; j < pic->nb_refs[i]; j++) {
1024  strp = pic->refs[i][j]->priv_data;
1025  rps_poc[rps_pics] = strp->pic_order_cnt;
1026  rps_used[rps_pics] = 1;
1027  ++rps_pics;
1028  }
1029  }
1030 
1031  for (i = 0; i < pic->nb_dpb_pics; i++) {
1032  if (pic->dpb[i] == pic)
1033  continue;
1034 
1035  for (j = 0; j < pic->nb_refs[0]; j++) {
1036  if (pic->dpb[i] == pic->refs[0][j])
1037  break;
1038  }
1039  if (j < pic->nb_refs[0])
1040  continue;
1041 
1042  for (j = 0; j < pic->nb_refs[1]; j++) {
1043  if (pic->dpb[i] == pic->refs[1][j])
1044  break;
1045  }
1046  if (j < pic->nb_refs[1])
1047  continue;
1048 
1049  strp = pic->dpb[i]->priv_data;
1050  rps_poc[rps_pics] = strp->pic_order_cnt;
1051  rps_used[rps_pics] = 0;
1052  ++rps_pics;
1053  }
1054 
1055  for (i = 1; i < rps_pics; i++) {
1056  for (j = i; j > 0; j--) {
1057  if (rps_poc[j] > rps_poc[j - 1])
1058  break;
1059  av_assert0(rps_poc[j] != rps_poc[j - 1]);
1060  FFSWAP(int, rps_poc[j], rps_poc[j - 1]);
1061  FFSWAP(int, rps_used[j], rps_used[j - 1]);
1062  }
1063  }
1064 
1065  av_log(avctx, AV_LOG_DEBUG, "RPS for POC %d:",
1066  hpic->pic_order_cnt);
1067  for (i = 0; i < rps_pics; i++) {
1068  av_log(avctx, AV_LOG_DEBUG, " (%d,%d)",
1069  rps_poc[i], rps_used[i]);
1070  }
1071  av_log(avctx, AV_LOG_DEBUG, "\n");
1072 
1073  for (i = 0; i < rps_pics; i++) {
1074  av_assert0(rps_poc[i] != hpic->pic_order_cnt);
1075  if (rps_poc[i] > hpic->pic_order_cnt)
1076  break;
1077  }
1078 
1079  rps->num_negative_pics = i;
1080  poc = hpic->pic_order_cnt;
1081  for (j = i - 1; j >= 0; j--) {
1082  rps->delta_poc_s0_minus1[i - 1 - j] = poc - rps_poc[j] - 1;
1083  rps->used_by_curr_pic_s0_flag[i - 1 - j] = rps_used[j];
1084  poc = rps_poc[j];
1085  }
1086 
1087  rps->num_positive_pics = rps_pics - i;
1088  poc = hpic->pic_order_cnt;
1089  for (j = i; j < rps_pics; j++) {
1090  rps->delta_poc_s1_minus1[j - i] = rps_poc[j] - poc - 1;
1091  rps->used_by_curr_pic_s1_flag[j - i] = rps_used[j];
1092  poc = rps_poc[j];
1093  }
1094 
1095  sh->num_long_term_sps = 0;
1096  sh->num_long_term_pics = 0;
1097 
1098  // when this flag is not present, it is inerred to 1.
1099  sh->collocated_from_l0_flag = 1;
1101  sps->sps_temporal_mvp_enabled_flag;
1103  if (sh->slice_type == HEVC_SLICE_B)
1104  sh->collocated_from_l0_flag = 1;
1105  sh->collocated_ref_idx = 0;
1106  }
1107 
1109  sh->num_ref_idx_l0_active_minus1 = pps->num_ref_idx_l0_default_active_minus1;
1110  sh->num_ref_idx_l1_active_minus1 = pps->num_ref_idx_l1_default_active_minus1;
1111  }
1112 
1114  sps->sample_adaptive_offset_enabled_flag;
1115 
1116  if (pic->type == PICTURE_TYPE_B)
1117  sh->slice_qp_delta = priv->fixed_qp_b - (pps->init_qp_minus26 + 26);
1118  else if (pic->type == PICTURE_TYPE_P)
1119  sh->slice_qp_delta = priv->fixed_qp_p - (pps->init_qp_minus26 + 26);
1120  else
1121  sh->slice_qp_delta = priv->fixed_qp_idr - (pps->init_qp_minus26 + 26);
1122 
1123 
1124  *vslice = (VAEncSliceParameterBufferHEVC) {
1125  .slice_segment_address = sh->slice_segment_address,
1126  .num_ctu_in_slice = slice->block_size,
1127 
1128  .slice_type = sh->slice_type,
1129  .slice_pic_parameter_set_id = sh->slice_pic_parameter_set_id,
1130 
1131  .num_ref_idx_l0_active_minus1 = sh->num_ref_idx_l0_active_minus1,
1132  .num_ref_idx_l1_active_minus1 = sh->num_ref_idx_l1_active_minus1,
1133 
1134  .luma_log2_weight_denom = sh->luma_log2_weight_denom,
1135  .delta_chroma_log2_weight_denom = sh->delta_chroma_log2_weight_denom,
1136 
1137  .max_num_merge_cand = 5 - sh->five_minus_max_num_merge_cand,
1138 
1139  .slice_qp_delta = sh->slice_qp_delta,
1140  .slice_cb_qp_offset = sh->slice_cb_qp_offset,
1141  .slice_cr_qp_offset = sh->slice_cr_qp_offset,
1142 
1143  .slice_beta_offset_div2 = sh->slice_beta_offset_div2,
1144  .slice_tc_offset_div2 = sh->slice_tc_offset_div2,
1145 
1146  .slice_fields.bits = {
1147  .last_slice_of_pic_flag = slice->index == pic->nb_slices - 1,
1148  .dependent_slice_segment_flag = sh->dependent_slice_segment_flag,
1149  .colour_plane_id = sh->colour_plane_id,
1150  .slice_temporal_mvp_enabled_flag =
1152  .slice_sao_luma_flag = sh->slice_sao_luma_flag,
1153  .slice_sao_chroma_flag = sh->slice_sao_chroma_flag,
1154  .num_ref_idx_active_override_flag =
1156  .mvd_l1_zero_flag = sh->mvd_l1_zero_flag,
1157  .cabac_init_flag = sh->cabac_init_flag,
1158  .slice_deblocking_filter_disabled_flag =
1160  .slice_loop_filter_across_slices_enabled_flag =
1162  .collocated_from_l0_flag = sh->collocated_from_l0_flag,
1163  },
1164  };
1165 
1166  for (i = 0; i < FF_ARRAY_ELEMS(vslice->ref_pic_list0); i++) {
1167  vslice->ref_pic_list0[i].picture_id = VA_INVALID_ID;
1168  vslice->ref_pic_list0[i].flags = VA_PICTURE_HEVC_INVALID;
1169  vslice->ref_pic_list1[i].picture_id = VA_INVALID_ID;
1170  vslice->ref_pic_list1[i].flags = VA_PICTURE_HEVC_INVALID;
1171  }
1172 
1173  if (pic->nb_refs[0]) {
1174  // Backward reference for P- or B-frame.
1175  av_assert0(pic->type == PICTURE_TYPE_P ||
1176  pic->type == PICTURE_TYPE_B);
1177  vslice->ref_pic_list0[0] = vpic->reference_frames[0];
1178  if (ctx->p_to_gpb && pic->type == PICTURE_TYPE_P)
1179  // Reference for GPB B-frame, L0 == L1
1180  vslice->ref_pic_list1[0] = vpic->reference_frames[0];
1181  }
1182  if (pic->nb_refs[1]) {
1183  // Forward reference for B-frame.
1184  av_assert0(pic->type == PICTURE_TYPE_B);
1185  vslice->ref_pic_list1[0] = vpic->reference_frames[1];
1186  }
1187 
1188  if (pic->type == PICTURE_TYPE_P && ctx->p_to_gpb) {
1189  vslice->slice_type = HEVC_SLICE_B;
1190  for (i = 0; i < FF_ARRAY_ELEMS(vslice->ref_pic_list0); i++) {
1191  vslice->ref_pic_list1[i].picture_id = vslice->ref_pic_list0[i].picture_id;
1192  vslice->ref_pic_list1[i].flags = vslice->ref_pic_list0[i].flags;
1193  }
1194  }
1195 
1196  return 0;
1197 }
1198 
1200 {
1201  VAAPIEncodeContext *ctx = avctx->priv_data;
1202  VAAPIEncodeH265Context *priv = avctx->priv_data;
1203 
1204 #if VA_CHECK_VERSION(1, 13, 0)
1205  {
1206  VAConfigAttribValEncHEVCBlockSizes block_size;
1207  VAConfigAttrib attr;
1208  VAStatus vas;
1209 
1210  attr.type = VAConfigAttribEncHEVCFeatures;
1211  vas = vaGetConfigAttributes(ctx->hwctx->display, ctx->va_profile,
1212  ctx->va_entrypoint, &attr, 1);
1213  if (vas != VA_STATUS_SUCCESS) {
1214  av_log(avctx, AV_LOG_ERROR, "Failed to query encoder "
1215  "features, using guessed defaults.\n");
1216  return AVERROR_EXTERNAL;
1217  } else if (attr.value == VA_ATTRIB_NOT_SUPPORTED) {
1218  av_log(avctx, AV_LOG_WARNING, "Driver does not advertise "
1219  "encoder features, using guessed defaults.\n");
1220  } else {
1221  priv->va_features = attr.value;
1222  }
1223 
1224  attr.type = VAConfigAttribEncHEVCBlockSizes;
1225  vas = vaGetConfigAttributes(ctx->hwctx->display, ctx->va_profile,
1226  ctx->va_entrypoint, &attr, 1);
1227  if (vas != VA_STATUS_SUCCESS) {
1228  av_log(avctx, AV_LOG_ERROR, "Failed to query encoder "
1229  "block size, using guessed defaults.\n");
1230  return AVERROR_EXTERNAL;
1231  } else if (attr.value == VA_ATTRIB_NOT_SUPPORTED) {
1232  av_log(avctx, AV_LOG_WARNING, "Driver does not advertise "
1233  "encoder block size, using guessed defaults.\n");
1234  } else {
1235  priv->va_bs = block_size.value = attr.value;
1236 
1237  priv->ctu_size =
1238  1 << block_size.bits.log2_max_coding_tree_block_size_minus3 + 3;
1239  priv->min_cb_size =
1240  1 << block_size.bits.log2_min_luma_coding_block_size_minus3 + 3;
1241  }
1242  }
1243 #endif
1244 
1245  if (!priv->ctu_size) {
1246  priv->ctu_size = 32;
1247  priv->min_cb_size = 16;
1248  }
1249  av_log(avctx, AV_LOG_VERBOSE, "Using CTU size %dx%d, "
1250  "min CB size %dx%d.\n", priv->ctu_size, priv->ctu_size,
1251  priv->min_cb_size, priv->min_cb_size);
1252 
1253  ctx->surface_width = FFALIGN(avctx->width, priv->min_cb_size);
1254  ctx->surface_height = FFALIGN(avctx->height, priv->min_cb_size);
1255 
1256  ctx->slice_block_width = ctx->slice_block_height = priv->ctu_size;
1257 
1258  return 0;
1259 }
1260 
1262 {
1263  VAAPIEncodeContext *ctx = avctx->priv_data;
1264  VAAPIEncodeH265Context *priv = avctx->priv_data;
1265  int err;
1266 
1267  err = ff_cbs_init(&priv->cbc, AV_CODEC_ID_HEVC, avctx);
1268  if (err < 0)
1269  return err;
1270 
1271  if (ctx->va_rc_mode == VA_RC_CQP) {
1272  // Note that VAAPI only supports positive QP values - the range is
1273  // therefore always bounded below by 1, even in 10-bit mode where
1274  // it should go down to -12.
1275 
1276  priv->fixed_qp_p = av_clip(ctx->rc_quality, 1, 51);
1277  if (avctx->i_quant_factor > 0.0)
1278  priv->fixed_qp_idr =
1279  av_clip((avctx->i_quant_factor * priv->fixed_qp_p +
1280  avctx->i_quant_offset) + 0.5, 1, 51);
1281  else
1282  priv->fixed_qp_idr = priv->fixed_qp_p;
1283  if (avctx->b_quant_factor > 0.0)
1284  priv->fixed_qp_b =
1285  av_clip((avctx->b_quant_factor * priv->fixed_qp_p +
1286  avctx->b_quant_offset) + 0.5, 1, 51);
1287  else
1288  priv->fixed_qp_b = priv->fixed_qp_p;
1289 
1290  av_log(avctx, AV_LOG_DEBUG, "Using fixed QP = "
1291  "%d / %d / %d for IDR- / P- / B-frames.\n",
1292  priv->fixed_qp_idr, priv->fixed_qp_p, priv->fixed_qp_b);
1293 
1294  } else {
1295  // These still need to be set for init_qp/slice_qp_delta.
1296  priv->fixed_qp_idr = 30;
1297  priv->fixed_qp_p = 30;
1298  priv->fixed_qp_b = 30;
1299  }
1300 
1301  ctx->roi_quant_range = 51 + 6 * (ctx->profile->depth - 8);
1302 
1303  return 0;
1304 }
1305 
1307  { AV_PROFILE_HEVC_MAIN, 8, 3, 1, 1, VAProfileHEVCMain },
1308  { AV_PROFILE_HEVC_REXT, 8, 3, 1, 1, VAProfileHEVCMain },
1309 #if VA_CHECK_VERSION(0, 37, 0)
1310  { AV_PROFILE_HEVC_MAIN_10, 10, 3, 1, 1, VAProfileHEVCMain10 },
1311  { AV_PROFILE_HEVC_REXT, 10, 3, 1, 1, VAProfileHEVCMain10 },
1312 #endif
1313 #if VA_CHECK_VERSION(1, 2, 0)
1314  { AV_PROFILE_HEVC_REXT, 12, 3, 1, 1, VAProfileHEVCMain12 },
1315  { AV_PROFILE_HEVC_REXT, 8, 3, 1, 0, VAProfileHEVCMain422_10 },
1316  { AV_PROFILE_HEVC_REXT, 10, 3, 1, 0, VAProfileHEVCMain422_10 },
1317  { AV_PROFILE_HEVC_REXT, 12, 3, 1, 0, VAProfileHEVCMain422_12 },
1318  { AV_PROFILE_HEVC_REXT, 8, 3, 0, 0, VAProfileHEVCMain444 },
1319  { AV_PROFILE_HEVC_REXT, 10, 3, 0, 0, VAProfileHEVCMain444_10 },
1320  { AV_PROFILE_HEVC_REXT, 12, 3, 0, 0, VAProfileHEVCMain444_12 },
1321 #endif
1322  { AV_PROFILE_UNKNOWN }
1323 };
1324 
1327 
1328  .flags = FLAG_SLICE_CONTROL |
1329  FLAG_B_PICTURES |
1332 
1333  .default_quality = 25,
1334 
1335  .get_encoder_caps = &vaapi_encode_h265_get_encoder_caps,
1336  .configure = &vaapi_encode_h265_configure,
1337 
1338  .picture_priv_data_size = sizeof(VAAPIEncodeH265Picture),
1339 
1340  .sequence_params_size = sizeof(VAEncSequenceParameterBufferHEVC),
1341  .init_sequence_params = &vaapi_encode_h265_init_sequence_params,
1342 
1343  .picture_params_size = sizeof(VAEncPictureParameterBufferHEVC),
1344  .init_picture_params = &vaapi_encode_h265_init_picture_params,
1345 
1346  .slice_params_size = sizeof(VAEncSliceParameterBufferHEVC),
1347  .init_slice_params = &vaapi_encode_h265_init_slice_params,
1348 
1349  .sequence_header_type = VAEncPackedHeaderSequence,
1350  .write_sequence_header = &vaapi_encode_h265_write_sequence_header,
1351 
1352  .slice_header_type = VAEncPackedHeaderHEVC_Slice,
1353  .write_slice_header = &vaapi_encode_h265_write_slice_header,
1354 
1355  .write_extra_header = &vaapi_encode_h265_write_extra_header,
1356 };
1357 
1359 {
1360  VAAPIEncodeContext *ctx = avctx->priv_data;
1361  VAAPIEncodeH265Context *priv = avctx->priv_data;
1362 
1363  ctx->codec = &vaapi_encode_type_h265;
1364 
1365  if (avctx->profile == AV_PROFILE_UNKNOWN)
1366  avctx->profile = priv->profile;
1367  if (avctx->level == AV_LEVEL_UNKNOWN)
1368  avctx->level = priv->level;
1369 
1370  if (avctx->level != AV_LEVEL_UNKNOWN && avctx->level & ~0xff) {
1371  av_log(avctx, AV_LOG_ERROR, "Invalid level %d: must fit "
1372  "in 8-bit unsigned integer.\n", avctx->level);
1373  return AVERROR(EINVAL);
1374  }
1375 
1376  ctx->desired_packed_headers =
1377  VA_ENC_PACKED_HEADER_SEQUENCE | // VPS, SPS and PPS.
1378  VA_ENC_PACKED_HEADER_SLICE | // Slice headers.
1379  VA_ENC_PACKED_HEADER_MISC; // SEI
1380 
1381  if (priv->qp > 0)
1382  ctx->explicit_qp = priv->qp;
1383 
1384  return ff_vaapi_encode_init(avctx);
1385 }
1386 
1388 {
1389  VAAPIEncodeH265Context *priv = avctx->priv_data;
1390 
1392  ff_cbs_close(&priv->cbc);
1393  av_freep(&priv->sei_a53cc_data);
1394 
1395  return ff_vaapi_encode_close(avctx);
1396 }
1397 
1398 #define OFFSET(x) offsetof(VAAPIEncodeH265Context, x)
1399 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
1403 
1404  { "qp", "Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)",
1405  OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 52, FLAGS },
1406 
1407  { "aud", "Include AUD",
1408  OFFSET(aud), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
1409 
1410  { "profile", "Set profile (general_profile_idc)",
1412  { .i64 = AV_PROFILE_UNKNOWN }, AV_PROFILE_UNKNOWN, 0xff, FLAGS, "profile" },
1413 
1414 #define PROFILE(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
1415  { .i64 = value }, 0, 0, FLAGS, "profile"
1416  { PROFILE("main", AV_PROFILE_HEVC_MAIN) },
1417  { PROFILE("main10", AV_PROFILE_HEVC_MAIN_10) },
1418  { PROFILE("rext", AV_PROFILE_HEVC_REXT) },
1419 #undef PROFILE
1420 
1421  { "tier", "Set tier (general_tier_flag)",
1423  { .i64 = 0 }, 0, 1, FLAGS, "tier" },
1424  { "main", NULL, 0, AV_OPT_TYPE_CONST,
1425  { .i64 = 0 }, 0, 0, FLAGS, "tier" },
1426  { "high", NULL, 0, AV_OPT_TYPE_CONST,
1427  { .i64 = 1 }, 0, 0, FLAGS, "tier" },
1428 
1429  { "level", "Set level (general_level_idc)",
1431  { .i64 = AV_LEVEL_UNKNOWN }, AV_LEVEL_UNKNOWN, 0xff, FLAGS, "level" },
1432 
1433 #define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
1434  { .i64 = value }, 0, 0, FLAGS, "level"
1435  { LEVEL("1", 30) },
1436  { LEVEL("2", 60) },
1437  { LEVEL("2.1", 63) },
1438  { LEVEL("3", 90) },
1439  { LEVEL("3.1", 93) },
1440  { LEVEL("4", 120) },
1441  { LEVEL("4.1", 123) },
1442  { LEVEL("5", 150) },
1443  { LEVEL("5.1", 153) },
1444  { LEVEL("5.2", 156) },
1445  { LEVEL("6", 180) },
1446  { LEVEL("6.1", 183) },
1447  { LEVEL("6.2", 186) },
1448 #undef LEVEL
1449 
1450  { "sei", "Set SEI to include",
1453  0, INT_MAX, FLAGS, "sei" },
1454  { "hdr",
1455  "Include HDR metadata for mastering display colour volume "
1456  "and content light level information",
1457  0, AV_OPT_TYPE_CONST,
1459  INT_MIN, INT_MAX, FLAGS, "sei" },
1460  { "a53_cc",
1461  "Include A/53 caption data",
1462  0, AV_OPT_TYPE_CONST,
1463  { .i64 = SEI_A53_CC },
1464  INT_MIN, INT_MAX, FLAGS, "sei" },
1465 
1466  { "tiles", "Tile columns x rows",
1467  OFFSET(common.tile_cols), AV_OPT_TYPE_IMAGE_SIZE,
1468  { .str = NULL }, 0, 0, FLAGS },
1469 
1470  { NULL },
1471 };
1472 
1474  { "b", "0" },
1475  { "bf", "2" },
1476  { "g", "120" },
1477  { "i_qfactor", "1" },
1478  { "i_qoffset", "0" },
1479  { "b_qfactor", "6/5" },
1480  { "b_qoffset", "0" },
1481  { "qmin", "-1" },
1482  { "qmax", "-1" },
1483  { NULL },
1484 };
1485 
1487  .class_name = "h265_vaapi",
1488  .item_name = av_default_item_name,
1489  .option = vaapi_encode_h265_options,
1490  .version = LIBAVUTIL_VERSION_INT,
1491 };
1492 
1494  .p.name = "hevc_vaapi",
1495  CODEC_LONG_NAME("H.265/HEVC (VAAPI)"),
1496  .p.type = AVMEDIA_TYPE_VIDEO,
1497  .p.id = AV_CODEC_ID_HEVC,
1498  .priv_data_size = sizeof(VAAPIEncodeH265Context),
1501  .close = &vaapi_encode_h265_close,
1502  .p.priv_class = &vaapi_encode_h265_class,
1503  .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE |
1505  .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE |
1507  .defaults = vaapi_encode_h265_defaults,
1508  .p.pix_fmts = (const enum AVPixelFormat[]) {
1511  },
1512  .hw_configs = ff_vaapi_encode_hw_configs,
1513  .p.wrapper_name = "vaapi",
1514 };
H265RawSliceHeader::slice_sao_chroma_flag
uint8_t slice_sao_chroma_flag
Definition: cbs_h265.h:476
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:489
H265RawVUI::log2_max_mv_length_horizontal
uint8_t log2_max_mv_length_horizontal
Definition: cbs_h265.h:173
SEIRawMasteringDisplayColourVolume::display_primaries_x
uint16_t display_primaries_x[3]
Definition: cbs_sei.h:47
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:25
H265RawSliceHeader::colour_plane_id
uint8_t colour_plane_id
Definition: cbs_h265.h:457
VAAPIEncodeH265Context::va_features
uint32_t va_features
Definition: vaapi_encode_h265.c:62
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
VAAPIEncodeSlice::codec_slice_params
void * codec_slice_params
Definition: vaapi_encode.h:70
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:64
H265RawSliceHeader::first_slice_segment_in_pic_flag
uint8_t first_slice_segment_in_pic_flag
Definition: cbs_h265.h:446
H265RawSliceHeader::num_ref_idx_l0_active_minus1
uint8_t num_ref_idx_l0_active_minus1
Definition: cbs_h265.h:479
level
uint8_t level
Definition: svq3.c:204
av_clip
#define av_clip
Definition: common.h:96
H265RawVUI::bitstream_restriction_flag
uint8_t bitstream_restriction_flag
Definition: cbs_h265.h:166
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:42
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:478
FLAG_B_PICTURE_REFERENCES
@ FLAG_B_PICTURE_REFERENCES
Definition: vaapi_encode.h:403
H265RawProfileTierLevel::general_interlaced_source_flag
uint8_t general_interlaced_source_flag
Definition: cbs_h265.h:43
AVCodecContext::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:1029
SEIRawUserDataRegistered
Definition: cbs_sei.h:33
ff_ctz
#define ff_ctz
Definition: intmath.h:107
H265RawProfileTierLevel::general_level_idc
uint8_t general_level_idc
Definition: cbs_h265.h:60
av_frame_get_side_data
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:824
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:179
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2964
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
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:268
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:519
VAAPIEncodeH265Context::raw_aud
H265RawAUD raw_aud
Definition: vaapi_encode_h265.c:82
H265RawVUI::colour_primaries
uint8_t colour_primaries
Definition: cbs_h265.h:140
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:776
H265RawSlice::header
H265RawSliceHeader header
Definition: cbs_h265.h:534
VAAPIEncodeH265Context::cbc
CodedBitstreamContext * cbc
Definition: vaapi_encode_h265.c:93
VAAPIEncodeH265Context::raw_pps
H265RawPPS raw_pps
Definition: vaapi_encode_h265.c:85
AV_PROFILE_HEVC_MAIN
#define AV_PROFILE_HEVC_MAIN
Definition: defs.h:158
AVContentLightMetadata::MaxCLL
unsigned MaxCLL
Max content light level (cd/m^2).
Definition: mastering_display_metadata.h:102
H265RawVUI
Definition: cbs_h265.h:127
vaapi_encode_h265_add_nal
static int vaapi_encode_h265_add_nal(AVCodecContext *avctx, CodedBitstreamFragment *au, void *nal_unit)
Definition: vaapi_encode_h265.c:126
pixdesc.h
VAAPIEncodeH265Context::raw_sps
H265RawSPS raw_sps
Definition: vaapi_encode_h265.c:84
AVCodecContext::color_trc
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:1022
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:673
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:165
H265RawSTRefPicSet::delta_poc_s1_minus1
uint16_t delta_poc_s1_minus1[HEVC_MAX_REFS]
Definition: cbs_h265.h:233
H265RawProfileTierLevel::general_max_8bit_constraint_flag
uint8_t general_max_8bit_constraint_flag
Definition: cbs_h265.h:49
H265RawVUI::aspect_ratio_info_present_flag
uint8_t aspect_ratio_info_present_flag
Definition: cbs_h265.h:128
CodedBitstreamContext
Context structure for coded bitstream operations.
Definition: cbs.h:219
VAAPIEncodeSlice
Definition: vaapi_encode.h:64
AVOption
AVOption.
Definition: opt.h:251
H265RawSTRefPicSet::used_by_curr_pic_s1_flag
uint8_t used_by_curr_pic_s1_flag[HEVC_MAX_REFS]
Definition: cbs_h265.h:234
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:573
H265RawSliceHeader::slice_temporal_mvp_enabled_flag
uint8_t slice_temporal_mvp_enabled_flag
Definition: cbs_h265.h:473
data
const char data[16]
Definition: mxf.c:148
AVCodecContext::b_quant_offset
float b_quant_offset
qscale offset between IP and B-frames
Definition: avcodec.h:736
VAAPIEncodeSlice::block_start
int block_start
Definition: vaapi_encode.h:68
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:34
FFCodec
Definition: codec_internal.h:127
HEVC_NAL_RASL_N
@ HEVC_NAL_RASL_N
Definition: hevc.h:37
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
H265RawVUI::vui_timing_info_present_flag
uint8_t vui_timing_info_present_flag
Definition: cbs_h265.h:158
ff_vaapi_encode_close
av_cold int ff_vaapi_encode_close(AVCodecContext *avctx)
Definition: vaapi_encode.c:2967
cbs.h
cbs_h265.h
VAAPIEncodeSlice::index
int index
Definition: vaapi_encode.h:65
PICTURE_TYPE_IDR
@ PICTURE_TYPE_IDR
Definition: vaapi_encode.h:58
VAAPIEncodeH265Context::raw_vps
H265RawVPS raw_vps
Definition: vaapi_encode_h265.c:83
H265RawProfileTierLevel::general_frame_only_constraint_flag
uint8_t general_frame_only_constraint_flag
Definition: cbs_h265.h:45
H265RawSliceHeader::num_long_term_sps
uint8_t num_long_term_sps
Definition: cbs_h265.h:465
bit_depth
static void bit_depth(AudioStatsContext *s, const uint64_t *const mask, uint8_t *depth)
Definition: af_astats.c:245
H265RawSliceHeader::luma_log2_weight_denom
uint8_t luma_log2_weight_denom
Definition: cbs_h265.h:492
H265RawVUI::log2_max_mv_length_vertical
uint8_t log2_max_mv_length_vertical
Definition: cbs_h265.h:174
VAAPIEncodeH265Context::profile
int profile
Definition: vaapi_encode_h265.c:71
H265RawSliceHeader::five_minus_max_num_merge_cand
uint8_t five_minus_max_num_merge_cand
Definition: cbs_h265.h:507
ff_cbs_close
av_cold void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
Definition: cbs.c:135
H265LevelDescriptor
Definition: h265_profile_level.h:27
H265RawProfileTierLevel::general_max_422chroma_constraint_flag
uint8_t general_max_422chroma_constraint_flag
Definition: cbs_h265.h:50
VAAPIEncodePicture::refs
struct VAAPIEncodePicture * refs[MAX_REFERENCE_LIST_NUM][MAX_PICTURE_REFERENCES]
Definition: vaapi_encode.h:124
H265RawSPS
Definition: cbs_h265.h:244
H265RawVPS
Definition: cbs_h265.h:183
vaapi_encode_h265_close
static av_cold int vaapi_encode_h265_close(AVCodecContext *avctx)
Definition: vaapi_encode_h265.c:1387
AVContentLightMetadata
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
Definition: mastering_display_metadata.h:98
H265RawPPS
Definition: cbs_h265.h:346
FLAG_NON_IDR_KEY_PICTURES
@ FLAG_NON_IDR_KEY_PICTURES
Definition: vaapi_encode.h:406
AVCodecContext::framerate
AVRational framerate
Definition: avcodec.h:1803
SEIRawContentLightLevelInfo
Definition: cbs_sei.h:55
VAAPIEncodePicture::nb_refs
int nb_refs[MAX_REFERENCE_LIST_NUM]
Definition: vaapi_encode.h:123
H265RawVUI::video_format
uint8_t video_format
Definition: cbs_h265.h:137
H265RawVUI::max_bits_per_min_cu_denom
uint8_t max_bits_per_min_cu_denom
Definition: cbs_h265.h:172
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:753
H265RawProfileTierLevel::general_progressive_source_flag
uint8_t general_progressive_source_flag
Definition: cbs_h265.h:42
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:232
H265RawSliceHeader::num_long_term_pics
uint8_t num_long_term_pics
Definition: cbs_h265.h:466
vaapi_encode.h
fail
#define fail()
Definition: checkasm.h:138
vaapi_encode_h265_init_sequence_params
static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx)
Definition: vaapi_encode_h265.c:261
FLAG_SLICE_CONTROL
@ FLAG_SLICE_CONTROL
Definition: vaapi_encode.h:395
H265RawSTRefPicSet::delta_poc_s0_minus1
uint16_t delta_poc_s0_minus1[HEVC_MAX_REFS]
Definition: cbs_h265.h:231
VAAPIEncodePicture
Definition: vaapi_encode.h:73
H265RawSliceHeader::short_term_ref_pic_set
H265RawSTRefPicSet short_term_ref_pic_set
Definition: cbs_h265.h:462
SEIRawMasteringDisplayColourVolume::max_display_mastering_luminance
uint32_t max_display_mastering_luminance
Definition: cbs_sei.h:51
vaapi_encode_h265_class
static const AVClass vaapi_encode_h265_class
Definition: vaapi_encode_h265.c:1486
H265RawProfileTierLevel::general_max_12bit_constraint_flag
uint8_t general_max_12bit_constraint_flag
Definition: cbs_h265.h:47
SEI_MASTERING_DISPLAY
@ SEI_MASTERING_DISPLAY
Definition: vaapi_encode_h265.c:43
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:487
H265RawProfileTierLevel::general_intra_constraint_flag
uint8_t general_intra_constraint_flag
Definition: cbs_h265.h:53
av_reduce
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:35
AVRational::num
int num
Numerator.
Definition: rational.h:59
VAAPIEncodeH265Context::fixed_qp_idr
int fixed_qp_idr
Definition: vaapi_encode_h265.c:77
H265RawVUI::sar_height
uint16_t sar_height
Definition: cbs_h265.h:131
H265RawSliceHeader::collocated_ref_idx
uint8_t collocated_ref_idx
Definition: cbs_h265.h:490
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
AVCodecContext::color_primaries
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:1015
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
H265RawSliceHeader::slice_cb_qp_offset
int8_t slice_cb_qp_offset
Definition: cbs_h265.h:511
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:459
AV_PROFILE_UNKNOWN
#define AV_PROFILE_UNKNOWN
Definition: defs.h:65
ptl
const H265RawProfileTierLevel * ptl
Definition: h265_levels.c:170
VAAPIEncodePicture::codec_picture_params
void * codec_picture_params
Definition: vaapi_encode.h:110
ff_h265_guess_level
const H265LevelDescriptor * ff_h265_guess_level(const H265RawProfileTierLevel *ptl, int64_t bitrate, int width, int height, int slice_segments, int tile_rows, int tile_cols, int max_dec_pic_buffering)
Guess the level of a stream from some parameters.
Definition: h265_profile_level.c:162
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
PICTURE_TYPE_P
@ PICTURE_TYPE_P
Definition: vaapi_encode.h:60
SEIRawMasteringDisplayColourVolume::white_point_y
uint16_t white_point_y
Definition: cbs_sei.h:50
CodedBitstreamFragment::data_size
size_t data_size
The number of bytes in the bitstream.
Definition: cbs.h:135
H265RawProfileTierLevel::general_profile_idc
uint8_t general_profile_idc
Definition: cbs_h265.h:38
FLAGS
#define FLAGS
Definition: vaapi_encode_h265.c:1399
H265RawProfileTierLevel::general_non_packed_constraint_flag
uint8_t general_non_packed_constraint_flag
Definition: cbs_h265.h:44
H265RawSliceHeader::slice_sao_luma_flag
uint8_t slice_sao_luma_flag
Definition: cbs_h265.h:475
av_q2d
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts_bsf.c:365
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:201
H265RawSliceHeader::num_ref_idx_l1_active_minus1
uint8_t num_ref_idx_l1_active_minus1
Definition: cbs_h265.h:480
H265RawSTRefPicSet::num_positive_pics
uint8_t num_positive_pics
Definition: cbs_h265.h:230
H265RawSliceHeader::slice_pic_parameter_set_id
uint8_t slice_pic_parameter_set_id
Definition: cbs_h265.h:448
ctx
AVFormatContext * ctx
Definition: movenc.c:48
VAAPIEncodeH265Context::aud
int aud
Definition: vaapi_encode_h265.c:70
H265RawProfileTierLevel::general_max_14bit_constraint_flag
uint8_t general_max_14bit_constraint_flag
Definition: cbs_h265.h:56
SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35
@ SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35
Definition: sei.h:34
ff_vaapi_encode_receive_packet
int ff_vaapi_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
Definition: vaapi_encode.c:1398
H265RawVUI::vui_time_scale
uint32_t vui_time_scale
Definition: cbs_h265.h:160
H265RawVUI::video_signal_type_present_flag
uint8_t video_signal_type_present_flag
Definition: cbs_h265.h:136
tier
int tier
Definition: av1_levels.c:48
HEVC_SLICE_I
@ HEVC_SLICE_I
Definition: hevc.h:98
VAAPIEncodeH265Context::tier
int tier
Definition: vaapi_encode_h265.c:72
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
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:548
VAAPIEncodeType
Definition: vaapi_encode.h:412
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
VAAPIEncodeH265Picture
Definition: vaapi_encode_h265.c:48
VAAPIEncodeContext
Definition: vaapi_encode.h:194
VAAPIEncodePicture::prev
struct VAAPIEncodePicture * prev
Definition: vaapi_encode.h:127
if
if(ret)
Definition: filter_design.txt:179
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
SEIRawMasteringDisplayColourVolume::min_display_mastering_luminance
uint32_t min_display_mastering_luminance
Definition: cbs_sei.h:52
HEVC_SLICE_B
@ HEVC_SLICE_B
Definition: hevc.h:96
H265RawVUI::matrix_coefficients
uint8_t matrix_coefficients
Definition: cbs_h265.h:142
H265RawSliceHeader::slice_segment_address
uint16_t slice_segment_address
Definition: cbs_h265.h:451
NULL
#define NULL
Definition: coverity.c:32
AVHWFramesContext::sw_format
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition: hwcontext.h:222
H265RawAUD
Definition: cbs_h265.h:437
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:1039
PROFILE
#define PROFILE(name, value)
H265RawSliceHeader::slice_tc_offset_div2
int8_t slice_tc_offset_div2
Definition: cbs_h265.h:521
HEVC_NAL_PPS
@ HEVC_NAL_PPS
Definition: hevc.h:63
H265RawSliceHeader::short_term_ref_pic_set_sps_flag
uint8_t short_term_ref_pic_set_sps_flag
Definition: cbs_h265.h:461
VAAPIEncodePicture::dpb
struct VAAPIEncodePicture * dpb[MAX_DPB_SIZE]
Definition: vaapi_encode.h:119
AV_LEVEL_UNKNOWN
#define AV_LEVEL_UNKNOWN
Definition: defs.h:196
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:176
VAAPIEncodeType::profiles
const VAAPIEncodeProfile * profiles
Definition: vaapi_encode.h:415
VAAPIEncodeH265Context::aud_needed
int aud_needed
Definition: vaapi_encode_h265.c:95
SEIRawMasteringDisplayColourVolume
Definition: cbs_sei.h:46
FF_CODEC_RECEIVE_PACKET_CB
#define FF_CODEC_RECEIVE_PACKET_CB(func)
Definition: codec_internal.h:321
AVCodecContext::bit_rate
int64_t bit_rate
the average bitrate
Definition: avcodec.h:491
AV_OPT_TYPE_IMAGE_SIZE
@ AV_OPT_TYPE_IMAGE_SIZE
offset must point to two consecutive integers
Definition: opt.h:235
OFFSET
#define OFFSET(x)
Definition: vaapi_encode_h265.c:1398
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
HEVC_NAL_CRA_NUT
@ HEVC_NAL_CRA_NUT
Definition: hevc.h:50
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:100
H265RawVUI::chroma_sample_loc_type_bottom_field
uint8_t chroma_sample_loc_type_bottom_field
Definition: cbs_h265.h:146
vaapi_encode_h265_options
static const AVOption vaapi_encode_h265_options[]
Definition: vaapi_encode_h265.c:1400
vaapi_encode_h265_init_picture_params
static int vaapi_encode_h265_init_picture_params(AVCodecContext *avctx, VAAPIEncodePicture *pic)
Definition: vaapi_encode_h265.c:758
vps
static int FUNC() vps(CodedBitstreamContext *ctx, RWContext *rw, H265RawVPS *current)
Definition: cbs_h265_syntax_template.c:423
H265RawProfileTierLevel::general_max_10bit_constraint_flag
uint8_t general_max_10bit_constraint_flag
Definition: cbs_h265.h:48
H265RawVUI::vui_num_ticks_poc_diff_one_minus1
uint32_t vui_num_ticks_poc_diff_one_minus1
Definition: cbs_h265.h:162
H265RawSliceHeader::slice_type
uint8_t slice_type
Definition: cbs_h265.h:454
VAAPIEncodeH265Context::sei_content_light_level
SEIRawContentLightLevelInfo sei_content_light_level
Definition: vaapi_encode_h265.c:89
H265RawVUI::video_full_range_flag
uint8_t video_full_range_flag
Definition: cbs_h265.h:138
H265RawProfileTierLevel::general_tier_flag
uint8_t general_tier_flag
Definition: cbs_h265.h:37
H265RawNALUnitHeader::nal_unit_type
uint8_t nal_unit_type
Definition: cbs_h265.h:30
sei
static int FUNC() sei(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEI *current)
Definition: cbs_h264_syntax_template.c:824
AVCodecContext::level
int level
Encoding level descriptor.
Definition: avcodec.h:1740
H265RawSliceHeader::slice_qp_delta
int8_t slice_qp_delta
Definition: cbs_h265.h:510
AV_PROFILE_HEVC_MAIN_10
#define AV_PROFILE_HEVC_MAIN_10
Definition: defs.h:159
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:639
HEVC_NAL_RASL_R
@ HEVC_NAL_RASL_R
Definition: hevc.h:38
H265RawNALUnitHeader
Definition: cbs_h265.h:29
AV_PROFILE_HEVC_REXT
#define AV_PROFILE_HEVC_REXT
Definition: defs.h:161
index
int index
Definition: gxfenc.c:89
VAAPIEncodeH265Context::va_bs
uint32_t va_bs
Definition: vaapi_encode_h265.c:64
vaapi_encode_h265_init
static av_cold int vaapi_encode_h265_init(AVCodecContext *avctx)
Definition: vaapi_encode_h265.c:1358
VAAPIEncodeH265Context::fixed_qp_b
int fixed_qp_b
Definition: vaapi_encode_h265.c:79
VAAPIEncodeH265Context::ctu_size
uint32_t ctu_size
Definition: vaapi_encode_h265.c:65
AVCodecContext::time_base
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avcodec.h:563
aud
static int FUNC() aud(CodedBitstreamContext *ctx, RWContext *rw, H264RawAUD *current)
Definition: cbs_h264_syntax_template.c:841
VAAPIEncodeH265Picture::slice_type
int slice_type
Definition: vaapi_encode_h265.c:54
H265RawVUI::chroma_loc_info_present_flag
uint8_t chroma_loc_info_present_flag
Definition: cbs_h265.h:144
H265RawVUI::sar_width
uint16_t sar_width
Definition: cbs_h265.h:130
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
VAAPIEncodePicture::type
int type
Definition: vaapi_encode.h:92
pps
static int FUNC() pps(CodedBitstreamContext *ctx, RWContext *rw, H264RawPPS *current)
Definition: cbs_h264_syntax_template.c:404
codec_internal.h
VAAPI_ENCODE_RC_OPTIONS
#define VAAPI_ENCODE_RC_OPTIONS
Definition: vaapi_encode.h:525
H265RawSliceHeader::cabac_init_flag
uint8_t cabac_init_flag
Definition: cbs_h265.h:488
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
H265RawProfileTierLevel::general_lower_bit_rate_constraint_flag
uint8_t general_lower_bit_rate_constraint_flag
Definition: cbs_h265.h:55
vaapi_encode_h265_get_encoder_caps
static av_cold int vaapi_encode_h265_get_encoder_caps(AVCodecContext *avctx)
Definition: vaapi_encode_h265.c:1199
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:86
H265RawProfileTierLevel::general_max_monochrome_constraint_flag
uint8_t general_max_monochrome_constraint_flag
Definition: cbs_h265.h:52
AVFrameSideData::data
uint8_t * data
Definition: frame.h:248
h265_profile_level.h
AVCHROMA_LOC_UNSPECIFIED
@ AVCHROMA_LOC_UNSPECIFIED
Definition: pixfmt.h:693
H265RawSliceHeader::dependent_slice_segment_flag
uint8_t dependent_slice_segment_flag
Definition: cbs_h265.h:450
H265RawSliceHeader::slice_cr_qp_offset
int8_t slice_cr_qp_offset
Definition: cbs_h265.h:512
FLAG_B_PICTURES
@ FLAG_B_PICTURES
Definition: vaapi_encode.h:401
header
static const uint8_t header[24]
Definition: sdr2.c:67
H265RawProfileTierLevel::general_one_picture_only_constraint_flag
uint8_t general_one_picture_only_constraint_flag
Definition: cbs_h265.h:54
H265RawAUD::nal_unit_header
H265RawNALUnitHeader nal_unit_header
Definition: cbs_h265.h:438
vaapi_encode_type_h265
static const VAAPIEncodeType vaapi_encode_type_h265
Definition: vaapi_encode_h265.c:1325
vaapi_encode_h265_profiles
static const VAAPIEncodeProfile vaapi_encode_h265_profiles[]
Definition: vaapi_encode_h265.c:1306
VAAPI_ENCODE_COMMON_OPTIONS
#define VAAPI_ENCODE_COMMON_OPTIONS
Definition: vaapi_encode.h:498
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:101
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:107
VAAPIEncodePicture::priv_data
void * priv_data
Definition: vaapi_encode.h:109
vaapi_encode_h265_configure
static av_cold int vaapi_encode_h265_configure(AVCodecContext *avctx)
Definition: vaapi_encode_h265.c:1261
vaapi_encode_h265_init_slice_params
static int vaapi_encode_h265_init_slice_params(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice)
Definition: vaapi_encode_h265.c:976
H265RawVUI::chroma_sample_loc_type_top_field
uint8_t chroma_sample_loc_type_top_field
Definition: cbs_h265.h:145
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:1493
VAAPIEncodePicture::display_order
int64_t display_order
Definition: vaapi_encode.h:76
AV_PIX_FMT_VAAPI
@ AV_PIX_FMT_VAAPI
Hardware acceleration through VA-API, data[3] contains a VASurfaceID.
Definition: pixfmt.h:119
PICTURE_TYPE_I
@ PICTURE_TYPE_I
Definition: vaapi_encode.h:59
VAAPIEncodePicture::nb_dpb_pics
int nb_dpb_pics
Definition: vaapi_encode.h:118
VAAPIEncodePicture::b_depth
int b_depth
Definition: vaapi_encode.h:93
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:729
H265RawVUI::max_bytes_per_pic_denom
uint8_t max_bytes_per_pic_denom
Definition: cbs_h265.h:171
H265RawSliceHeader
Definition: cbs_h265.h:443
SEI_A53_CC
@ SEI_A53_CC
Definition: vaapi_encode_h265.c:45
VAAPIEncodeH265Context::sei_a53cc_data
void * sei_a53cc_data
Definition: vaapi_encode_h265.c:91
HEVC_NAL_TRAIL_R
@ HEVC_NAL_TRAIL_R
Definition: hevc.h:30
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:255
VAAPIEncodeH265Picture::slice_nal_unit
int slice_nal_unit
Definition: vaapi_encode_h265.c:53
H265RawVUI::vui_hrd_parameters_present_flag
uint8_t vui_hrd_parameters_present_flag
Definition: cbs_h265.h:163
SEIRawMasteringDisplayColourVolume::white_point_x
uint16_t white_point_x
Definition: cbs_sei.h:49
VAAPIEncodeContext::input_frames
AVHWFramesContext * input_frames
Definition: vaapi_encode.h:271
VAAPIEncodeH265Context
Definition: vaapi_encode_h265.c:58
PICTURE_TYPE_B
@ PICTURE_TYPE_B
Definition: vaapi_encode.h:61
common.h
H265RawVUI::vui_num_units_in_tick
uint32_t vui_num_units_in_tick
Definition: cbs_h265.h:159
AV_CODEC_ID_HEVC
@ AV_CODEC_ID_HEVC
Definition: codec_id.h:226
HEVC_SLICE_P
@ HEVC_SLICE_P
Definition: hevc.h:97
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
H265RawSliceHeader::nal_unit_header
H265RawNALUnitHeader nal_unit_header
Definition: cbs_h265.h:444
H265RawSliceHeader::slice_beta_offset_div2
int8_t slice_beta_offset_div2
Definition: cbs_h265.h:520
H265RawSTRefPicSet
Definition: cbs_h265.h:219
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
ff_h2645_pixel_aspect
const AVRational ff_h2645_pixel_aspect[]
Definition: h2645data.c:21
AVCodecContext::chroma_sample_location
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
Definition: avcodec.h:1046
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:2115
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:602
VAAPIEncodeH265Context::sei_mastering_display
SEIRawMasteringDisplayColourVolume sei_mastering_display
Definition: vaapi_encode_h265.c:88
AVCodecContext::height
int height
Definition: avcodec.h:621
H265RawProfileTierLevel
Definition: cbs_h265.h:35
SEIRawMasteringDisplayColourVolume::display_primaries_y
uint16_t display_primaries_y[3]
Definition: cbs_sei.h:48
H265RawProfileTierLevel::general_max_420chroma_constraint_flag
uint8_t general_max_420chroma_constraint_flag
Definition: cbs_h265.h:51
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:402
hevc.h
H265RawProfileTierLevel::general_profile_space
uint8_t general_profile_space
Definition: cbs_h265.h:36
avcodec.h
HEVC_NAL_VPS
@ HEVC_NAL_VPS
Definition: hevc.h:61
ff_vaapi_encode_hw_configs
const AVCodecHWConfigInternal *const ff_vaapi_encode_hw_configs[]
Definition: vaapi_encode.c:34
HEVC_NAL_IDR_W_RADL
@ HEVC_NAL_IDR_W_RADL
Definition: hevc.h:48
H265RawProfileTierLevel::general_profile_compatibility_flag
uint8_t general_profile_compatibility_flag[32]
Definition: cbs_h265.h:40
ff_vaapi_encode_init
av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
Definition: vaapi_encode.c:2759
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:71
VAAPIEncodeH265Context::common
VAAPIEncodeContext common
Definition: vaapi_encode_h265.c:59
atsc_a53.h
MAX_DPB_SIZE
@ MAX_DPB_SIZE
Definition: vaapi_encode.h:43
SEIRawContentLightLevelInfo::max_content_light_level
uint16_t max_content_light_level
Definition: cbs_sei.h:56
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:78
LEVEL
#define LEVEL(name, value)
HEVC_NAL_TRAIL_N
@ HEVC_NAL_TRAIL_N
Definition: hevc.h:29
H265RawSliceHeader::slice_loop_filter_across_slices_enabled_flag
uint8_t slice_loop_filter_across_slices_enabled_flag
Definition: cbs_h265.h:522
HEVC_NAL_AUD
@ HEVC_NAL_AUD
Definition: hevc.h:64
AVCodecContext
main external API structure.
Definition: avcodec.h:441
H265RawSTRefPicSet::num_negative_pics
uint8_t num_negative_pics
Definition: cbs_h265.h:229
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:144
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
SEI_CONTENT_LIGHT_LEVEL
@ SEI_CONTENT_LIGHT_LEVEL
Definition: vaapi_encode_h265.c:44
H265RawVUI::colour_description_present_flag
uint8_t colour_description_present_flag
Definition: cbs_h265.h:139
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
AVCodecContext::profile
int profile
profile
Definition: avcodec.h:1596
VAAPIEncodeH265Context::qp
int qp
Definition: vaapi_encode_h265.c:69
AVCodecContext::i_quant_offset
float i_quant_offset
qscale offset between P and I-frames
Definition: avcodec.h:760
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:112
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
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:55
H265RawVUI::transfer_characteristics
uint8_t transfer_characteristics
Definition: cbs_h265.h:141
desc
const char * desc
Definition: libsvtav1.c:83
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
HEVC_NAL_SPS
@ HEVC_NAL_SPS
Definition: hevc.h:62
mastering_display_metadata.h
vaapi_encode_h265_write_extra_header
static int vaapi_encode_h265_write_extra_header(AVCodecContext *avctx, VAAPIEncodePicture *pic, int index, int *type, char *data, size_t *data_len)
Definition: vaapi_encode_h265.c:202
VAAPIEncodePicture::input_image
AVFrame * input_image
Definition: vaapi_encode.h:97
VAAPIEncodeSlice::block_size
int block_size
Definition: vaapi_encode.h:69
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:246
VAAPIEncodeH265Picture::last_idr_frame
int64_t last_idr_frame
Definition: vaapi_encode_h265.c:51
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
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:83
VAAPIEncodeH265Context::sei
int sei
Definition: vaapi_encode_h265.c:74
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:107
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:468
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:244
VAAPIEncodePicture::encode_order
int64_t encode_order
Definition: vaapi_encode.h:77
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
VAAPIEncodeH265Context::current_access_unit
CodedBitstreamFragment current_access_unit
Definition: vaapi_encode_h265.c:94
VAAPIEncodeH265Context::sei_a53cc
SEIRawUserDataRegistered sei_a53cc
Definition: vaapi_encode_h265.c:90
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:621
AV_OPT_TYPE_FLAGS
@ AV_OPT_TYPE_FLAGS
Definition: opt.h:224
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
H265RawVUI::vui_poc_proportional_to_timing_flag
uint8_t vui_poc_proportional_to_timing_flag
Definition: cbs_h265.h:161
SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO
@ SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO
Definition: sei.h:103
VAAPIEncodeH265Context::level
int level
Definition: vaapi_encode_h265.c:73
H265RawVUI::aspect_ratio_idc
uint8_t aspect_ratio_idc
Definition: cbs_h265.h:129
put_bits.h
H265RawVUI::restricted_ref_pic_lists_flag
uint8_t restricted_ref_pic_lists_flag
Definition: cbs_h265.h:169
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
hevc_sei.h
H265RawSliceHeader::delta_chroma_log2_weight_denom
int8_t delta_chroma_log2_weight_denom
Definition: cbs_h265.h:493
AVCodecContext::sample_aspect_ratio
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:822
MAX_REFERENCE_LIST_NUM
@ MAX_REFERENCE_LIST_NUM
Definition: vaapi_encode.h:52
VAAPIEncodeH265Context::min_cb_size
uint32_t min_cb_size
Definition: vaapi_encode_h265.c:66
VAAPIEncodeProfile
Definition: vaapi_encode.h:149
H265RawVUI::motion_vectors_over_pic_boundaries_flag
uint8_t motion_vectors_over_pic_boundaries_flag
Definition: cbs_h265.h:168
H265RawSlice
Definition: cbs_h265.h:533
VAAPIEncodePicture::nb_slices
int nb_slices
Definition: vaapi_encode.h:134
vaapi_encode_h265_defaults
static const FFCodecDefault vaapi_encode_h265_defaults[]
Definition: vaapi_encode_h265.c:1473
VAAPIEncodeH265Context::sei_needed
int sei_needed
Definition: vaapi_encode_h265.c:96
VAAPIEncodeH265Picture::pic_order_cnt
int pic_order_cnt
Definition: vaapi_encode_h265.c:49