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