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 "avcodec.h"
31 #include "cbs.h"
32 #include "cbs_h265.h"
33 #include "h265_profile_level.h"
34 #include "hevc.h"
35 #include "hevc_sei.h"
36 #include "internal.h"
37 #include "put_bits.h"
38 #include "vaapi_encode.h"
39 
40 enum {
43 };
44 
45 typedef struct VAAPIEncodeH265Picture {
47 
48  int64_t last_idr_frame;
49 
52  int pic_type;
54 
55 typedef struct VAAPIEncodeH265Context {
57 
58  // User options.
59  int qp;
60  int aud;
61  int profile;
62  int tier;
63  int level;
64  int sei;
65 
66  // Derived settings.
70 
71  // Writer structures.
78 
81 
87 
88 
90  char *data, size_t *data_len,
92 {
93  VAAPIEncodeH265Context *priv = avctx->priv_data;
94  int err;
95 
96  err = ff_cbs_write_fragment_data(priv->cbc, au);
97  if (err < 0) {
98  av_log(avctx, AV_LOG_ERROR, "Failed to write packed header.\n");
99  return err;
100  }
101 
102  if (*data_len < 8 * au->data_size - au->data_bit_padding) {
103  av_log(avctx, AV_LOG_ERROR, "Access unit too large: "
104  "%zu < %zu.\n", *data_len,
105  8 * au->data_size - au->data_bit_padding);
106  return AVERROR(ENOSPC);
107  }
108 
109  memcpy(data, au->data, au->data_size);
110  *data_len = 8 * au->data_size - au->data_bit_padding;
111 
112  return 0;
113 }
114 
117  void *nal_unit)
118 {
119  VAAPIEncodeH265Context *priv = avctx->priv_data;
120  H265RawNALUnitHeader *header = nal_unit;
121  int err;
122 
123  err = ff_cbs_insert_unit_content(priv->cbc, au, -1,
124  header->nal_unit_type, nal_unit, NULL);
125  if (err < 0) {
126  av_log(avctx, AV_LOG_ERROR, "Failed to add NAL unit: "
127  "type = %d.\n", header->nal_unit_type);
128  return err;
129  }
130 
131  return 0;
132 }
133 
135  char *data, size_t *data_len)
136 {
137  VAAPIEncodeH265Context *priv = avctx->priv_data;
139  int err;
140 
141  if (priv->aud_needed) {
142  err = vaapi_encode_h265_add_nal(avctx, au, &priv->raw_aud);
143  if (err < 0)
144  goto fail;
145  priv->aud_needed = 0;
146  }
147 
148  err = vaapi_encode_h265_add_nal(avctx, au, &priv->raw_vps);
149  if (err < 0)
150  goto fail;
151 
152  err = vaapi_encode_h265_add_nal(avctx, au, &priv->raw_sps);
153  if (err < 0)
154  goto fail;
155 
156  err = vaapi_encode_h265_add_nal(avctx, au, &priv->raw_pps);
157  if (err < 0)
158  goto fail;
159 
160  err = vaapi_encode_h265_write_access_unit(avctx, data, data_len, au);
161 fail:
162  ff_cbs_fragment_reset(priv->cbc, au);
163  return err;
164 }
165 
167  VAAPIEncodePicture *pic,
168  VAAPIEncodeSlice *slice,
169  char *data, size_t *data_len)
170 {
171  VAAPIEncodeH265Context *priv = avctx->priv_data;
173  int err;
174 
175  if (priv->aud_needed) {
176  err = vaapi_encode_h265_add_nal(avctx, au, &priv->raw_aud);
177  if (err < 0)
178  goto fail;
179  priv->aud_needed = 0;
180  }
181 
182  err = vaapi_encode_h265_add_nal(avctx, au, &priv->raw_slice);
183  if (err < 0)
184  goto fail;
185 
186  err = vaapi_encode_h265_write_access_unit(avctx, data, data_len, au);
187 fail:
188  ff_cbs_fragment_reset(priv->cbc, au);
189  return err;
190 }
191 
193  VAAPIEncodePicture *pic,
194  int index, int *type,
195  char *data, size_t *data_len)
196 {
197  VAAPIEncodeH265Context *priv = avctx->priv_data;
199  int err, i;
200 
201  if (priv->sei_needed) {
202  H265RawSEI *sei = &priv->raw_sei;
203 
204  if (priv->aud_needed) {
205  err = vaapi_encode_h265_add_nal(avctx, au, &priv->aud);
206  if (err < 0)
207  goto fail;
208  priv->aud_needed = 0;
209  }
210 
211  *sei = (H265RawSEI) {
212  .nal_unit_header = {
213  .nal_unit_type = HEVC_NAL_SEI_PREFIX,
214  .nuh_layer_id = 0,
215  .nuh_temporal_id_plus1 = 1,
216  },
217  };
218 
219  i = 0;
220 
221  if (priv->sei_needed & SEI_MASTERING_DISPLAY) {
222  sei->payload[i].payload_type = HEVC_SEI_TYPE_MASTERING_DISPLAY_INFO;
223  sei->payload[i].payload.mastering_display = priv->sei_mastering_display;
224  ++i;
225  }
226 
227  if (priv->sei_needed & SEI_CONTENT_LIGHT_LEVEL) {
228  sei->payload[i].payload_type = HEVC_SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO;
229  sei->payload[i].payload.content_light_level = priv->sei_content_light_level;
230  ++i;
231  }
232 
233  sei->payload_count = i;
234  av_assert0(sei->payload_count > 0);
235 
236  err = vaapi_encode_h265_add_nal(avctx, au, sei);
237  if (err < 0)
238  goto fail;
239  priv->sei_needed = 0;
240 
241  err = vaapi_encode_h265_write_access_unit(avctx, data, data_len, au);
242  if (err < 0)
243  goto fail;
244 
245  ff_cbs_fragment_reset(priv->cbc, au);
246 
247  *type = VAEncPackedHeaderRawData;
248  return 0;
249  } else {
250  return AVERROR_EOF;
251  }
252 
253 fail:
254  ff_cbs_fragment_reset(priv->cbc, au);
255  return err;
256 }
257 
259 {
260  VAAPIEncodeContext *ctx = avctx->priv_data;
261  VAAPIEncodeH265Context *priv = avctx->priv_data;
262  H265RawVPS *vps = &priv->raw_vps;
263  H265RawSPS *sps = &priv->raw_sps;
264  H265RawPPS *pps = &priv->raw_pps;
265  H265RawProfileTierLevel *ptl = &vps->profile_tier_level;
266  H265RawVUI *vui = &sps->vui;
267  VAEncSequenceParameterBufferHEVC *vseq = ctx->codec_sequence_params;
268  VAEncPictureParameterBufferHEVC *vpic = ctx->codec_picture_params;
269  const AVPixFmtDescriptor *desc;
270  int chroma_format, bit_depth;
271  int i;
272 
273  memset(vps, 0, sizeof(*vps));
274  memset(sps, 0, sizeof(*sps));
275  memset(pps, 0, sizeof(*pps));
276 
277 
279  av_assert0(desc);
280  if (desc->nb_components == 1) {
281  chroma_format = 0;
282  } else {
283  if (desc->log2_chroma_w == 1 && desc->log2_chroma_h == 1) {
284  chroma_format = 1;
285  } else if (desc->log2_chroma_w == 1 && desc->log2_chroma_h == 0) {
286  chroma_format = 2;
287  } else if (desc->log2_chroma_w == 0 && desc->log2_chroma_h == 0) {
288  chroma_format = 3;
289  } else {
290  av_log(avctx, AV_LOG_ERROR, "Chroma format of input pixel format "
291  "%s is not supported.\n", desc->name);
292  return AVERROR(EINVAL);
293  }
294  }
295  bit_depth = desc->comp[0].depth;
296 
297 
298  // VPS
299 
300  vps->nal_unit_header = (H265RawNALUnitHeader) {
301  .nal_unit_type = HEVC_NAL_VPS,
302  .nuh_layer_id = 0,
303  .nuh_temporal_id_plus1 = 1,
304  };
305 
306  vps->vps_video_parameter_set_id = 0;
307 
308  vps->vps_base_layer_internal_flag = 1;
309  vps->vps_base_layer_available_flag = 1;
310  vps->vps_max_layers_minus1 = 0;
311  vps->vps_max_sub_layers_minus1 = 0;
312  vps->vps_temporal_id_nesting_flag = 1;
313 
315  ptl->general_profile_idc = avctx->profile;
316  ptl->general_tier_flag = priv->tier;
317 
318  if (chroma_format == 1) {
321  }
323 
328 
332 
333  ptl->general_max_422chroma_constraint_flag = chroma_format <= 2;
334  ptl->general_max_420chroma_constraint_flag = chroma_format <= 1;
335  ptl->general_max_monochrome_constraint_flag = chroma_format == 0;
336 
337  ptl->general_intra_constraint_flag = ctx->gop_size == 1;
338 
340 
341  if (avctx->level != FF_LEVEL_UNKNOWN) {
342  ptl->general_level_idc = avctx->level;
343  } else {
344  const H265LevelDescriptor *level;
345 
347  ctx->surface_width, ctx->surface_height,
348  ctx->nb_slices, 1, 1,
349  (ctx->b_per_p > 0) + 1);
350  if (level) {
351  av_log(avctx, AV_LOG_VERBOSE, "Using level %s.\n", level->name);
352  ptl->general_level_idc = level->level_idc;
353  } else {
354  av_log(avctx, AV_LOG_VERBOSE, "Stream will not conform to "
355  "any normal level; using level 8.5.\n");
356  ptl->general_level_idc = 255;
357  // The tier flag must be set in level 8.5.
358  ptl->general_tier_flag = 1;
359  }
360  }
361 
362  vps->vps_sub_layer_ordering_info_present_flag = 0;
363  vps->vps_max_dec_pic_buffering_minus1[0] = ctx->max_b_depth + 1;
364  vps->vps_max_num_reorder_pics[0] = ctx->max_b_depth;
365  vps->vps_max_latency_increase_plus1[0] = 0;
366 
367  vps->vps_max_layer_id = 0;
368  vps->vps_num_layer_sets_minus1 = 0;
369  vps->layer_id_included_flag[0][0] = 1;
370 
371  vps->vps_timing_info_present_flag = 1;
372  if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
373  vps->vps_num_units_in_tick = avctx->framerate.den;
374  vps->vps_time_scale = avctx->framerate.num;
375  vps->vps_poc_proportional_to_timing_flag = 1;
376  vps->vps_num_ticks_poc_diff_one_minus1 = 0;
377  } else {
378  vps->vps_num_units_in_tick = avctx->time_base.num;
379  vps->vps_time_scale = avctx->time_base.den;
380  vps->vps_poc_proportional_to_timing_flag = 0;
381  }
382  vps->vps_num_hrd_parameters = 0;
383 
384 
385  // SPS
386 
387  sps->nal_unit_header = (H265RawNALUnitHeader) {
388  .nal_unit_type = HEVC_NAL_SPS,
389  .nuh_layer_id = 0,
390  .nuh_temporal_id_plus1 = 1,
391  };
392 
393  sps->sps_video_parameter_set_id = vps->vps_video_parameter_set_id;
394 
395  sps->sps_max_sub_layers_minus1 = vps->vps_max_sub_layers_minus1;
396  sps->sps_temporal_id_nesting_flag = vps->vps_temporal_id_nesting_flag;
397 
398  sps->profile_tier_level = vps->profile_tier_level;
399 
400  sps->sps_seq_parameter_set_id = 0;
401 
402  sps->chroma_format_idc = chroma_format;
403  sps->separate_colour_plane_flag = 0;
404 
405  sps->pic_width_in_luma_samples = ctx->surface_width;
406  sps->pic_height_in_luma_samples = ctx->surface_height;
407 
408  if (avctx->width != ctx->surface_width ||
409  avctx->height != ctx->surface_height) {
410  sps->conformance_window_flag = 1;
411  sps->conf_win_left_offset = 0;
412  sps->conf_win_right_offset =
413  (ctx->surface_width - avctx->width) >> desc->log2_chroma_w;
414  sps->conf_win_top_offset = 0;
415  sps->conf_win_bottom_offset =
416  (ctx->surface_height - avctx->height) >> desc->log2_chroma_h;
417  } else {
418  sps->conformance_window_flag = 0;
419  }
420 
421  sps->bit_depth_luma_minus8 = bit_depth - 8;
422  sps->bit_depth_chroma_minus8 = bit_depth - 8;
423 
424  sps->log2_max_pic_order_cnt_lsb_minus4 = 8;
425 
426  sps->sps_sub_layer_ordering_info_present_flag =
427  vps->vps_sub_layer_ordering_info_present_flag;
428  for (i = 0; i <= sps->sps_max_sub_layers_minus1; i++) {
429  sps->sps_max_dec_pic_buffering_minus1[i] =
430  vps->vps_max_dec_pic_buffering_minus1[i];
431  sps->sps_max_num_reorder_pics[i] =
432  vps->vps_max_num_reorder_pics[i];
433  sps->sps_max_latency_increase_plus1[i] =
434  vps->vps_max_latency_increase_plus1[i];
435  }
436 
437  // These have to come from the capabilities of the encoder. We have no
438  // way to query them, so just hardcode parameters which work on the Intel
439  // driver.
440  // CTB size from 8x8 to 32x32.
441  sps->log2_min_luma_coding_block_size_minus3 = 0;
442  sps->log2_diff_max_min_luma_coding_block_size = 2;
443  // Transform size from 4x4 to 32x32.
444  sps->log2_min_luma_transform_block_size_minus2 = 0;
445  sps->log2_diff_max_min_luma_transform_block_size = 3;
446  // Full transform hierarchy allowed (2-5).
447  sps->max_transform_hierarchy_depth_inter = 3;
448  sps->max_transform_hierarchy_depth_intra = 3;
449  // AMP works.
450  sps->amp_enabled_flag = 1;
451  // SAO and temporal MVP do not work.
452  sps->sample_adaptive_offset_enabled_flag = 0;
453  sps->sps_temporal_mvp_enabled_flag = 0;
454 
455  sps->pcm_enabled_flag = 0;
456 
457  // STRPSs should ideally be here rather than defined individually in
458  // each slice, but the structure isn't completely fixed so for now
459  // don't bother.
460  sps->num_short_term_ref_pic_sets = 0;
461  sps->long_term_ref_pics_present_flag = 0;
462 
463  sps->vui_parameters_present_flag = 1;
464 
465  if (avctx->sample_aspect_ratio.num != 0 &&
466  avctx->sample_aspect_ratio.den != 0) {
467  static const AVRational sar_idc[] = {
468  { 0, 0 },
469  { 1, 1 }, { 12, 11 }, { 10, 11 }, { 16, 11 },
470  { 40, 33 }, { 24, 11 }, { 20, 11 }, { 32, 11 },
471  { 80, 33 }, { 18, 11 }, { 15, 11 }, { 64, 33 },
472  { 160, 99 }, { 4, 3 }, { 3, 2 }, { 2, 1 },
473  };
474  int num, den, i;
475  av_reduce(&num, &den, avctx->sample_aspect_ratio.num,
476  avctx->sample_aspect_ratio.den, 65535);
477  for (i = 0; i < FF_ARRAY_ELEMS(sar_idc); i++) {
478  if (num == sar_idc[i].num &&
479  den == sar_idc[i].den) {
480  vui->aspect_ratio_idc = i;
481  break;
482  }
483  }
484  if (i >= FF_ARRAY_ELEMS(sar_idc)) {
485  vui->aspect_ratio_idc = 255;
486  vui->sar_width = num;
487  vui->sar_height = den;
488  }
490  }
491 
492  if (avctx->color_range != AVCOL_RANGE_UNSPECIFIED ||
494  avctx->color_trc != AVCOL_TRC_UNSPECIFIED ||
495  avctx->colorspace != AVCOL_SPC_UNSPECIFIED) {
497  vui->video_format = 5; // Unspecified.
498  vui->video_full_range_flag =
499  avctx->color_range == AVCOL_RANGE_JPEG;
500 
501  if (avctx->color_primaries != AVCOL_PRI_UNSPECIFIED ||
502  avctx->color_trc != AVCOL_TRC_UNSPECIFIED ||
503  avctx->colorspace != AVCOL_SPC_UNSPECIFIED) {
505  vui->colour_primaries = avctx->color_primaries;
506  vui->transfer_characteristics = avctx->color_trc;
507  vui->matrix_coefficients = avctx->colorspace;
508  }
509  } else {
510  vui->video_format = 5;
511  vui->video_full_range_flag = 0;
512  vui->colour_primaries = avctx->color_primaries;
513  vui->transfer_characteristics = avctx->color_trc;
514  vui->matrix_coefficients = avctx->colorspace;
515  }
516 
521  avctx->chroma_sample_location - 1;
522  }
523 
525  vui->vui_num_units_in_tick = vps->vps_num_units_in_tick;
526  vui->vui_time_scale = vps->vps_time_scale;
527  vui->vui_poc_proportional_to_timing_flag = vps->vps_poc_proportional_to_timing_flag;
528  vui->vui_num_ticks_poc_diff_one_minus1 = vps->vps_num_ticks_poc_diff_one_minus1;
530 
534  vui->max_bytes_per_pic_denom = 0;
535  vui->max_bits_per_min_cu_denom = 0;
537  vui->log2_max_mv_length_vertical = 15;
538 
539 
540  // PPS
541 
542  pps->nal_unit_header = (H265RawNALUnitHeader) {
543  .nal_unit_type = HEVC_NAL_PPS,
544  .nuh_layer_id = 0,
545  .nuh_temporal_id_plus1 = 1,
546  };
547 
548  pps->pps_pic_parameter_set_id = 0;
549  pps->pps_seq_parameter_set_id = sps->sps_seq_parameter_set_id;
550 
551  pps->num_ref_idx_l0_default_active_minus1 = 0;
552  pps->num_ref_idx_l1_default_active_minus1 = 0;
553 
554  pps->init_qp_minus26 = priv->fixed_qp_idr - 26;
555 
556  pps->cu_qp_delta_enabled_flag = (ctx->va_rc_mode != VA_RC_CQP);
557  pps->diff_cu_qp_delta_depth = 0;
558 
559  pps->pps_loop_filter_across_slices_enabled_flag = 1;
560 
561 
562  // Fill VAAPI parameter buffers.
563 
564  *vseq = (VAEncSequenceParameterBufferHEVC) {
565  .general_profile_idc = vps->profile_tier_level.general_profile_idc,
566  .general_level_idc = vps->profile_tier_level.general_level_idc,
567  .general_tier_flag = vps->profile_tier_level.general_tier_flag,
568 
569  .intra_period = ctx->gop_size,
570  .intra_idr_period = ctx->gop_size,
571  .ip_period = ctx->b_per_p + 1,
572  .bits_per_second = ctx->va_bit_rate,
573 
574  .pic_width_in_luma_samples = sps->pic_width_in_luma_samples,
575  .pic_height_in_luma_samples = sps->pic_height_in_luma_samples,
576 
577  .seq_fields.bits = {
578  .chroma_format_idc = sps->chroma_format_idc,
579  .separate_colour_plane_flag = sps->separate_colour_plane_flag,
580  .bit_depth_luma_minus8 = sps->bit_depth_luma_minus8,
581  .bit_depth_chroma_minus8 = sps->bit_depth_chroma_minus8,
582  .scaling_list_enabled_flag = sps->scaling_list_enabled_flag,
583  .strong_intra_smoothing_enabled_flag =
584  sps->strong_intra_smoothing_enabled_flag,
585  .amp_enabled_flag = sps->amp_enabled_flag,
586  .sample_adaptive_offset_enabled_flag =
587  sps->sample_adaptive_offset_enabled_flag,
588  .pcm_enabled_flag = sps->pcm_enabled_flag,
589  .pcm_loop_filter_disabled_flag = sps->pcm_loop_filter_disabled_flag,
590  .sps_temporal_mvp_enabled_flag = sps->sps_temporal_mvp_enabled_flag,
591  },
592 
593  .log2_min_luma_coding_block_size_minus3 =
594  sps->log2_min_luma_coding_block_size_minus3,
595  .log2_diff_max_min_luma_coding_block_size =
596  sps->log2_diff_max_min_luma_coding_block_size,
597  .log2_min_transform_block_size_minus2 =
598  sps->log2_min_luma_transform_block_size_minus2,
599  .log2_diff_max_min_transform_block_size =
600  sps->log2_diff_max_min_luma_transform_block_size,
601  .max_transform_hierarchy_depth_inter =
602  sps->max_transform_hierarchy_depth_inter,
603  .max_transform_hierarchy_depth_intra =
604  sps->max_transform_hierarchy_depth_intra,
605 
606  .pcm_sample_bit_depth_luma_minus1 =
607  sps->pcm_sample_bit_depth_luma_minus1,
608  .pcm_sample_bit_depth_chroma_minus1 =
609  sps->pcm_sample_bit_depth_chroma_minus1,
610  .log2_min_pcm_luma_coding_block_size_minus3 =
611  sps->log2_min_pcm_luma_coding_block_size_minus3,
612  .log2_max_pcm_luma_coding_block_size_minus3 =
613  sps->log2_min_pcm_luma_coding_block_size_minus3 +
614  sps->log2_diff_max_min_pcm_luma_coding_block_size,
615 
616  .vui_parameters_present_flag = 0,
617  };
618 
619  *vpic = (VAEncPictureParameterBufferHEVC) {
620  .decoded_curr_pic = {
621  .picture_id = VA_INVALID_ID,
622  .flags = VA_PICTURE_HEVC_INVALID,
623  },
624 
625  .coded_buf = VA_INVALID_ID,
626 
627  .collocated_ref_pic_index = 0xff,
628 
629  .last_picture = 0,
630 
631  .pic_init_qp = pps->init_qp_minus26 + 26,
632  .diff_cu_qp_delta_depth = pps->diff_cu_qp_delta_depth,
633  .pps_cb_qp_offset = pps->pps_cb_qp_offset,
634  .pps_cr_qp_offset = pps->pps_cr_qp_offset,
635 
636  .num_tile_columns_minus1 = pps->num_tile_columns_minus1,
637  .num_tile_rows_minus1 = pps->num_tile_rows_minus1,
638 
639  .log2_parallel_merge_level_minus2 = pps->log2_parallel_merge_level_minus2,
640  .ctu_max_bitsize_allowed = 0,
641 
642  .num_ref_idx_l0_default_active_minus1 =
643  pps->num_ref_idx_l0_default_active_minus1,
644  .num_ref_idx_l1_default_active_minus1 =
645  pps->num_ref_idx_l1_default_active_minus1,
646 
647  .slice_pic_parameter_set_id = pps->pps_pic_parameter_set_id,
648 
649  .pic_fields.bits = {
650  .sign_data_hiding_enabled_flag = pps->sign_data_hiding_enabled_flag,
651  .constrained_intra_pred_flag = pps->constrained_intra_pred_flag,
652  .transform_skip_enabled_flag = pps->transform_skip_enabled_flag,
653  .cu_qp_delta_enabled_flag = pps->cu_qp_delta_enabled_flag,
654  .weighted_pred_flag = pps->weighted_pred_flag,
655  .weighted_bipred_flag = pps->weighted_bipred_flag,
656  .transquant_bypass_enabled_flag = pps->transquant_bypass_enabled_flag,
657  .tiles_enabled_flag = pps->tiles_enabled_flag,
658  .entropy_coding_sync_enabled_flag = pps->entropy_coding_sync_enabled_flag,
659  .loop_filter_across_tiles_enabled_flag =
660  pps->loop_filter_across_tiles_enabled_flag,
661  .scaling_list_data_present_flag = (sps->sps_scaling_list_data_present_flag |
662  pps->pps_scaling_list_data_present_flag),
663  .screen_content_flag = 0,
664  .enable_gpu_weighted_prediction = 0,
665  .no_output_of_prior_pics_flag = 0,
666  },
667  };
668 
669  return 0;
670 }
671 
673  VAAPIEncodePicture *pic)
674 {
675  VAAPIEncodeContext *ctx = avctx->priv_data;
676  VAAPIEncodeH265Context *priv = avctx->priv_data;
677  VAAPIEncodeH265Picture *hpic = pic->priv_data;
678  VAAPIEncodePicture *prev = pic->prev;
679  VAAPIEncodeH265Picture *hprev = prev ? prev->priv_data : NULL;
680  VAEncPictureParameterBufferHEVC *vpic = pic->codec_picture_params;
681  int i;
682 
683  if (pic->type == PICTURE_TYPE_IDR) {
684  av_assert0(pic->display_order == pic->encode_order);
685 
686  hpic->last_idr_frame = pic->display_order;
687 
689  hpic->slice_type = HEVC_SLICE_I;
690  hpic->pic_type = 0;
691  } else {
692  av_assert0(prev);
693  hpic->last_idr_frame = hprev->last_idr_frame;
694 
695  if (pic->type == PICTURE_TYPE_I) {
697  hpic->slice_type = HEVC_SLICE_I;
698  hpic->pic_type = 0;
699  } else if (pic->type == PICTURE_TYPE_P) {
700  av_assert0(pic->refs[0]);
702  hpic->slice_type = HEVC_SLICE_P;
703  hpic->pic_type = 1;
704  } else {
705  VAAPIEncodePicture *irap_ref;
706  av_assert0(pic->refs[0] && pic->refs[1]);
707  for (irap_ref = pic; irap_ref; irap_ref = irap_ref->refs[1]) {
708  if (irap_ref->type == PICTURE_TYPE_I)
709  break;
710  }
711  if (pic->b_depth == ctx->max_b_depth) {
712  hpic->slice_nal_unit = irap_ref ? HEVC_NAL_RASL_N
714  } else {
715  hpic->slice_nal_unit = irap_ref ? HEVC_NAL_RASL_R
717  }
718  hpic->slice_type = HEVC_SLICE_B;
719  hpic->pic_type = 2;
720  }
721  }
722  hpic->pic_order_cnt = pic->display_order - hpic->last_idr_frame;
723 
724  if (priv->aud) {
725  priv->aud_needed = 1;
726  priv->raw_aud = (H265RawAUD) {
727  .nal_unit_header = {
729  .nuh_layer_id = 0,
730  .nuh_temporal_id_plus1 = 1,
731  },
732  .pic_type = hpic->pic_type,
733  };
734  } else {
735  priv->aud_needed = 0;
736  }
737 
738  priv->sei_needed = 0;
739 
740  // Only look for the metadata on I/IDR frame on the output. We
741  // may force an IDR frame on the output where the medadata gets
742  // changed on the input frame.
743  if ((priv->sei & SEI_MASTERING_DISPLAY) &&
744  (pic->type == PICTURE_TYPE_I || pic->type == PICTURE_TYPE_IDR)) {
745  AVFrameSideData *sd =
748 
749  if (sd) {
752 
753  // SEI is needed when both the primaries and luminance are set
754  if (mdm->has_primaries && mdm->has_luminance) {
756  &priv->sei_mastering_display;
757  const int mapping[3] = {1, 2, 0};
758  const int chroma_den = 50000;
759  const int luma_den = 10000;
760 
761  for (i = 0; i < 3; i++) {
762  const int j = mapping[i];
763  mdcv->display_primaries_x[i] =
764  FFMIN(lrint(chroma_den *
765  av_q2d(mdm->display_primaries[j][0])),
766  chroma_den);
767  mdcv->display_primaries_y[i] =
768  FFMIN(lrint(chroma_den *
769  av_q2d(mdm->display_primaries[j][1])),
770  chroma_den);
771  }
772 
773  mdcv->white_point_x =
774  FFMIN(lrint(chroma_den * av_q2d(mdm->white_point[0])),
775  chroma_den);
776  mdcv->white_point_y =
777  FFMIN(lrint(chroma_den * av_q2d(mdm->white_point[1])),
778  chroma_den);
779 
781  lrint(luma_den * av_q2d(mdm->max_luminance));
783  FFMIN(lrint(luma_den * av_q2d(mdm->min_luminance)),
785 
787  }
788  }
789  }
790 
791  if ((priv->sei & SEI_CONTENT_LIGHT_LEVEL) &&
792  (pic->type == PICTURE_TYPE_I || pic->type == PICTURE_TYPE_IDR)) {
793  AVFrameSideData *sd =
796 
797  if (sd) {
802 
803  clli->max_content_light_level = FFMIN(clm->MaxCLL, 65535);
804  clli->max_pic_average_light_level = FFMIN(clm->MaxFALL, 65535);
805 
807  }
808  }
809 
810  vpic->decoded_curr_pic = (VAPictureHEVC) {
811  .picture_id = pic->recon_surface,
812  .pic_order_cnt = hpic->pic_order_cnt,
813  .flags = 0,
814  };
815 
816  for (i = 0; i < pic->nb_refs; i++) {
817  VAAPIEncodePicture *ref = pic->refs[i];
819 
820  av_assert0(ref && ref->encode_order < pic->encode_order);
821  href = ref->priv_data;
822 
823  vpic->reference_frames[i] = (VAPictureHEVC) {
824  .picture_id = ref->recon_surface,
825  .pic_order_cnt = href->pic_order_cnt,
826  .flags = (ref->display_order < pic->display_order ?
827  VA_PICTURE_HEVC_RPS_ST_CURR_BEFORE : 0) |
828  (ref->display_order > pic->display_order ?
829  VA_PICTURE_HEVC_RPS_ST_CURR_AFTER : 0),
830  };
831  }
832  for (; i < FF_ARRAY_ELEMS(vpic->reference_frames); i++) {
833  vpic->reference_frames[i] = (VAPictureHEVC) {
834  .picture_id = VA_INVALID_ID,
835  .flags = VA_PICTURE_HEVC_INVALID,
836  };
837  }
838 
839  vpic->coded_buf = pic->output_buffer;
840 
841  vpic->nal_unit_type = hpic->slice_nal_unit;
842 
843  switch (pic->type) {
844  case PICTURE_TYPE_IDR:
845  vpic->pic_fields.bits.idr_pic_flag = 1;
846  vpic->pic_fields.bits.coding_type = 1;
847  vpic->pic_fields.bits.reference_pic_flag = 1;
848  break;
849  case PICTURE_TYPE_I:
850  vpic->pic_fields.bits.idr_pic_flag = 0;
851  vpic->pic_fields.bits.coding_type = 1;
852  vpic->pic_fields.bits.reference_pic_flag = 1;
853  break;
854  case PICTURE_TYPE_P:
855  vpic->pic_fields.bits.idr_pic_flag = 0;
856  vpic->pic_fields.bits.coding_type = 2;
857  vpic->pic_fields.bits.reference_pic_flag = 1;
858  break;
859  case PICTURE_TYPE_B:
860  vpic->pic_fields.bits.idr_pic_flag = 0;
861  vpic->pic_fields.bits.coding_type = 3;
862  vpic->pic_fields.bits.reference_pic_flag = 0;
863  break;
864  default:
865  av_assert0(0 && "invalid picture type");
866  }
867 
868  return 0;
869 }
870 
872  VAAPIEncodePicture *pic,
873  VAAPIEncodeSlice *slice)
874 {
875  VAAPIEncodeH265Context *priv = avctx->priv_data;
876  VAAPIEncodeH265Picture *hpic = pic->priv_data;
877  const H265RawSPS *sps = &priv->raw_sps;
878  const H265RawPPS *pps = &priv->raw_pps;
879  H265RawSliceHeader *sh = &priv->raw_slice.header;
880  VAEncPictureParameterBufferHEVC *vpic = pic->codec_picture_params;
881  VAEncSliceParameterBufferHEVC *vslice = slice->codec_slice_params;
882  int i;
883 
885  .nal_unit_type = hpic->slice_nal_unit,
886  .nuh_layer_id = 0,
887  .nuh_temporal_id_plus1 = 1,
888  };
889 
890  sh->slice_pic_parameter_set_id = pps->pps_pic_parameter_set_id;
891 
892  sh->first_slice_segment_in_pic_flag = slice->index == 0;
893  sh->slice_segment_address = slice->block_start;
894 
895  sh->slice_type = hpic->slice_type;
896 
898  (1 << (sps->log2_max_pic_order_cnt_lsb_minus4 + 4)) - 1;
899 
900  if (pic->type != PICTURE_TYPE_IDR) {
901  H265RawSTRefPicSet *rps;
902  const VAAPIEncodeH265Picture *strp;
903  int rps_poc[MAX_DPB_SIZE];
904  int rps_used[MAX_DPB_SIZE];
905  int i, j, poc, rps_pics;
906 
908 
909  rps = &sh->short_term_ref_pic_set;
910  memset(rps, 0, sizeof(*rps));
911 
912  rps_pics = 0;
913  for (i = 0; i < pic->nb_refs; i++) {
914  strp = pic->refs[i]->priv_data;
915  rps_poc[rps_pics] = strp->pic_order_cnt;
916  rps_used[rps_pics] = 1;
917  ++rps_pics;
918  }
919  for (i = 0; i < pic->nb_dpb_pics; i++) {
920  if (pic->dpb[i] == pic)
921  continue;
922  for (j = 0; j < pic->nb_refs; j++) {
923  if (pic->dpb[i] == pic->refs[j])
924  break;
925  }
926  if (j < pic->nb_refs)
927  continue;
928  strp = pic->dpb[i]->priv_data;
929  rps_poc[rps_pics] = strp->pic_order_cnt;
930  rps_used[rps_pics] = 0;
931  ++rps_pics;
932  }
933 
934  for (i = 1; i < rps_pics; i++) {
935  for (j = i; j > 0; j--) {
936  if (rps_poc[j] > rps_poc[j - 1])
937  break;
938  av_assert0(rps_poc[j] != rps_poc[j - 1]);
939  FFSWAP(int, rps_poc[j], rps_poc[j - 1]);
940  FFSWAP(int, rps_used[j], rps_used[j - 1]);
941  }
942  }
943 
944  av_log(avctx, AV_LOG_DEBUG, "RPS for POC %d:",
945  hpic->pic_order_cnt);
946  for (i = 0; i < rps_pics; i++) {
947  av_log(avctx, AV_LOG_DEBUG, " (%d,%d)",
948  rps_poc[i], rps_used[i]);
949  }
950  av_log(avctx, AV_LOG_DEBUG, "\n");
951 
952  for (i = 0; i < rps_pics; i++) {
953  av_assert0(rps_poc[i] != hpic->pic_order_cnt);
954  if (rps_poc[i] > hpic->pic_order_cnt)
955  break;
956  }
957 
958  rps->num_negative_pics = i;
959  poc = hpic->pic_order_cnt;
960  for (j = i - 1; j >= 0; j--) {
961  rps->delta_poc_s0_minus1[i - 1 - j] = poc - rps_poc[j] - 1;
962  rps->used_by_curr_pic_s0_flag[i - 1 - j] = rps_used[j];
963  poc = rps_poc[j];
964  }
965 
966  rps->num_positive_pics = rps_pics - i;
967  poc = hpic->pic_order_cnt;
968  for (j = i; j < rps_pics; j++) {
969  rps->delta_poc_s1_minus1[j - i] = rps_poc[j] - poc - 1;
970  rps->used_by_curr_pic_s1_flag[j - i] = rps_used[j];
971  poc = rps_poc[j];
972  }
973 
974  sh->num_long_term_sps = 0;
975  sh->num_long_term_pics = 0;
976 
978  sps->sps_temporal_mvp_enabled_flag;
981  sh->collocated_ref_idx = 0;
982  }
983 
985  sh->num_ref_idx_l0_active_minus1 = pps->num_ref_idx_l0_default_active_minus1;
986  sh->num_ref_idx_l1_active_minus1 = pps->num_ref_idx_l1_default_active_minus1;
987  }
988 
990  sps->sample_adaptive_offset_enabled_flag;
991 
992  if (pic->type == PICTURE_TYPE_B)
993  sh->slice_qp_delta = priv->fixed_qp_b - (pps->init_qp_minus26 + 26);
994  else if (pic->type == PICTURE_TYPE_P)
995  sh->slice_qp_delta = priv->fixed_qp_p - (pps->init_qp_minus26 + 26);
996  else
997  sh->slice_qp_delta = priv->fixed_qp_idr - (pps->init_qp_minus26 + 26);
998 
999 
1000  *vslice = (VAEncSliceParameterBufferHEVC) {
1001  .slice_segment_address = sh->slice_segment_address,
1002  .num_ctu_in_slice = slice->block_size,
1003 
1004  .slice_type = sh->slice_type,
1005  .slice_pic_parameter_set_id = sh->slice_pic_parameter_set_id,
1006 
1007  .num_ref_idx_l0_active_minus1 = sh->num_ref_idx_l0_active_minus1,
1008  .num_ref_idx_l1_active_minus1 = sh->num_ref_idx_l1_active_minus1,
1009 
1010  .luma_log2_weight_denom = sh->luma_log2_weight_denom,
1011  .delta_chroma_log2_weight_denom = sh->delta_chroma_log2_weight_denom,
1012 
1013  .max_num_merge_cand = 5 - sh->five_minus_max_num_merge_cand,
1014 
1015  .slice_qp_delta = sh->slice_qp_delta,
1016  .slice_cb_qp_offset = sh->slice_cb_qp_offset,
1017  .slice_cr_qp_offset = sh->slice_cr_qp_offset,
1018 
1019  .slice_beta_offset_div2 = sh->slice_beta_offset_div2,
1020  .slice_tc_offset_div2 = sh->slice_tc_offset_div2,
1021 
1022  .slice_fields.bits = {
1023  .last_slice_of_pic_flag = slice->index == pic->nb_slices - 1,
1024  .dependent_slice_segment_flag = sh->dependent_slice_segment_flag,
1025  .colour_plane_id = sh->colour_plane_id,
1026  .slice_temporal_mvp_enabled_flag =
1028  .slice_sao_luma_flag = sh->slice_sao_luma_flag,
1029  .slice_sao_chroma_flag = sh->slice_sao_chroma_flag,
1030  .num_ref_idx_active_override_flag =
1032  .mvd_l1_zero_flag = sh->mvd_l1_zero_flag,
1033  .cabac_init_flag = sh->cabac_init_flag,
1034  .slice_deblocking_filter_disabled_flag =
1036  .slice_loop_filter_across_slices_enabled_flag =
1038  .collocated_from_l0_flag = sh->collocated_from_l0_flag,
1039  },
1040  };
1041 
1042  for (i = 0; i < FF_ARRAY_ELEMS(vslice->ref_pic_list0); i++) {
1043  vslice->ref_pic_list0[i].picture_id = VA_INVALID_ID;
1044  vslice->ref_pic_list0[i].flags = VA_PICTURE_HEVC_INVALID;
1045  vslice->ref_pic_list1[i].picture_id = VA_INVALID_ID;
1046  vslice->ref_pic_list1[i].flags = VA_PICTURE_HEVC_INVALID;
1047  }
1048 
1049  av_assert0(pic->nb_refs <= 2);
1050  if (pic->nb_refs >= 1) {
1051  // Backward reference for P- or B-frame.
1052  av_assert0(pic->type == PICTURE_TYPE_P ||
1053  pic->type == PICTURE_TYPE_B);
1054  vslice->ref_pic_list0[0] = vpic->reference_frames[0];
1055  }
1056  if (pic->nb_refs >= 2) {
1057  // Forward reference for B-frame.
1058  av_assert0(pic->type == PICTURE_TYPE_B);
1059  vslice->ref_pic_list1[0] = vpic->reference_frames[1];
1060  }
1061 
1062  return 0;
1063 }
1064 
1066 {
1067  VAAPIEncodeContext *ctx = avctx->priv_data;
1068  VAAPIEncodeH265Context *priv = avctx->priv_data;
1069  int err;
1070 
1071  err = ff_cbs_init(&priv->cbc, AV_CODEC_ID_HEVC, avctx);
1072  if (err < 0)
1073  return err;
1074 
1075  if (ctx->va_rc_mode == VA_RC_CQP) {
1076  // Note that VAAPI only supports positive QP values - the range is
1077  // therefore always bounded below by 1, even in 10-bit mode where
1078  // it should go down to -12.
1079 
1080  priv->fixed_qp_p = av_clip(ctx->rc_quality, 1, 51);
1081  if (avctx->i_quant_factor > 0.0)
1082  priv->fixed_qp_idr =
1083  av_clip((avctx->i_quant_factor * priv->fixed_qp_p +
1084  avctx->i_quant_offset) + 0.5, 1, 51);
1085  else
1086  priv->fixed_qp_idr = priv->fixed_qp_p;
1087  if (avctx->b_quant_factor > 0.0)
1088  priv->fixed_qp_b =
1089  av_clip((avctx->b_quant_factor * priv->fixed_qp_p +
1090  avctx->b_quant_offset) + 0.5, 1, 51);
1091  else
1092  priv->fixed_qp_b = priv->fixed_qp_p;
1093 
1094  av_log(avctx, AV_LOG_DEBUG, "Using fixed QP = "
1095  "%d / %d / %d for IDR- / P- / B-frames.\n",
1096  priv->fixed_qp_idr, priv->fixed_qp_p, priv->fixed_qp_b);
1097 
1098  } else {
1099  // These still need to be set for init_qp/slice_qp_delta.
1100  priv->fixed_qp_idr = 30;
1101  priv->fixed_qp_p = 30;
1102  priv->fixed_qp_b = 30;
1103  }
1104 
1105  ctx->roi_quant_range = 51 + 6 * (ctx->profile->depth - 8);
1106 
1107  return 0;
1108 }
1109 
1111  { FF_PROFILE_HEVC_MAIN, 8, 3, 1, 1, VAProfileHEVCMain },
1112  { FF_PROFILE_HEVC_REXT, 8, 3, 1, 1, VAProfileHEVCMain },
1113 #if VA_CHECK_VERSION(0, 37, 0)
1114  { FF_PROFILE_HEVC_MAIN_10, 10, 3, 1, 1, VAProfileHEVCMain10 },
1115  { FF_PROFILE_HEVC_REXT, 10, 3, 1, 1, VAProfileHEVCMain10 },
1116 #endif
1117  { FF_PROFILE_UNKNOWN }
1118 };
1119 
1122 
1123  .flags = FLAG_SLICE_CONTROL |
1124  FLAG_B_PICTURES |
1127 
1128  .default_quality = 25,
1129 
1130  .configure = &vaapi_encode_h265_configure,
1131 
1132  .picture_priv_data_size = sizeof(VAAPIEncodeH265Picture),
1133 
1134  .sequence_params_size = sizeof(VAEncSequenceParameterBufferHEVC),
1135  .init_sequence_params = &vaapi_encode_h265_init_sequence_params,
1136 
1137  .picture_params_size = sizeof(VAEncPictureParameterBufferHEVC),
1138  .init_picture_params = &vaapi_encode_h265_init_picture_params,
1139 
1140  .slice_params_size = sizeof(VAEncSliceParameterBufferHEVC),
1141  .init_slice_params = &vaapi_encode_h265_init_slice_params,
1142 
1143  .sequence_header_type = VAEncPackedHeaderSequence,
1144  .write_sequence_header = &vaapi_encode_h265_write_sequence_header,
1145 
1146  .slice_header_type = VAEncPackedHeaderHEVC_Slice,
1147  .write_slice_header = &vaapi_encode_h265_write_slice_header,
1148 
1149  .write_extra_header = &vaapi_encode_h265_write_extra_header,
1150 };
1151 
1153 {
1154  VAAPIEncodeContext *ctx = avctx->priv_data;
1155  VAAPIEncodeH265Context *priv = avctx->priv_data;
1156 
1157  ctx->codec = &vaapi_encode_type_h265;
1158 
1159  if (avctx->profile == FF_PROFILE_UNKNOWN)
1160  avctx->profile = priv->profile;
1161  if (avctx->level == FF_LEVEL_UNKNOWN)
1162  avctx->level = priv->level;
1163 
1164  if (avctx->level != FF_LEVEL_UNKNOWN && avctx->level & ~0xff) {
1165  av_log(avctx, AV_LOG_ERROR, "Invalid level %d: must fit "
1166  "in 8-bit unsigned integer.\n", avctx->level);
1167  return AVERROR(EINVAL);
1168  }
1169 
1170  ctx->desired_packed_headers =
1171  VA_ENC_PACKED_HEADER_SEQUENCE | // VPS, SPS and PPS.
1172  VA_ENC_PACKED_HEADER_SLICE | // Slice headers.
1173  VA_ENC_PACKED_HEADER_MISC; // SEI
1174 
1175  ctx->surface_width = FFALIGN(avctx->width, 16);
1176  ctx->surface_height = FFALIGN(avctx->height, 16);
1177 
1178  // CTU size is currently hard-coded to 32.
1179  ctx->slice_block_width = ctx->slice_block_height = 32;
1180 
1181  if (priv->qp > 0)
1182  ctx->explicit_qp = priv->qp;
1183 
1184  return ff_vaapi_encode_init(avctx);
1185 }
1186 
1188 {
1189  VAAPIEncodeH265Context *priv = avctx->priv_data;
1190 
1192  ff_cbs_close(&priv->cbc);
1193 
1194  return ff_vaapi_encode_close(avctx);
1195 }
1196 
1197 #define OFFSET(x) offsetof(VAAPIEncodeH265Context, x)
1198 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
1202 
1203  { "qp", "Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)",
1204  OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 52, FLAGS },
1205 
1206  { "aud", "Include AUD",
1207  OFFSET(aud), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
1208 
1209  { "profile", "Set profile (general_profile_idc)",
1211  { .i64 = FF_PROFILE_UNKNOWN }, FF_PROFILE_UNKNOWN, 0xff, FLAGS, "profile" },
1212 
1213 #define PROFILE(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
1214  { .i64 = value }, 0, 0, FLAGS, "profile"
1215  { PROFILE("main", FF_PROFILE_HEVC_MAIN) },
1216  { PROFILE("main10", FF_PROFILE_HEVC_MAIN_10) },
1217  { PROFILE("rext", FF_PROFILE_HEVC_REXT) },
1218 #undef PROFILE
1219 
1220  { "tier", "Set tier (general_tier_flag)",
1221  OFFSET(tier), AV_OPT_TYPE_INT,
1222  { .i64 = 0 }, 0, 1, FLAGS, "tier" },
1223  { "main", NULL, 0, AV_OPT_TYPE_CONST,
1224  { .i64 = 0 }, 0, 0, FLAGS, "tier" },
1225  { "high", NULL, 0, AV_OPT_TYPE_CONST,
1226  { .i64 = 1 }, 0, 0, FLAGS, "tier" },
1227 
1228  { "level", "Set level (general_level_idc)",
1230  { .i64 = FF_LEVEL_UNKNOWN }, FF_LEVEL_UNKNOWN, 0xff, FLAGS, "level" },
1231 
1232 #define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
1233  { .i64 = value }, 0, 0, FLAGS, "level"
1234  { LEVEL("1", 30) },
1235  { LEVEL("2", 60) },
1236  { LEVEL("2.1", 63) },
1237  { LEVEL("3", 90) },
1238  { LEVEL("3.1", 93) },
1239  { LEVEL("4", 120) },
1240  { LEVEL("4.1", 123) },
1241  { LEVEL("5", 150) },
1242  { LEVEL("5.1", 153) },
1243  { LEVEL("5.2", 156) },
1244  { LEVEL("6", 180) },
1245  { LEVEL("6.1", 183) },
1246  { LEVEL("6.2", 186) },
1247 #undef LEVEL
1248 
1249  { "sei", "Set SEI to include",
1252  0, INT_MAX, FLAGS, "sei" },
1253  { "hdr",
1254  "Include HDR metadata for mastering display colour volume "
1255  "and content light level information",
1256  0, AV_OPT_TYPE_CONST,
1258  INT_MIN, INT_MAX, FLAGS, "sei" },
1259 
1260  { NULL },
1261 };
1262 
1264  { "b", "0" },
1265  { "bf", "2" },
1266  { "g", "120" },
1267  { "i_qfactor", "1" },
1268  { "i_qoffset", "0" },
1269  { "b_qfactor", "6/5" },
1270  { "b_qoffset", "0" },
1271  { "qmin", "-1" },
1272  { "qmax", "-1" },
1273  { NULL },
1274 };
1275 
1277  .class_name = "h265_vaapi",
1278  .item_name = av_default_item_name,
1279  .option = vaapi_encode_h265_options,
1280  .version = LIBAVUTIL_VERSION_INT,
1281 };
1282 
1284  .name = "hevc_vaapi",
1285  .long_name = NULL_IF_CONFIG_SMALL("H.265/HEVC (VAAPI)"),
1286  .type = AVMEDIA_TYPE_VIDEO,
1287  .id = AV_CODEC_ID_HEVC,
1288  .priv_data_size = sizeof(VAAPIEncodeH265Context),
1290  .send_frame = &ff_vaapi_encode_send_frame,
1291  .receive_packet = &ff_vaapi_encode_receive_packet,
1292  .close = &vaapi_encode_h265_close,
1293  .priv_class = &vaapi_encode_h265_class,
1294  .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE,
1295  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
1297  .pix_fmts = (const enum AVPixelFormat[]) {
1300  },
1301  .hw_configs = ff_vaapi_encode_hw_configs,
1302  .wrapper_name = "vaapi",
1303 };
H265RawSliceHeader::slice_sao_chroma_flag
uint8_t slice_sao_chroma_flag
Definition: cbs_h265.h:484
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:497
H265RawVUI::log2_max_mv_length_horizontal
uint8_t log2_max_mv_length_horizontal
Definition: cbs_h265.h:181
FF_PROFILE_HEVC_REXT
#define FF_PROFILE_HEVC_REXT
Definition: avcodec.h:1950
AVCodec
AVCodec.
Definition: codec.h:190
HEVC_SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO
@ HEVC_SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO
Definition: hevc_sei.h:57
H265RawSliceHeader::colour_plane_id
uint8_t colour_plane_id
Definition: cbs_h265.h:465
bit_depth
static void bit_depth(AudioStatsContext *s, uint64_t mask, uint64_t imask, AVRational *depth)
Definition: af_astats.c:254
VAAPIEncodeSlice::codec_slice_params
void * codec_slice_params
Definition: vaapi_encode.h:64
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:454
H265RawSliceHeader::num_ref_idx_l0_active_minus1
uint8_t num_ref_idx_l0_active_minus1
Definition: cbs_h265.h:487
level
uint8_t level
Definition: svq3.c:210
H265RawVUI::bitstream_restriction_flag
uint8_t bitstream_restriction_flag
Definition: cbs_h265.h:174
init
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
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:486
H265RawProfileTierLevel::general_interlaced_source_flag
uint8_t general_interlaced_source_flag
Definition: cbs_h265.h:51
AVCodecContext::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:1154
PICTURE_TYPE_I
@ PICTURE_TYPE_I
Definition: vaapi_encode.h:52
H265RawProfileTierLevel::general_level_idc
uint8_t general_level_idc
Definition: cbs_h265.h:68
FFSWAP
#define FFSWAP(type, a, b)
Definition: common.h:99
av_frame_get_side_data
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:739
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2549
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:55
AV_CODEC_CAP_HARDWARE
#define AV_CODEC_CAP_HARDWARE
Codec is backed by a hardware implementation.
Definition: codec.h:150
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:527
VAAPIEncodeH265Context::raw_aud
H265RawAUD raw_aud
Definition: vaapi_encode_h265.c:72
H265RawVUI::colour_primaries
uint8_t colour_primaries
Definition: cbs_h265.h:148
H265RawSlice::header
H265RawSliceHeader header
Definition: cbs_h265.h:542
VAAPIEncodeH265Context::cbc
CodedBitstreamContext * cbc
Definition: vaapi_encode_h265.c:82
VAAPIEncodeH265Context::raw_pps
H265RawPPS raw_pps
Definition: vaapi_encode_h265.c:75
AVContentLightMetadata::MaxCLL
unsigned MaxCLL
Max content light level (cd/m^2).
Definition: mastering_display_metadata.h:102
profile
mfxU16 profile
Definition: qsvenc.c:45
H265RawVUI
Definition: cbs_h265.h:135
vaapi_encode_h265_add_nal
static int vaapi_encode_h265_add_nal(AVCodecContext *avctx, CodedBitstreamFragment *au, void *nal_unit)
Definition: vaapi_encode_h265.c:115
pixdesc.h
VAAPIEncodeH265Context::raw_sps
H265RawSPS raw_sps
Definition: vaapi_encode_h265.c:74
H265RawSEI
Definition: cbs_h265.h:721
AVCodecContext::color_trc
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:1147
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
the normal 2^n-1 "JPEG" YUV ranges
Definition: pixfmt.h:535
internal.h
H265RawSTRefPicSet::delta_poc_s1_minus1
uint16_t delta_poc_s1_minus1[HEVC_MAX_REFS]
Definition: cbs_h265.h:241
H265RawProfileTierLevel::general_max_8bit_constraint_flag
uint8_t general_max_8bit_constraint_flag
Definition: cbs_h265.h:57
H265RawVUI::aspect_ratio_info_present_flag
uint8_t aspect_ratio_info_present_flag
Definition: cbs_h265.h:136
CodedBitstreamContext
Context structure for coded bitstream operations.
Definition: cbs.h:168
ff_cbs_close
void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
Definition: cbs.c:115
VAAPIEncodeSlice
Definition: vaapi_encode.h:57
AVOption
AVOption.
Definition: opt.h:246
VAAPIEncodePicture::refs
struct VAAPIEncodePicture * refs[MAX_PICTURE_REFERENCES]
Definition: vaapi_encode.h:113
H265RawSTRefPicSet::used_by_curr_pic_s1_flag
uint8_t used_by_curr_pic_s1_flag[HEVC_MAX_REFS]
Definition: cbs_h265.h:242
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:483
H265RawSliceHeader::slice_temporal_mvp_enabled_flag
uint8_t slice_temporal_mvp_enabled_flag
Definition: cbs_h265.h:481
data
const char data[16]
Definition: mxf.c:91
PICTURE_TYPE_P
@ PICTURE_TYPE_P
Definition: vaapi_encode.h:53
H265RawSEIMasteringDisplayColourVolume::white_point_y
uint16_t white_point_y
Definition: cbs_h265.h:668
AVCodecContext::b_quant_offset
float b_quant_offset
qscale offset between IP and B-frames
Definition: avcodec.h:808
VAAPIEncodeSlice::block_start
int block_start
Definition: vaapi_encode.h:61
ff_cbs_fragment_free
void ff_cbs_fragment_free(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Free the units array of a fragment in addition to what ff_cbs_fragment_reset does.
Definition: cbs.c:157
HEVC_NAL_RASL_N
@ HEVC_NAL_RASL_N
Definition: hevc.h:37
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
H265RawVUI::vui_timing_info_present_flag
uint8_t vui_timing_info_present_flag
Definition: cbs_h265.h:166
ff_vaapi_encode_close
av_cold int ff_vaapi_encode_close(AVCodecContext *avctx)
Definition: vaapi_encode.c:2372
cbs.h
cbs_h265.h
FF_LEVEL_UNKNOWN
#define FF_LEVEL_UNKNOWN
Definition: avcodec.h:1983
VAAPIEncodeSlice::index
int index
Definition: vaapi_encode.h:58
VAAPIEncodePicture::nb_refs
int nb_refs
Definition: vaapi_encode.h:112
VAAPIEncodeH265Context::raw_vps
H265RawVPS raw_vps
Definition: vaapi_encode_h265.c:73
H265RawProfileTierLevel::general_frame_only_constraint_flag
uint8_t general_frame_only_constraint_flag
Definition: cbs_h265.h:53
H265RawSliceHeader::num_long_term_sps
uint8_t num_long_term_sps
Definition: cbs_h265.h:473
ff_vaapi_encode_hw_configs
const AVCodecHWConfigInternal * ff_vaapi_encode_hw_configs[]
Definition: vaapi_encode.c:30
H265RawSliceHeader::luma_log2_weight_denom
uint8_t luma_log2_weight_denom
Definition: cbs_h265.h:500
H265RawVUI::log2_max_mv_length_vertical
uint8_t log2_max_mv_length_vertical
Definition: cbs_h265.h:182
VAAPIEncodeH265Context::sei_content_light_level
H265RawSEIContentLightLevelInfo sei_content_light_level
Definition: vaapi_encode_h265.c:80
VAAPIEncodeH265Context::profile
int profile
Definition: vaapi_encode_h265.c:61
H265RawSliceHeader::five_minus_max_num_merge_cand
uint8_t five_minus_max_num_merge_cand
Definition: cbs_h265.h:515
H265LevelDescriptor
Definition: h265_profile_level.h:27
H265RawProfileTierLevel::general_max_422chroma_constraint_flag
uint8_t general_max_422chroma_constraint_flag
Definition: cbs_h265.h:58
vaapi_encode_h265_defaults
static const AVCodecDefault vaapi_encode_h265_defaults[]
Definition: vaapi_encode_h265.c:1263
H265RawSPS
Definition: cbs_h265.h:252
H265RawVPS
Definition: cbs_h265.h:191
vaapi_encode_h265_close
static av_cold int vaapi_encode_h265_close(AVCodecContext *avctx)
Definition: vaapi_encode_h265.c:1187
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:354
AVCodecContext::framerate
AVRational framerate
Definition: avcodec.h:2069
H265RawVUI::video_format
uint8_t video_format
Definition: cbs_h265.h:145
H265RawVUI::max_bits_per_min_cu_denom
uint8_t max_bits_per_min_cu_denom
Definition: cbs_h265.h:180
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:831
H265RawProfileTierLevel::general_progressive_source_flag
uint8_t general_progressive_source_flag
Definition: cbs_h265.h:50
H265RawSTRefPicSet::used_by_curr_pic_s0_flag
uint8_t used_by_curr_pic_s0_flag[HEVC_MAX_REFS]
Definition: cbs_h265.h:240
H265RawSliceHeader::num_long_term_pics
uint8_t num_long_term_pics
Definition: cbs_h265.h:474
vaapi_encode.h
fail
#define fail()
Definition: checkasm.h:123
vaapi_encode_h265_init_sequence_params
static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx)
Definition: vaapi_encode_h265.c:258
H265RawSTRefPicSet::delta_poc_s0_minus1
uint16_t delta_poc_s0_minus1[HEVC_MAX_REFS]
Definition: cbs_h265.h:239
VAAPIEncodePicture
Definition: vaapi_encode.h:67
H265RawSliceHeader::short_term_ref_pic_set
H265RawSTRefPicSet short_term_ref_pic_set
Definition: cbs_h265.h:470
vaapi_encode_h265_class
static const AVClass vaapi_encode_h265_class
Definition: vaapi_encode_h265.c:1276
defaults
static const AVCodecDefault defaults[]
Definition: amfenc_h264.c:361
H265RawProfileTierLevel::general_max_12bit_constraint_flag
uint8_t general_max_12bit_constraint_flag
Definition: cbs_h265.h:55
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:495
H265RawProfileTierLevel::general_intra_constraint_flag
uint8_t general_intra_constraint_flag
Definition: cbs_h265.h:61
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:67
H265RawVUI::sar_height
uint16_t sar_height
Definition: cbs_h265.h:139
H265RawSliceHeader::collocated_ref_idx
uint8_t collocated_ref_idx
Definition: cbs_h265.h:498
avassert.h
lrint
#define lrint
Definition: tablegen.h:53
AVCodecContext::color_primaries
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:1140
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
H265RawSliceHeader::slice_cb_qp_offset
int8_t slice_cb_qp_offset
Definition: cbs_h265.h:519
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:467
FF_PROFILE_HEVC_MAIN
#define FF_PROFILE_HEVC_MAIN
Definition: avcodec.h:1947
ptl
const H265RawProfileTierLevel * ptl
Definition: h265_levels.c:170
VAAPIEncodePicture::codec_picture_params
void * codec_picture_params
Definition: vaapi_encode.h:100
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:174
CodedBitstreamFragment
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:116
AVMasteringDisplayMetadata::white_point
AVRational white_point[2]
CIE 1931 xy chromaticity coords of white point.
Definition: mastering_display_metadata.h:47
CodedBitstreamFragment::data_size
size_t data_size
The number of bytes in the bitstream.
Definition: cbs.h:129
H265RawProfileTierLevel::general_profile_idc
uint8_t general_profile_idc
Definition: cbs_h265.h:46
FLAGS
#define FLAGS
Definition: vaapi_encode_h265.c:1198
H265RawProfileTierLevel::general_non_packed_constraint_flag
uint8_t general_non_packed_constraint_flag
Definition: cbs_h265.h:52
H265RawSliceHeader::slice_sao_luma_flag
uint8_t slice_sao_luma_flag
Definition: cbs_h265.h:483
av_q2d
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
FF_PROFILE_UNKNOWN
#define FF_PROFILE_UNKNOWN
Definition: avcodec.h:1860
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:275
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
H265RawSliceHeader::num_ref_idx_l1_active_minus1
uint8_t num_ref_idx_l1_active_minus1
Definition: cbs_h265.h:488
H265RawSTRefPicSet::num_positive_pics
uint8_t num_positive_pics
Definition: cbs_h265.h:238
H265RawSliceHeader::slice_pic_parameter_set_id
uint8_t slice_pic_parameter_set_id
Definition: cbs_h265.h:456
ctx
AVFormatContext * ctx
Definition: movenc.c:48
VAAPIEncodeH265Context::aud
int aud
Definition: vaapi_encode_h265.c:60
SEI_CONTENT_LIGHT_LEVEL
@ SEI_CONTENT_LIGHT_LEVEL
Definition: vaapi_encode_h265.c:42
ff_vaapi_encode_receive_packet
int ff_vaapi_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
Definition: vaapi_encode.c:1113
H265RawVUI::vui_time_scale
uint32_t vui_time_scale
Definition: cbs_h265.h:168
H265RawVUI::video_signal_type_present_flag
uint8_t video_signal_type_present_flag
Definition: cbs_h265.h:144
HEVC_SLICE_I
@ HEVC_SLICE_I
Definition: hevc.h:98
VAAPIEncodeH265Context::tier
int tier
Definition: vaapi_encode_h265.c:62
CodedBitstreamFragment::data_bit_padding
size_t data_bit_padding
The number of bits which should be ignored in the final byte.
Definition: cbs.h:133
ff_vaapi_encode_send_frame
int ff_vaapi_encode_send_frame(AVCodecContext *avctx, const AVFrame *frame)
Definition: vaapi_encode.c:1046
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:458
SEI_MASTERING_DISPLAY
@ SEI_MASTERING_DISPLAY
Definition: vaapi_encode_h265.c:41
VAAPIEncodeType
Definition: vaapi_encode.h:349
VAAPIEncodeH265Picture
Definition: vaapi_encode_h265.c:45
VAAPIEncodeContext
Definition: vaapi_encode.h:172
VAAPIEncodePicture::prev
struct VAAPIEncodePicture * prev
Definition: vaapi_encode.h:116
if
if(ret)
Definition: filter_design.txt:179
AVCodecDefault
Definition: internal.h:201
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
HEVC_SLICE_B
@ HEVC_SLICE_B
Definition: hevc.h:96
H265RawVUI::matrix_coefficients
uint8_t matrix_coefficients
Definition: cbs_h265.h:150
H265RawSliceHeader::slice_segment_address
uint16_t slice_segment_address
Definition: cbs_h265.h:459
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:445
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:1161
PROFILE
#define PROFILE(name, value)
H265RawSliceHeader::slice_tc_offset_div2
int8_t slice_tc_offset_div2
Definition: cbs_h265.h:529
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:469
VAAPIEncodePicture::dpb
struct VAAPIEncodePicture * dpb[MAX_DPB_SIZE]
Definition: vaapi_encode.h:109
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:166
ff_hevc_vaapi_encoder
AVCodec ff_hevc_vaapi_encoder
Definition: vaapi_encode_h265.c:1283
VAAPIEncodeType::profiles
const VAAPIEncodeProfile * profiles
Definition: vaapi_encode.h:352
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
VAAPIEncodeH265Context::aud_needed
int aud_needed
Definition: vaapi_encode_h265.c:84
AVCodecContext::bit_rate
int64_t bit_rate
the average bitrate
Definition: avcodec.h:576
MAX_DPB_SIZE
@ MAX_DPB_SIZE
Definition: vaapi_encode.h:42
OFFSET
#define OFFSET(x)
Definition: vaapi_encode_h265.c:1197
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
FF_PROFILE_HEVC_MAIN_10
#define FF_PROFILE_HEVC_MAIN_10
Definition: avcodec.h:1948
H265RawSEIMasteringDisplayColourVolume::max_display_mastering_luminance
uint32_t max_display_mastering_luminance
Definition: cbs_h265.h:669
AV_FRAME_DATA_MASTERING_DISPLAY_METADATA
@ AV_FRAME_DATA_MASTERING_DISPLAY_METADATA
Mastering display metadata associated with a video frame.
Definition: frame.h:119
H265RawSEIContentLightLevelInfo::max_content_light_level
uint16_t max_content_light_level
Definition: cbs_h265.h:674
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:89
H265RawVUI::chroma_sample_loc_type_bottom_field
uint8_t chroma_sample_loc_type_bottom_field
Definition: cbs_h265.h:154
vaapi_encode_h265_options
static const AVOption vaapi_encode_h265_options[]
Definition: vaapi_encode_h265.c:1199
vaapi_encode_h265_init_picture_params
static int vaapi_encode_h265_init_picture_params(AVCodecContext *avctx, VAAPIEncodePicture *pic)
Definition: vaapi_encode_h265.c:672
vps
static int FUNC() vps(CodedBitstreamContext *ctx, RWContext *rw, H265RawVPS *current)
Definition: cbs_h265_syntax_template.c:420
H265RawProfileTierLevel::general_max_10bit_constraint_flag
uint8_t general_max_10bit_constraint_flag
Definition: cbs_h265.h:56
H265RawVUI::vui_num_ticks_poc_diff_one_minus1
uint32_t vui_num_ticks_poc_diff_one_minus1
Definition: cbs_h265.h:170
H265RawSliceHeader::slice_type
uint8_t slice_type
Definition: cbs_h265.h:462
H265RawVUI::video_full_range_flag
uint8_t video_full_range_flag
Definition: cbs_h265.h:146
H265RawProfileTierLevel::general_tier_flag
uint8_t general_tier_flag
Definition: cbs_h265.h:45
H265RawNALUnitHeader::nal_unit_type
uint8_t nal_unit_type
Definition: cbs_h265.h:38
sei
static int FUNC() sei(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEI *current)
Definition: cbs_h264_syntax_template.c:924
AVCodecContext::level
int level
level
Definition: avcodec.h:1982
H265RawSliceHeader::slice_qp_delta
int8_t slice_qp_delta
Definition: cbs_h265.h:518
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:533
HEVC_NAL_RASL_R
@ HEVC_NAL_RASL_R
Definition: hevc.h:38
H265RawNALUnitHeader
Definition: cbs_h265.h:37
index
int index
Definition: gxfenc.c:89
vaapi_encode_h265_init
static av_cold int vaapi_encode_h265_init(AVCodecContext *avctx)
Definition: vaapi_encode_h265.c:1152
VAAPIEncodeH265Context::fixed_qp_b
int fixed_qp_b
Definition: vaapi_encode_h265.c:69
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:649
aud
static int FUNC() aud(CodedBitstreamContext *ctx, RWContext *rw, H264RawAUD *current)
Definition: cbs_h264_syntax_template.c:1006
VAAPIEncodeH265Picture::slice_type
int slice_type
Definition: vaapi_encode_h265.c:51
H265RawVUI::chroma_loc_info_present_flag
uint8_t chroma_loc_info_present_flag
Definition: cbs_h265.h:152
H265RawSEIMasteringDisplayColourVolume::display_primaries_x
uint16_t display_primaries_x[3]
Definition: cbs_h265.h:665
desc
const char * desc
Definition: nvenc.c:79
H265RawVUI::sar_width
uint16_t sar_width
Definition: cbs_h265.h:138
VAAPIEncodePicture::type
int type
Definition: vaapi_encode.h:82
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:188
pps
static int FUNC() pps(CodedBitstreamContext *ctx, RWContext *rw, H264RawPPS *current)
Definition: cbs_h264_syntax_template.c:404
FLAG_B_PICTURE_REFERENCES
@ FLAG_B_PICTURE_REFERENCES
Definition: vaapi_encode.h:343
VAAPI_ENCODE_RC_OPTIONS
#define VAAPI_ENCODE_RC_OPTIONS
Definition: vaapi_encode.h:447
H265RawSliceHeader::cabac_init_flag
uint8_t cabac_init_flag
Definition: cbs_h265.h:496
H265RawSEIMasteringDisplayColourVolume::min_display_mastering_luminance
uint32_t min_display_mastering_luminance
Definition: cbs_h265.h:670
H265RawProfileTierLevel::general_lower_bit_rate_constraint_flag
uint8_t general_lower_bit_rate_constraint_flag
Definition: cbs_h265.h:63
CodedBitstreamFragment::data
uint8_t * data
Pointer to the bitstream form of this fragment.
Definition: cbs.h:122
VAAPIEncodeH265Context::raw_slice
H265RawSlice raw_slice
Definition: vaapi_encode_h265.c:77
H265RawProfileTierLevel::general_max_monochrome_constraint_flag
uint8_t general_max_monochrome_constraint_flag
Definition: cbs_h265.h:60
AVFrameSideData::data
uint8_t * data
Definition: frame.h:208
h265_profile_level.h
AVCHROMA_LOC_UNSPECIFIED
@ AVCHROMA_LOC_UNSPECIFIED
Definition: pixfmt.h:555
H265RawSliceHeader::dependent_slice_segment_flag
uint8_t dependent_slice_segment_flag
Definition: cbs_h265.h:458
H265RawSliceHeader::slice_cr_qp_offset
int8_t slice_cr_qp_offset
Definition: cbs_h265.h:520
header
static const uint8_t header[24]
Definition: sdr2.c:67
FLAG_NON_IDR_KEY_PICTURES
@ FLAG_NON_IDR_KEY_PICTURES
Definition: vaapi_encode.h:346
H265RawAUD::nal_unit_header
H265RawNALUnitHeader nal_unit_header
Definition: cbs_h265.h:446
vaapi_encode_type_h265
static const VAAPIEncodeType vaapi_encode_type_h265
Definition: vaapi_encode_h265.c:1120
vaapi_encode_h265_profiles
static const VAAPIEncodeProfile vaapi_encode_h265_profiles[]
Definition: vaapi_encode_h265.c:1110
VAAPI_ENCODE_COMMON_OPTIONS
#define VAAPI_ENCODE_COMMON_OPTIONS
Definition: vaapi_encode.h:429
FFMIN
#define FFMIN(a, b)
Definition: common.h:96
VAAPIEncodePicture::recon_surface
VASurfaceID recon_surface
Definition: vaapi_encode.h:91
VAAPIEncodePicture::output_buffer
VABufferID output_buffer
Definition: vaapi_encode.h:97
VAAPIEncodePicture::priv_data
void * priv_data
Definition: vaapi_encode.h:99
vaapi_encode_h265_configure
static av_cold int vaapi_encode_h265_configure(AVCodecContext *avctx)
Definition: vaapi_encode_h265.c:1065
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:871
H265RawVUI::chroma_sample_loc_type_top_field
uint8_t chroma_sample_loc_type_top_field
Definition: cbs_h265.h:153
VAAPIEncodePicture::display_order
int64_t display_order
Definition: vaapi_encode.h:70
AV_PIX_FMT_VAAPI
@ AV_PIX_FMT_VAAPI
Definition: pixfmt.h:122
VAAPIEncodePicture::nb_dpb_pics
int nb_dpb_pics
Definition: vaapi_encode.h:108
VAAPIEncodePicture::b_depth
int b_depth
Definition: vaapi_encode.h:83
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:795
H265RawVUI::max_bytes_per_pic_denom
uint8_t max_bytes_per_pic_denom
Definition: cbs_h265.h:179
H265RawSliceHeader
Definition: cbs_h265.h:451
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:136
H265RawSEIContentLightLevelInfo
Definition: cbs_h265.h:673
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
VAAPIEncodeH265Picture::slice_nal_unit
int slice_nal_unit
Definition: vaapi_encode_h265.c:50
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: internal.h:48
H265RawVUI::vui_hrd_parameters_present_flag
uint8_t vui_hrd_parameters_present_flag
Definition: cbs_h265.h:171
HEVC_SEI_TYPE_MASTERING_DISPLAY_INFO
@ HEVC_SEI_TYPE_MASTERING_DISPLAY_INFO
Definition: hevc_sei.h:56
VAAPIEncodeContext::input_frames
AVHWFramesContext * input_frames
Definition: vaapi_encode.h:246
VAAPIEncodeH265Context
Definition: vaapi_encode_h265.c:55
common.h
H265RawVUI::vui_num_units_in_tick
uint32_t vui_num_units_in_tick
Definition: cbs_h265.h:167
FLAG_SLICE_CONTROL
@ FLAG_SLICE_CONTROL
Definition: vaapi_encode.h:335
AV_CODEC_ID_HEVC
@ AV_CODEC_ID_HEVC
Definition: codec_id.h:223
HEVC_SLICE_P
@ HEVC_SLICE_P
Definition: hevc.h:97
H265RawSliceHeader::nal_unit_header
H265RawNALUnitHeader nal_unit_header
Definition: cbs_h265.h:452
H265RawSliceHeader::slice_beta_offset_div2
int8_t slice_beta_offset_div2
Definition: cbs_h265.h:528
H265RawSTRefPicSet
Definition: cbs_h265.h:227
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:197
AVCodecContext::chroma_sample_location
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
Definition: avcodec.h:1168
AVMasteringDisplayMetadata
Mastering display metadata capable of representing the color volume of the display used to master the...
Definition: mastering_display_metadata.h:38
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:512
AVCodecContext::height
int height
Definition: avcodec.h:699
H265RawProfileTierLevel
Definition: cbs_h265.h:43
H265RawProfileTierLevel::general_max_420chroma_constraint_flag
uint8_t general_max_420chroma_constraint_flag
Definition: cbs_h265.h:59
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:340
hevc.h
H265RawProfileTierLevel::general_profile_space
uint8_t general_profile_space
Definition: cbs_h265.h:44
avcodec.h
HEVC_NAL_VPS
@ HEVC_NAL_VPS
Definition: hevc.h:61
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:48
ff_vaapi_encode_init
av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
Definition: vaapi_encode.c:2210
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:72
VAAPIEncodeH265Context::common
VAAPIEncodeContext common
Definition: vaapi_encode_h265.c:56
sps
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
Definition: cbs_h264_syntax_template.c:260
ff_cbs_init
int ff_cbs_init(CodedBitstreamContext **ctx_ptr, enum AVCodecID codec_id, void *log_ctx)
Create and initialise a new context for the given codec.
Definition: cbs.c:74
VAAPIEncodeH265Context::fixed_qp_p
int fixed_qp_p
Definition: vaapi_encode_h265.c:68
LEVEL
#define LEVEL(name, value)
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen_template.c:38
VAAPIEncodeH265Context::raw_sei
H265RawSEI raw_sei
Definition: vaapi_encode_h265.c:76
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:530
HEVC_NAL_AUD
@ HEVC_NAL_AUD
Definition: hevc.h:64
AVCodecContext
main external API structure.
Definition: avcodec.h:526
H265RawSTRefPicSet::num_negative_pics
uint8_t num_negative_pics
Definition: cbs_h265.h:237
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:134
H265RawSEIMasteringDisplayColourVolume::white_point_x
uint16_t white_point_x
Definition: cbs_h265.h:667
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
H265RawVUI::colour_description_present_flag
uint8_t colour_description_present_flag
Definition: cbs_h265.h:147
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:223
AVCodecContext::profile
int profile
profile
Definition: avcodec.h:1859
VAAPIEncodeH265Context::qp
int qp
Definition: vaapi_encode_h265.c:59
AVCodecContext::i_quant_offset
float i_quant_offset
qscale offset between P and I-frames
Definition: avcodec.h:838
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:107
PICTURE_TYPE_B
@ PICTURE_TYPE_B
Definition: vaapi_encode.h:54
H265RawSEIMasteringDisplayColourVolume::display_primaries_y
uint16_t display_primaries_y[3]
Definition: cbs_h265.h:666
ff_cbs_fragment_reset
void ff_cbs_fragment_reset(CodedBitstreamContext *ctx, 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:142
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:75
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:52
H265RawVUI::transfer_characteristics
uint8_t transfer_characteristics
Definition: cbs_h265.h:149
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
HEVC_NAL_SPS
@ HEVC_NAL_SPS
Definition: hevc.h:62
PICTURE_TYPE_IDR
@ PICTURE_TYPE_IDR
Definition: vaapi_encode.h:51
ff_cbs_insert_unit_content
int ff_cbs_insert_unit_content(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int position, CodedBitstreamUnitType type, void *content, AVBufferRef *content_buf)
Insert a new unit into a fragment with the given content.
Definition: cbs.c:722
mastering_display_metadata.h
FLAG_B_PICTURES
@ FLAG_B_PICTURES
Definition: vaapi_encode.h:341
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:192
VAAPIEncodePicture::input_image
AVFrame * input_image
Definition: vaapi_encode.h:87
VAAPIEncodeSlice::block_size
int block_size
Definition: vaapi_encode.h:62
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:206
VAAPIEncodeH265Picture::last_idr_frame
int64_t last_idr_frame
Definition: vaapi_encode_h265.c:48
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
VAAPIEncodeH265Context::sei
int sei
Definition: vaapi_encode_h265.c:64
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:48
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:553
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:240
VAAPIEncodePicture::encode_order
int64_t encode_order
Definition: vaapi_encode.h:71
VAAPIEncodeH265Context::current_access_unit
CodedBitstreamFragment current_access_unit
Definition: vaapi_encode_h265.c:83
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:699
AV_OPT_TYPE_FLAGS
@ AV_OPT_TYPE_FLAGS
Definition: opt.h:222
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
H265RawVUI::vui_poc_proportional_to_timing_flag
uint8_t vui_poc_proportional_to_timing_flag
Definition: cbs_h265.h:169
VAAPIEncodeH265Context::sei_mastering_display
H265RawSEIMasteringDisplayColourVolume sei_mastering_display
Definition: vaapi_encode_h265.c:79
VAAPIEncodeH265Context::level
int level
Definition: vaapi_encode_h265.c:63
H265RawSEIMasteringDisplayColourVolume
Definition: cbs_h265.h:664
H265RawVUI::aspect_ratio_idc
uint8_t aspect_ratio_idc
Definition: cbs_h265.h:137
HEVC_NAL_SEI_PREFIX
@ HEVC_NAL_SEI_PREFIX
Definition: hevc.h:68
put_bits.h
H265RawVUI::restricted_ref_pic_lists_flag
uint8_t restricted_ref_pic_lists_flag
Definition: cbs_h265.h:177
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:232
hevc_sei.h
H265RawSliceHeader::delta_chroma_log2_weight_denom
int8_t delta_chroma_log2_weight_denom
Definition: cbs_h265.h:501
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:905
VAAPIEncodeProfile
Definition: vaapi_encode.h:127
H265RawVUI::motion_vectors_over_pic_boundaries_flag
uint8_t motion_vectors_over_pic_boundaries_flag
Definition: cbs_h265.h:176
H265RawSlice
Definition: cbs_h265.h:541
VAAPIEncodePicture::nb_slices
int nb_slices
Definition: vaapi_encode.h:123
VAAPIEncodeH265Context::sei_needed
int sei_needed
Definition: vaapi_encode_h265.c:85
VAAPIEncodeH265Picture::pic_order_cnt
int pic_order_cnt
Definition: vaapi_encode_h265.c:46