2 * This file is part of FFmpeg.
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.
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.
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
22 #include <va/va_enc_hevc.h>
24 #include "libavutil/avassert.h"
25 #include "libavutil/common.h"
26 #include "libavutil/pixdesc.h"
27 #include "libavutil/opt.h"
28 #include "libavutil/mastering_display_metadata.h"
33 #include "h265_profile_level.h"
38 #include "vaapi_encode.h"
41 SEI_MASTERING_DISPLAY = 0x08,
42 SEI_CONTENT_LIGHT_LEVEL = 0x10,
45 typedef struct VAAPIEncodeH265Picture {
48 int64_t last_idr_frame;
53 } VAAPIEncodeH265Picture;
55 typedef struct VAAPIEncodeH265Context {
56 VAAPIEncodeContext common;
77 H265RawSlice raw_slice;
79 H265RawSEIMasteringDisplayColourVolume sei_mastering_display;
80 H265RawSEIContentLightLevelInfo sei_content_light_level;
82 CodedBitstreamContext *cbc;
83 CodedBitstreamFragment current_access_unit;
86 } VAAPIEncodeH265Context;
89 static int vaapi_encode_h265_write_access_unit(AVCodecContext *avctx,
90 char *data, size_t *data_len,
91 CodedBitstreamFragment *au)
93 VAAPIEncodeH265Context *priv = avctx->priv_data;
96 err = ff_cbs_write_fragment_data(priv->cbc, au);
98 av_log(avctx, AV_LOG_ERROR, "Failed to write packed header.\n");
102 if (*data_len < 8 * au->data_size - au->data_bit_padding) {
103 av_log(avctx, AV_LOG_ERROR, "Access unit too large: "
104 "%zu < %zu.\n", *data_len,
105 8 * au->data_size - au->data_bit_padding);
106 return AVERROR(ENOSPC);
109 memcpy(data, au->data, au->data_size);
110 *data_len = 8 * au->data_size - au->data_bit_padding;
115 static int vaapi_encode_h265_add_nal(AVCodecContext *avctx,
116 CodedBitstreamFragment *au,
119 VAAPIEncodeH265Context *priv = avctx->priv_data;
120 H265RawNALUnitHeader *header = nal_unit;
123 err = ff_cbs_insert_unit_content(priv->cbc, au, -1,
124 header->nal_unit_type, nal_unit, NULL);
126 av_log(avctx, AV_LOG_ERROR, "Failed to add NAL unit: "
127 "type = %d.\n", header->nal_unit_type);
134 static int vaapi_encode_h265_write_sequence_header(AVCodecContext *avctx,
135 char *data, size_t *data_len)
137 VAAPIEncodeH265Context *priv = avctx->priv_data;
138 CodedBitstreamFragment *au = &priv->current_access_unit;
141 if (priv->aud_needed) {
142 err = vaapi_encode_h265_add_nal(avctx, au, &priv->raw_aud);
145 priv->aud_needed = 0;
148 err = vaapi_encode_h265_add_nal(avctx, au, &priv->raw_vps);
152 err = vaapi_encode_h265_add_nal(avctx, au, &priv->raw_sps);
156 err = vaapi_encode_h265_add_nal(avctx, au, &priv->raw_pps);
160 err = vaapi_encode_h265_write_access_unit(avctx, data, data_len, au);
162 ff_cbs_fragment_uninit(priv->cbc, au);
166 static int vaapi_encode_h265_write_slice_header(AVCodecContext *avctx,
167 VAAPIEncodePicture *pic,
168 VAAPIEncodeSlice *slice,
169 char *data, size_t *data_len)
171 VAAPIEncodeH265Context *priv = avctx->priv_data;
172 CodedBitstreamFragment *au = &priv->current_access_unit;
175 if (priv->aud_needed) {
176 err = vaapi_encode_h265_add_nal(avctx, au, &priv->raw_aud);
179 priv->aud_needed = 0;
182 err = vaapi_encode_h265_add_nal(avctx, au, &priv->raw_slice);
186 err = vaapi_encode_h265_write_access_unit(avctx, data, data_len, au);
188 ff_cbs_fragment_uninit(priv->cbc, au);
192 static int vaapi_encode_h265_write_extra_header(AVCodecContext *avctx,
193 VAAPIEncodePicture *pic,
194 int index, int *type,
195 char *data, size_t *data_len)
197 VAAPIEncodeH265Context *priv = avctx->priv_data;
198 CodedBitstreamFragment *au = &priv->current_access_unit;
201 if (priv->sei_needed) {
202 H265RawSEI *sei = &priv->raw_sei;
204 if (priv->aud_needed) {
205 err = vaapi_encode_h265_add_nal(avctx, au, &priv->aud);
208 priv->aud_needed = 0;
211 *sei = (H265RawSEI) {
213 .nal_unit_type = HEVC_NAL_SEI_PREFIX,
215 .nuh_temporal_id_plus1 = 1,
221 if (priv->sei_needed & SEI_MASTERING_DISPLAY) {
222 sei->payload[i].payload_type = HEVC_SEI_TYPE_MASTERING_DISPLAY_INFO;
223 sei->payload[i].payload.mastering_display = priv->sei_mastering_display;
227 if (priv->sei_needed & SEI_CONTENT_LIGHT_LEVEL) {
228 sei->payload[i].payload_type = HEVC_SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO;
229 sei->payload[i].payload.content_light_level = priv->sei_content_light_level;
233 sei->payload_count = i;
234 av_assert0(sei->payload_count > 0);
236 err = vaapi_encode_h265_add_nal(avctx, au, sei);
239 priv->sei_needed = 0;
241 err = vaapi_encode_h265_write_access_unit(avctx, data, data_len, au);
245 ff_cbs_fragment_uninit(priv->cbc, au);
247 *type = VAEncPackedHeaderRawData;
254 ff_cbs_fragment_uninit(priv->cbc, au);
258 static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx)
260 VAAPIEncodeContext *ctx = avctx->priv_data;
261 VAAPIEncodeH265Context *priv = avctx->priv_data;
262 H265RawVPS *vps = &priv->raw_vps;
263 H265RawSPS *sps = &priv->raw_sps;
264 H265RawPPS *pps = &priv->raw_pps;
265 H265RawProfileTierLevel *ptl = &vps->profile_tier_level;
266 H265RawVUI *vui = &sps->vui;
267 VAEncSequenceParameterBufferHEVC *vseq = ctx->codec_sequence_params;
268 VAEncPictureParameterBufferHEVC *vpic = ctx->codec_picture_params;
269 const AVPixFmtDescriptor *desc;
270 int chroma_format, bit_depth;
273 memset(&priv->current_access_unit, 0,
274 sizeof(priv->current_access_unit));
276 memset(vps, 0, sizeof(*vps));
277 memset(sps, 0, sizeof(*sps));
278 memset(pps, 0, sizeof(*pps));
281 desc = av_pix_fmt_desc_get(priv->common.input_frames->sw_format);
283 if (desc->nb_components == 1) {
286 if (desc->log2_chroma_w == 1 && desc->log2_chroma_h == 1) {
288 } else if (desc->log2_chroma_w == 1 && desc->log2_chroma_h == 0) {
290 } else if (desc->log2_chroma_w == 0 && desc->log2_chroma_h == 0) {
293 av_log(avctx, AV_LOG_ERROR, "Chroma format of input pixel format "
294 "%s is not supported.\n", desc->name);
295 return AVERROR(EINVAL);
298 bit_depth = desc->comp[0].depth;
303 vps->nal_unit_header = (H265RawNALUnitHeader) {
304 .nal_unit_type = HEVC_NAL_VPS,
306 .nuh_temporal_id_plus1 = 1,
309 vps->vps_video_parameter_set_id = 0;
311 vps->vps_base_layer_internal_flag = 1;
312 vps->vps_base_layer_available_flag = 1;
313 vps->vps_max_layers_minus1 = 0;
314 vps->vps_max_sub_layers_minus1 = 0;
315 vps->vps_temporal_id_nesting_flag = 1;
317 ptl->general_profile_space = 0;
318 ptl->general_profile_idc = avctx->profile;
319 ptl->general_tier_flag = priv->tier;
321 if (chroma_format == 1) {
322 ptl->general_profile_compatibility_flag[1] = bit_depth == 8;
323 ptl->general_profile_compatibility_flag[2] = bit_depth <= 10;
325 ptl->general_profile_compatibility_flag[4] = 1;
327 ptl->general_progressive_source_flag = 1;
328 ptl->general_interlaced_source_flag = 0;
329 ptl->general_non_packed_constraint_flag = 1;
330 ptl->general_frame_only_constraint_flag = 1;
332 ptl->general_max_12bit_constraint_flag = bit_depth <= 12;
333 ptl->general_max_10bit_constraint_flag = bit_depth <= 10;
334 ptl->general_max_8bit_constraint_flag = bit_depth == 8;
336 ptl->general_max_422chroma_constraint_flag = chroma_format <= 2;
337 ptl->general_max_420chroma_constraint_flag = chroma_format <= 1;
338 ptl->general_max_monochrome_constraint_flag = chroma_format == 0;
340 ptl->general_intra_constraint_flag = ctx->gop_size == 1;
342 ptl->general_lower_bit_rate_constraint_flag = 1;
344 if (avctx->level != FF_LEVEL_UNKNOWN) {
345 ptl->general_level_idc = avctx->level;
347 const H265LevelDescriptor *level;
349 level = ff_h265_guess_level(ptl, avctx->bit_rate,
350 ctx->surface_width, ctx->surface_height,
351 ctx->nb_slices, 1, 1,
352 (ctx->b_per_p > 0) + 1);
354 av_log(avctx, AV_LOG_VERBOSE, "Using level %s.\n", level->name);
355 ptl->general_level_idc = level->level_idc;
357 av_log(avctx, AV_LOG_VERBOSE, "Stream will not conform to "
358 "any normal level; using level 8.5.\n");
359 ptl->general_level_idc = 255;
360 // The tier flag must be set in level 8.5.
361 ptl->general_tier_flag = 1;
365 vps->vps_sub_layer_ordering_info_present_flag = 0;
366 vps->vps_max_dec_pic_buffering_minus1[0] = ctx->max_b_depth + 1;
367 vps->vps_max_num_reorder_pics[0] = ctx->max_b_depth;
368 vps->vps_max_latency_increase_plus1[0] = 0;
370 vps->vps_max_layer_id = 0;
371 vps->vps_num_layer_sets_minus1 = 0;
372 vps->layer_id_included_flag[0][0] = 1;
374 vps->vps_timing_info_present_flag = 1;
375 if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
376 vps->vps_num_units_in_tick = avctx->framerate.den;
377 vps->vps_time_scale = avctx->framerate.num;
378 vps->vps_poc_proportional_to_timing_flag = 1;
379 vps->vps_num_ticks_poc_diff_one_minus1 = 0;
381 vps->vps_num_units_in_tick = avctx->time_base.num;
382 vps->vps_time_scale = avctx->time_base.den;
383 vps->vps_poc_proportional_to_timing_flag = 0;
385 vps->vps_num_hrd_parameters = 0;
390 sps->nal_unit_header = (H265RawNALUnitHeader) {
391 .nal_unit_type = HEVC_NAL_SPS,
393 .nuh_temporal_id_plus1 = 1,
396 sps->sps_video_parameter_set_id = vps->vps_video_parameter_set_id;
398 sps->sps_max_sub_layers_minus1 = vps->vps_max_sub_layers_minus1;
399 sps->sps_temporal_id_nesting_flag = vps->vps_temporal_id_nesting_flag;
401 sps->profile_tier_level = vps->profile_tier_level;
403 sps->sps_seq_parameter_set_id = 0;
405 sps->chroma_format_idc = chroma_format;
406 sps->separate_colour_plane_flag = 0;
408 sps->pic_width_in_luma_samples = ctx->surface_width;
409 sps->pic_height_in_luma_samples = ctx->surface_height;
411 if (avctx->width != ctx->surface_width ||
412 avctx->height != ctx->surface_height) {
413 sps->conformance_window_flag = 1;
414 sps->conf_win_left_offset = 0;
415 sps->conf_win_right_offset =
416 (ctx->surface_width - avctx->width) / 2;
417 sps->conf_win_top_offset = 0;
418 sps->conf_win_bottom_offset =
419 (ctx->surface_height - avctx->height) / 2;
421 sps->conformance_window_flag = 0;
424 sps->bit_depth_luma_minus8 = bit_depth - 8;
425 sps->bit_depth_chroma_minus8 = bit_depth - 8;
427 sps->log2_max_pic_order_cnt_lsb_minus4 = 8;
429 sps->sps_sub_layer_ordering_info_present_flag =
430 vps->vps_sub_layer_ordering_info_present_flag;
431 for (i = 0; i <= sps->sps_max_sub_layers_minus1; i++) {
432 sps->sps_max_dec_pic_buffering_minus1[i] =
433 vps->vps_max_dec_pic_buffering_minus1[i];
434 sps->sps_max_num_reorder_pics[i] =
435 vps->vps_max_num_reorder_pics[i];
436 sps->sps_max_latency_increase_plus1[i] =
437 vps->vps_max_latency_increase_plus1[i];
440 // These have to come from the capabilities of the encoder. We have no
441 // way to query them, so just hardcode parameters which work on the Intel
443 // CTB size from 8x8 to 32x32.
444 sps->log2_min_luma_coding_block_size_minus3 = 0;
445 sps->log2_diff_max_min_luma_coding_block_size = 2;
446 // Transform size from 4x4 to 32x32.
447 sps->log2_min_luma_transform_block_size_minus2 = 0;
448 sps->log2_diff_max_min_luma_transform_block_size = 3;
449 // Full transform hierarchy allowed (2-5).
450 sps->max_transform_hierarchy_depth_inter = 3;
451 sps->max_transform_hierarchy_depth_intra = 3;
453 sps->amp_enabled_flag = 1;
454 // SAO and temporal MVP do not work.
455 sps->sample_adaptive_offset_enabled_flag = 0;
456 sps->sps_temporal_mvp_enabled_flag = 0;
458 sps->pcm_enabled_flag = 0;
460 // STRPSs should ideally be here rather than defined individually in
461 // each slice, but the structure isn't completely fixed so for now
463 sps->num_short_term_ref_pic_sets = 0;
464 sps->long_term_ref_pics_present_flag = 0;
466 sps->vui_parameters_present_flag = 1;
468 if (avctx->sample_aspect_ratio.num != 0 &&
469 avctx->sample_aspect_ratio.den != 0) {
470 static const AVRational sar_idc[] = {
472 { 1, 1 }, { 12, 11 }, { 10, 11 }, { 16, 11 },
473 { 40, 33 }, { 24, 11 }, { 20, 11 }, { 32, 11 },
474 { 80, 33 }, { 18, 11 }, { 15, 11 }, { 64, 33 },
475 { 160, 99 }, { 4, 3 }, { 3, 2 }, { 2, 1 },
478 av_reduce(&num, &den, avctx->sample_aspect_ratio.num,
479 avctx->sample_aspect_ratio.den, 65535);
480 for (i = 0; i < FF_ARRAY_ELEMS(sar_idc); i++) {
481 if (num == sar_idc[i].num &&
482 den == sar_idc[i].den) {
483 vui->aspect_ratio_idc = i;
487 if (i >= FF_ARRAY_ELEMS(sar_idc)) {
488 vui->aspect_ratio_idc = 255;
489 vui->sar_width = num;
490 vui->sar_height = den;
492 vui->aspect_ratio_info_present_flag = 1;
495 if (avctx->color_range != AVCOL_RANGE_UNSPECIFIED ||
496 avctx->color_primaries != AVCOL_PRI_UNSPECIFIED ||
497 avctx->color_trc != AVCOL_TRC_UNSPECIFIED ||
498 avctx->colorspace != AVCOL_SPC_UNSPECIFIED) {
499 vui->video_signal_type_present_flag = 1;
500 vui->video_format = 5; // Unspecified.
501 vui->video_full_range_flag =
502 avctx->color_range == AVCOL_RANGE_JPEG;
504 if (avctx->color_primaries != AVCOL_PRI_UNSPECIFIED ||
505 avctx->color_trc != AVCOL_TRC_UNSPECIFIED ||
506 avctx->colorspace != AVCOL_SPC_UNSPECIFIED) {
507 vui->colour_description_present_flag = 1;
508 vui->colour_primaries = avctx->color_primaries;
509 vui->transfer_characteristics = avctx->color_trc;
510 vui->matrix_coefficients = avctx->colorspace;
513 vui->video_format = 5;
514 vui->video_full_range_flag = 0;
515 vui->colour_primaries = avctx->color_primaries;
516 vui->transfer_characteristics = avctx->color_trc;
517 vui->matrix_coefficients = avctx->colorspace;
520 if (avctx->chroma_sample_location != AVCHROMA_LOC_UNSPECIFIED) {
521 vui->chroma_loc_info_present_flag = 1;
522 vui->chroma_sample_loc_type_top_field =
523 vui->chroma_sample_loc_type_bottom_field =
524 avctx->chroma_sample_location - 1;
527 vui->vui_timing_info_present_flag = 1;
528 vui->vui_num_units_in_tick = vps->vps_num_units_in_tick;
529 vui->vui_time_scale = vps->vps_time_scale;
530 vui->vui_poc_proportional_to_timing_flag = vps->vps_poc_proportional_to_timing_flag;
531 vui->vui_num_ticks_poc_diff_one_minus1 = vps->vps_num_ticks_poc_diff_one_minus1;
532 vui->vui_hrd_parameters_present_flag = 0;
534 vui->bitstream_restriction_flag = 1;
535 vui->motion_vectors_over_pic_boundaries_flag = 1;
536 vui->restricted_ref_pic_lists_flag = 1;
537 vui->max_bytes_per_pic_denom = 0;
538 vui->max_bits_per_min_cu_denom = 0;
539 vui->log2_max_mv_length_horizontal = 15;
540 vui->log2_max_mv_length_vertical = 15;
545 pps->nal_unit_header = (H265RawNALUnitHeader) {
546 .nal_unit_type = HEVC_NAL_PPS,
548 .nuh_temporal_id_plus1 = 1,
551 pps->pps_pic_parameter_set_id = 0;
552 pps->pps_seq_parameter_set_id = sps->sps_seq_parameter_set_id;
554 pps->num_ref_idx_l0_default_active_minus1 = 0;
555 pps->num_ref_idx_l1_default_active_minus1 = 0;
557 pps->init_qp_minus26 = priv->fixed_qp_idr - 26;
559 pps->cu_qp_delta_enabled_flag = (ctx->va_rc_mode != VA_RC_CQP);
560 pps->diff_cu_qp_delta_depth = 0;
562 pps->pps_loop_filter_across_slices_enabled_flag = 1;
565 // Fill VAAPI parameter buffers.
567 *vseq = (VAEncSequenceParameterBufferHEVC) {
568 .general_profile_idc = vps->profile_tier_level.general_profile_idc,
569 .general_level_idc = vps->profile_tier_level.general_level_idc,
570 .general_tier_flag = vps->profile_tier_level.general_tier_flag,
572 .intra_period = ctx->gop_size,
573 .intra_idr_period = ctx->gop_size,
574 .ip_period = ctx->b_per_p + 1,
575 .bits_per_second = ctx->va_bit_rate,
577 .pic_width_in_luma_samples = sps->pic_width_in_luma_samples,
578 .pic_height_in_luma_samples = sps->pic_height_in_luma_samples,
581 .chroma_format_idc = sps->chroma_format_idc,
582 .separate_colour_plane_flag = sps->separate_colour_plane_flag,
583 .bit_depth_luma_minus8 = sps->bit_depth_luma_minus8,
584 .bit_depth_chroma_minus8 = sps->bit_depth_chroma_minus8,
585 .scaling_list_enabled_flag = sps->scaling_list_enabled_flag,
586 .strong_intra_smoothing_enabled_flag =
587 sps->strong_intra_smoothing_enabled_flag,
588 .amp_enabled_flag = sps->amp_enabled_flag,
589 .sample_adaptive_offset_enabled_flag =
590 sps->sample_adaptive_offset_enabled_flag,
591 .pcm_enabled_flag = sps->pcm_enabled_flag,
592 .pcm_loop_filter_disabled_flag = sps->pcm_loop_filter_disabled_flag,
593 .sps_temporal_mvp_enabled_flag = sps->sps_temporal_mvp_enabled_flag,
596 .log2_min_luma_coding_block_size_minus3 =
597 sps->log2_min_luma_coding_block_size_minus3,
598 .log2_diff_max_min_luma_coding_block_size =
599 sps->log2_diff_max_min_luma_coding_block_size,
600 .log2_min_transform_block_size_minus2 =
601 sps->log2_min_luma_transform_block_size_minus2,
602 .log2_diff_max_min_transform_block_size =
603 sps->log2_diff_max_min_luma_transform_block_size,
604 .max_transform_hierarchy_depth_inter =
605 sps->max_transform_hierarchy_depth_inter,
606 .max_transform_hierarchy_depth_intra =
607 sps->max_transform_hierarchy_depth_intra,
609 .pcm_sample_bit_depth_luma_minus1 =
610 sps->pcm_sample_bit_depth_luma_minus1,
611 .pcm_sample_bit_depth_chroma_minus1 =
612 sps->pcm_sample_bit_depth_chroma_minus1,
613 .log2_min_pcm_luma_coding_block_size_minus3 =
614 sps->log2_min_pcm_luma_coding_block_size_minus3,
615 .log2_max_pcm_luma_coding_block_size_minus3 =
616 sps->log2_min_pcm_luma_coding_block_size_minus3 +
617 sps->log2_diff_max_min_pcm_luma_coding_block_size,
619 .vui_parameters_present_flag = 0,
622 *vpic = (VAEncPictureParameterBufferHEVC) {
623 .decoded_curr_pic = {
624 .picture_id = VA_INVALID_ID,
625 .flags = VA_PICTURE_HEVC_INVALID,
628 .coded_buf = VA_INVALID_ID,
630 .collocated_ref_pic_index = 0xff,
634 .pic_init_qp = pps->init_qp_minus26 + 26,
635 .diff_cu_qp_delta_depth = pps->diff_cu_qp_delta_depth,
636 .pps_cb_qp_offset = pps->pps_cb_qp_offset,
637 .pps_cr_qp_offset = pps->pps_cr_qp_offset,
639 .num_tile_columns_minus1 = pps->num_tile_columns_minus1,
640 .num_tile_rows_minus1 = pps->num_tile_rows_minus1,
642 .log2_parallel_merge_level_minus2 = pps->log2_parallel_merge_level_minus2,
643 .ctu_max_bitsize_allowed = 0,
645 .num_ref_idx_l0_default_active_minus1 =
646 pps->num_ref_idx_l0_default_active_minus1,
647 .num_ref_idx_l1_default_active_minus1 =
648 pps->num_ref_idx_l1_default_active_minus1,
650 .slice_pic_parameter_set_id = pps->pps_pic_parameter_set_id,
653 .sign_data_hiding_enabled_flag = pps->sign_data_hiding_enabled_flag,
654 .constrained_intra_pred_flag = pps->constrained_intra_pred_flag,
655 .transform_skip_enabled_flag = pps->transform_skip_enabled_flag,
656 .cu_qp_delta_enabled_flag = pps->cu_qp_delta_enabled_flag,
657 .weighted_pred_flag = pps->weighted_pred_flag,
658 .weighted_bipred_flag = pps->weighted_bipred_flag,
659 .transquant_bypass_enabled_flag = pps->transquant_bypass_enabled_flag,
660 .tiles_enabled_flag = pps->tiles_enabled_flag,
661 .entropy_coding_sync_enabled_flag = pps->entropy_coding_sync_enabled_flag,
662 .loop_filter_across_tiles_enabled_flag =
663 pps->loop_filter_across_tiles_enabled_flag,
664 .scaling_list_data_present_flag = (sps->sps_scaling_list_data_present_flag |
665 pps->pps_scaling_list_data_present_flag),
666 .screen_content_flag = 0,
667 .enable_gpu_weighted_prediction = 0,
668 .no_output_of_prior_pics_flag = 0,
675 static int vaapi_encode_h265_init_picture_params(AVCodecContext *avctx,
676 VAAPIEncodePicture *pic)
678 VAAPIEncodeContext *ctx = avctx->priv_data;
679 VAAPIEncodeH265Context *priv = avctx->priv_data;
680 VAAPIEncodeH265Picture *hpic = pic->priv_data;
681 VAAPIEncodePicture *prev = pic->prev;
682 VAAPIEncodeH265Picture *hprev = prev ? prev->priv_data : NULL;
683 VAEncPictureParameterBufferHEVC *vpic = pic->codec_picture_params;
686 if (pic->type == PICTURE_TYPE_IDR) {
687 av_assert0(pic->display_order == pic->encode_order);
689 hpic->last_idr_frame = pic->display_order;
691 hpic->slice_nal_unit = HEVC_NAL_IDR_W_RADL;
692 hpic->slice_type = HEVC_SLICE_I;
696 hpic->last_idr_frame = hprev->last_idr_frame;
698 if (pic->type == PICTURE_TYPE_I) {
699 hpic->slice_nal_unit = HEVC_NAL_CRA_NUT;
700 hpic->slice_type = HEVC_SLICE_I;
702 } else if (pic->type == PICTURE_TYPE_P) {
703 av_assert0(pic->refs[0]);
704 hpic->slice_nal_unit = HEVC_NAL_TRAIL_R;
705 hpic->slice_type = HEVC_SLICE_P;
708 VAAPIEncodePicture *irap_ref;
709 av_assert0(pic->refs[0] && pic->refs[1]);
710 for (irap_ref = pic; irap_ref; irap_ref = irap_ref->refs[1]) {
711 if (irap_ref->type == PICTURE_TYPE_I)
714 if (pic->b_depth == ctx->max_b_depth) {
715 hpic->slice_nal_unit = irap_ref ? HEVC_NAL_RASL_N
718 hpic->slice_nal_unit = irap_ref ? HEVC_NAL_RASL_R
721 hpic->slice_type = HEVC_SLICE_B;
725 hpic->pic_order_cnt = pic->display_order - hpic->last_idr_frame;
728 priv->aud_needed = 1;
729 priv->raw_aud = (H265RawAUD) {
731 .nal_unit_type = HEVC_NAL_AUD,
733 .nuh_temporal_id_plus1 = 1,
735 .pic_type = hpic->pic_type,
738 priv->aud_needed = 0;
741 priv->sei_needed = 0;
743 // Only look for the metadata on I/IDR frame on the output. We
744 // may force an IDR frame on the output where the medadata gets
745 // changed on the input frame.
746 if ((priv->sei & SEI_MASTERING_DISPLAY) &&
747 (pic->type == PICTURE_TYPE_I || pic->type == PICTURE_TYPE_IDR)) {
748 AVFrameSideData *sd =
749 av_frame_get_side_data(pic->input_image,
750 AV_FRAME_DATA_MASTERING_DISPLAY_METADATA);
753 AVMasteringDisplayMetadata *mdm =
754 (AVMasteringDisplayMetadata *)sd->data;
756 // SEI is needed when both the primaries and luminance are set
757 if (mdm->has_primaries && mdm->has_luminance) {
758 H265RawSEIMasteringDisplayColourVolume *mdcv =
759 &priv->sei_mastering_display;
760 const int mapping[3] = {1, 2, 0};
761 const int chroma_den = 50000;
762 const int luma_den = 10000;
764 for (i = 0; i < 3; i++) {
765 const int j = mapping[i];
766 mdcv->display_primaries_x[i] =
767 FFMIN(lrint(chroma_den *
768 av_q2d(mdm->display_primaries[j][0])),
770 mdcv->display_primaries_y[i] =
771 FFMIN(lrint(chroma_den *
772 av_q2d(mdm->display_primaries[j][1])),
776 mdcv->white_point_x =
777 FFMIN(lrint(chroma_den * av_q2d(mdm->white_point[0])),
779 mdcv->white_point_y =
780 FFMIN(lrint(chroma_den * av_q2d(mdm->white_point[1])),
783 mdcv->max_display_mastering_luminance =
784 lrint(luma_den * av_q2d(mdm->max_luminance));
785 mdcv->min_display_mastering_luminance =
786 FFMIN(lrint(luma_den * av_q2d(mdm->min_luminance)),
787 mdcv->max_display_mastering_luminance);
789 priv->sei_needed |= SEI_MASTERING_DISPLAY;
794 if ((priv->sei & SEI_CONTENT_LIGHT_LEVEL) &&
795 (pic->type == PICTURE_TYPE_I || pic->type == PICTURE_TYPE_IDR)) {
796 AVFrameSideData *sd =
797 av_frame_get_side_data(pic->input_image,
798 AV_FRAME_DATA_CONTENT_LIGHT_LEVEL);
801 AVContentLightMetadata *clm =
802 (AVContentLightMetadata *)sd->data;
803 H265RawSEIContentLightLevelInfo *clli =
804 &priv->sei_content_light_level;
806 clli->max_content_light_level = FFMIN(clm->MaxCLL, 65535);
807 clli->max_pic_average_light_level = FFMIN(clm->MaxFALL, 65535);
809 priv->sei_needed |= SEI_CONTENT_LIGHT_LEVEL;
813 vpic->decoded_curr_pic = (VAPictureHEVC) {
814 .picture_id = pic->recon_surface,
815 .pic_order_cnt = hpic->pic_order_cnt,
819 for (i = 0; i < pic->nb_refs; i++) {
820 VAAPIEncodePicture *ref = pic->refs[i];
821 VAAPIEncodeH265Picture *href;
823 av_assert0(ref && ref->encode_order < pic->encode_order);
824 href = ref->priv_data;
826 vpic->reference_frames[i] = (VAPictureHEVC) {
827 .picture_id = ref->recon_surface,
828 .pic_order_cnt = href->pic_order_cnt,
829 .flags = (ref->display_order < pic->display_order ?
830 VA_PICTURE_HEVC_RPS_ST_CURR_BEFORE : 0) |
831 (ref->display_order > pic->display_order ?
832 VA_PICTURE_HEVC_RPS_ST_CURR_AFTER : 0),
835 for (; i < FF_ARRAY_ELEMS(vpic->reference_frames); i++) {
836 vpic->reference_frames[i] = (VAPictureHEVC) {
837 .picture_id = VA_INVALID_ID,
838 .flags = VA_PICTURE_HEVC_INVALID,
842 vpic->coded_buf = pic->output_buffer;
844 vpic->nal_unit_type = hpic->slice_nal_unit;
847 case PICTURE_TYPE_IDR:
848 vpic->pic_fields.bits.idr_pic_flag = 1;
849 vpic->pic_fields.bits.coding_type = 1;
850 vpic->pic_fields.bits.reference_pic_flag = 1;
853 vpic->pic_fields.bits.idr_pic_flag = 0;
854 vpic->pic_fields.bits.coding_type = 1;
855 vpic->pic_fields.bits.reference_pic_flag = 1;
858 vpic->pic_fields.bits.idr_pic_flag = 0;
859 vpic->pic_fields.bits.coding_type = 2;
860 vpic->pic_fields.bits.reference_pic_flag = 1;
863 vpic->pic_fields.bits.idr_pic_flag = 0;
864 vpic->pic_fields.bits.coding_type = 3;
865 vpic->pic_fields.bits.reference_pic_flag = 0;
868 av_assert0(0 && "invalid picture type");
874 static int vaapi_encode_h265_init_slice_params(AVCodecContext *avctx,
875 VAAPIEncodePicture *pic,
876 VAAPIEncodeSlice *slice)
878 VAAPIEncodeH265Context *priv = avctx->priv_data;
879 VAAPIEncodeH265Picture *hpic = pic->priv_data;
880 const H265RawSPS *sps = &priv->raw_sps;
881 const H265RawPPS *pps = &priv->raw_pps;
882 H265RawSliceHeader *sh = &priv->raw_slice.header;
883 VAEncPictureParameterBufferHEVC *vpic = pic->codec_picture_params;
884 VAEncSliceParameterBufferHEVC *vslice = slice->codec_slice_params;
887 sh->nal_unit_header = (H265RawNALUnitHeader) {
888 .nal_unit_type = hpic->slice_nal_unit,
890 .nuh_temporal_id_plus1 = 1,
893 sh->slice_pic_parameter_set_id = pps->pps_pic_parameter_set_id;
895 sh->first_slice_segment_in_pic_flag = slice->index == 0;
896 sh->slice_segment_address = slice->block_start;
898 sh->slice_type = hpic->slice_type;
900 sh->slice_pic_order_cnt_lsb = hpic->pic_order_cnt &
901 (1 << (sps->log2_max_pic_order_cnt_lsb_minus4 + 4)) - 1;
903 if (pic->type != PICTURE_TYPE_IDR) {
904 H265RawSTRefPicSet *rps;
905 const VAAPIEncodeH265Picture *strp;
906 int rps_poc[MAX_DPB_SIZE];
907 int rps_used[MAX_DPB_SIZE];
908 int i, j, poc, rps_pics;
910 sh->short_term_ref_pic_set_sps_flag = 0;
912 rps = &sh->short_term_ref_pic_set;
913 memset(rps, 0, sizeof(*rps));
916 for (i = 0; i < pic->nb_refs; i++) {
917 strp = pic->refs[i]->priv_data;
918 rps_poc[rps_pics] = strp->pic_order_cnt;
919 rps_used[rps_pics] = 1;
922 for (i = 0; i < pic->nb_dpb_pics; i++) {
923 if (pic->dpb[i] == pic)
925 for (j = 0; j < pic->nb_refs; j++) {
926 if (pic->dpb[i] == pic->refs[j])
929 if (j < pic->nb_refs)
931 strp = pic->dpb[i]->priv_data;
932 rps_poc[rps_pics] = strp->pic_order_cnt;
933 rps_used[rps_pics] = 0;
937 for (i = 1; i < rps_pics; i++) {
938 for (j = i; j > 0; j--) {
939 if (rps_poc[j] > rps_poc[j - 1])
941 av_assert0(rps_poc[j] != rps_poc[j - 1]);
942 FFSWAP(int, rps_poc[j], rps_poc[j - 1]);
943 FFSWAP(int, rps_used[j], rps_used[j - 1]);
947 av_log(avctx, AV_LOG_DEBUG, "RPS for POC %d:",
948 hpic->pic_order_cnt);
949 for (i = 0; i < rps_pics; i++) {
950 av_log(avctx, AV_LOG_DEBUG, " (%d,%d)",
951 rps_poc[i], rps_used[i]);
953 av_log(avctx, AV_LOG_DEBUG, "\n");
955 for (i = 0; i < rps_pics; i++) {
956 av_assert0(rps_poc[i] != hpic->pic_order_cnt);
957 if (rps_poc[i] > hpic->pic_order_cnt)
961 rps->num_negative_pics = i;
962 poc = hpic->pic_order_cnt;
963 for (j = i - 1; j >= 0; j--) {
964 rps->delta_poc_s0_minus1[i - 1 - j] = poc - rps_poc[j] - 1;
965 rps->used_by_curr_pic_s0_flag[i - 1 - j] = rps_used[j];
969 rps->num_positive_pics = rps_pics - i;
970 poc = hpic->pic_order_cnt;
971 for (j = i; j < rps_pics; j++) {
972 rps->delta_poc_s1_minus1[j - i] = rps_poc[j] - poc - 1;
973 rps->used_by_curr_pic_s1_flag[j - i] = rps_used[j];
977 sh->num_long_term_sps = 0;
978 sh->num_long_term_pics = 0;
980 sh->slice_temporal_mvp_enabled_flag =
981 sps->sps_temporal_mvp_enabled_flag;
982 if (sh->slice_temporal_mvp_enabled_flag) {
983 sh->collocated_from_l0_flag = sh->slice_type == HEVC_SLICE_B;
984 sh->collocated_ref_idx = 0;
987 sh->num_ref_idx_active_override_flag = 0;
988 sh->num_ref_idx_l0_active_minus1 = pps->num_ref_idx_l0_default_active_minus1;
989 sh->num_ref_idx_l1_active_minus1 = pps->num_ref_idx_l1_default_active_minus1;
992 sh->slice_sao_luma_flag = sh->slice_sao_chroma_flag =
993 sps->sample_adaptive_offset_enabled_flag;
995 if (pic->type == PICTURE_TYPE_B)
996 sh->slice_qp_delta = priv->fixed_qp_b - (pps->init_qp_minus26 + 26);
997 else if (pic->type == PICTURE_TYPE_P)
998 sh->slice_qp_delta = priv->fixed_qp_p - (pps->init_qp_minus26 + 26);
1000 sh->slice_qp_delta = priv->fixed_qp_idr - (pps->init_qp_minus26 + 26);
1003 *vslice = (VAEncSliceParameterBufferHEVC) {
1004 .slice_segment_address = sh->slice_segment_address,
1005 .num_ctu_in_slice = slice->block_size,
1007 .slice_type = sh->slice_type,
1008 .slice_pic_parameter_set_id = sh->slice_pic_parameter_set_id,
1010 .num_ref_idx_l0_active_minus1 = sh->num_ref_idx_l0_active_minus1,
1011 .num_ref_idx_l1_active_minus1 = sh->num_ref_idx_l1_active_minus1,
1013 .luma_log2_weight_denom = sh->luma_log2_weight_denom,
1014 .delta_chroma_log2_weight_denom = sh->delta_chroma_log2_weight_denom,
1016 .max_num_merge_cand = 5 - sh->five_minus_max_num_merge_cand,
1018 .slice_qp_delta = sh->slice_qp_delta,
1019 .slice_cb_qp_offset = sh->slice_cb_qp_offset,
1020 .slice_cr_qp_offset = sh->slice_cr_qp_offset,
1022 .slice_beta_offset_div2 = sh->slice_beta_offset_div2,
1023 .slice_tc_offset_div2 = sh->slice_tc_offset_div2,
1025 .slice_fields.bits = {
1026 .last_slice_of_pic_flag = slice->index == pic->nb_slices - 1,
1027 .dependent_slice_segment_flag = sh->dependent_slice_segment_flag,
1028 .colour_plane_id = sh->colour_plane_id,
1029 .slice_temporal_mvp_enabled_flag =
1030 sh->slice_temporal_mvp_enabled_flag,
1031 .slice_sao_luma_flag = sh->slice_sao_luma_flag,
1032 .slice_sao_chroma_flag = sh->slice_sao_chroma_flag,
1033 .num_ref_idx_active_override_flag =
1034 sh->num_ref_idx_active_override_flag,
1035 .mvd_l1_zero_flag = sh->mvd_l1_zero_flag,
1036 .cabac_init_flag = sh->cabac_init_flag,
1037 .slice_deblocking_filter_disabled_flag =
1038 sh->slice_deblocking_filter_disabled_flag,
1039 .slice_loop_filter_across_slices_enabled_flag =
1040 sh->slice_loop_filter_across_slices_enabled_flag,
1041 .collocated_from_l0_flag = sh->collocated_from_l0_flag,
1045 for (i = 0; i < FF_ARRAY_ELEMS(vslice->ref_pic_list0); i++) {
1046 vslice->ref_pic_list0[i].picture_id = VA_INVALID_ID;
1047 vslice->ref_pic_list0[i].flags = VA_PICTURE_HEVC_INVALID;
1048 vslice->ref_pic_list1[i].picture_id = VA_INVALID_ID;
1049 vslice->ref_pic_list1[i].flags = VA_PICTURE_HEVC_INVALID;
1052 av_assert0(pic->nb_refs <= 2);
1053 if (pic->nb_refs >= 1) {
1054 // Backward reference for P- or B-frame.
1055 av_assert0(pic->type == PICTURE_TYPE_P ||
1056 pic->type == PICTURE_TYPE_B);
1057 vslice->ref_pic_list0[0] = vpic->reference_frames[0];
1059 if (pic->nb_refs >= 2) {
1060 // Forward reference for B-frame.
1061 av_assert0(pic->type == PICTURE_TYPE_B);
1062 vslice->ref_pic_list1[0] = vpic->reference_frames[1];
1068 static av_cold int vaapi_encode_h265_configure(AVCodecContext *avctx)
1070 VAAPIEncodeContext *ctx = avctx->priv_data;
1071 VAAPIEncodeH265Context *priv = avctx->priv_data;
1074 err = ff_cbs_init(&priv->cbc, AV_CODEC_ID_HEVC, avctx);
1078 if (ctx->va_rc_mode == VA_RC_CQP) {
1079 priv->fixed_qp_p = priv->qp;
1080 if (avctx->i_quant_factor > 0.0)
1081 priv->fixed_qp_idr = (int)((priv->fixed_qp_p * avctx->i_quant_factor +
1082 avctx->i_quant_offset) + 0.5);
1084 priv->fixed_qp_idr = priv->fixed_qp_p;
1085 if (avctx->b_quant_factor > 0.0)
1086 priv->fixed_qp_b = (int)((priv->fixed_qp_p * avctx->b_quant_factor +
1087 avctx->b_quant_offset) + 0.5);
1089 priv->fixed_qp_b = priv->fixed_qp_p;
1091 av_log(avctx, AV_LOG_DEBUG, "Using fixed QP = "
1092 "%d / %d / %d for IDR- / P- / B-frames.\n",
1093 priv->fixed_qp_idr, priv->fixed_qp_p, priv->fixed_qp_b);
1095 } else if (ctx->va_rc_mode == VA_RC_CBR ||
1096 ctx->va_rc_mode == VA_RC_VBR) {
1097 // These still need to be set for pic_init_qp/slice_qp_delta.
1098 priv->fixed_qp_idr = 30;
1099 priv->fixed_qp_p = 30;
1100 priv->fixed_qp_b = 30;
1103 av_assert0(0 && "Invalid RC mode.");
1109 static const VAAPIEncodeProfile vaapi_encode_h265_profiles[] = {
1110 { FF_PROFILE_HEVC_MAIN, 8, 3, 1, 1, VAProfileHEVCMain },
1111 { FF_PROFILE_HEVC_REXT, 8, 3, 1, 1, VAProfileHEVCMain },
1112 #if VA_CHECK_VERSION(0, 37, 0)
1113 { FF_PROFILE_HEVC_MAIN_10, 10, 3, 1, 1, VAProfileHEVCMain10 },
1114 { FF_PROFILE_HEVC_REXT, 10, 3, 1, 1, VAProfileHEVCMain10 },
1116 { FF_PROFILE_UNKNOWN }
1119 static const VAAPIEncodeType vaapi_encode_type_h265 = {
1120 .profiles = vaapi_encode_h265_profiles,
1122 .flags = FLAG_SLICE_CONTROL |
1124 FLAG_B_PICTURE_REFERENCES |
1125 FLAG_NON_IDR_KEY_PICTURES,
1127 .configure = &vaapi_encode_h265_configure,
1129 .picture_priv_data_size = sizeof(VAAPIEncodeH265Picture),
1131 .sequence_params_size = sizeof(VAEncSequenceParameterBufferHEVC),
1132 .init_sequence_params = &vaapi_encode_h265_init_sequence_params,
1134 .picture_params_size = sizeof(VAEncPictureParameterBufferHEVC),
1135 .init_picture_params = &vaapi_encode_h265_init_picture_params,
1137 .slice_params_size = sizeof(VAEncSliceParameterBufferHEVC),
1138 .init_slice_params = &vaapi_encode_h265_init_slice_params,
1140 .sequence_header_type = VAEncPackedHeaderSequence,
1141 .write_sequence_header = &vaapi_encode_h265_write_sequence_header,
1143 .slice_header_type = VAEncPackedHeaderHEVC_Slice,
1144 .write_slice_header = &vaapi_encode_h265_write_slice_header,
1146 .write_extra_header = &vaapi_encode_h265_write_extra_header,
1149 static av_cold int vaapi_encode_h265_init(AVCodecContext *avctx)
1151 VAAPIEncodeContext *ctx = avctx->priv_data;
1152 VAAPIEncodeH265Context *priv = avctx->priv_data;
1154 ctx->codec = &vaapi_encode_type_h265;
1156 if (avctx->profile == FF_PROFILE_UNKNOWN)
1157 avctx->profile = priv->profile;
1158 if (avctx->level == FF_LEVEL_UNKNOWN)
1159 avctx->level = priv->level;
1161 if (avctx->level != FF_LEVEL_UNKNOWN && avctx->level & ~0xff) {
1162 av_log(avctx, AV_LOG_ERROR, "Invalid level %d: must fit "
1163 "in 8-bit unsigned integer.\n", avctx->level);
1164 return AVERROR(EINVAL);
1167 ctx->desired_packed_headers =
1168 VA_ENC_PACKED_HEADER_SEQUENCE | // VPS, SPS and PPS.
1169 VA_ENC_PACKED_HEADER_SLICE | // Slice headers.
1170 VA_ENC_PACKED_HEADER_MISC; // SEI
1172 ctx->surface_width = FFALIGN(avctx->width, 16);
1173 ctx->surface_height = FFALIGN(avctx->height, 16);
1175 // CTU size is currently hard-coded to 32.
1176 ctx->slice_block_width = ctx->slice_block_height = 32;
1178 return ff_vaapi_encode_init(avctx);
1181 static av_cold int vaapi_encode_h265_close(AVCodecContext *avctx)
1183 VAAPIEncodeH265Context *priv = avctx->priv_data;
1185 ff_cbs_close(&priv->cbc);
1187 return ff_vaapi_encode_close(avctx);
1190 #define OFFSET(x) offsetof(VAAPIEncodeH265Context, x)
1191 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
1192 static const AVOption vaapi_encode_h265_options[] = {
1193 VAAPI_ENCODE_COMMON_OPTIONS,
1195 { "qp", "Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)",
1196 OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 25 }, 0, 52, FLAGS },
1198 { "aud", "Include AUD",
1199 OFFSET(aud), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
1201 { "profile", "Set profile (general_profile_idc)",
1202 OFFSET(profile), AV_OPT_TYPE_INT,
1203 { .i64 = FF_PROFILE_UNKNOWN }, FF_PROFILE_UNKNOWN, 0xff, FLAGS, "profile" },
1205 #define PROFILE(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
1206 { .i64 = value }, 0, 0, FLAGS, "profile"
1207 { PROFILE("main", FF_PROFILE_HEVC_MAIN) },
1208 { PROFILE("main10", FF_PROFILE_HEVC_MAIN_10) },
1209 { PROFILE("rext", FF_PROFILE_HEVC_REXT) },
1212 { "tier", "Set tier (general_tier_flag)",
1213 OFFSET(tier), AV_OPT_TYPE_INT,
1214 { .i64 = 0 }, 0, 1, FLAGS, "tier" },
1215 { "main", NULL, 0, AV_OPT_TYPE_CONST,
1216 { .i64 = 0 }, 0, 0, FLAGS, "tier" },
1217 { "high", NULL, 0, AV_OPT_TYPE_CONST,
1218 { .i64 = 1 }, 0, 0, FLAGS, "tier" },
1220 { "level", "Set level (general_level_idc)",
1221 OFFSET(level), AV_OPT_TYPE_INT,
1222 { .i64 = FF_LEVEL_UNKNOWN }, FF_LEVEL_UNKNOWN, 0xff, FLAGS, "level" },
1224 #define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
1225 { .i64 = value }, 0, 0, FLAGS, "level"
1228 { LEVEL("2.1", 63) },
1230 { LEVEL("3.1", 93) },
1231 { LEVEL("4", 120) },
1232 { LEVEL("4.1", 123) },
1233 { LEVEL("5", 150) },
1234 { LEVEL("5.1", 153) },
1235 { LEVEL("5.2", 156) },
1236 { LEVEL("6", 180) },
1237 { LEVEL("6.1", 183) },
1238 { LEVEL("6.2", 186) },
1241 { "sei", "Set SEI to include",
1242 OFFSET(sei), AV_OPT_TYPE_FLAGS,
1243 { .i64 = SEI_MASTERING_DISPLAY | SEI_CONTENT_LIGHT_LEVEL },
1244 0, INT_MAX, FLAGS, "sei" },
1246 "Include HDR metadata for mastering display colour volume "
1247 "and content light level information",
1248 0, AV_OPT_TYPE_CONST,
1249 { .i64 = SEI_MASTERING_DISPLAY | SEI_CONTENT_LIGHT_LEVEL },
1250 INT_MIN, INT_MAX, FLAGS, "sei" },
1255 static const AVCodecDefault vaapi_encode_h265_defaults[] = {
1259 { "i_qfactor", "1" },
1260 { "i_qoffset", "0" },
1261 { "b_qfactor", "6/5" },
1262 { "b_qoffset", "0" },
1268 static const AVClass vaapi_encode_h265_class = {
1269 .class_name = "h265_vaapi",
1270 .item_name = av_default_item_name,
1271 .option = vaapi_encode_h265_options,
1272 .version = LIBAVUTIL_VERSION_INT,
1275 AVCodec ff_hevc_vaapi_encoder = {
1276 .name = "hevc_vaapi",
1277 .long_name = NULL_IF_CONFIG_SMALL("H.265/HEVC (VAAPI)"),
1278 .type = AVMEDIA_TYPE_VIDEO,
1279 .id = AV_CODEC_ID_HEVC,
1280 .priv_data_size = sizeof(VAAPIEncodeH265Context),
1281 .init = &vaapi_encode_h265_init,
1282 .send_frame = &ff_vaapi_encode_send_frame,
1283 .receive_packet = &ff_vaapi_encode_receive_packet,
1284 .close = &vaapi_encode_h265_close,
1285 .priv_class = &vaapi_encode_h265_class,
1286 .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE,
1287 .defaults = vaapi_encode_h265_defaults,
1288 .pix_fmts = (const enum AVPixelFormat[]) {
1292 .wrapper_name = "vaapi",