FFmpeg
Loading...
Searching...
No Matches
vaapi_encode_h264.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_h264.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"
29
30#include "atsc_a53.h"
31#include "avcodec.h"
32#include "cbs.h"
33#include "cbs_h264.h"
34#include "codec_internal.h"
35#include "h264.h"
36#include "hw_base_encode_h264.h"
37#include "h264_levels.h"
38#include "h2645data.h"
39#include "vaapi_encode.h"
40#include "version.h"
41
42enum {
43 SEI_TIMING = 0x01,
46 SEI_A53_CC = 0x08,
47};
48
49// Random (version 4) ISO 11578 UUID.
50static const uint8_t vaapi_encode_h264_sei_identifier_uuid[16] = {
51 0x59, 0x94, 0x8b, 0x28, 0x11, 0xec, 0x45, 0xaf,
52 0x96, 0x75, 0x19, 0xd4, 0x1f, 0xea, 0xa9, 0x4d,
53};
54
68
108
109
111 char *data, size_t *data_len,
113{
114 VAAPIEncodeH264Context *priv = avctx->priv_data;
115 int err;
116
117 err = ff_cbs_write_fragment_data(priv->cbc, au);
118 if (err < 0) {
119 av_log(avctx, AV_LOG_ERROR, "Failed to write packed header.\n");
120 return err;
121 }
122
123 if (*data_len < 8 * au->data_size - au->data_bit_padding) {
124 av_log(avctx, AV_LOG_ERROR, "Access unit too large: "
125 "%zu < %zu.\n", *data_len,
126 8 * au->data_size - au->data_bit_padding);
127 return AVERROR(ENOSPC);
128 }
129
130 memcpy(data, au->data, au->data_size);
131 *data_len = 8 * au->data_size - au->data_bit_padding;
132
133 return 0;
134}
135
138 void *nal_unit)
139{
140 H264RawNALUnitHeader *header = nal_unit;
141 int err;
142
143 err = ff_cbs_insert_unit_content(au, -1,
144 header->nal_unit_type, nal_unit, NULL);
145 if (err < 0) {
146 av_log(avctx, AV_LOG_ERROR, "Failed to add NAL unit: "
147 "type = %d.\n", header->nal_unit_type);
148 return err;
149 }
150
151 return 0;
152}
153
155 char *data, size_t *data_len)
156{
157 VAAPIEncodeH264Context *priv = avctx->priv_data;
159 int err;
160
161 if (priv->aud_needed) {
162 err = vaapi_encode_h264_add_nal(avctx, au, &priv->raw_aud);
163 if (err < 0)
164 goto fail;
165 priv->aud_needed = 0;
166 }
167
168 err = vaapi_encode_h264_add_nal(avctx, au, &priv->units.raw_sps);
169 if (err < 0)
170 goto fail;
171
172 err = vaapi_encode_h264_add_nal(avctx, au, &priv->units.raw_pps);
173 if (err < 0)
174 goto fail;
175
176 err = vaapi_encode_h264_write_access_unit(avctx, data, data_len, au);
177fail:
178 ff_cbs_fragment_reset(au);
179 return err;
180}
181
184 VAAPIEncodeSlice *slice,
185 char *data, size_t *data_len)
186{
187 VAAPIEncodeH264Context *priv = avctx->priv_data;
189 int err;
190
191 if (priv->aud_needed) {
192 err = vaapi_encode_h264_add_nal(avctx, au, &priv->raw_aud);
193 if (err < 0)
194 goto fail;
195 priv->aud_needed = 0;
196 }
197
198 err = vaapi_encode_h264_add_nal(avctx, au, &priv->raw_slice);
199 if (err < 0)
200 goto fail;
201
202 err = vaapi_encode_h264_write_access_unit(avctx, data, data_len, au);
203fail:
204 ff_cbs_fragment_reset(au);
205 return err;
206}
207
210 int index, int *type,
211 char *data, size_t *data_len)
212{
213 VAAPIEncodeH264Context *priv = avctx->priv_data;
215 int err;
216
217 if (priv->sei_needed) {
218 if (priv->aud_needed) {
219 err = vaapi_encode_h264_add_nal(avctx, au, &priv->raw_aud);
220 if (err < 0)
221 goto fail;
222 priv->aud_needed = 0;
223 }
224
225 if (priv->sei_needed & SEI_IDENTIFIER) {
226 err = ff_cbs_sei_add_message(priv->cbc, au, 1,
228 &priv->sei_identifier, NULL);
229 if (err < 0)
230 goto fail;
231 }
232 if (priv->sei_needed & SEI_TIMING) {
233 if (base->type == FF_HW_PICTURE_TYPE_IDR) {
234 err = ff_cbs_sei_add_message(priv->cbc, au, 1,
237 if (err < 0)
238 goto fail;
239 }
240 err = ff_cbs_sei_add_message(priv->cbc, au, 1,
242 &priv->sei_pic_timing, NULL);
243 if (err < 0)
244 goto fail;
245 }
246 if (priv->sei_needed & SEI_RECOVERY_POINT) {
247 err = ff_cbs_sei_add_message(priv->cbc, au, 1,
249 &priv->sei_recovery_point, NULL);
250 if (err < 0)
251 goto fail;
252 }
253 if (priv->sei_needed & SEI_A53_CC) {
254 err = ff_cbs_sei_add_message(priv->cbc, au, 1,
256 &priv->sei_a53cc, NULL);
257 if (err < 0)
258 goto fail;
259 }
260
261 priv->sei_needed = 0;
262
263 err = vaapi_encode_h264_write_access_unit(avctx, data, data_len, au);
264 if (err < 0)
265 goto fail;
266
267 ff_cbs_fragment_reset(au);
268
269 *type = VAEncPackedHeaderRawData;
270 return 0;
271
272#if !CONFIG_VAAPI_1
273 } else if (priv->sei_cbr_workaround_needed) {
274 // Insert a zero-length header using the old SEI type. This is
275 // required to avoid triggering broken behaviour on Intel platforms
276 // in CBR mode where an invalid SEI message is generated by the
277 // driver and inserted into the stream.
278 *data_len = 0;
279 *type = VAEncPackedHeaderH264_SEI;
281 return 0;
282#endif
283
284 } else {
285 return AVERROR_EOF;
286 }
287
288fail:
289 ff_cbs_fragment_reset(au);
290 return err;
291}
292
294{
295 FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
297 VAAPIEncodeH264Context *priv = avctx->priv_data;
298 H264RawSPS *sps = &priv->units.raw_sps;
299 H264RawPPS *pps = &priv->units.raw_pps;
300 VAEncSequenceParameterBufferH264 *vseq = ctx->codec_sequence_params;
301 VAEncPictureParameterBufferH264 *vpic = ctx->codec_picture_params;
302
303 FFHWBaseEncodeH264Opts unit_opts = {
304 .flags = (priv->sei & SEI_TIMING) ? FF_HW_H264_SEI_TIMING : 0,
305 .mb_width = priv->mb_width,
306 .mb_height = priv->mb_height,
307 .cabac = priv->coder,
308 .hrd_buffer_size = ctx->hrd_params.buffer_size,
309 .fixed_qp_idr = priv->fixed_qp_idr,
310 .initial_buffer_fullness = ctx->hrd_params.initial_buffer_fullness,
311 .bit_rate = ctx->va_bit_rate,
312 };
313
314 int err = ff_hw_base_encode_init_params_h264(base_ctx, avctx,
315 &priv->units, &unit_opts);
316 if (err < 0)
317 return err;
318
319 *vseq = (VAEncSequenceParameterBufferH264) {
320 .seq_parameter_set_id = sps->seq_parameter_set_id,
321 .level_idc = sps->level_idc,
322 .intra_period = base_ctx->gop_size,
323 .intra_idr_period = base_ctx->gop_size,
324 .ip_period = base_ctx->b_per_p + 1,
325
326 .bits_per_second = ctx->va_bit_rate,
327 .max_num_ref_frames = sps->max_num_ref_frames,
328 .picture_width_in_mbs = sps->pic_width_in_mbs_minus1 + 1,
329 .picture_height_in_mbs = sps->pic_height_in_map_units_minus1 + 1,
330
331 .seq_fields.bits = {
332 .chroma_format_idc = sps->chroma_format_idc,
333 .frame_mbs_only_flag = sps->frame_mbs_only_flag,
334 .mb_adaptive_frame_field_flag = sps->mb_adaptive_frame_field_flag,
335 .seq_scaling_matrix_present_flag = sps->seq_scaling_matrix_present_flag,
336 .direct_8x8_inference_flag = sps->direct_8x8_inference_flag,
337 .log2_max_frame_num_minus4 = sps->log2_max_frame_num_minus4,
338 .pic_order_cnt_type = sps->pic_order_cnt_type,
339 .log2_max_pic_order_cnt_lsb_minus4 = sps->log2_max_pic_order_cnt_lsb_minus4,
340 .delta_pic_order_always_zero_flag = sps->delta_pic_order_always_zero_flag,
341 },
342
343 .bit_depth_luma_minus8 = sps->bit_depth_luma_minus8,
344 .bit_depth_chroma_minus8 = sps->bit_depth_chroma_minus8,
345
346 .frame_cropping_flag = sps->frame_cropping_flag,
347 .frame_crop_left_offset = sps->frame_crop_left_offset,
348 .frame_crop_right_offset = sps->frame_crop_right_offset,
349 .frame_crop_top_offset = sps->frame_crop_top_offset,
350 .frame_crop_bottom_offset = sps->frame_crop_bottom_offset,
351
352 .vui_parameters_present_flag = sps->vui_parameters_present_flag,
353
354 .vui_fields.bits = {
355 .aspect_ratio_info_present_flag = sps->vui.aspect_ratio_info_present_flag,
356 .timing_info_present_flag = sps->vui.timing_info_present_flag,
357 .bitstream_restriction_flag = sps->vui.bitstream_restriction_flag,
358 .log2_max_mv_length_horizontal = sps->vui.log2_max_mv_length_horizontal,
359 .log2_max_mv_length_vertical = sps->vui.log2_max_mv_length_vertical,
360 },
361
362 .aspect_ratio_idc = sps->vui.aspect_ratio_idc,
363 .sar_width = sps->vui.sar_width,
364 .sar_height = sps->vui.sar_height,
365 .num_units_in_tick = sps->vui.num_units_in_tick,
366 .time_scale = sps->vui.time_scale,
367 };
368
369 *vpic = (VAEncPictureParameterBufferH264) {
370 .CurrPic = {
371 .picture_id = VA_INVALID_ID,
372 .flags = VA_PICTURE_H264_INVALID,
373 },
374
375 .coded_buf = VA_INVALID_ID,
376
377 .pic_parameter_set_id = pps->pic_parameter_set_id,
378 .seq_parameter_set_id = pps->seq_parameter_set_id,
379
380 .pic_init_qp = pps->pic_init_qp_minus26 + 26,
381 .num_ref_idx_l0_active_minus1 = pps->num_ref_idx_l0_default_active_minus1,
382 .num_ref_idx_l1_active_minus1 = pps->num_ref_idx_l1_default_active_minus1,
383
384 .chroma_qp_index_offset = pps->chroma_qp_index_offset,
385 .second_chroma_qp_index_offset = pps->second_chroma_qp_index_offset,
386
387 .pic_fields.bits = {
388 .entropy_coding_mode_flag = pps->entropy_coding_mode_flag,
389 .weighted_pred_flag = pps->weighted_pred_flag,
390 .weighted_bipred_idc = pps->weighted_bipred_idc,
391 .constrained_intra_pred_flag = pps->constrained_intra_pred_flag,
392 .transform_8x8_mode_flag = pps->transform_8x8_mode_flag,
393 .deblocking_filter_control_present_flag =
394 pps->deblocking_filter_control_present_flag,
395 .redundant_pic_cnt_present_flag = pps->redundant_pic_cnt_present_flag,
396 .pic_order_present_flag =
397 pps->bottom_field_pic_order_in_frame_present_flag,
398 .pic_scaling_matrix_present_flag = pps->pic_scaling_matrix_present_flag,
399 },
400 };
401
402 return 0;
403}
404
407{
408 FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
409#if !CONFIG_VAAPI_1
411#endif
412 VAAPIEncodeH264Context *priv = avctx->priv_data;
413 VAAPIEncodePicture *vaapi_pic = pic->priv;
415 FFHWBaseEncodePicture *prev = pic->prev;
416 VAAPIEncodeH264Picture *hprev = prev ? prev->codec_priv : NULL;
417 VAEncPictureParameterBufferH264 *vpic = vaapi_pic->codec_picture_params;
418 int i, j = 0;
419
420 if (pic->type == FF_HW_PICTURE_TYPE_IDR) {
422
423 hpic->frame_num = 0;
424 hpic->last_idr_frame = pic->display_order;
425 hpic->idr_pic_id = hprev ? hprev->idr_pic_id + 1 : 0;
426
427 hpic->primary_pic_type = 0;
428 hpic->slice_type = 7;
429 } else {
430 av_assert0(prev);
431
432 hpic->frame_num = hprev->frame_num + prev->is_reference;
433
434 hpic->last_idr_frame = hprev->last_idr_frame;
435 hpic->idr_pic_id = hprev->idr_pic_id;
436
437 if (pic->type == FF_HW_PICTURE_TYPE_I) {
438 hpic->slice_type = 7;
439 hpic->primary_pic_type = 0;
440 } else if (pic->type == FF_HW_PICTURE_TYPE_P) {
441 hpic->slice_type = 5;
442 hpic->primary_pic_type = 1;
443 } else {
444 hpic->slice_type = 6;
445 hpic->primary_pic_type = 2;
446 }
447 }
448 hpic->pic_order_cnt = pic->display_order - hpic->last_idr_frame;
449 if (priv->units.raw_sps.pic_order_cnt_type == 2) {
450 hpic->pic_order_cnt *= 2;
451 }
452
453 hpic->dpb_delay = pic->display_order - pic->encode_order + base_ctx->max_b_depth;
454 hpic->cpb_delay = pic->encode_order - hpic->last_idr_frame;
455
456 if (priv->aud) {
457 priv->aud_needed = 1;
458 priv->raw_aud = (H264RawAUD) {
459 .nal_unit_header = {
460 .nal_unit_type = H264_NAL_AUD,
461 },
462 .primary_pic_type = hpic->primary_pic_type,
463 };
464 } else {
465 priv->aud_needed = 0;
466 }
467
468 priv->sei_needed = 0;
469
470 if (priv->sei & SEI_IDENTIFIER && pic->encode_order == 0)
471 priv->sei_needed |= SEI_IDENTIFIER;
472#if !CONFIG_VAAPI_1
473 if (ctx->va_rc_mode == VA_RC_CBR)
475#endif
476
477 if (priv->sei & SEI_TIMING) {
479 .cpb_removal_delay = 2 * hpic->cpb_delay,
480 .dpb_output_delay = 2 * hpic->dpb_delay,
481 };
482
483 priv->sei_needed |= SEI_TIMING;
484 }
485
486 if (priv->sei & SEI_RECOVERY_POINT && pic->type == FF_HW_PICTURE_TYPE_I) {
488 .recovery_frame_cnt = 0,
489 .exact_match_flag = 1,
490 .broken_link_flag = base_ctx->b_per_p > 0,
491 };
492
494 }
495
496 if (priv->sei & SEI_A53_CC) {
497 int err;
498 size_t sei_a53cc_len;
499 av_freep(&priv->sei_a53cc_data);
500 err = ff_alloc_a53_sei(pic->input_image, 0, &priv->sei_a53cc_data, &sei_a53cc_len);
501 if (err < 0)
502 return err;
503 if (priv->sei_a53cc_data != NULL) {
505 priv->sei_a53cc.data = (uint8_t *)priv->sei_a53cc_data + 1;
506 priv->sei_a53cc.data_length = sei_a53cc_len - 1;
507
508 priv->sei_needed |= SEI_A53_CC;
509 }
510 }
511
512 vpic->CurrPic = (VAPictureH264) {
513 .picture_id = vaapi_pic->recon_surface,
514 .frame_idx = hpic->frame_num,
515 .flags = 0,
516 .TopFieldOrderCnt = hpic->pic_order_cnt,
517 .BottomFieldOrderCnt = hpic->pic_order_cnt,
518 };
519 for (int k = 0; k < MAX_REFERENCE_LIST_NUM; k++) {
520 for (i = 0; i < pic->nb_refs[k]; i++) {
521 FFHWBaseEncodePicture *ref = pic->refs[k][i];
523
524 av_assert0(ref && ref->encode_order < pic->encode_order);
525 href = ref->codec_priv;
526
527 vpic->ReferenceFrames[j++] = (VAPictureH264) {
528 .picture_id = ((VAAPIEncodePicture *)ref->priv)->recon_surface,
529 .frame_idx = href->frame_num,
530 .flags = VA_PICTURE_H264_SHORT_TERM_REFERENCE,
531 .TopFieldOrderCnt = href->pic_order_cnt,
532 .BottomFieldOrderCnt = href->pic_order_cnt,
533 };
534 }
535 }
536
537 for (; j < FF_ARRAY_ELEMS(vpic->ReferenceFrames); j++) {
538 vpic->ReferenceFrames[j] = (VAPictureH264) {
539 .picture_id = VA_INVALID_ID,
540 .flags = VA_PICTURE_H264_INVALID,
541 };
542 }
543
544 vpic->coded_buf = vaapi_pic->output_buffer;
545
546 vpic->frame_num = hpic->frame_num;
547
548 vpic->pic_fields.bits.idr_pic_flag = (pic->type == FF_HW_PICTURE_TYPE_IDR);
549 vpic->pic_fields.bits.reference_pic_flag = pic->is_reference;
550
551 return 0;
552}
553
558 int *rpl_size)
559{
561 VAAPIEncodeH264Picture *hp, *hn, *hc;
562 int i, j, n = 0;
563
564 prev = pic->prev;
565 av_assert0(prev);
566 hp = pic->codec_priv;
567
568 for (i = 0; i < pic->prev->nb_dpb_pics; i++) {
569 hn = prev->dpb[i]->codec_priv;
570 av_assert0(hn->frame_num < hp->frame_num);
571
572 if (pic->type == FF_HW_PICTURE_TYPE_P) {
573 for (j = n; j > 0; j--) {
574 hc = rpl0[j - 1]->codec_priv;
575 av_assert0(hc->frame_num != hn->frame_num);
576 if (hc->frame_num > hn->frame_num)
577 break;
578 rpl0[j] = rpl0[j - 1];
579 }
580 rpl0[j] = prev->dpb[i];
581
582 } else if (pic->type == FF_HW_PICTURE_TYPE_B) {
583 for (j = n; j > 0; j--) {
584 hc = rpl0[j - 1]->codec_priv;
586 if (hc->pic_order_cnt < hp->pic_order_cnt) {
587 if (hn->pic_order_cnt > hp->pic_order_cnt ||
588 hn->pic_order_cnt < hc->pic_order_cnt)
589 break;
590 } else {
591 if (hn->pic_order_cnt > hc->pic_order_cnt)
592 break;
593 }
594 rpl0[j] = rpl0[j - 1];
595 }
596 rpl0[j] = prev->dpb[i];
597
598 for (j = n; j > 0; j--) {
599 hc = rpl1[j - 1]->codec_priv;
601 if (hc->pic_order_cnt > hp->pic_order_cnt) {
602 if (hn->pic_order_cnt < hp->pic_order_cnt ||
603 hn->pic_order_cnt > hc->pic_order_cnt)
604 break;
605 } else {
606 if (hn->pic_order_cnt < hc->pic_order_cnt)
607 break;
608 }
609 rpl1[j] = rpl1[j - 1];
610 }
611 rpl1[j] = prev->dpb[i];
612 }
613
614 ++n;
615 }
616
617 if (pic->type == FF_HW_PICTURE_TYPE_B) {
618 for (i = 0; i < n; i++) {
619 if (rpl0[i] != rpl1[i])
620 break;
621 }
622 if (i == n)
623 FFSWAP(FFHWBaseEncodePicture *, rpl1[0], rpl1[1]);
624 }
625
626 if (pic->type == FF_HW_PICTURE_TYPE_P ||
627 pic->type == FF_HW_PICTURE_TYPE_B) {
628 av_log(avctx, AV_LOG_DEBUG, "Default RefPicList0 for fn=%d/poc=%d:",
629 hp->frame_num, hp->pic_order_cnt);
630 for (i = 0; i < n; i++) {
631 hn = rpl0[i]->codec_priv;
632 av_log(avctx, AV_LOG_DEBUG, " fn=%d/poc=%d",
633 hn->frame_num, hn->pic_order_cnt);
634 }
635 av_log(avctx, AV_LOG_DEBUG, "\n");
636 }
637 if (pic->type == FF_HW_PICTURE_TYPE_B) {
638 av_log(avctx, AV_LOG_DEBUG, "Default RefPicList1 for fn=%d/poc=%d:",
639 hp->frame_num, hp->pic_order_cnt);
640 for (i = 0; i < n; i++) {
641 hn = rpl1[i]->codec_priv;
642 av_log(avctx, AV_LOG_DEBUG, " fn=%d/poc=%d",
643 hn->frame_num, hn->pic_order_cnt);
644 }
645 av_log(avctx, AV_LOG_DEBUG, "\n");
646 }
647
648 *rpl_size = n;
649}
650
653 VAAPIEncodeSlice *slice)
654{
655 VAAPIEncodeH264Context *priv = avctx->priv_data;
656 VAAPIEncodePicture *vaapi_pic = pic->priv;
658 FFHWBaseEncodePicture *prev = pic->prev;
659 H264RawSPS *sps = &priv->units.raw_sps;
660 H264RawPPS *pps = &priv->units.raw_pps;
662 VAEncPictureParameterBufferH264 *vpic = vaapi_pic->codec_picture_params;
663 VAEncSliceParameterBufferH264 *vslice = slice->codec_slice_params;
664 int i, j;
665
666 if (pic->type == FF_HW_PICTURE_TYPE_IDR) {
669 } else {
672 }
673
674 sh->first_mb_in_slice = slice->block_start;
675 sh->slice_type = hpic->slice_type;
676
677 sh->pic_parameter_set_id = pps->pic_parameter_set_id;
678
679 sh->frame_num = hpic->frame_num &
680 ((1 << (4 + sps->log2_max_frame_num_minus4)) - 1);
681 sh->idr_pic_id = hpic->idr_pic_id;
682 sh->pic_order_cnt_lsb = hpic->pic_order_cnt &
683 ((1 << (4 + sps->log2_max_pic_order_cnt_lsb_minus4)) - 1);
684
686
687 if (pic->type == FF_HW_PICTURE_TYPE_B)
688 sh->slice_qp_delta = priv->fixed_qp_b - (pps->pic_init_qp_minus26 + 26);
689 else if (pic->type == FF_HW_PICTURE_TYPE_P)
690 sh->slice_qp_delta = priv->fixed_qp_p - (pps->pic_init_qp_minus26 + 26);
691 else
692 sh->slice_qp_delta = priv->fixed_qp_idr - (pps->pic_init_qp_minus26 + 26);
693
694 if (pic->is_reference && pic->type != FF_HW_PICTURE_TYPE_IDR) {
695 FFHWBaseEncodePicture *discard_list[MAX_DPB_SIZE];
696 int discard = 0, keep = 0;
697
698 // Discard everything which is in the DPB of the previous frame but
699 // not in the DPB of this one.
700 for (i = 0; i < prev->nb_dpb_pics; i++) {
701 for (j = 0; j < pic->nb_dpb_pics; j++) {
702 if (prev->dpb[i] == pic->dpb[j])
703 break;
704 }
705 if (j == pic->nb_dpb_pics) {
706 discard_list[discard] = prev->dpb[i];
707 ++discard;
708 } else {
709 ++keep;
710 }
711 }
712 av_assert0(keep <= priv->units.dpb_frames);
713
714 if (discard == 0) {
716 } else {
718 for (i = 0; i < discard; i++) {
719 VAAPIEncodeH264Picture *old = discard_list[i]->codec_priv;
720 av_assert0(old->frame_num < hpic->frame_num);
723 hpic->frame_num - old->frame_num - 1;
724 }
726 }
727 }
728
729 // If the intended references are not the first entries of RefPicListN
730 // by default, use ref-pic-list-modification to move them there.
731 if (pic->type == FF_HW_PICTURE_TYPE_P || pic->type == FF_HW_PICTURE_TYPE_B) {
734 int n;
735
737 def_l0, def_l1, &n);
738
739 if (pic->type == FF_HW_PICTURE_TYPE_P) {
740 int need_rplm = 0;
741 for (i = 0; i < pic->nb_refs[0]; i++) {
742 av_assert0(pic->refs[0][i]);
743 if (pic->refs[0][i] != (FFHWBaseEncodePicture *)def_l0[i])
744 need_rplm = 1;
745 }
746
747 sh->ref_pic_list_modification_flag_l0 = need_rplm;
748 if (need_rplm) {
749 int pic_num = hpic->frame_num;
750 for (i = 0; i < pic->nb_refs[0]; i++) {
751 href = pic->refs[0][i]->codec_priv;
752 av_assert0(href->frame_num != pic_num);
753 if (href->frame_num < pic_num) {
756 pic_num - href->frame_num - 1;
757 } else {
760 href->frame_num - pic_num - 1;
761 }
762 pic_num = href->frame_num;
763 }
765 }
766
767 } else {
768 int need_rplm_l0 = 0, need_rplm_l1 = 0;
769 int n0 = 0, n1 = 0;
770 for (i = 0; i < pic->nb_refs[0]; i++) {
771 av_assert0(pic->refs[0][i]);
772 href = pic->refs[0][i]->codec_priv;
774 if (pic->refs[0][i] != (FFHWBaseEncodePicture *)def_l0[n0])
775 need_rplm_l0 = 1;
776 ++n0;
777 }
778
779 for (i = 0; i < pic->nb_refs[1]; i++) {
780 av_assert0(pic->refs[1][i]);
781 href = pic->refs[1][i]->codec_priv;
783 if (pic->refs[1][i] != (FFHWBaseEncodePicture *)def_l1[n1])
784 need_rplm_l1 = 1;
785 ++n1;
786 }
787
788 sh->ref_pic_list_modification_flag_l0 = need_rplm_l0;
789 if (need_rplm_l0) {
790 int pic_num = hpic->frame_num;
791 for (i = j = 0; i < pic->nb_refs[0]; i++) {
792 href = pic->refs[0][i]->codec_priv;
793 av_assert0(href->frame_num != pic_num);
794 if (href->frame_num < pic_num) {
797 pic_num - href->frame_num - 1;
798 } else {
801 href->frame_num - pic_num - 1;
802 }
803 pic_num = href->frame_num;
804 ++j;
805 }
806 av_assert0(j == n0);
808 }
809
810 sh->ref_pic_list_modification_flag_l1 = need_rplm_l1;
811 if (need_rplm_l1) {
812 int pic_num = hpic->frame_num;
813 for (i = j = 0; i < pic->nb_refs[1]; i++) {
814 href = pic->refs[1][i]->codec_priv;
815 av_assert0(href->frame_num != pic_num);
816 if (href->frame_num < pic_num) {
819 pic_num - href->frame_num - 1;
820 } else {
823 href->frame_num - pic_num - 1;
824 }
825 pic_num = href->frame_num;
826 ++j;
827 }
828 av_assert0(j == n1);
830 }
831 }
832 }
833
834 vslice->macroblock_address = slice->block_start;
835 vslice->num_macroblocks = slice->block_size;
836
837 vslice->macroblock_info = VA_INVALID_ID;
838
839 vslice->slice_type = sh->slice_type % 5;
840 vslice->pic_parameter_set_id = sh->pic_parameter_set_id;
841 vslice->idr_pic_id = sh->idr_pic_id;
842
843 vslice->pic_order_cnt_lsb = sh->pic_order_cnt_lsb;
844
845 vslice->direct_spatial_mv_pred_flag = sh->direct_spatial_mv_pred_flag;
846
847 for (i = 0; i < FF_ARRAY_ELEMS(vslice->RefPicList0); i++) {
848 vslice->RefPicList0[i].picture_id = VA_INVALID_ID;
849 vslice->RefPicList0[i].flags = VA_PICTURE_H264_INVALID;
850 vslice->RefPicList1[i].picture_id = VA_INVALID_ID;
851 vslice->RefPicList1[i].flags = VA_PICTURE_H264_INVALID;
852 }
853
854 if (pic->nb_refs[0]) {
855 // Backward reference for P- or B-frame.
857 pic->type == FF_HW_PICTURE_TYPE_B);
858 vslice->RefPicList0[0] = vpic->ReferenceFrames[0];
859 }
860 if (pic->nb_refs[1]) {
861 // Forward reference for B-frame.
863 vslice->RefPicList1[0] = vpic->ReferenceFrames[1];
864 }
865
866 vslice->slice_qp_delta = sh->slice_qp_delta;
867
868 return 0;
869}
870
872{
874 VAAPIEncodeH264Context *priv = avctx->priv_data;
875 int err;
876
877 err = ff_cbs_init(&priv->cbc, AV_CODEC_ID_H264, avctx);
878 if (err < 0)
879 return err;
880
881 priv->mb_width = FFALIGN(avctx->width, 16) / 16;
882 priv->mb_height = FFALIGN(avctx->height, 16) / 16;
883
884 if (ctx->va_rc_mode == VA_RC_CQP) {
885 priv->fixed_qp_p = av_clip(ctx->rc_quality, 1, 51);
886 if (avctx->i_quant_factor > 0.0)
887 priv->fixed_qp_idr =
888 av_clip((avctx->i_quant_factor * priv->fixed_qp_p +
889 avctx->i_quant_offset) + 0.5, 1, 51);
890 else
891 priv->fixed_qp_idr = priv->fixed_qp_p;
892 if (avctx->b_quant_factor > 0.0)
893 priv->fixed_qp_b =
894 av_clip((avctx->b_quant_factor * priv->fixed_qp_p +
895 avctx->b_quant_offset) + 0.5, 1, 51);
896 else
897 priv->fixed_qp_b = priv->fixed_qp_p;
898
899 av_log(avctx, AV_LOG_DEBUG, "Using fixed QP = "
900 "%d / %d / %d for IDR- / P- / B-frames.\n",
901 priv->fixed_qp_idr, priv->fixed_qp_p, priv->fixed_qp_b);
902
903 } else {
904 // These still need to be set for pic_init_qp/slice_qp_delta.
905 priv->fixed_qp_idr = 26;
906 priv->fixed_qp_p = 26;
907 priv->fixed_qp_b = 26;
908 }
909
910 if (!ctx->rc_mode->hrd) {
911 // Timing SEI requires a mode respecting HRD parameters.
912 priv->sei &= ~SEI_TIMING;
913 }
914
915 if (priv->sei & SEI_IDENTIFIER) {
916 const char *lavc = LIBAVCODEC_IDENT;
917 const char *vaapi = VA_VERSION_S;
918 const char *driver;
919 int len;
920
923 sizeof(priv->sei_identifier.uuid_iso_iec_11578));
924
925 driver = vaQueryVendorString(ctx->hwctx->display);
926 if (!driver)
927 driver = "unknown driver";
928
929 len = snprintf(NULL, 0, "%s / VAAPI %s / %s", lavc, vaapi, driver);
930 if (len >= 0) {
932 if (!priv->sei_identifier_string)
933 return AVERROR(ENOMEM);
934
936 "%s / VAAPI %s / %s", lavc, vaapi, driver);
937
939 priv->sei_identifier.data_length = len + 1;
940 }
941 }
942
943 ctx->roi_quant_range = 51 + 6 * (ctx->profile->depth - 8);
944
945 return 0;
946}
947
949#if VA_CHECK_VERSION(1, 18, 0)
950 { AV_PROFILE_H264_HIGH_10, 10, 3, 1, 1, VAProfileH264High10 },
951#endif
952 { AV_PROFILE_H264_HIGH, 8, 3, 1, 1, VAProfileH264High },
953 { AV_PROFILE_H264_MAIN, 8, 3, 1, 1, VAProfileH264Main },
955 8, 3, 1, 1, VAProfileH264ConstrainedBaseline },
957};
958
960 .profiles = vaapi_encode_h264_profiles,
961
962 .flags = FF_HW_FLAG_SLICE_CONTROL |
966
967 .default_quality = 20,
968
969 .configure = &vaapi_encode_h264_configure,
970
971 .picture_priv_data_size = sizeof(VAAPIEncodeH264Picture),
972
973 .sequence_params_size = sizeof(VAEncSequenceParameterBufferH264),
974 .init_sequence_params = &vaapi_encode_h264_init_sequence_params,
975
976 .picture_params_size = sizeof(VAEncPictureParameterBufferH264),
977 .init_picture_params = &vaapi_encode_h264_init_picture_params,
978
979 .slice_params_size = sizeof(VAEncSliceParameterBufferH264),
980 .init_slice_params = &vaapi_encode_h264_init_slice_params,
981
982 .sequence_header_type = VAEncPackedHeaderSequence,
983 .write_sequence_header = &vaapi_encode_h264_write_sequence_header,
984
985 .slice_header_type = VAEncPackedHeaderH264_Slice,
986 .write_slice_header = &vaapi_encode_h264_write_slice_header,
987
988 .write_extra_header = &vaapi_encode_h264_write_extra_header,
989};
990
992{
993 FFHWBaseEncodeContext *base_ctx = avctx->priv_data;
995 VAAPIEncodeH264Context *priv = avctx->priv_data;
996
997 ctx->codec = &vaapi_encode_type_h264;
998
999 if (avctx->profile == AV_PROFILE_UNKNOWN)
1000 avctx->profile = priv->profile;
1001 if (avctx->level == AV_LEVEL_UNKNOWN)
1002 avctx->level = priv->level;
1004 avctx->compression_level = priv->quality;
1005
1006 // Reject unsupported profiles.
1007 switch (avctx->profile) {
1009 av_log(avctx, AV_LOG_WARNING, "H.264 baseline profile is not "
1010 "supported, using constrained baseline profile instead.\n");
1012 break;
1014 av_log(avctx, AV_LOG_ERROR, "H.264 extended profile "
1015 "is not supported.\n");
1016 return AVERROR_PATCHWELCOME;
1018 av_log(avctx, AV_LOG_ERROR, "H.264 high 10 intra profile "
1019 "is not supported.\n");
1020 return AVERROR_PATCHWELCOME;
1027 av_log(avctx, AV_LOG_ERROR, "H.264 non-4:2:0 profiles "
1028 "are not supported.\n");
1029 return AVERROR_PATCHWELCOME;
1030 }
1031
1032 if (avctx->level != AV_LEVEL_UNKNOWN && avctx->level & ~0xff) {
1033 av_log(avctx, AV_LOG_ERROR, "Invalid level %d: must fit "
1034 "in 8-bit unsigned integer.\n", avctx->level);
1035 return AVERROR(EINVAL);
1036 }
1037
1038 ctx->desired_packed_headers =
1039 VA_ENC_PACKED_HEADER_SEQUENCE | // SPS and PPS.
1040 VA_ENC_PACKED_HEADER_SLICE | // Slice headers.
1041 VA_ENC_PACKED_HEADER_MISC; // SEI.
1042
1043 base_ctx->surface_width = FFALIGN(avctx->width, 16);
1044 base_ctx->surface_height = FFALIGN(avctx->height, 16);
1045
1046 base_ctx->slice_block_height = base_ctx->slice_block_width = 16;
1047
1048 if (priv->qp > 0)
1049 ctx->explicit_qp = priv->qp;
1050
1051 return ff_vaapi_encode_init(avctx);
1052}
1053
1055{
1056 VAAPIEncodeH264Context *priv = avctx->priv_data;
1057
1058 ff_cbs_fragment_free(&priv->current_access_unit);
1059 ff_cbs_close(&priv->cbc);
1061 av_freep(&priv->sei_a53cc_data);
1062
1063 return ff_vaapi_encode_close(avctx);
1064}
1065
1066#define OFFSET(x) offsetof(VAAPIEncodeH264Context, x)
1067#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
1072
1073 { "qp", "Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)",
1074 OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 52, FLAGS },
1075 { "quality", "Set encode quality (trades off against speed, higher is faster)",
1076 OFFSET(quality), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS },
1077 { "coder", "Entropy coder type",
1078 OFFSET(coder), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, FLAGS, .unit = "coder" },
1079 { "cavlc", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, INT_MIN, INT_MAX, FLAGS, .unit = "coder" },
1080 { "cabac", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, FLAGS, .unit = "coder" },
1081 { "vlc", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, INT_MIN, INT_MAX, FLAGS, .unit = "coder" },
1082 { "ac", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, FLAGS, .unit = "coder" },
1083
1084 { "aud", "Include AUD",
1085 OFFSET(aud), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
1086
1087 { "sei", "Set SEI to include",
1090 0, INT_MAX, FLAGS, .unit = "sei" },
1091 { "identifier", "Include encoder version identifier",
1092 0, AV_OPT_TYPE_CONST, { .i64 = SEI_IDENTIFIER },
1093 INT_MIN, INT_MAX, FLAGS, .unit = "sei" },
1094 { "timing", "Include timing parameters (buffering_period and pic_timing)",
1095 0, AV_OPT_TYPE_CONST, { .i64 = SEI_TIMING },
1096 INT_MIN, INT_MAX, FLAGS, .unit = "sei" },
1097 { "recovery_point", "Include recovery points where appropriate",
1099 INT_MIN, INT_MAX, FLAGS, .unit = "sei" },
1100 { "a53_cc", "Include A/53 caption data",
1101 0, AV_OPT_TYPE_CONST, { .i64 = SEI_A53_CC },
1102 INT_MIN, INT_MAX, FLAGS, .unit = "sei" },
1103
1104 { "profile", "Set profile (profile_idc and constraint_set*_flag)",
1106 { .i64 = AV_PROFILE_UNKNOWN }, AV_PROFILE_UNKNOWN, 0xffff, FLAGS, .unit = "profile" },
1107
1108#define PROFILE(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
1109 { .i64 = value }, 0, 0, FLAGS, .unit = "profile"
1110 { PROFILE("constrained_baseline", AV_PROFILE_H264_CONSTRAINED_BASELINE) },
1111 { PROFILE("main", AV_PROFILE_H264_MAIN) },
1112 { PROFILE("high", AV_PROFILE_H264_HIGH) },
1113 { PROFILE("high10", AV_PROFILE_H264_HIGH_10) },
1114#undef PROFILE
1115
1116 { "level", "Set level (level_idc)",
1118 { .i64 = AV_LEVEL_UNKNOWN }, AV_LEVEL_UNKNOWN, 0xff, FLAGS, .unit = "level" },
1119
1120#define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
1121 { .i64 = value }, 0, 0, FLAGS, .unit = "level"
1122 { LEVEL("1", 10) },
1123 { LEVEL("1.1", 11) },
1124 { LEVEL("1.2", 12) },
1125 { LEVEL("1.3", 13) },
1126 { LEVEL("2", 20) },
1127 { LEVEL("2.1", 21) },
1128 { LEVEL("2.2", 22) },
1129 { LEVEL("3", 30) },
1130 { LEVEL("3.1", 31) },
1131 { LEVEL("3.2", 32) },
1132 { LEVEL("4", 40) },
1133 { LEVEL("4.1", 41) },
1134 { LEVEL("4.2", 42) },
1135 { LEVEL("5", 50) },
1136 { LEVEL("5.1", 51) },
1137 { LEVEL("5.2", 52) },
1138 { LEVEL("6", 60) },
1139 { LEVEL("6.1", 61) },
1140 { LEVEL("6.2", 62) },
1141#undef LEVEL
1142
1143 { NULL },
1144};
1145
1147 { "b", "0" },
1148 { "bf", "2" },
1149 { "g", "120" },
1150 { "i_qfactor", "1" },
1151 { "i_qoffset", "0" },
1152 { "b_qfactor", "6/5" },
1153 { "b_qoffset", "0" },
1154 { "qmin", "-1" },
1155 { "qmax", "-1" },
1156 { "refs", "0" },
1157 { NULL },
1158};
1159
1161 .class_name = "h264_vaapi",
1162 .item_name = av_default_item_name,
1163 .option = vaapi_encode_h264_options,
1164 .version = LIBAVUTIL_VERSION_INT,
1165};
1166
1168 .p.name = "h264_vaapi",
1169 CODEC_LONG_NAME("H.264/AVC (VAAPI)"),
1170 .p.type = AVMEDIA_TYPE_VIDEO,
1171 .p.id = AV_CODEC_ID_H264,
1172 .priv_data_size = sizeof(VAAPIEncodeH264Context),
1175 .close = &vaapi_encode_h264_close,
1176 .p.priv_class = &vaapi_encode_h264_class,
1177 .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE |
1179 .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE |
1181 .defaults = vaapi_encode_h264_defaults,
1183 .color_ranges = AVCOL_RANGE_MPEG | AVCOL_RANGE_JPEG,
1184 .hw_configs = ff_vaapi_encode_hw_configs,
1185 .p.wrapper_name = "vaapi",
1186};
static float hn(int n, EqParameter *param, float fs)
const FFCodec ff_h264_vaapi_encoder
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 FF_COMPRESSION_DEFAULT
Definition avcodec.h:1242
#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)
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_H264_MAIN
Definition defs.h:112
#define AV_PROFILE_H264_EXTENDED
Definition defs.h:113
#define AV_PROFILE_UNKNOWN
Definition defs.h:65
#define AV_PROFILE_H264_HIGH_444_PREDICTIVE
Definition defs.h:122
#define AV_LEVEL_UNKNOWN
Definition defs.h:209
#define AV_PROFILE_H264_HIGH_444
Definition defs.h:121
#define AV_PROFILE_H264_CAVLC_444
Definition defs.h:124
#define AV_PROFILE_H264_HIGH_422_INTRA
Definition defs.h:119
#define AV_PROFILE_H264_HIGH_444_INTRA
Definition defs.h:123
#define AV_PROFILE_H264_HIGH
Definition defs.h:114
#define AV_PROFILE_H264_CONSTRAINED_BASELINE
Definition defs.h:111
#define AV_PROFILE_H264_HIGH_10
Definition defs.h:115
#define AV_PROFILE_H264_HIGH_422
Definition defs.h:118
#define AV_PROFILE_H264_HIGH_10_INTRA
Definition defs.h:116
#define AV_PROFILE_H264_BASELINE
Definition defs.h:110
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_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_H264
Definition codec_id.h:77
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition error.h:64
#define AVERROR_EOF
End of file.
Definition error.h:57
#define AVERROR(e)
Definition error.h:45
#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_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
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
int index
Definition gxfenc.c:90
H.264 common definitions.
@ H264_NAL_SLICE
Definition h264.h:35
@ H264_NAL_AUD
Definition h264.h:43
@ H264_NAL_IDR_SLICE
Definition h264.h:39
#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_h264(FFHWBaseEncodeContext *base_ctx, AVCodecContext *avctx, FFHWBaseEncodeH264 *common, FFHWBaseEncodeH264Opts *opts)
#define FF_HW_H264_SEI_TIMING
cl_device_type type
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)
Libavcodec version macros.
#define LIBAVCODEC_IDENT
Definition version.h:43
#define av_cold
Definition attributes.h:117
#define FFSWAP(type, a, b)
Definition macros.h:52
#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
#define av_malloc(s)
Definition ops_static.c:52
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_RECOVERY_POINT
Definition sei.h:36
@ SEI_TYPE_PIC_TIMING
Definition sei.h:31
@ SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35
Definition sei.h:34
@ SEI_TYPE_USER_DATA_UNREGISTERED
Definition sei.h:35
@ SEI_TYPE_BUFFERING_PERIOD
Definition sei.h:30
#define FF_ARRAY_ELEMS(a)
#define snprintf
Definition snprintf.h:34
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
int compression_level
Definition avcodec.h:1241
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
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
H264RawSEIBufferingPeriod sei_buffering_period
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 nal_unit_type
Definition cbs_h264.h:33
uint8_t pic_order_cnt_type
Definition cbs_h264.h:129
uint8_t ref_pic_list_modification_flag_l0
Definition cbs_h264.h:357
int32_t abs_diff_pic_num_minus1
Definition cbs_h264.h:361
uint16_t idr_pic_id
Definition cbs_h264.h:344
struct H264RawSliceHeader::@327131344327015270015167334360064261102064024262 rplm_l1[H264_MAX_RPLM_COUNT]
struct H264RawSliceHeader::@270001324256267363175166122233254040337357331112 mmco[H264_MAX_MMCO_COUNT]
uint8_t memory_management_control_operation
Definition cbs_h264.h:387
uint8_t adaptive_ref_pic_marking_mode_flag
Definition cbs_h264.h:385
uint8_t pic_parameter_set_id
Definition cbs_h264.h:336
uint8_t direct_spatial_mv_pred_flag
Definition cbs_h264.h:351
int8_t slice_qp_delta
Definition cbs_h264.h:396
struct H264RawSliceHeader::@327131344327015270015167334360064261102064024262 rplm_l0[H264_MAX_RPLM_COUNT]
uint16_t frame_num
Definition cbs_h264.h:340
uint8_t ref_pic_list_modification_flag_l1
Definition cbs_h264.h:358
uint32_t first_mb_in_slice
Definition cbs_h264.h:333
uint8_t modification_of_pic_nums_idc
Definition cbs_h264.h:360
H264RawNALUnitHeader nal_unit_header
Definition cbs_h264.h:331
int32_t difference_of_pic_nums_minus1
Definition cbs_h264.h:388
uint16_t pic_order_cnt_lsb
Definition cbs_h264.h:346
H264RawSliceHeader header
Definition cbs_h264.h:409
uint8_t itu_t_t35_country_code
Definition cbs_sei.h:34
uint8_t uuid_iso_iec_11578[16]
Definition cbs_sei.h:42
VAAPIEncodeContext common
H264RawSEIPicTiming sei_pic_timing
H264RawSEIRecoveryPoint sei_recovery_point
SEIRawUserDataRegistered sei_a53cc
SEIRawUserDataUnregistered sei_identifier
CodedBitstreamFragment current_access_unit
FFHWBaseEncodeH264 units
CodedBitstreamContext * cbc
void * codec_picture_params
VASurfaceID recon_surface
VABufferID output_buffer
void * codec_slice_params
uint8_t level
Definition svq3.c:208
#define av_freep(p)
#define av_log(a,...)
static int ref[MAX_W *MAX_W]
static AVFormatContext * ctx
Definition movenc.c:49
#define VAAPI_ENCODE_COMMON_OPTIONS
#define VAAPI_ENCODE_RC_OPTIONS
static int vaapi_encode_h264_init_slice_params(AVCodecContext *avctx, FFHWBaseEncodePicture *pic, VAAPIEncodeSlice *slice)
static int vaapi_encode_h264_write_sequence_header(AVCodecContext *avctx, char *data, size_t *data_len)
static av_cold int vaapi_encode_h264_init(AVCodecContext *avctx)
static const FFCodecDefault vaapi_encode_h264_defaults[]
static const VAAPIEncodeType vaapi_encode_type_h264
static int vaapi_encode_h264_write_slice_header(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice, char *data, size_t *data_len)
static av_cold int vaapi_encode_h264_close(AVCodecContext *avctx)
static int vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx)
static void vaapi_encode_h264_default_ref_pic_list(AVCodecContext *avctx, FFHWBaseEncodePicture *pic, FFHWBaseEncodePicture **rpl0, FFHWBaseEncodePicture **rpl1, int *rpl_size)
static const VAAPIEncodeProfile vaapi_encode_h264_profiles[]
static const AVOption vaapi_encode_h264_options[]
static const uint8_t vaapi_encode_h264_sei_identifier_uuid[16]
#define LEVEL(name, value)
@ SEI_A53_CC
@ SEI_TIMING
@ SEI_IDENTIFIER
@ SEI_RECOVERY_POINT
static int vaapi_encode_h264_write_extra_header(AVCodecContext *avctx, FFHWBaseEncodePicture *base, int index, int *type, char *data, size_t *data_len)
#define PROFILE(name, value)
static int vaapi_encode_h264_init_picture_params(AVCodecContext *avctx, FFHWBaseEncodePicture *pic)
static const AVClass vaapi_encode_h264_class
#define OFFSET(x)
static int vaapi_encode_h264_add_nal(AVCodecContext *avctx, CodedBitstreamFragment *au, void *nal_unit)
static av_cold int vaapi_encode_h264_configure(AVCodecContext *avctx)
static int vaapi_encode_h264_write_access_unit(AVCodecContext *avctx, char *data, size_t *data_len, CodedBitstreamFragment *au)
static const uint8_t quality[]
Definition vmixdec.c:58
int len
uint8_t base
Definition vp3data.h:128