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