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_reset(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_reset(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_reset(priv->cbc, au);
247 *type = VAEncPackedHeaderRawData;
254 ff_cbs_fragment_reset(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(vps, 0, sizeof(*vps));
274 memset(sps, 0, sizeof(*sps));
275 memset(pps, 0, sizeof(*pps));
278 desc = av_pix_fmt_desc_get(priv->common.input_frames->sw_format);
280 if (desc->nb_components == 1) {
283 if (desc->log2_chroma_w == 1 && desc->log2_chroma_h == 1) {
285 } else if (desc->log2_chroma_w == 1 && desc->log2_chroma_h == 0) {
287 } else if (desc->log2_chroma_w == 0 && desc->log2_chroma_h == 0) {
290 av_log(avctx, AV_LOG_ERROR, "Chroma format of input pixel format "
291 "%s is not supported.\n", desc->name);
292 return AVERROR(EINVAL);
295 bit_depth = desc->comp[0].depth;
300 vps->nal_unit_header = (H265RawNALUnitHeader) {
301 .nal_unit_type = HEVC_NAL_VPS,
303 .nuh_temporal_id_plus1 = 1,
306 vps->vps_video_parameter_set_id = 0;
308 vps->vps_base_layer_internal_flag = 1;
309 vps->vps_base_layer_available_flag = 1;
310 vps->vps_max_layers_minus1 = 0;
311 vps->vps_max_sub_layers_minus1 = 0;
312 vps->vps_temporal_id_nesting_flag = 1;
314 ptl->general_profile_space = 0;
315 ptl->general_profile_idc = avctx->profile;
316 ptl->general_tier_flag = priv->tier;
318 if (chroma_format == 1) {
319 ptl->general_profile_compatibility_flag[1] = bit_depth == 8;
320 ptl->general_profile_compatibility_flag[2] = bit_depth <= 10;
322 ptl->general_profile_compatibility_flag[4] = 1;
324 ptl->general_progressive_source_flag = 1;
325 ptl->general_interlaced_source_flag = 0;
326 ptl->general_non_packed_constraint_flag = 1;
327 ptl->general_frame_only_constraint_flag = 1;
329 ptl->general_max_12bit_constraint_flag = bit_depth <= 12;
330 ptl->general_max_10bit_constraint_flag = bit_depth <= 10;
331 ptl->general_max_8bit_constraint_flag = bit_depth == 8;
333 ptl->general_max_422chroma_constraint_flag = chroma_format <= 2;
334 ptl->general_max_420chroma_constraint_flag = chroma_format <= 1;
335 ptl->general_max_monochrome_constraint_flag = chroma_format == 0;
337 ptl->general_intra_constraint_flag = ctx->gop_size == 1;
339 ptl->general_lower_bit_rate_constraint_flag = 1;
341 if (avctx->level != FF_LEVEL_UNKNOWN) {
342 ptl->general_level_idc = avctx->level;
344 const H265LevelDescriptor *level;
346 level = ff_h265_guess_level(ptl, avctx->bit_rate,
347 ctx->surface_width, ctx->surface_height,
348 ctx->nb_slices, 1, 1,
349 (ctx->b_per_p > 0) + 1);
351 av_log(avctx, AV_LOG_VERBOSE, "Using level %s.\n", level->name);
352 ptl->general_level_idc = level->level_idc;
354 av_log(avctx, AV_LOG_VERBOSE, "Stream will not conform to "
355 "any normal level; using level 8.5.\n");
356 ptl->general_level_idc = 255;
357 // The tier flag must be set in level 8.5.
358 ptl->general_tier_flag = 1;
362 vps->vps_sub_layer_ordering_info_present_flag = 0;
363 vps->vps_max_dec_pic_buffering_minus1[0] = ctx->max_b_depth + 1;
364 vps->vps_max_num_reorder_pics[0] = ctx->max_b_depth;
365 vps->vps_max_latency_increase_plus1[0] = 0;
367 vps->vps_max_layer_id = 0;
368 vps->vps_num_layer_sets_minus1 = 0;
369 vps->layer_id_included_flag[0][0] = 1;
371 vps->vps_timing_info_present_flag = 1;
372 if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
373 vps->vps_num_units_in_tick = avctx->framerate.den;
374 vps->vps_time_scale = avctx->framerate.num;
375 vps->vps_poc_proportional_to_timing_flag = 1;
376 vps->vps_num_ticks_poc_diff_one_minus1 = 0;
378 vps->vps_num_units_in_tick = avctx->time_base.num;
379 vps->vps_time_scale = avctx->time_base.den;
380 vps->vps_poc_proportional_to_timing_flag = 0;
382 vps->vps_num_hrd_parameters = 0;
387 sps->nal_unit_header = (H265RawNALUnitHeader) {
388 .nal_unit_type = HEVC_NAL_SPS,
390 .nuh_temporal_id_plus1 = 1,
393 sps->sps_video_parameter_set_id = vps->vps_video_parameter_set_id;
395 sps->sps_max_sub_layers_minus1 = vps->vps_max_sub_layers_minus1;
396 sps->sps_temporal_id_nesting_flag = vps->vps_temporal_id_nesting_flag;
398 sps->profile_tier_level = vps->profile_tier_level;
400 sps->sps_seq_parameter_set_id = 0;
402 sps->chroma_format_idc = chroma_format;
403 sps->separate_colour_plane_flag = 0;
405 sps->pic_width_in_luma_samples = ctx->surface_width;
406 sps->pic_height_in_luma_samples = ctx->surface_height;
408 if (avctx->width != ctx->surface_width ||
409 avctx->height != ctx->surface_height) {
410 sps->conformance_window_flag = 1;
411 sps->conf_win_left_offset = 0;
412 sps->conf_win_right_offset =
413 (ctx->surface_width - avctx->width) / 2;
414 sps->conf_win_top_offset = 0;
415 sps->conf_win_bottom_offset =
416 (ctx->surface_height - avctx->height) / 2;
418 sps->conformance_window_flag = 0;
421 sps->bit_depth_luma_minus8 = bit_depth - 8;
422 sps->bit_depth_chroma_minus8 = bit_depth - 8;
424 sps->log2_max_pic_order_cnt_lsb_minus4 = 8;
426 sps->sps_sub_layer_ordering_info_present_flag =
427 vps->vps_sub_layer_ordering_info_present_flag;
428 for (i = 0; i <= sps->sps_max_sub_layers_minus1; i++) {
429 sps->sps_max_dec_pic_buffering_minus1[i] =
430 vps->vps_max_dec_pic_buffering_minus1[i];
431 sps->sps_max_num_reorder_pics[i] =
432 vps->vps_max_num_reorder_pics[i];
433 sps->sps_max_latency_increase_plus1[i] =
434 vps->vps_max_latency_increase_plus1[i];
437 // These have to come from the capabilities of the encoder. We have no
438 // way to query them, so just hardcode parameters which work on the Intel
440 // CTB size from 8x8 to 32x32.
441 sps->log2_min_luma_coding_block_size_minus3 = 0;
442 sps->log2_diff_max_min_luma_coding_block_size = 2;
443 // Transform size from 4x4 to 32x32.
444 sps->log2_min_luma_transform_block_size_minus2 = 0;
445 sps->log2_diff_max_min_luma_transform_block_size = 3;
446 // Full transform hierarchy allowed (2-5).
447 sps->max_transform_hierarchy_depth_inter = 3;
448 sps->max_transform_hierarchy_depth_intra = 3;
450 sps->amp_enabled_flag = 1;
451 // SAO and temporal MVP do not work.
452 sps->sample_adaptive_offset_enabled_flag = 0;
453 sps->sps_temporal_mvp_enabled_flag = 0;
455 sps->pcm_enabled_flag = 0;
457 // STRPSs should ideally be here rather than defined individually in
458 // each slice, but the structure isn't completely fixed so for now
460 sps->num_short_term_ref_pic_sets = 0;
461 sps->long_term_ref_pics_present_flag = 0;
463 sps->vui_parameters_present_flag = 1;
465 if (avctx->sample_aspect_ratio.num != 0 &&
466 avctx->sample_aspect_ratio.den != 0) {
467 static const AVRational sar_idc[] = {
469 { 1, 1 }, { 12, 11 }, { 10, 11 }, { 16, 11 },
470 { 40, 33 }, { 24, 11 }, { 20, 11 }, { 32, 11 },
471 { 80, 33 }, { 18, 11 }, { 15, 11 }, { 64, 33 },
472 { 160, 99 }, { 4, 3 }, { 3, 2 }, { 2, 1 },
475 av_reduce(&num, &den, avctx->sample_aspect_ratio.num,
476 avctx->sample_aspect_ratio.den, 65535);
477 for (i = 0; i < FF_ARRAY_ELEMS(sar_idc); i++) {
478 if (num == sar_idc[i].num &&
479 den == sar_idc[i].den) {
480 vui->aspect_ratio_idc = i;
484 if (i >= FF_ARRAY_ELEMS(sar_idc)) {
485 vui->aspect_ratio_idc = 255;
486 vui->sar_width = num;
487 vui->sar_height = den;
489 vui->aspect_ratio_info_present_flag = 1;
492 if (avctx->color_range != AVCOL_RANGE_UNSPECIFIED ||
493 avctx->color_primaries != AVCOL_PRI_UNSPECIFIED ||
494 avctx->color_trc != AVCOL_TRC_UNSPECIFIED ||
495 avctx->colorspace != AVCOL_SPC_UNSPECIFIED) {
496 vui->video_signal_type_present_flag = 1;
497 vui->video_format = 5; // Unspecified.
498 vui->video_full_range_flag =
499 avctx->color_range == AVCOL_RANGE_JPEG;
501 if (avctx->color_primaries != AVCOL_PRI_UNSPECIFIED ||
502 avctx->color_trc != AVCOL_TRC_UNSPECIFIED ||
503 avctx->colorspace != AVCOL_SPC_UNSPECIFIED) {
504 vui->colour_description_present_flag = 1;
505 vui->colour_primaries = avctx->color_primaries;
506 vui->transfer_characteristics = avctx->color_trc;
507 vui->matrix_coefficients = avctx->colorspace;
510 vui->video_format = 5;
511 vui->video_full_range_flag = 0;
512 vui->colour_primaries = avctx->color_primaries;
513 vui->transfer_characteristics = avctx->color_trc;
514 vui->matrix_coefficients = avctx->colorspace;
517 if (avctx->chroma_sample_location != AVCHROMA_LOC_UNSPECIFIED) {
518 vui->chroma_loc_info_present_flag = 1;
519 vui->chroma_sample_loc_type_top_field =
520 vui->chroma_sample_loc_type_bottom_field =
521 avctx->chroma_sample_location - 1;
524 vui->vui_timing_info_present_flag = 1;
525 vui->vui_num_units_in_tick = vps->vps_num_units_in_tick;
526 vui->vui_time_scale = vps->vps_time_scale;
527 vui->vui_poc_proportional_to_timing_flag = vps->vps_poc_proportional_to_timing_flag;
528 vui->vui_num_ticks_poc_diff_one_minus1 = vps->vps_num_ticks_poc_diff_one_minus1;
529 vui->vui_hrd_parameters_present_flag = 0;
531 vui->bitstream_restriction_flag = 1;
532 vui->motion_vectors_over_pic_boundaries_flag = 1;
533 vui->restricted_ref_pic_lists_flag = 1;
534 vui->max_bytes_per_pic_denom = 0;
535 vui->max_bits_per_min_cu_denom = 0;
536 vui->log2_max_mv_length_horizontal = 15;
537 vui->log2_max_mv_length_vertical = 15;
542 pps->nal_unit_header = (H265RawNALUnitHeader) {
543 .nal_unit_type = HEVC_NAL_PPS,
545 .nuh_temporal_id_plus1 = 1,
548 pps->pps_pic_parameter_set_id = 0;
549 pps->pps_seq_parameter_set_id = sps->sps_seq_parameter_set_id;
551 pps->num_ref_idx_l0_default_active_minus1 = 0;
552 pps->num_ref_idx_l1_default_active_minus1 = 0;
554 pps->init_qp_minus26 = priv->fixed_qp_idr - 26;
556 pps->cu_qp_delta_enabled_flag = (ctx->va_rc_mode != VA_RC_CQP);
557 pps->diff_cu_qp_delta_depth = 0;
559 pps->pps_loop_filter_across_slices_enabled_flag = 1;
562 // Fill VAAPI parameter buffers.
564 *vseq = (VAEncSequenceParameterBufferHEVC) {
565 .general_profile_idc = vps->profile_tier_level.general_profile_idc,
566 .general_level_idc = vps->profile_tier_level.general_level_idc,
567 .general_tier_flag = vps->profile_tier_level.general_tier_flag,
569 .intra_period = ctx->gop_size,
570 .intra_idr_period = ctx->gop_size,
571 .ip_period = ctx->b_per_p + 1,
572 .bits_per_second = ctx->va_bit_rate,
574 .pic_width_in_luma_samples = sps->pic_width_in_luma_samples,
575 .pic_height_in_luma_samples = sps->pic_height_in_luma_samples,
578 .chroma_format_idc = sps->chroma_format_idc,
579 .separate_colour_plane_flag = sps->separate_colour_plane_flag,
580 .bit_depth_luma_minus8 = sps->bit_depth_luma_minus8,
581 .bit_depth_chroma_minus8 = sps->bit_depth_chroma_minus8,
582 .scaling_list_enabled_flag = sps->scaling_list_enabled_flag,
583 .strong_intra_smoothing_enabled_flag =
584 sps->strong_intra_smoothing_enabled_flag,
585 .amp_enabled_flag = sps->amp_enabled_flag,
586 .sample_adaptive_offset_enabled_flag =
587 sps->sample_adaptive_offset_enabled_flag,
588 .pcm_enabled_flag = sps->pcm_enabled_flag,
589 .pcm_loop_filter_disabled_flag = sps->pcm_loop_filter_disabled_flag,
590 .sps_temporal_mvp_enabled_flag = sps->sps_temporal_mvp_enabled_flag,
593 .log2_min_luma_coding_block_size_minus3 =
594 sps->log2_min_luma_coding_block_size_minus3,
595 .log2_diff_max_min_luma_coding_block_size =
596 sps->log2_diff_max_min_luma_coding_block_size,
597 .log2_min_transform_block_size_minus2 =
598 sps->log2_min_luma_transform_block_size_minus2,
599 .log2_diff_max_min_transform_block_size =
600 sps->log2_diff_max_min_luma_transform_block_size,
601 .max_transform_hierarchy_depth_inter =
602 sps->max_transform_hierarchy_depth_inter,
603 .max_transform_hierarchy_depth_intra =
604 sps->max_transform_hierarchy_depth_intra,
606 .pcm_sample_bit_depth_luma_minus1 =
607 sps->pcm_sample_bit_depth_luma_minus1,
608 .pcm_sample_bit_depth_chroma_minus1 =
609 sps->pcm_sample_bit_depth_chroma_minus1,
610 .log2_min_pcm_luma_coding_block_size_minus3 =
611 sps->log2_min_pcm_luma_coding_block_size_minus3,
612 .log2_max_pcm_luma_coding_block_size_minus3 =
613 sps->log2_min_pcm_luma_coding_block_size_minus3 +
614 sps->log2_diff_max_min_pcm_luma_coding_block_size,
616 .vui_parameters_present_flag = 0,
619 *vpic = (VAEncPictureParameterBufferHEVC) {
620 .decoded_curr_pic = {
621 .picture_id = VA_INVALID_ID,
622 .flags = VA_PICTURE_HEVC_INVALID,
625 .coded_buf = VA_INVALID_ID,
627 .collocated_ref_pic_index = 0xff,
631 .pic_init_qp = pps->init_qp_minus26 + 26,
632 .diff_cu_qp_delta_depth = pps->diff_cu_qp_delta_depth,
633 .pps_cb_qp_offset = pps->pps_cb_qp_offset,
634 .pps_cr_qp_offset = pps->pps_cr_qp_offset,
636 .num_tile_columns_minus1 = pps->num_tile_columns_minus1,
637 .num_tile_rows_minus1 = pps->num_tile_rows_minus1,
639 .log2_parallel_merge_level_minus2 = pps->log2_parallel_merge_level_minus2,
640 .ctu_max_bitsize_allowed = 0,
642 .num_ref_idx_l0_default_active_minus1 =
643 pps->num_ref_idx_l0_default_active_minus1,
644 .num_ref_idx_l1_default_active_minus1 =
645 pps->num_ref_idx_l1_default_active_minus1,
647 .slice_pic_parameter_set_id = pps->pps_pic_parameter_set_id,
650 .sign_data_hiding_enabled_flag = pps->sign_data_hiding_enabled_flag,
651 .constrained_intra_pred_flag = pps->constrained_intra_pred_flag,
652 .transform_skip_enabled_flag = pps->transform_skip_enabled_flag,
653 .cu_qp_delta_enabled_flag = pps->cu_qp_delta_enabled_flag,
654 .weighted_pred_flag = pps->weighted_pred_flag,
655 .weighted_bipred_flag = pps->weighted_bipred_flag,
656 .transquant_bypass_enabled_flag = pps->transquant_bypass_enabled_flag,
657 .tiles_enabled_flag = pps->tiles_enabled_flag,
658 .entropy_coding_sync_enabled_flag = pps->entropy_coding_sync_enabled_flag,
659 .loop_filter_across_tiles_enabled_flag =
660 pps->loop_filter_across_tiles_enabled_flag,
661 .scaling_list_data_present_flag = (sps->sps_scaling_list_data_present_flag |
662 pps->pps_scaling_list_data_present_flag),
663 .screen_content_flag = 0,
664 .enable_gpu_weighted_prediction = 0,
665 .no_output_of_prior_pics_flag = 0,
672 static int vaapi_encode_h265_init_picture_params(AVCodecContext *avctx,
673 VAAPIEncodePicture *pic)
675 VAAPIEncodeContext *ctx = avctx->priv_data;
676 VAAPIEncodeH265Context *priv = avctx->priv_data;
677 VAAPIEncodeH265Picture *hpic = pic->priv_data;
678 VAAPIEncodePicture *prev = pic->prev;
679 VAAPIEncodeH265Picture *hprev = prev ? prev->priv_data : NULL;
680 VAEncPictureParameterBufferHEVC *vpic = pic->codec_picture_params;
683 if (pic->type == PICTURE_TYPE_IDR) {
684 av_assert0(pic->display_order == pic->encode_order);
686 hpic->last_idr_frame = pic->display_order;
688 hpic->slice_nal_unit = HEVC_NAL_IDR_W_RADL;
689 hpic->slice_type = HEVC_SLICE_I;
693 hpic->last_idr_frame = hprev->last_idr_frame;
695 if (pic->type == PICTURE_TYPE_I) {
696 hpic->slice_nal_unit = HEVC_NAL_CRA_NUT;
697 hpic->slice_type = HEVC_SLICE_I;
699 } else if (pic->type == PICTURE_TYPE_P) {
700 av_assert0(pic->refs[0]);
701 hpic->slice_nal_unit = HEVC_NAL_TRAIL_R;
702 hpic->slice_type = HEVC_SLICE_P;
705 VAAPIEncodePicture *irap_ref;
706 av_assert0(pic->refs[0] && pic->refs[1]);
707 for (irap_ref = pic; irap_ref; irap_ref = irap_ref->refs[1]) {
708 if (irap_ref->type == PICTURE_TYPE_I)
711 if (pic->b_depth == ctx->max_b_depth) {
712 hpic->slice_nal_unit = irap_ref ? HEVC_NAL_RASL_N
715 hpic->slice_nal_unit = irap_ref ? HEVC_NAL_RASL_R
718 hpic->slice_type = HEVC_SLICE_B;
722 hpic->pic_order_cnt = pic->display_order - hpic->last_idr_frame;
725 priv->aud_needed = 1;
726 priv->raw_aud = (H265RawAUD) {
728 .nal_unit_type = HEVC_NAL_AUD,
730 .nuh_temporal_id_plus1 = 1,
732 .pic_type = hpic->pic_type,
735 priv->aud_needed = 0;
738 priv->sei_needed = 0;
740 // Only look for the metadata on I/IDR frame on the output. We
741 // may force an IDR frame on the output where the medadata gets
742 // changed on the input frame.
743 if ((priv->sei & SEI_MASTERING_DISPLAY) &&
744 (pic->type == PICTURE_TYPE_I || pic->type == PICTURE_TYPE_IDR)) {
745 AVFrameSideData *sd =
746 av_frame_get_side_data(pic->input_image,
747 AV_FRAME_DATA_MASTERING_DISPLAY_METADATA);
750 AVMasteringDisplayMetadata *mdm =
751 (AVMasteringDisplayMetadata *)sd->data;
753 // SEI is needed when both the primaries and luminance are set
754 if (mdm->has_primaries && mdm->has_luminance) {
755 H265RawSEIMasteringDisplayColourVolume *mdcv =
756 &priv->sei_mastering_display;
757 const int mapping[3] = {1, 2, 0};
758 const int chroma_den = 50000;
759 const int luma_den = 10000;
761 for (i = 0; i < 3; i++) {
762 const int j = mapping[i];
763 mdcv->display_primaries_x[i] =
764 FFMIN(lrint(chroma_den *
765 av_q2d(mdm->display_primaries[j][0])),
767 mdcv->display_primaries_y[i] =
768 FFMIN(lrint(chroma_den *
769 av_q2d(mdm->display_primaries[j][1])),
773 mdcv->white_point_x =
774 FFMIN(lrint(chroma_den * av_q2d(mdm->white_point[0])),
776 mdcv->white_point_y =
777 FFMIN(lrint(chroma_den * av_q2d(mdm->white_point[1])),
780 mdcv->max_display_mastering_luminance =
781 lrint(luma_den * av_q2d(mdm->max_luminance));
782 mdcv->min_display_mastering_luminance =
783 FFMIN(lrint(luma_den * av_q2d(mdm->min_luminance)),
784 mdcv->max_display_mastering_luminance);
786 priv->sei_needed |= SEI_MASTERING_DISPLAY;
791 if ((priv->sei & SEI_CONTENT_LIGHT_LEVEL) &&
792 (pic->type == PICTURE_TYPE_I || pic->type == PICTURE_TYPE_IDR)) {
793 AVFrameSideData *sd =
794 av_frame_get_side_data(pic->input_image,
795 AV_FRAME_DATA_CONTENT_LIGHT_LEVEL);
798 AVContentLightMetadata *clm =
799 (AVContentLightMetadata *)sd->data;
800 H265RawSEIContentLightLevelInfo *clli =
801 &priv->sei_content_light_level;
803 clli->max_content_light_level = FFMIN(clm->MaxCLL, 65535);
804 clli->max_pic_average_light_level = FFMIN(clm->MaxFALL, 65535);
806 priv->sei_needed |= SEI_CONTENT_LIGHT_LEVEL;
810 vpic->decoded_curr_pic = (VAPictureHEVC) {
811 .picture_id = pic->recon_surface,
812 .pic_order_cnt = hpic->pic_order_cnt,
816 for (i = 0; i < pic->nb_refs; i++) {
817 VAAPIEncodePicture *ref = pic->refs[i];
818 VAAPIEncodeH265Picture *href;
820 av_assert0(ref && ref->encode_order < pic->encode_order);
821 href = ref->priv_data;
823 vpic->reference_frames[i] = (VAPictureHEVC) {
824 .picture_id = ref->recon_surface,
825 .pic_order_cnt = href->pic_order_cnt,
826 .flags = (ref->display_order < pic->display_order ?
827 VA_PICTURE_HEVC_RPS_ST_CURR_BEFORE : 0) |
828 (ref->display_order > pic->display_order ?
829 VA_PICTURE_HEVC_RPS_ST_CURR_AFTER : 0),
832 for (; i < FF_ARRAY_ELEMS(vpic->reference_frames); i++) {
833 vpic->reference_frames[i] = (VAPictureHEVC) {
834 .picture_id = VA_INVALID_ID,
835 .flags = VA_PICTURE_HEVC_INVALID,
839 vpic->coded_buf = pic->output_buffer;
841 vpic->nal_unit_type = hpic->slice_nal_unit;
844 case PICTURE_TYPE_IDR:
845 vpic->pic_fields.bits.idr_pic_flag = 1;
846 vpic->pic_fields.bits.coding_type = 1;
847 vpic->pic_fields.bits.reference_pic_flag = 1;
850 vpic->pic_fields.bits.idr_pic_flag = 0;
851 vpic->pic_fields.bits.coding_type = 1;
852 vpic->pic_fields.bits.reference_pic_flag = 1;
855 vpic->pic_fields.bits.idr_pic_flag = 0;
856 vpic->pic_fields.bits.coding_type = 2;
857 vpic->pic_fields.bits.reference_pic_flag = 1;
860 vpic->pic_fields.bits.idr_pic_flag = 0;
861 vpic->pic_fields.bits.coding_type = 3;
862 vpic->pic_fields.bits.reference_pic_flag = 0;
865 av_assert0(0 && "invalid picture type");
871 static int vaapi_encode_h265_init_slice_params(AVCodecContext *avctx,
872 VAAPIEncodePicture *pic,
873 VAAPIEncodeSlice *slice)
875 VAAPIEncodeH265Context *priv = avctx->priv_data;
876 VAAPIEncodeH265Picture *hpic = pic->priv_data;
877 const H265RawSPS *sps = &priv->raw_sps;
878 const H265RawPPS *pps = &priv->raw_pps;
879 H265RawSliceHeader *sh = &priv->raw_slice.header;
880 VAEncPictureParameterBufferHEVC *vpic = pic->codec_picture_params;
881 VAEncSliceParameterBufferHEVC *vslice = slice->codec_slice_params;
884 sh->nal_unit_header = (H265RawNALUnitHeader) {
885 .nal_unit_type = hpic->slice_nal_unit,
887 .nuh_temporal_id_plus1 = 1,
890 sh->slice_pic_parameter_set_id = pps->pps_pic_parameter_set_id;
892 sh->first_slice_segment_in_pic_flag = slice->index == 0;
893 sh->slice_segment_address = slice->block_start;
895 sh->slice_type = hpic->slice_type;
897 sh->slice_pic_order_cnt_lsb = hpic->pic_order_cnt &
898 (1 << (sps->log2_max_pic_order_cnt_lsb_minus4 + 4)) - 1;
900 if (pic->type != PICTURE_TYPE_IDR) {
901 H265RawSTRefPicSet *rps;
902 const VAAPIEncodeH265Picture *strp;
903 int rps_poc[MAX_DPB_SIZE];
904 int rps_used[MAX_DPB_SIZE];
905 int i, j, poc, rps_pics;
907 sh->short_term_ref_pic_set_sps_flag = 0;
909 rps = &sh->short_term_ref_pic_set;
910 memset(rps, 0, sizeof(*rps));
913 for (i = 0; i < pic->nb_refs; i++) {
914 strp = pic->refs[i]->priv_data;
915 rps_poc[rps_pics] = strp->pic_order_cnt;
916 rps_used[rps_pics] = 1;
919 for (i = 0; i < pic->nb_dpb_pics; i++) {
920 if (pic->dpb[i] == pic)
922 for (j = 0; j < pic->nb_refs; j++) {
923 if (pic->dpb[i] == pic->refs[j])
926 if (j < pic->nb_refs)
928 strp = pic->dpb[i]->priv_data;
929 rps_poc[rps_pics] = strp->pic_order_cnt;
930 rps_used[rps_pics] = 0;
934 for (i = 1; i < rps_pics; i++) {
935 for (j = i; j > 0; j--) {
936 if (rps_poc[j] > rps_poc[j - 1])
938 av_assert0(rps_poc[j] != rps_poc[j - 1]);
939 FFSWAP(int, rps_poc[j], rps_poc[j - 1]);
940 FFSWAP(int, rps_used[j], rps_used[j - 1]);
944 av_log(avctx, AV_LOG_DEBUG, "RPS for POC %d:",
945 hpic->pic_order_cnt);
946 for (i = 0; i < rps_pics; i++) {
947 av_log(avctx, AV_LOG_DEBUG, " (%d,%d)",
948 rps_poc[i], rps_used[i]);
950 av_log(avctx, AV_LOG_DEBUG, "\n");
952 for (i = 0; i < rps_pics; i++) {
953 av_assert0(rps_poc[i] != hpic->pic_order_cnt);
954 if (rps_poc[i] > hpic->pic_order_cnt)
958 rps->num_negative_pics = i;
959 poc = hpic->pic_order_cnt;
960 for (j = i - 1; j >= 0; j--) {
961 rps->delta_poc_s0_minus1[i - 1 - j] = poc - rps_poc[j] - 1;
962 rps->used_by_curr_pic_s0_flag[i - 1 - j] = rps_used[j];
966 rps->num_positive_pics = rps_pics - i;
967 poc = hpic->pic_order_cnt;
968 for (j = i; j < rps_pics; j++) {
969 rps->delta_poc_s1_minus1[j - i] = rps_poc[j] - poc - 1;
970 rps->used_by_curr_pic_s1_flag[j - i] = rps_used[j];
974 sh->num_long_term_sps = 0;
975 sh->num_long_term_pics = 0;
977 sh->slice_temporal_mvp_enabled_flag =
978 sps->sps_temporal_mvp_enabled_flag;
979 if (sh->slice_temporal_mvp_enabled_flag) {
980 sh->collocated_from_l0_flag = sh->slice_type == HEVC_SLICE_B;
981 sh->collocated_ref_idx = 0;
984 sh->num_ref_idx_active_override_flag = 0;
985 sh->num_ref_idx_l0_active_minus1 = pps->num_ref_idx_l0_default_active_minus1;
986 sh->num_ref_idx_l1_active_minus1 = pps->num_ref_idx_l1_default_active_minus1;
989 sh->slice_sao_luma_flag = sh->slice_sao_chroma_flag =
990 sps->sample_adaptive_offset_enabled_flag;
992 if (pic->type == PICTURE_TYPE_B)
993 sh->slice_qp_delta = priv->fixed_qp_b - (pps->init_qp_minus26 + 26);
994 else if (pic->type == PICTURE_TYPE_P)
995 sh->slice_qp_delta = priv->fixed_qp_p - (pps->init_qp_minus26 + 26);
997 sh->slice_qp_delta = priv->fixed_qp_idr - (pps->init_qp_minus26 + 26);
1000 *vslice = (VAEncSliceParameterBufferHEVC) {
1001 .slice_segment_address = sh->slice_segment_address,
1002 .num_ctu_in_slice = slice->block_size,
1004 .slice_type = sh->slice_type,
1005 .slice_pic_parameter_set_id = sh->slice_pic_parameter_set_id,
1007 .num_ref_idx_l0_active_minus1 = sh->num_ref_idx_l0_active_minus1,
1008 .num_ref_idx_l1_active_minus1 = sh->num_ref_idx_l1_active_minus1,
1010 .luma_log2_weight_denom = sh->luma_log2_weight_denom,
1011 .delta_chroma_log2_weight_denom = sh->delta_chroma_log2_weight_denom,
1013 .max_num_merge_cand = 5 - sh->five_minus_max_num_merge_cand,
1015 .slice_qp_delta = sh->slice_qp_delta,
1016 .slice_cb_qp_offset = sh->slice_cb_qp_offset,
1017 .slice_cr_qp_offset = sh->slice_cr_qp_offset,
1019 .slice_beta_offset_div2 = sh->slice_beta_offset_div2,
1020 .slice_tc_offset_div2 = sh->slice_tc_offset_div2,
1022 .slice_fields.bits = {
1023 .last_slice_of_pic_flag = slice->index == pic->nb_slices - 1,
1024 .dependent_slice_segment_flag = sh->dependent_slice_segment_flag,
1025 .colour_plane_id = sh->colour_plane_id,
1026 .slice_temporal_mvp_enabled_flag =
1027 sh->slice_temporal_mvp_enabled_flag,
1028 .slice_sao_luma_flag = sh->slice_sao_luma_flag,
1029 .slice_sao_chroma_flag = sh->slice_sao_chroma_flag,
1030 .num_ref_idx_active_override_flag =
1031 sh->num_ref_idx_active_override_flag,
1032 .mvd_l1_zero_flag = sh->mvd_l1_zero_flag,
1033 .cabac_init_flag = sh->cabac_init_flag,
1034 .slice_deblocking_filter_disabled_flag =
1035 sh->slice_deblocking_filter_disabled_flag,
1036 .slice_loop_filter_across_slices_enabled_flag =
1037 sh->slice_loop_filter_across_slices_enabled_flag,
1038 .collocated_from_l0_flag = sh->collocated_from_l0_flag,
1042 for (i = 0; i < FF_ARRAY_ELEMS(vslice->ref_pic_list0); i++) {
1043 vslice->ref_pic_list0[i].picture_id = VA_INVALID_ID;
1044 vslice->ref_pic_list0[i].flags = VA_PICTURE_HEVC_INVALID;
1045 vslice->ref_pic_list1[i].picture_id = VA_INVALID_ID;
1046 vslice->ref_pic_list1[i].flags = VA_PICTURE_HEVC_INVALID;
1049 av_assert0(pic->nb_refs <= 2);
1050 if (pic->nb_refs >= 1) {
1051 // Backward reference for P- or B-frame.
1052 av_assert0(pic->type == PICTURE_TYPE_P ||
1053 pic->type == PICTURE_TYPE_B);
1054 vslice->ref_pic_list0[0] = vpic->reference_frames[0];
1056 if (pic->nb_refs >= 2) {
1057 // Forward reference for B-frame.
1058 av_assert0(pic->type == PICTURE_TYPE_B);
1059 vslice->ref_pic_list1[0] = vpic->reference_frames[1];
1065 static av_cold int vaapi_encode_h265_configure(AVCodecContext *avctx)
1067 VAAPIEncodeContext *ctx = avctx->priv_data;
1068 VAAPIEncodeH265Context *priv = avctx->priv_data;
1071 err = ff_cbs_init(&priv->cbc, AV_CODEC_ID_HEVC, avctx);
1075 if (ctx->va_rc_mode == VA_RC_CQP) {
1076 priv->fixed_qp_p = priv->qp;
1077 if (avctx->i_quant_factor > 0.0)
1078 priv->fixed_qp_idr = (int)((priv->fixed_qp_p * avctx->i_quant_factor +
1079 avctx->i_quant_offset) + 0.5);
1081 priv->fixed_qp_idr = priv->fixed_qp_p;
1082 if (avctx->b_quant_factor > 0.0)
1083 priv->fixed_qp_b = (int)((priv->fixed_qp_p * avctx->b_quant_factor +
1084 avctx->b_quant_offset) + 0.5);
1086 priv->fixed_qp_b = priv->fixed_qp_p;
1088 av_log(avctx, AV_LOG_DEBUG, "Using fixed QP = "
1089 "%d / %d / %d for IDR- / P- / B-frames.\n",
1090 priv->fixed_qp_idr, priv->fixed_qp_p, priv->fixed_qp_b);
1092 } else if (ctx->va_rc_mode == VA_RC_CBR ||
1093 ctx->va_rc_mode == VA_RC_VBR) {
1094 // These still need to be set for pic_init_qp/slice_qp_delta.
1095 priv->fixed_qp_idr = 30;
1096 priv->fixed_qp_p = 30;
1097 priv->fixed_qp_b = 30;
1100 av_assert0(0 && "Invalid RC mode.");
1106 static const VAAPIEncodeProfile vaapi_encode_h265_profiles[] = {
1107 { FF_PROFILE_HEVC_MAIN, 8, 3, 1, 1, VAProfileHEVCMain },
1108 { FF_PROFILE_HEVC_REXT, 8, 3, 1, 1, VAProfileHEVCMain },
1109 #if VA_CHECK_VERSION(0, 37, 0)
1110 { FF_PROFILE_HEVC_MAIN_10, 10, 3, 1, 1, VAProfileHEVCMain10 },
1111 { FF_PROFILE_HEVC_REXT, 10, 3, 1, 1, VAProfileHEVCMain10 },
1113 { FF_PROFILE_UNKNOWN }
1116 static const VAAPIEncodeType vaapi_encode_type_h265 = {
1117 .profiles = vaapi_encode_h265_profiles,
1119 .flags = FLAG_SLICE_CONTROL |
1121 FLAG_B_PICTURE_REFERENCES |
1122 FLAG_NON_IDR_KEY_PICTURES,
1124 .configure = &vaapi_encode_h265_configure,
1126 .picture_priv_data_size = sizeof(VAAPIEncodeH265Picture),
1128 .sequence_params_size = sizeof(VAEncSequenceParameterBufferHEVC),
1129 .init_sequence_params = &vaapi_encode_h265_init_sequence_params,
1131 .picture_params_size = sizeof(VAEncPictureParameterBufferHEVC),
1132 .init_picture_params = &vaapi_encode_h265_init_picture_params,
1134 .slice_params_size = sizeof(VAEncSliceParameterBufferHEVC),
1135 .init_slice_params = &vaapi_encode_h265_init_slice_params,
1137 .sequence_header_type = VAEncPackedHeaderSequence,
1138 .write_sequence_header = &vaapi_encode_h265_write_sequence_header,
1140 .slice_header_type = VAEncPackedHeaderHEVC_Slice,
1141 .write_slice_header = &vaapi_encode_h265_write_slice_header,
1143 .write_extra_header = &vaapi_encode_h265_write_extra_header,
1146 static av_cold int vaapi_encode_h265_init(AVCodecContext *avctx)
1148 VAAPIEncodeContext *ctx = avctx->priv_data;
1149 VAAPIEncodeH265Context *priv = avctx->priv_data;
1151 ctx->codec = &vaapi_encode_type_h265;
1153 if (avctx->profile == FF_PROFILE_UNKNOWN)
1154 avctx->profile = priv->profile;
1155 if (avctx->level == FF_LEVEL_UNKNOWN)
1156 avctx->level = priv->level;
1158 if (avctx->level != FF_LEVEL_UNKNOWN && avctx->level & ~0xff) {
1159 av_log(avctx, AV_LOG_ERROR, "Invalid level %d: must fit "
1160 "in 8-bit unsigned integer.\n", avctx->level);
1161 return AVERROR(EINVAL);
1164 ctx->desired_packed_headers =
1165 VA_ENC_PACKED_HEADER_SEQUENCE | // VPS, SPS and PPS.
1166 VA_ENC_PACKED_HEADER_SLICE | // Slice headers.
1167 VA_ENC_PACKED_HEADER_MISC; // SEI
1169 ctx->surface_width = FFALIGN(avctx->width, 16);
1170 ctx->surface_height = FFALIGN(avctx->height, 16);
1172 // CTU size is currently hard-coded to 32.
1173 ctx->slice_block_width = ctx->slice_block_height = 32;
1175 return ff_vaapi_encode_init(avctx);
1178 static av_cold int vaapi_encode_h265_close(AVCodecContext *avctx)
1180 VAAPIEncodeH265Context *priv = avctx->priv_data;
1182 ff_cbs_fragment_free(priv->cbc, &priv->current_access_unit);
1183 ff_cbs_close(&priv->cbc);
1185 return ff_vaapi_encode_close(avctx);
1188 #define OFFSET(x) offsetof(VAAPIEncodeH265Context, x)
1189 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
1190 static const AVOption vaapi_encode_h265_options[] = {
1191 VAAPI_ENCODE_COMMON_OPTIONS,
1193 { "qp", "Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)",
1194 OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 25 }, 0, 52, FLAGS },
1196 { "aud", "Include AUD",
1197 OFFSET(aud), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
1199 { "profile", "Set profile (general_profile_idc)",
1200 OFFSET(profile), AV_OPT_TYPE_INT,
1201 { .i64 = FF_PROFILE_UNKNOWN }, FF_PROFILE_UNKNOWN, 0xff, FLAGS, "profile" },
1203 #define PROFILE(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
1204 { .i64 = value }, 0, 0, FLAGS, "profile"
1205 { PROFILE("main", FF_PROFILE_HEVC_MAIN) },
1206 { PROFILE("main10", FF_PROFILE_HEVC_MAIN_10) },
1207 { PROFILE("rext", FF_PROFILE_HEVC_REXT) },
1210 { "tier", "Set tier (general_tier_flag)",
1211 OFFSET(tier), AV_OPT_TYPE_INT,
1212 { .i64 = 0 }, 0, 1, FLAGS, "tier" },
1213 { "main", NULL, 0, AV_OPT_TYPE_CONST,
1214 { .i64 = 0 }, 0, 0, FLAGS, "tier" },
1215 { "high", NULL, 0, AV_OPT_TYPE_CONST,
1216 { .i64 = 1 }, 0, 0, FLAGS, "tier" },
1218 { "level", "Set level (general_level_idc)",
1219 OFFSET(level), AV_OPT_TYPE_INT,
1220 { .i64 = FF_LEVEL_UNKNOWN }, FF_LEVEL_UNKNOWN, 0xff, FLAGS, "level" },
1222 #define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
1223 { .i64 = value }, 0, 0, FLAGS, "level"
1226 { LEVEL("2.1", 63) },
1228 { LEVEL("3.1", 93) },
1229 { LEVEL("4", 120) },
1230 { LEVEL("4.1", 123) },
1231 { LEVEL("5", 150) },
1232 { LEVEL("5.1", 153) },
1233 { LEVEL("5.2", 156) },
1234 { LEVEL("6", 180) },
1235 { LEVEL("6.1", 183) },
1236 { LEVEL("6.2", 186) },
1239 { "sei", "Set SEI to include",
1240 OFFSET(sei), AV_OPT_TYPE_FLAGS,
1241 { .i64 = SEI_MASTERING_DISPLAY | SEI_CONTENT_LIGHT_LEVEL },
1242 0, INT_MAX, FLAGS, "sei" },
1244 "Include HDR metadata for mastering display colour volume "
1245 "and content light level information",
1246 0, AV_OPT_TYPE_CONST,
1247 { .i64 = SEI_MASTERING_DISPLAY | SEI_CONTENT_LIGHT_LEVEL },
1248 INT_MIN, INT_MAX, FLAGS, "sei" },
1253 static const AVCodecDefault vaapi_encode_h265_defaults[] = {
1257 { "i_qfactor", "1" },
1258 { "i_qoffset", "0" },
1259 { "b_qfactor", "6/5" },
1260 { "b_qoffset", "0" },
1266 static const AVClass vaapi_encode_h265_class = {
1267 .class_name = "h265_vaapi",
1268 .item_name = av_default_item_name,
1269 .option = vaapi_encode_h265_options,
1270 .version = LIBAVUTIL_VERSION_INT,
1273 AVCodec ff_hevc_vaapi_encoder = {
1274 .name = "hevc_vaapi",
1275 .long_name = NULL_IF_CONFIG_SMALL("H.265/HEVC (VAAPI)"),
1276 .type = AVMEDIA_TYPE_VIDEO,
1277 .id = AV_CODEC_ID_HEVC,
1278 .priv_data_size = sizeof(VAAPIEncodeH265Context),
1279 .init = &vaapi_encode_h265_init,
1280 .send_frame = &ff_vaapi_encode_send_frame,
1281 .receive_packet = &ff_vaapi_encode_receive_packet,
1282 .close = &vaapi_encode_h265_close,
1283 .priv_class = &vaapi_encode_h265_class,
1284 .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE,
1285 .defaults = vaapi_encode_h265_defaults,
1286 .pix_fmts = (const enum AVPixelFormat[]) {
1290 .wrapper_name = "vaapi",