FFmpeg
Loading...
Searching...
No Matches
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/mem.h"
27#include "libavutil/pixdesc.h"
28#include "libavutil/opt.h"
30
31#include "atsc_a53.h"
32#include "avcodec.h"
33#include "cbs.h"
34#include "cbs_h265.h"
35#include "hw_base_encode_h265.h"
36#include "codec_internal.h"
37#include "h2645data.h"
38#include "h265_profile_level.h"
39#include "vaapi_encode.h"
40
41#include "hevc/hevc.h"
42
43enum {
46 SEI_A53_CC = 0x20,
47};
48
58
96
97
99 char *data, size_t *data_len,
101{
102 VAAPIEncodeH265Context *priv = avctx->priv_data;
103 int err;
104
105 err = ff_cbs_write_fragment_data(priv->cbc, au);
106 if (err < 0) {
107 av_log(avctx, AV_LOG_ERROR, "Failed to write packed header.\n");
108 return err;
109 }
110
111 if (*data_len < 8 * au->data_size - au->data_bit_padding) {
112 av_log(avctx, AV_LOG_ERROR, "Access unit too large: "
113 "%zu < %zu.\n", *data_len,
114 8 * au->data_size - au->data_bit_padding);
115 return AVERROR(ENOSPC);
116 }
117
118 memcpy(data, au->data, au->data_size);
119 *data_len = 8 * au->data_size - au->data_bit_padding;
120
121 return 0;
122}
123
126 void *nal_unit)
127{
128 H265RawNALUnitHeader *header = nal_unit;
129 int err;
130
131 err = ff_cbs_insert_unit_content(au, -1,
132 header->nal_unit_type, nal_unit, NULL);
133 if (err < 0) {
134 av_log(avctx, AV_LOG_ERROR, "Failed to add NAL unit: "
135 "type = %d.\n", header->nal_unit_type);
136 return err;
137 }
138
139 return 0;
140}
141
143 char *data, size_t *data_len)
144{
145 VAAPIEncodeH265Context *priv = avctx->priv_data;
147 int err;
148
149 if (priv->aud_needed) {
150 err = vaapi_encode_h265_add_nal(avctx, au, &priv->raw_aud);
151 if (err < 0)
152 goto fail;
153 priv->aud_needed = 0;
154 }
155
156 err = vaapi_encode_h265_add_nal(avctx, au, &priv->units.raw_vps);
157 if (err < 0)
158 goto fail;
159
160 err = vaapi_encode_h265_add_nal(avctx, au, &priv->units.raw_sps);
161 if (err < 0)
162 goto fail;
163
164 err = vaapi_encode_h265_add_nal(avctx, au, &priv->units.raw_pps);
165 if (err < 0)
166 goto fail;
167
168 err = vaapi_encode_h265_write_access_unit(avctx, data, data_len, au);
169fail:
170 ff_cbs_fragment_reset(au);
171 return err;
172}
173
176 VAAPIEncodeSlice *slice,
177 char *data, size_t *data_len)
178{
179 VAAPIEncodeH265Context *priv = avctx->priv_data;
181 int err;
182
183 if (priv->aud_needed) {
184 err = vaapi_encode_h265_add_nal(avctx, au, &priv->raw_aud);
185 if (err < 0)
186 goto fail;
187 priv->aud_needed = 0;
188 }
189
190 err = vaapi_encode_h265_add_nal(avctx, au, &priv->raw_slice);
191 if (err < 0)
192 goto fail;
193
194 err = vaapi_encode_h265_write_access_unit(avctx, data, data_len, au);
195fail:
196 ff_cbs_fragment_reset(au);
197 return err;
198}
199
202 int index, int *type,
203 char *data, size_t *data_len)
204{
205 VAAPIEncodeH265Context *priv = avctx->priv_data;
207 int err;
208
209 if (priv->sei_needed) {
210 if (priv->aud_needed) {
211 err = vaapi_encode_h265_add_nal(avctx, au, &priv->aud);
212 if (err < 0)
213 goto fail;
214 priv->aud_needed = 0;
215 }
216
217 if (priv->sei_needed & SEI_MASTERING_DISPLAY) {
218 err = ff_cbs_sei_add_message(priv->cbc, au, 1,
221 if (err < 0)
222 goto fail;
223 }
224
226 err = ff_cbs_sei_add_message(priv->cbc, au, 1,
229 if (err < 0)
230 goto fail;
231 }
232 if (priv->sei_needed & SEI_A53_CC) {
233 err = ff_cbs_sei_add_message(priv->cbc, au, 1,
235 &priv->sei_a53cc, NULL);
236 if (err < 0)
237 goto fail;
238 }
239
240 priv->sei_needed = 0;
241
242 err = vaapi_encode_h265_write_access_unit(avctx, data, data_len, au);
243 if (err < 0)
244 goto fail;
245
246 ff_cbs_fragment_reset(au);
247
248 *type = VAEncPackedHeaderRawData;
249 return 0;
250 } else {
251 return AVERROR_EOF;
252 }
253
254fail:
255 ff_cbs_fragment_reset(au);
256 return err;
257}
258
260{
261 FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
263 VAAPIEncodeH265Context *priv = avctx->priv_data;
264 H265RawVPS *vps = &priv->units.raw_vps;
265 H265RawSPS *sps = &priv->units.raw_sps;
266 H265RawPPS *pps = &priv->units.raw_pps;
267 VAEncSequenceParameterBufferHEVC *vseq = ctx->codec_sequence_params;
268 VAEncPictureParameterBufferHEVC *vpic = ctx->codec_picture_params;
269 int i, err;
270
271 // priv->unit_opts.tier already set
272 // priv->unit_opts.fixed_qp_idr already set
273 priv->unit_opts.cu_qp_delta_enabled_flag = (ctx->va_rc_mode != VA_RC_CQP);
274 priv->unit_opts.tile_rows = ctx->tile_rows;
275 priv->unit_opts.tile_cols = ctx->tile_cols;
276 priv->unit_opts.nb_slices = ctx->nb_slices;
277 priv->unit_opts.slice_block_rows = ctx->slice_block_rows;
278 priv->unit_opts.slice_block_cols = ctx->slice_block_cols;
279 memcpy(priv->unit_opts.col_width, ctx->col_width,
280 ctx->tile_rows*sizeof(*priv->unit_opts.col_width));
281 memcpy(priv->unit_opts.row_height, ctx->row_height,
282 ctx->tile_cols*sizeof(*priv->unit_opts.row_height));
283
284 err = ff_hw_base_encode_init_params_h265(base_ctx, avctx,
285 &priv->units, &priv->unit_opts);
286 if (err < 0)
287 return err;
288
289#if VA_CHECK_VERSION(1, 13, 0)
290 // update sps setting according to queried result
291 if (priv->va_features) {
292 VAConfigAttribValEncHEVCFeatures features = { .value = priv->va_features };
293
294 // Enable feature if get queried result is VA_FEATURE_SUPPORTED | VA_FEATURE_REQUIRED
295 sps->amp_enabled_flag =
296 !!features.bits.amp;
297 sps->sample_adaptive_offset_enabled_flag =
298 !!features.bits.sao;
299 sps->sps_temporal_mvp_enabled_flag =
300 !!features.bits.temporal_mvp;
301 sps->pcm_enabled_flag =
302 !!features.bits.pcm;
303 }
304
305 if (priv->va_bs) {
306 VAConfigAttribValEncHEVCBlockSizes bs = { .value = priv->va_bs };
307 sps->log2_min_luma_coding_block_size_minus3 =
308 ff_ctz(priv->min_cb_size) - 3;
309 sps->log2_diff_max_min_luma_coding_block_size =
310 ff_ctz(priv->ctu_size) - ff_ctz(priv->min_cb_size);
311
312 sps->log2_min_luma_transform_block_size_minus2 =
313 bs.bits.log2_min_luma_transform_block_size_minus2;
314 sps->log2_diff_max_min_luma_transform_block_size =
315 bs.bits.log2_max_luma_transform_block_size_minus2 -
316 bs.bits.log2_min_luma_transform_block_size_minus2;
317
318 sps->max_transform_hierarchy_depth_inter =
319 bs.bits.max_max_transform_hierarchy_depth_inter;
320 sps->max_transform_hierarchy_depth_intra =
321 bs.bits.max_max_transform_hierarchy_depth_intra;
322 }
323
324 // update pps setting according to queried result
325 if (priv->va_features) {
326 VAConfigAttribValEncHEVCFeatures features = { .value = priv->va_features };
327 if (ctx->va_rc_mode != VA_RC_CQP)
328 pps->cu_qp_delta_enabled_flag =
329 !!features.bits.cu_qp_delta;
330
331 pps->transform_skip_enabled_flag =
332 !!features.bits.transform_skip;
333 // set diff_cu_qp_delta_depth as its max value if cu_qp_delta enabled. Otherwise
334 // 0 will make cu_qp_delta invalid.
335 if (pps->cu_qp_delta_enabled_flag)
336 pps->diff_cu_qp_delta_depth = sps->log2_diff_max_min_luma_coding_block_size;
337 }
338#endif
339
340 // Fill VAAPI parameter buffers.
341
342 *vseq = (VAEncSequenceParameterBufferHEVC) {
343 .general_profile_idc = vps->profile_tier_level.general_profile_idc,
344 .general_level_idc = vps->profile_tier_level.general_level_idc,
345 .general_tier_flag = vps->profile_tier_level.general_tier_flag,
346
347 .intra_period = base_ctx->gop_size,
348 .intra_idr_period = base_ctx->gop_size,
349 .ip_period = base_ctx->b_per_p + 1,
350 .bits_per_second = ctx->va_bit_rate,
351
352 .pic_width_in_luma_samples = sps->pic_width_in_luma_samples,
353 .pic_height_in_luma_samples = sps->pic_height_in_luma_samples,
354
355 .seq_fields.bits = {
356 .chroma_format_idc = sps->chroma_format_idc,
357 .separate_colour_plane_flag = sps->separate_colour_plane_flag,
358 .bit_depth_luma_minus8 = sps->bit_depth_luma_minus8,
359 .bit_depth_chroma_minus8 = sps->bit_depth_chroma_minus8,
360 .scaling_list_enabled_flag = sps->scaling_list_enabled_flag,
361 .strong_intra_smoothing_enabled_flag =
362 sps->strong_intra_smoothing_enabled_flag,
363 .amp_enabled_flag = sps->amp_enabled_flag,
364 .sample_adaptive_offset_enabled_flag =
365 sps->sample_adaptive_offset_enabled_flag,
366 .pcm_enabled_flag = sps->pcm_enabled_flag,
367 .pcm_loop_filter_disabled_flag = sps->pcm_loop_filter_disabled_flag,
368 .sps_temporal_mvp_enabled_flag = sps->sps_temporal_mvp_enabled_flag,
369 },
370
371 .log2_min_luma_coding_block_size_minus3 =
372 sps->log2_min_luma_coding_block_size_minus3,
373 .log2_diff_max_min_luma_coding_block_size =
374 sps->log2_diff_max_min_luma_coding_block_size,
375 .log2_min_transform_block_size_minus2 =
376 sps->log2_min_luma_transform_block_size_minus2,
377 .log2_diff_max_min_transform_block_size =
378 sps->log2_diff_max_min_luma_transform_block_size,
379 .max_transform_hierarchy_depth_inter =
380 sps->max_transform_hierarchy_depth_inter,
381 .max_transform_hierarchy_depth_intra =
382 sps->max_transform_hierarchy_depth_intra,
383
384 .pcm_sample_bit_depth_luma_minus1 =
385 sps->pcm_sample_bit_depth_luma_minus1,
386 .pcm_sample_bit_depth_chroma_minus1 =
387 sps->pcm_sample_bit_depth_chroma_minus1,
388 .log2_min_pcm_luma_coding_block_size_minus3 =
389 sps->log2_min_pcm_luma_coding_block_size_minus3,
390 .log2_max_pcm_luma_coding_block_size_minus3 =
391 sps->log2_min_pcm_luma_coding_block_size_minus3 +
392 sps->log2_diff_max_min_pcm_luma_coding_block_size,
393
394 .vui_parameters_present_flag = 0,
395 };
396
397 *vpic = (VAEncPictureParameterBufferHEVC) {
398 .decoded_curr_pic = {
399 .picture_id = VA_INVALID_ID,
400 .flags = VA_PICTURE_HEVC_INVALID,
401 },
402
403 .coded_buf = VA_INVALID_ID,
404
405 .collocated_ref_pic_index = sps->sps_temporal_mvp_enabled_flag ?
406 0 : 0xff,
407 .last_picture = 0,
408
409 .pic_init_qp = pps->init_qp_minus26 + 26,
410 .diff_cu_qp_delta_depth = pps->diff_cu_qp_delta_depth,
411 .pps_cb_qp_offset = pps->pps_cb_qp_offset,
412 .pps_cr_qp_offset = pps->pps_cr_qp_offset,
413
414 .num_tile_columns_minus1 = pps->num_tile_columns_minus1,
415 .num_tile_rows_minus1 = pps->num_tile_rows_minus1,
416
417 .log2_parallel_merge_level_minus2 = pps->log2_parallel_merge_level_minus2,
418 .ctu_max_bitsize_allowed = 0,
419
420 .num_ref_idx_l0_default_active_minus1 =
421 pps->num_ref_idx_l0_default_active_minus1,
422 .num_ref_idx_l1_default_active_minus1 =
423 pps->num_ref_idx_l1_default_active_minus1,
424
425 .slice_pic_parameter_set_id = pps->pps_pic_parameter_set_id,
426
427 .pic_fields.bits = {
428 .sign_data_hiding_enabled_flag = pps->sign_data_hiding_enabled_flag,
429 .constrained_intra_pred_flag = pps->constrained_intra_pred_flag,
430 .transform_skip_enabled_flag = pps->transform_skip_enabled_flag,
431 .cu_qp_delta_enabled_flag = pps->cu_qp_delta_enabled_flag,
432 .weighted_pred_flag = pps->weighted_pred_flag,
433 .weighted_bipred_flag = pps->weighted_bipred_flag,
434 .transquant_bypass_enabled_flag = pps->transquant_bypass_enabled_flag,
435 .tiles_enabled_flag = pps->tiles_enabled_flag,
436 .entropy_coding_sync_enabled_flag = pps->entropy_coding_sync_enabled_flag,
437 .loop_filter_across_tiles_enabled_flag =
438 pps->loop_filter_across_tiles_enabled_flag,
439 .pps_loop_filter_across_slices_enabled_flag =
440 pps->pps_loop_filter_across_slices_enabled_flag,
441 .scaling_list_data_present_flag = (sps->sps_scaling_list_data_present_flag |
442 pps->pps_scaling_list_data_present_flag),
443 .screen_content_flag = 0,
444 .enable_gpu_weighted_prediction = 0,
445 .no_output_of_prior_pics_flag = 0,
446 },
447 };
448
449 if (pps->tiles_enabled_flag) {
450 for (i = 0; i <= vpic->num_tile_rows_minus1; i++)
451 vpic->row_height_minus1[i] = pps->row_height_minus1[i];
452 for (i = 0; i <= vpic->num_tile_columns_minus1; i++)
453 vpic->column_width_minus1[i] = pps->column_width_minus1[i];
454 }
455
456 return 0;
457}
458
461{
462 FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
463 VAAPIEncodeH265Context *priv = avctx->priv_data;
464 VAAPIEncodePicture *vaapi_pic = pic->priv;
466 FFHWBaseEncodePicture *prev = pic->prev;
467 VAAPIEncodeH265Picture *hprev = prev ? prev->codec_priv : NULL;
468 VAEncPictureParameterBufferHEVC *vpic = vaapi_pic->codec_picture_params;
469 int i, j = 0;
470
471 if (pic->type == FF_HW_PICTURE_TYPE_IDR) {
473
474 hpic->last_idr_frame = pic->display_order;
475
477 hpic->slice_type = HEVC_SLICE_I;
478 hpic->pic_type = 0;
479 } else {
480 av_assert0(prev);
481 hpic->last_idr_frame = hprev->last_idr_frame;
482
483 if (pic->type == FF_HW_PICTURE_TYPE_I) {
485 hpic->slice_type = HEVC_SLICE_I;
486 hpic->pic_type = 0;
487 } else if (pic->type == FF_HW_PICTURE_TYPE_P) {
488 av_assert0(pic->refs[0]);
490 hpic->slice_type = HEVC_SLICE_P;
491 hpic->pic_type = 1;
492 } else {
493 FFHWBaseEncodePicture *irap_ref;
494 av_assert0(pic->refs[0][0] && pic->refs[1][0]);
495 for (irap_ref = pic; irap_ref; irap_ref = irap_ref->refs[1][0]) {
496 if (irap_ref->type == FF_HW_PICTURE_TYPE_I)
497 break;
498 }
499 if (pic->b_depth == base_ctx->max_b_depth) {
500 hpic->slice_nal_unit = irap_ref ? HEVC_NAL_RASL_N
502 } else {
503 hpic->slice_nal_unit = irap_ref ? HEVC_NAL_RASL_R
505 }
506 hpic->slice_type = HEVC_SLICE_B;
507 hpic->pic_type = 2;
508 }
509 }
510 hpic->pic_order_cnt = pic->display_order - hpic->last_idr_frame;
511
512 if (priv->aud) {
513 priv->aud_needed = 1;
514 priv->raw_aud = (H265RawAUD) {
515 .nal_unit_header = {
516 .nal_unit_type = HEVC_NAL_AUD,
517 .nuh_layer_id = 0,
518 .nuh_temporal_id_plus1 = 1,
519 },
520 .pic_type = hpic->pic_type,
521 };
522 } else {
523 priv->aud_needed = 0;
524 }
525
526 priv->sei_needed = 0;
527
528 // Only look for the metadata on I/IDR frame on the output. We
529 // may force an IDR frame on the output where the metadata gets
530 // changed on the input frame.
531 if ((priv->sei & SEI_MASTERING_DISPLAY) &&
533 AVFrameSideData *sd =
536
537 if (sd) {
540
541 // SEI is needed when both the primaries and luminance are set
542 if (mdm->has_primaries && mdm->has_luminance) {
545 const int mapping[3] = {1, 2, 0};
546 const int chroma_den = 50000;
547 const int luma_den = 10000;
548
549 for (i = 0; i < 3; i++) {
550 const int j = mapping[i];
551 mdcv->display_primaries_x[i] =
552 FFMIN(lrint(chroma_den *
553 av_q2d(mdm->display_primaries[j][0])),
554 chroma_den);
555 mdcv->display_primaries_y[i] =
556 FFMIN(lrint(chroma_den *
557 av_q2d(mdm->display_primaries[j][1])),
558 chroma_den);
559 }
560
561 mdcv->white_point_x =
562 FFMIN(lrint(chroma_den * av_q2d(mdm->white_point[0])),
563 chroma_den);
564 mdcv->white_point_y =
565 FFMIN(lrint(chroma_den * av_q2d(mdm->white_point[1])),
566 chroma_den);
567
569 lrint(luma_den * av_q2d(mdm->max_luminance));
571 FFMIN(lrint(luma_den * av_q2d(mdm->min_luminance)),
573
575 }
576 }
577 }
578
579 if ((priv->sei & SEI_CONTENT_LIGHT_LEVEL) &&
581 AVFrameSideData *sd =
584
585 if (sd) {
590
591 clli->max_content_light_level = FFMIN(clm->MaxCLL, 65535);
592 clli->max_pic_average_light_level = FFMIN(clm->MaxFALL, 65535);
593
595 }
596 }
597
598 if (priv->sei & SEI_A53_CC) {
599 int err;
600 size_t sei_a53cc_len;
601 av_freep(&priv->sei_a53cc_data);
602 err = ff_alloc_a53_sei(pic->input_image, 0, &priv->sei_a53cc_data, &sei_a53cc_len);
603 if (err < 0)
604 return err;
605 if (priv->sei_a53cc_data != NULL) {
607 priv->sei_a53cc.data = (uint8_t *)priv->sei_a53cc_data + 1;
608 priv->sei_a53cc.data_length = sei_a53cc_len - 1;
609
610 priv->sei_needed |= SEI_A53_CC;
611 }
612 }
613
614 vpic->decoded_curr_pic = (VAPictureHEVC) {
615 .picture_id = vaapi_pic->recon_surface,
616 .pic_order_cnt = hpic->pic_order_cnt,
617 .flags = 0,
618 };
619
620 for (int k = 0; k < MAX_REFERENCE_LIST_NUM; k++) {
621 for (i = 0; i < pic->nb_refs[k]; i++) {
622 FFHWBaseEncodePicture *ref = pic->refs[k][i];
624
625 av_assert0(ref && ref->encode_order < pic->encode_order);
626 href = ref->codec_priv;
627
628 vpic->reference_frames[j++] = (VAPictureHEVC) {
629 .picture_id = ((VAAPIEncodePicture *)ref->priv)->recon_surface,
630 .pic_order_cnt = href->pic_order_cnt,
631 .flags = (ref->display_order < pic->display_order ?
632 VA_PICTURE_HEVC_RPS_ST_CURR_BEFORE : 0) |
633 (ref->display_order > pic->display_order ?
634 VA_PICTURE_HEVC_RPS_ST_CURR_AFTER : 0),
635 };
636 }
637 }
638
639 for (; j < FF_ARRAY_ELEMS(vpic->reference_frames); j++) {
640 vpic->reference_frames[j] = (VAPictureHEVC) {
641 .picture_id = VA_INVALID_ID,
642 .flags = VA_PICTURE_HEVC_INVALID,
643 };
644 }
645
646 vpic->coded_buf = vaapi_pic->output_buffer;
647
648 vpic->nal_unit_type = hpic->slice_nal_unit;
649
650 vpic->pic_fields.bits.reference_pic_flag = pic->is_reference;
651 switch (pic->type) {
653 vpic->pic_fields.bits.idr_pic_flag = 1;
654 vpic->pic_fields.bits.coding_type = 1;
655 break;
657 vpic->pic_fields.bits.idr_pic_flag = 0;
658 vpic->pic_fields.bits.coding_type = 1;
659 break;
661 vpic->pic_fields.bits.idr_pic_flag = 0;
662 vpic->pic_fields.bits.coding_type = 2;
663 break;
665 vpic->pic_fields.bits.idr_pic_flag = 0;
666 vpic->pic_fields.bits.coding_type = 3;
667 break;
668 default:
669 av_assert0(0 && "invalid picture type");
670 }
671
672 return 0;
673}
674
677 VAAPIEncodeSlice *slice)
678{
679 FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
680 VAAPIEncodeH265Context *priv = avctx->priv_data;
681 VAAPIEncodePicture *vaapi_pic = pic->priv;
683 const H265RawSPS *sps = &priv->units.raw_sps;
684 const H265RawPPS *pps = &priv->units.raw_pps;
686 VAEncPictureParameterBufferHEVC *vpic = vaapi_pic->codec_picture_params;
687 VAEncSliceParameterBufferHEVC *vslice = slice->codec_slice_params;
688 int i;
689
691 .nal_unit_type = hpic->slice_nal_unit,
692 .nuh_layer_id = 0,
693 .nuh_temporal_id_plus1 = 1,
694 };
695
696 sh->slice_pic_parameter_set_id = pps->pps_pic_parameter_set_id;
697
698 sh->first_slice_segment_in_pic_flag = slice->index == 0;
700
701 sh->slice_type = hpic->slice_type;
702
703 if (sh->slice_type == HEVC_SLICE_P && base_ctx->p_to_gpb)
705
707 (1 << (sps->log2_max_pic_order_cnt_lsb_minus4 + 4)) - 1;
708
709 if (pic->type != FF_HW_PICTURE_TYPE_IDR) {
711 const VAAPIEncodeH265Picture *strp;
712 int rps_poc[MAX_DPB_SIZE];
713 int rps_used[MAX_DPB_SIZE];
714 int i, j, poc, rps_pics;
715
717
718 rps = &sh->short_term_ref_pic_set;
719 memset(rps, 0, sizeof(*rps));
720
721 rps_pics = 0;
722 for (i = 0; i < MAX_REFERENCE_LIST_NUM; i++) {
723 for (j = 0; j < pic->nb_refs[i]; j++) {
724 strp = pic->refs[i][j]->codec_priv;
725 rps_poc[rps_pics] = strp->pic_order_cnt;
726 rps_used[rps_pics] = 1;
727 ++rps_pics;
728 }
729 }
730
731 for (i = 0; i < pic->nb_dpb_pics; i++) {
732 if (pic->dpb[i] == pic)
733 continue;
734
735 for (j = 0; j < pic->nb_refs[0]; j++) {
736 if (pic->dpb[i] == pic->refs[0][j])
737 break;
738 }
739 if (j < pic->nb_refs[0])
740 continue;
741
742 for (j = 0; j < pic->nb_refs[1]; j++) {
743 if (pic->dpb[i] == pic->refs[1][j])
744 break;
745 }
746 if (j < pic->nb_refs[1])
747 continue;
748
749 strp = pic->dpb[i]->codec_priv;
750 rps_poc[rps_pics] = strp->pic_order_cnt;
751 rps_used[rps_pics] = 0;
752 ++rps_pics;
753 }
754
755 for (i = 1; i < rps_pics; i++) {
756 for (j = i; j > 0; j--) {
757 if (rps_poc[j] > rps_poc[j - 1])
758 break;
759 av_assert0(rps_poc[j] != rps_poc[j - 1]);
760 FFSWAP(int, rps_poc[j], rps_poc[j - 1]);
761 FFSWAP(int, rps_used[j], rps_used[j - 1]);
762 }
763 }
764
765 av_log(avctx, AV_LOG_DEBUG, "RPS for POC %d:",
766 hpic->pic_order_cnt);
767 for (i = 0; i < rps_pics; i++) {
768 av_log(avctx, AV_LOG_DEBUG, " (%d,%d)",
769 rps_poc[i], rps_used[i]);
770 }
771 av_log(avctx, AV_LOG_DEBUG, "\n");
772
773 for (i = 0; i < rps_pics; i++) {
774 av_assert0(rps_poc[i] != hpic->pic_order_cnt);
775 if (rps_poc[i] > hpic->pic_order_cnt)
776 break;
777 }
778
779 rps->num_negative_pics = i;
780 poc = hpic->pic_order_cnt;
781 for (j = i - 1; j >= 0; j--) {
782 rps->delta_poc_s0_minus1[i - 1 - j] = poc - rps_poc[j] - 1;
783 rps->used_by_curr_pic_s0_flag[i - 1 - j] = rps_used[j];
784 poc = rps_poc[j];
785 }
786
787 rps->num_positive_pics = rps_pics - i;
788 poc = hpic->pic_order_cnt;
789 for (j = i; j < rps_pics; j++) {
790 rps->delta_poc_s1_minus1[j - i] = rps_poc[j] - poc - 1;
791 rps->used_by_curr_pic_s1_flag[j - i] = rps_used[j];
792 poc = rps_poc[j];
793 }
794
795 sh->num_long_term_sps = 0;
796 sh->num_long_term_pics = 0;
797
798 // when this flag is not present, it is inerred to 1.
801 sps->sps_temporal_mvp_enabled_flag;
803 if (sh->slice_type == HEVC_SLICE_B)
805 sh->collocated_ref_idx = 0;
806 }
807
809 sh->num_ref_idx_l0_active_minus1 = pps->num_ref_idx_l0_default_active_minus1;
810 sh->num_ref_idx_l1_active_minus1 = pps->num_ref_idx_l1_default_active_minus1;
811 }
812
814 sps->sample_adaptive_offset_enabled_flag;
815
816 if (pic->type == FF_HW_PICTURE_TYPE_B)
817 sh->slice_qp_delta = priv->fixed_qp_b - (pps->init_qp_minus26 + 26);
818 else if (pic->type == FF_HW_PICTURE_TYPE_P)
819 sh->slice_qp_delta = priv->fixed_qp_p - (pps->init_qp_minus26 + 26);
820 else
821 sh->slice_qp_delta = priv->unit_opts.fixed_qp_idr - (pps->init_qp_minus26 + 26);
822
823
824 *vslice = (VAEncSliceParameterBufferHEVC) {
825 .slice_segment_address = sh->slice_segment_address,
826 .num_ctu_in_slice = slice->block_size,
827
828 .slice_type = sh->slice_type,
829 .slice_pic_parameter_set_id = sh->slice_pic_parameter_set_id,
830
831 .num_ref_idx_l0_active_minus1 = sh->num_ref_idx_l0_active_minus1,
832 .num_ref_idx_l1_active_minus1 = sh->num_ref_idx_l1_active_minus1,
833
834 .luma_log2_weight_denom = sh->luma_log2_weight_denom,
835 .delta_chroma_log2_weight_denom = sh->delta_chroma_log2_weight_denom,
836
837 .max_num_merge_cand = 5 - sh->five_minus_max_num_merge_cand,
838
839 .slice_qp_delta = sh->slice_qp_delta,
840 .slice_cb_qp_offset = sh->slice_cb_qp_offset,
841 .slice_cr_qp_offset = sh->slice_cr_qp_offset,
842
843 .slice_beta_offset_div2 = sh->slice_beta_offset_div2,
844 .slice_tc_offset_div2 = sh->slice_tc_offset_div2,
845
846 .slice_fields.bits = {
847 .last_slice_of_pic_flag = slice->index == vaapi_pic->nb_slices - 1,
848 .dependent_slice_segment_flag = sh->dependent_slice_segment_flag,
849 .colour_plane_id = sh->colour_plane_id,
850 .slice_temporal_mvp_enabled_flag =
852 .slice_sao_luma_flag = sh->slice_sao_luma_flag,
853 .slice_sao_chroma_flag = sh->slice_sao_chroma_flag,
854 .num_ref_idx_active_override_flag =
856 .mvd_l1_zero_flag = sh->mvd_l1_zero_flag,
857 .cabac_init_flag = sh->cabac_init_flag,
858 .slice_deblocking_filter_disabled_flag =
860 .slice_loop_filter_across_slices_enabled_flag =
862 .collocated_from_l0_flag = sh->collocated_from_l0_flag,
863 },
864 };
865
866 for (i = 0; i < FF_ARRAY_ELEMS(vslice->ref_pic_list0); i++) {
867 vslice->ref_pic_list0[i].picture_id = VA_INVALID_ID;
868 vslice->ref_pic_list0[i].flags = VA_PICTURE_HEVC_INVALID;
869 vslice->ref_pic_list1[i].picture_id = VA_INVALID_ID;
870 vslice->ref_pic_list1[i].flags = VA_PICTURE_HEVC_INVALID;
871 }
872
873 if (pic->nb_refs[0]) {
874 // Backward reference for P- or B-frame.
876 pic->type == FF_HW_PICTURE_TYPE_B);
877 vslice->ref_pic_list0[0] = vpic->reference_frames[0];
878 if (base_ctx->p_to_gpb && pic->type == FF_HW_PICTURE_TYPE_P)
879 // Reference for GPB B-frame, L0 == L1
880 vslice->ref_pic_list1[0] = vpic->reference_frames[0];
881 }
882 if (pic->nb_refs[1]) {
883 // Forward reference for B-frame.
885 vslice->ref_pic_list1[0] = vpic->reference_frames[1];
886 }
887
888 if (pic->type == FF_HW_PICTURE_TYPE_P && base_ctx->p_to_gpb) {
889 vslice->slice_type = HEVC_SLICE_B;
890 for (i = 0; i < FF_ARRAY_ELEMS(vslice->ref_pic_list0); i++) {
891 vslice->ref_pic_list1[i].picture_id = vslice->ref_pic_list0[i].picture_id;
892 vslice->ref_pic_list1[i].flags = vslice->ref_pic_list0[i].flags;
893 }
894 }
895
896 return 0;
897}
898
900{
901 FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
902 VAAPIEncodeH265Context *priv = avctx->priv_data;
903
904#if VA_CHECK_VERSION(1, 13, 0)
905 {
907 VAConfigAttribValEncHEVCBlockSizes block_size;
908 VAConfigAttrib attr;
909 VAStatus vas;
910
911 attr.type = VAConfigAttribEncHEVCFeatures;
912 vas = vaGetConfigAttributes(ctx->hwctx->display, ctx->va_profile,
913 ctx->va_entrypoint, &attr, 1);
914 if (vas != VA_STATUS_SUCCESS) {
915 av_log(avctx, AV_LOG_ERROR, "Failed to query encoder "
916 "features, using guessed defaults.\n");
917 return AVERROR_EXTERNAL;
918 } else if (attr.value == VA_ATTRIB_NOT_SUPPORTED) {
919 av_log(avctx, AV_LOG_WARNING, "Driver does not advertise "
920 "encoder features, using guessed defaults.\n");
921 } else {
922 priv->va_features = attr.value;
923 }
924
925 attr.type = VAConfigAttribEncHEVCBlockSizes;
926 vas = vaGetConfigAttributes(ctx->hwctx->display, ctx->va_profile,
927 ctx->va_entrypoint, &attr, 1);
928 if (vas != VA_STATUS_SUCCESS) {
929 av_log(avctx, AV_LOG_ERROR, "Failed to query encoder "
930 "block size, using guessed defaults.\n");
931 return AVERROR_EXTERNAL;
932 } else if (attr.value == VA_ATTRIB_NOT_SUPPORTED) {
933 av_log(avctx, AV_LOG_WARNING, "Driver does not advertise "
934 "encoder block size, using guessed defaults.\n");
935 } else {
936 priv->va_bs = block_size.value = attr.value;
937
938 priv->ctu_size =
939 1 << block_size.bits.log2_max_coding_tree_block_size_minus3 + 3;
940 priv->min_cb_size =
941 1 << block_size.bits.log2_min_luma_coding_block_size_minus3 + 3;
942 }
943 }
944#endif
945
946 if (!priv->ctu_size) {
947 priv->ctu_size = 32;
948 priv->min_cb_size = 16;
949 }
950 av_log(avctx, AV_LOG_VERBOSE, "Using CTU size %dx%d, "
951 "min CB size %dx%d.\n", priv->ctu_size, priv->ctu_size,
952 priv->min_cb_size, priv->min_cb_size);
953
954 base_ctx->surface_width = FFALIGN(avctx->width,
956 base_ctx->surface_height = FFALIGN(avctx->height,
958
959 base_ctx->slice_block_width = base_ctx->slice_block_height = priv->ctu_size;
960
961 return 0;
962}
963
965{
967 VAAPIEncodeH265Context *priv = avctx->priv_data;
968 int err;
969
970 err = ff_cbs_init(&priv->cbc, AV_CODEC_ID_HEVC, avctx);
971 if (err < 0)
972 return err;
973
974 if (ctx->va_rc_mode == VA_RC_CQP) {
975 // Note that VAAPI only supports positive QP values - the range is
976 // therefore always bounded below by 1, even in 10-bit mode where
977 // it should go down to -12.
978
979 priv->fixed_qp_p = av_clip(ctx->rc_quality, 1, 51);
980 if (avctx->i_quant_factor > 0.0)
981 priv->unit_opts.fixed_qp_idr =
982 av_clip((avctx->i_quant_factor * priv->fixed_qp_p +
983 avctx->i_quant_offset) + 0.5, 1, 51);
984 else
985 priv->unit_opts.fixed_qp_idr = priv->fixed_qp_p;
986 if (avctx->b_quant_factor > 0.0)
987 priv->fixed_qp_b =
988 av_clip((avctx->b_quant_factor * priv->fixed_qp_p +
989 avctx->b_quant_offset) + 0.5, 1, 51);
990 else
991 priv->fixed_qp_b = priv->fixed_qp_p;
992
993 av_log(avctx, AV_LOG_DEBUG, "Using fixed QP = "
994 "%d / %d / %d for IDR- / P- / B-frames.\n",
995 priv->unit_opts.fixed_qp_idr, priv->fixed_qp_p, priv->fixed_qp_b);
996
997 } else {
998 // These still need to be set for init_qp/slice_qp_delta.
999 priv->unit_opts.fixed_qp_idr = 30;
1000 priv->fixed_qp_p = 30;
1001 priv->fixed_qp_b = 30;
1002 }
1003
1004 ctx->roi_quant_range = 51 + 6 * (ctx->profile->depth - 8);
1005
1006 return 0;
1007}
1008
1010 { AV_PROFILE_HEVC_MAIN, 8, 3, 1, 1, VAProfileHEVCMain },
1011 { AV_PROFILE_HEVC_REXT, 8, 3, 1, 1, VAProfileHEVCMain },
1012#if VA_CHECK_VERSION(0, 37, 0)
1013 { AV_PROFILE_HEVC_MAIN_10, 10, 3, 1, 1, VAProfileHEVCMain10 },
1014 { AV_PROFILE_HEVC_REXT, 10, 3, 1, 1, VAProfileHEVCMain10 },
1015#endif
1016#if VA_CHECK_VERSION(1, 2, 0)
1017 { AV_PROFILE_HEVC_REXT, 12, 3, 1, 1, VAProfileHEVCMain12 },
1018 { AV_PROFILE_HEVC_REXT, 8, 3, 1, 0, VAProfileHEVCMain422_10 },
1019 { AV_PROFILE_HEVC_REXT, 10, 3, 1, 0, VAProfileHEVCMain422_10 },
1020 { AV_PROFILE_HEVC_REXT, 12, 3, 1, 0, VAProfileHEVCMain422_12 },
1021 { AV_PROFILE_HEVC_REXT, 8, 3, 0, 0, VAProfileHEVCMain444 },
1022 { AV_PROFILE_HEVC_REXT, 10, 3, 0, 0, VAProfileHEVCMain444_10 },
1023 { AV_PROFILE_HEVC_REXT, 12, 3, 0, 0, VAProfileHEVCMain444_12 },
1024#endif
1026};
1027
1029 .profiles = vaapi_encode_h265_profiles,
1030
1031 .flags = FF_HW_FLAG_SLICE_CONTROL |
1035
1036 .default_quality = 25,
1037
1038 .get_encoder_caps = &vaapi_encode_h265_get_encoder_caps,
1039 .configure = &vaapi_encode_h265_configure,
1040
1041 .picture_priv_data_size = sizeof(VAAPIEncodeH265Picture),
1042
1043 .sequence_params_size = sizeof(VAEncSequenceParameterBufferHEVC),
1044 .init_sequence_params = &vaapi_encode_h265_init_sequence_params,
1045
1046 .picture_params_size = sizeof(VAEncPictureParameterBufferHEVC),
1047 .init_picture_params = &vaapi_encode_h265_init_picture_params,
1048
1049 .slice_params_size = sizeof(VAEncSliceParameterBufferHEVC),
1050 .init_slice_params = &vaapi_encode_h265_init_slice_params,
1051
1052 .sequence_header_type = VAEncPackedHeaderSequence,
1053 .write_sequence_header = &vaapi_encode_h265_write_sequence_header,
1054
1055 .slice_header_type = VAEncPackedHeaderHEVC_Slice,
1056 .write_slice_header = &vaapi_encode_h265_write_slice_header,
1057
1058 .write_extra_header = &vaapi_encode_h265_write_extra_header,
1059};
1060
1062{
1064 VAAPIEncodeH265Context *priv = avctx->priv_data;
1065
1066 ctx->codec = &vaapi_encode_type_h265;
1067
1068 if (avctx->profile == AV_PROFILE_UNKNOWN)
1069 avctx->profile = priv->profile;
1070 if (avctx->level == AV_LEVEL_UNKNOWN)
1071 avctx->level = priv->level;
1072
1073 if (avctx->level != AV_LEVEL_UNKNOWN && avctx->level & ~0xff) {
1074 av_log(avctx, AV_LOG_ERROR, "Invalid level %d: must fit "
1075 "in 8-bit unsigned integer.\n", avctx->level);
1076 return AVERROR(EINVAL);
1077 }
1078
1079 ctx->desired_packed_headers =
1080 VA_ENC_PACKED_HEADER_SEQUENCE | // VPS, SPS and PPS.
1081 VA_ENC_PACKED_HEADER_SLICE | // Slice headers.
1082 VA_ENC_PACKED_HEADER_MISC; // SEI
1083
1084 if (priv->qp > 0)
1085 ctx->explicit_qp = priv->qp;
1086
1087 return ff_vaapi_encode_init(avctx);
1088}
1089
1091{
1092 VAAPIEncodeH265Context *priv = avctx->priv_data;
1093
1094 ff_cbs_fragment_free(&priv->current_access_unit);
1095 ff_cbs_close(&priv->cbc);
1096 av_freep(&priv->sei_a53cc_data);
1097
1098 return ff_vaapi_encode_close(avctx);
1099}
1100
1101#define OFFSET(x) offsetof(VAAPIEncodeH265Context, x)
1102#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
1107
1108 { "qp", "Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)",
1109 OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 52, FLAGS },
1110
1111 { "aud", "Include AUD",
1112 OFFSET(aud), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
1113
1114 { "profile", "Set profile (general_profile_idc)",
1116 { .i64 = AV_PROFILE_UNKNOWN }, AV_PROFILE_UNKNOWN, 0xff, FLAGS, .unit = "profile" },
1117
1118#define PROFILE(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
1119 { .i64 = value }, 0, 0, FLAGS, .unit = "profile"
1120 { PROFILE("main", AV_PROFILE_HEVC_MAIN) },
1121 { PROFILE("main10", AV_PROFILE_HEVC_MAIN_10) },
1122 { PROFILE("rext", AV_PROFILE_HEVC_REXT) },
1123#undef PROFILE
1124
1125 { "tier", "Set tier (general_tier_flag)",
1126 OFFSET(unit_opts.tier), AV_OPT_TYPE_INT,
1127 { .i64 = 0 }, 0, 1, FLAGS, .unit = "tier" },
1128 { "main", NULL, 0, AV_OPT_TYPE_CONST,
1129 { .i64 = 0 }, 0, 0, FLAGS, .unit = "tier" },
1130 { "high", NULL, 0, AV_OPT_TYPE_CONST,
1131 { .i64 = 1 }, 0, 0, FLAGS, .unit = "tier" },
1132
1133 { "level", "Set level (general_level_idc)",
1135 { .i64 = AV_LEVEL_UNKNOWN }, AV_LEVEL_UNKNOWN, 0xff, FLAGS, .unit = "level" },
1136
1137#define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
1138 { .i64 = value }, 0, 0, FLAGS, .unit = "level"
1139 { LEVEL("1", 30) },
1140 { LEVEL("2", 60) },
1141 { LEVEL("2.1", 63) },
1142 { LEVEL("3", 90) },
1143 { LEVEL("3.1", 93) },
1144 { LEVEL("4", 120) },
1145 { LEVEL("4.1", 123) },
1146 { LEVEL("5", 150) },
1147 { LEVEL("5.1", 153) },
1148 { LEVEL("5.2", 156) },
1149 { LEVEL("6", 180) },
1150 { LEVEL("6.1", 183) },
1151 { LEVEL("6.2", 186) },
1152#undef LEVEL
1153
1154 { "sei", "Set SEI to include",
1157 0, INT_MAX, FLAGS, .unit = "sei" },
1158 { "hdr",
1159 "Include HDR metadata for mastering display colour volume "
1160 "and content light level information",
1163 INT_MIN, INT_MAX, FLAGS, .unit = "sei" },
1164 { "a53_cc",
1165 "Include A/53 caption data",
1167 { .i64 = SEI_A53_CC },
1168 INT_MIN, INT_MAX, FLAGS, .unit = "sei" },
1169
1170 { "tiles", "Tile columns x rows",
1171 OFFSET(common.tile_cols), AV_OPT_TYPE_IMAGE_SIZE,
1172 { .str = NULL }, 0, 0, FLAGS },
1173
1174 { NULL },
1175};
1176
1178 { "b", "0" },
1179 { "bf", "2" },
1180 { "g", "120" },
1181 { "i_qfactor", "1" },
1182 { "i_qoffset", "0" },
1183 { "b_qfactor", "6/5" },
1184 { "b_qoffset", "0" },
1185 { "qmin", "-1" },
1186 { "qmax", "-1" },
1187 { "refs", "0" },
1188 { NULL },
1189};
1190
1192 .class_name = "h265_vaapi",
1193 .item_name = av_default_item_name,
1194 .option = vaapi_encode_h265_options,
1195 .version = LIBAVUTIL_VERSION_INT,
1196};
1197
1199 .p.name = "hevc_vaapi",
1200 CODEC_LONG_NAME("H.265/HEVC (VAAPI)"),
1201 .p.type = AVMEDIA_TYPE_VIDEO,
1202 .p.id = AV_CODEC_ID_HEVC,
1203 .priv_data_size = sizeof(VAAPIEncodeH265Context),
1206 .close = &vaapi_encode_h265_close,
1207 .p.priv_class = &vaapi_encode_h265_class,
1208 .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE |
1210 .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE |
1212 .defaults = vaapi_encode_h265_defaults,
1214 .color_ranges = AVCOL_RANGE_MPEG | AVCOL_RANGE_JPEG,
1215 .hw_configs = ff_vaapi_encode_hw_configs,
1216 .p.wrapper_name = "vaapi",
1217};
const FFCodec ff_hevc_vaapi_encoder
static AVFormatContext * ctx
int ff_alloc_a53_sei(const AVFrame *frame, size_t prefix_len, void **data, size_t *sei_size)
Check AVFrame for A53 side data and allocate and fill SEI message with A53 info.
Definition atsc_a53.c:26
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
Libavcodec external API header.
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
static int FUNC sei(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEI *current)
static int FUNC aud(CodedBitstreamContext *ctx, RWContext *rw, H264RawAUD *current)
static int FUNC sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
static int FUNC vps(CodedBitstreamContext *ctx, RWContext *rw, H265RawVPS *current)
int ff_cbs_sei_add_message(CodedBitstreamContext *ctx, CodedBitstreamFragment *au, int prefix, uint32_t payload_type, void *payload_data, void *payload_ref)
Add an SEI message to an access unit.
Definition cbs_sei.c:467
#define FLAGS
Definition cmdutils.c:598
#define CODEC_PIXFMTS(...)
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
#define FF_CODEC_RECEIVE_PACKET_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
common internal and external API header
#define av_clip
Definition common.h:100
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
#define AV_PROFILE_UNKNOWN
Definition defs.h:65
#define AV_LEVEL_UNKNOWN
Definition defs.h:209
#define AV_PROFILE_HEVC_REXT
Definition defs.h:162
#define AV_PROFILE_HEVC_MAIN
Definition defs.h:159
#define AV_PROFILE_HEVC_MAIN_10
Definition defs.h:160
uint64_t pps
Definition dovi_rpuenc.c:36
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
#define fail
Definition test.h:479
@ AV_OPT_TYPE_IMAGE_SIZE
Underlying C type is two consecutive integers.
Definition opt.h:302
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition opt.h:298
@ AV_OPT_TYPE_FLAGS
Underlying C type is unsigned int.
Definition opt.h:254
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition opt.h:326
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
Definition codec.h:147
#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:79
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
#define AV_CODEC_CAP_HARDWARE
Codec is backed by a hardware implementation.
Definition codec.h:133
@ AV_CODEC_ID_HEVC
Definition codec_id.h:223
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition error.h:59
#define AVERROR_EOF
End of file.
Definition error.h:57
#define AVERROR(e)
Definition error.h:45
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition frame.c:659
@ AV_FRAME_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
Definition frame.h:137
@ AV_FRAME_DATA_MASTERING_DISPLAY_METADATA
Mastering display metadata associated with a video frame.
Definition frame.h:120
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_VERBOSE
Detailed information.
Definition log.h:226
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:241
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition rational.h:104
#define ff_ctz
Definition intmath.h:105
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
int index
Definition gxfenc.c:90
#define HW_BASE_ENCODE_COMMON_OPTIONS
#define MAX_DPB_SIZE
@ FF_HW_FLAG_SLICE_CONTROL
@ FF_HW_FLAG_NON_IDR_KEY_PICTURES
@ FF_HW_FLAG_B_PICTURE_REFERENCES
@ FF_HW_FLAG_B_PICTURES
@ FF_HW_PICTURE_TYPE_P
@ FF_HW_PICTURE_TYPE_I
@ FF_HW_PICTURE_TYPE_B
@ FF_HW_PICTURE_TYPE_IDR
#define MAX_REFERENCE_LIST_NUM
int ff_hw_base_encode_init_params_h265(FFHWBaseEncodeContext *base_ctx, AVCodecContext *avctx, FFHWBaseEncodeH265 *common, FFHWBaseEncodeH265Opts *opts)
cl_device_type type
@ HEVC_NAL_RASL_N
Definition hevc.h:37
@ HEVC_NAL_CRA_NUT
Definition hevc.h:50
@ HEVC_NAL_TRAIL_N
Definition hevc.h:29
@ HEVC_NAL_AUD
Definition hevc.h:64
@ HEVC_NAL_IDR_W_RADL
Definition hevc.h:48
@ HEVC_NAL_TRAIL_R
Definition hevc.h:30
@ HEVC_NAL_RASL_R
Definition hevc.h:38
@ HEVC_SLICE_P
Definition hevc.h:97
@ HEVC_SLICE_I
Definition hevc.h:98
@ HEVC_SLICE_B
Definition hevc.h:96
const AVCodecHWConfigInternal *const ff_vaapi_encode_hw_configs[]
int ff_vaapi_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
av_cold int ff_vaapi_encode_close(AVCodecContext *avctx)
#define av_cold
Definition attributes.h:117
#define FFSWAP(type, a, b)
Definition macros.h:52
#define FFMIN(a, b)
Definition macros.h:49
#define FFMAX(a, b)
Definition macros.h:47
#define FFALIGN(x, a)
Definition macros.h:78
Memory handling functions.
const char data[16]
Definition mxf.c:149
int profile
Definition mxfenc.c:2299
AVOptions.
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition pixfmt.h:766
@ AVCOL_RANGE_JPEG
Full range content.
Definition pixfmt.h:783
@ AV_PIX_FMT_VAAPI
Hardware acceleration through VA-API, data[3] contains a VASurfaceID.
Definition pixfmt.h:126
static const uint8_t header[24]
Definition sdr2.c:68
@ SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35
Definition sei.h:34
@ SEI_TYPE_CONTENT_LIGHT_LEVEL_INFO
Definition sei.h:103
@ SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME
Definition sei.h:96
#define FF_ARRAY_ELEMS(a)
Describe the class of an AVClass context structure.
Definition log.h:76
main external API structure.
Definition avcodec.h:443
int width
picture width / height.
Definition avcodec.h:604
float b_quant_offset
qscale offset between IP and B-frames
Definition avcodec.h:797
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:790
int level
Encoding level descriptor.
Definition avcodec.h:1646
int profile
profile
Definition avcodec.h:1636
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:806
void * priv_data
Definition avcodec.h:470
float i_quant_offset
qscale offset between P and I-frames
Definition avcodec.h:813
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
unsigned MaxFALL
Max average light level per frame (cd/m^2).
unsigned MaxCLL
Max content light level (cd/m^2).
Structure to hold side data for an AVFrame.
Definition frame.h:327
uint8_t * data
Definition frame.h:329
Mastering display metadata capable of representing the color volume of the display used to master the...
int has_primaries
Flag indicating whether the display primaries (and white point) are set.
AVRational max_luminance
Max luminance of mastering display (cd/m^2).
AVRational min_luminance
Min luminance of mastering display (cd/m^2).
AVRational display_primaries[3][2]
CIE 1931 xy chromaticity coords of color primaries (r, g, b order).
AVRational white_point[2]
CIE 1931 xy chromaticity coords of white point.
int has_luminance
Flag indicating whether the luminance (min_ and max_) have been set.
AVOption.
Definition opt.h:428
Context structure for coded bitstream operations.
Definition cbs.h:226
Coded bitstream fragment structure, combining one or more units.
Definition cbs.h:129
size_t data_bit_padding
The number of bits which should be ignored in the final byte.
Definition cbs.h:146
size_t data_size
The number of bytes in the bitstream.
Definition cbs.h:142
uint8_t * data
Pointer to the bitstream form of this fragment.
Definition cbs.h:135
struct FFHWBaseEncodePicture * dpb[MAX_DPB_SIZE]
struct FFHWBaseEncodePicture * prev
int nb_refs[MAX_REFERENCE_LIST_NUM]
struct FFHWBaseEncodePicture * refs[MAX_REFERENCE_LIST_NUM][MAX_PICTURE_REFERENCES]
uint8_t num_positive_pics
Definition cbs_h265.h:232
uint16_t delta_poc_s0_minus1[HEVC_MAX_REFS]
Definition cbs_h265.h:233
uint8_t num_negative_pics
Definition cbs_h265.h:231
uint8_t used_by_curr_pic_s0_flag[HEVC_MAX_REFS]
Definition cbs_h265.h:234
uint16_t delta_poc_s1_minus1[HEVC_MAX_REFS]
Definition cbs_h265.h:235
uint8_t used_by_curr_pic_s1_flag[HEVC_MAX_REFS]
Definition cbs_h265.h:236
uint8_t mvd_l1_zero_flag
Definition cbs_h265.h:538
uint8_t num_ref_idx_l1_active_minus1
Definition cbs_h265.h:531
uint16_t slice_segment_address
Definition cbs_h265.h:502
int8_t slice_cb_qp_offset
Definition cbs_h265.h:562
uint16_t slice_pic_order_cnt_lsb
Definition cbs_h265.h:510
uint8_t colour_plane_id
Definition cbs_h265.h:508
uint8_t first_slice_segment_in_pic_flag
Definition cbs_h265.h:497
uint8_t slice_temporal_mvp_enabled_flag
Definition cbs_h265.h:524
uint8_t slice_sao_luma_flag
Definition cbs_h265.h:526
uint8_t num_ref_idx_l0_active_minus1
Definition cbs_h265.h:530
uint8_t cabac_init_flag
Definition cbs_h265.h:539
int8_t slice_cr_qp_offset
Definition cbs_h265.h:563
uint8_t slice_loop_filter_across_slices_enabled_flag
Definition cbs_h265.h:573
uint8_t collocated_ref_idx
Definition cbs_h265.h:541
int8_t delta_chroma_log2_weight_denom
Definition cbs_h265.h:544
uint8_t luma_log2_weight_denom
Definition cbs_h265.h:543
H265RawSTRefPicSet short_term_ref_pic_set
Definition cbs_h265.h:513
uint8_t num_long_term_pics
Definition cbs_h265.h:517
uint8_t slice_deblocking_filter_disabled_flag
Definition cbs_h265.h:570
uint8_t slice_pic_parameter_set_id
Definition cbs_h265.h:499
int8_t slice_beta_offset_div2
Definition cbs_h265.h:571
uint8_t num_ref_idx_active_override_flag
Definition cbs_h265.h:529
uint8_t short_term_ref_pic_set_sps_flag
Definition cbs_h265.h:512
uint8_t five_minus_max_num_merge_cand
Definition cbs_h265.h:558
int8_t slice_qp_delta
Definition cbs_h265.h:561
uint8_t collocated_from_l0_flag
Definition cbs_h265.h:540
int8_t slice_tc_offset_div2
Definition cbs_h265.h:572
uint8_t dependent_slice_segment_flag
Definition cbs_h265.h:501
H265RawNALUnitHeader nal_unit_header
Definition cbs_h265.h:495
uint8_t slice_sao_chroma_flag
Definition cbs_h265.h:527
uint8_t num_long_term_sps
Definition cbs_h265.h:516
H265RawSliceHeader header
Definition cbs_h265.h:585
uint16_t max_pic_average_light_level
Definition cbs_sei.h:89
uint16_t max_content_light_level
Definition cbs_sei.h:88
uint8_t itu_t_t35_country_code
Definition cbs_sei.h:34
SEIRawMasteringDisplayColourVolume sei_mastering_display
FFHWBaseEncodeH265Opts unit_opts
FFHWBaseEncodeH265 units
VAAPIEncodeContext common
SEIRawContentLightLevelInfo sei_content_light_level
CodedBitstreamFragment current_access_unit
CodedBitstreamContext * cbc
SEIRawUserDataRegistered sei_a53cc
void * codec_picture_params
VASurfaceID recon_surface
VABufferID output_buffer
void * codec_slice_params
uint8_t level
Definition svq3.c:208
#define lrint
Definition tablegen.h:53
#define av_freep(p)
#define av_log(a,...)
static int ref[MAX_W *MAX_W]
#define VAAPI_ENCODE_COMMON_OPTIONS
#define VAAPI_ENCODE_RC_OPTIONS
@ SEI_A53_CC
static const FFCodecDefault vaapi_encode_h265_defaults[]
static int vaapi_encode_h265_init_picture_params(AVCodecContext *avctx, FFHWBaseEncodePicture *pic)
static int vaapi_encode_h265_write_slice_header(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice, char *data, size_t *data_len)
static int vaapi_encode_h265_write_sequence_header(AVCodecContext *avctx, char *data, size_t *data_len)
static av_cold int vaapi_encode_h265_init(AVCodecContext *avctx)
static const VAAPIEncodeType vaapi_encode_type_h265
static int vaapi_encode_h265_write_access_unit(AVCodecContext *avctx, char *data, size_t *data_len, CodedBitstreamFragment *au)
static av_cold int vaapi_encode_h265_close(AVCodecContext *avctx)
static int vaapi_encode_h265_add_nal(AVCodecContext *avctx, CodedBitstreamFragment *au, void *nal_unit)
#define LEVEL(name, value)
static av_cold int vaapi_encode_h265_configure(AVCodecContext *avctx)
static const VAAPIEncodeProfile vaapi_encode_h265_profiles[]
static const AVOption vaapi_encode_h265_options[]
static int vaapi_encode_h265_init_sequence_params(AVCodecContext *avctx)
#define PROFILE(name, value)
#define OFFSET(x)
static av_cold int vaapi_encode_h265_get_encoder_caps(AVCodecContext *avctx)
@ SEI_MASTERING_DISPLAY
@ SEI_CONTENT_LIGHT_LEVEL
static const AVClass vaapi_encode_h265_class
static int vaapi_encode_h265_init_slice_params(AVCodecContext *avctx, FFHWBaseEncodePicture *pic, VAAPIEncodeSlice *slice)
static int vaapi_encode_h265_write_extra_header(AVCodecContext *avctx, FFHWBaseEncodePicture *base, int index, int *type, char *data, size_t *data_len)
uint8_t base
Definition vp3data.h:128