FFmpeg
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/internal.h"
27 #include "libavutil/opt.h"
28 
29 #include "avcodec.h"
30 #include "cbs.h"
31 #include "cbs_h264.h"
32 #include "h264.h"
33 #include "h264_levels.h"
34 #include "h264_sei.h"
35 #include "internal.h"
36 #include "vaapi_encode.h"
37 
38 enum {
39  SEI_TIMING = 0x01,
42 };
43 
44 // Random (version 4) ISO 11578 UUID.
46  0x59, 0x94, 0x8b, 0x28, 0x11, 0xec, 0x45, 0xaf,
47  0x96, 0x75, 0x19, 0xd4, 0x1f, 0xea, 0xa9, 0x4d,
48 };
49 
50 typedef struct VAAPIEncodeH264Picture {
51  int frame_num;
53 
54  int64_t last_idr_frame;
55  uint16_t idr_pic_id;
56 
59 
60  int cpb_delay;
61  int dpb_delay;
63 
64 typedef struct VAAPIEncodeH264Context {
66 
67  // User options.
68  int qp;
69  int quality;
70  int coder;
71  int aud;
72  int sei;
73  int profile;
74  int level;
75 
76  // Derived settings.
77  int mb_width;
78  int mb_height;
79 
83 
85 
86  // Writer structures.
89 
95 
101 
106 
107 
109  char *data, size_t *data_len,
111 {
112  VAAPIEncodeH264Context *priv = avctx->priv_data;
113  int err;
114 
115  err = ff_cbs_write_fragment_data(priv->cbc, au);
116  if (err < 0) {
117  av_log(avctx, AV_LOG_ERROR, "Failed to write packed header.\n");
118  return err;
119  }
120 
121  if (*data_len < 8 * au->data_size - au->data_bit_padding) {
122  av_log(avctx, AV_LOG_ERROR, "Access unit too large: "
123  "%zu < %zu.\n", *data_len,
124  8 * au->data_size - au->data_bit_padding);
125  return AVERROR(ENOSPC);
126  }
127 
128  memcpy(data, au->data, au->data_size);
129  *data_len = 8 * au->data_size - au->data_bit_padding;
130 
131  return 0;
132 }
133 
136  void *nal_unit)
137 {
138  H264RawNALUnitHeader *header = nal_unit;
139  int err;
140 
141  err = ff_cbs_insert_unit_content(au, -1,
142  header->nal_unit_type, nal_unit, NULL);
143  if (err < 0) {
144  av_log(avctx, AV_LOG_ERROR, "Failed to add NAL unit: "
145  "type = %d.\n", header->nal_unit_type);
146  return err;
147  }
148 
149  return 0;
150 }
151 
153  char *data, size_t *data_len)
154 {
155  VAAPIEncodeH264Context *priv = avctx->priv_data;
157  int err;
158 
159  if (priv->aud_needed) {
160  err = vaapi_encode_h264_add_nal(avctx, au, &priv->raw_aud);
161  if (err < 0)
162  goto fail;
163  priv->aud_needed = 0;
164  }
165 
166  err = vaapi_encode_h264_add_nal(avctx, au, &priv->raw_sps);
167  if (err < 0)
168  goto fail;
169 
170  err = vaapi_encode_h264_add_nal(avctx, au, &priv->raw_pps);
171  if (err < 0)
172  goto fail;
173 
174  err = vaapi_encode_h264_write_access_unit(avctx, data, data_len, au);
175 fail:
177  return err;
178 }
179 
181  VAAPIEncodePicture *pic,
182  VAAPIEncodeSlice *slice,
183  char *data, size_t *data_len)
184 {
185  VAAPIEncodeH264Context *priv = avctx->priv_data;
187  int err;
188 
189  if (priv->aud_needed) {
190  err = vaapi_encode_h264_add_nal(avctx, au, &priv->raw_aud);
191  if (err < 0)
192  goto fail;
193  priv->aud_needed = 0;
194  }
195 
196  err = vaapi_encode_h264_add_nal(avctx, au, &priv->raw_slice);
197  if (err < 0)
198  goto fail;
199 
200  err = vaapi_encode_h264_write_access_unit(avctx, data, data_len, au);
201 fail:
203  return err;
204 }
205 
207  VAAPIEncodePicture *pic,
208  int index, int *type,
209  char *data, size_t *data_len)
210 {
211  VAAPIEncodeH264Context *priv = avctx->priv_data;
213  int err, i;
214 
215  if (priv->sei_needed) {
216  H264RawSEI *sei = &priv->raw_sei;
217 
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  *sei = (H264RawSEI) {
226  .nal_unit_header = {
228  },
229  };
230 
231  i = 0;
232 
233  if (priv->sei_needed & SEI_IDENTIFIER) {
236  ++i;
237  }
238  if (priv->sei_needed & SEI_TIMING) {
239  if (pic->type == PICTURE_TYPE_IDR) {
242  ++i;
243  }
245  sei->payload[i].payload.pic_timing = priv->sei_pic_timing;
246  ++i;
247  }
248  if (priv->sei_needed & SEI_RECOVERY_POINT) {
251  ++i;
252  }
253 
254  sei->payload_count = i;
255  av_assert0(sei->payload_count > 0);
256 
257  err = vaapi_encode_h264_add_nal(avctx, au, sei);
258  if (err < 0)
259  goto fail;
260  priv->sei_needed = 0;
261 
262  err = vaapi_encode_h264_write_access_unit(avctx, data, data_len, au);
263  if (err < 0)
264  goto fail;
265 
267 
268  *type = VAEncPackedHeaderRawData;
269  return 0;
270 
271 #if !CONFIG_VAAPI_1
272  } else if (priv->sei_cbr_workaround_needed) {
273  // Insert a zero-length header using the old SEI type. This is
274  // required to avoid triggering broken behaviour on Intel platforms
275  // in CBR mode where an invalid SEI message is generated by the
276  // driver and inserted into the stream.
277  *data_len = 0;
278  *type = VAEncPackedHeaderH264_SEI;
279  priv->sei_cbr_workaround_needed = 0;
280  return 0;
281 #endif
282 
283  } else {
284  return AVERROR_EOF;
285  }
286 
287 fail:
289  return err;
290 }
291 
293 {
294  VAAPIEncodeContext *ctx = avctx->priv_data;
295  VAAPIEncodeH264Context *priv = avctx->priv_data;
296  H264RawSPS *sps = &priv->raw_sps;
297  H264RawPPS *pps = &priv->raw_pps;
298  VAEncSequenceParameterBufferH264 *vseq = ctx->codec_sequence_params;
299  VAEncPictureParameterBufferH264 *vpic = ctx->codec_picture_params;
300 
301  memset(sps, 0, sizeof(*sps));
302  memset(pps, 0, sizeof(*pps));
303 
304  sps->nal_unit_header.nal_ref_idc = 3;
306 
307  sps->profile_idc = avctx->profile & 0xff;
308 
310  avctx->profile == FF_PROFILE_H264_MAIN)
311  sps->constraint_set1_flag = 1;
312 
313  if (avctx->profile == FF_PROFILE_H264_HIGH)
314  sps->constraint_set3_flag = ctx->gop_size == 1;
315 
316  if (avctx->profile == FF_PROFILE_H264_MAIN ||
317  avctx->profile == FF_PROFILE_H264_HIGH) {
318  sps->constraint_set4_flag = 1;
319  sps->constraint_set5_flag = ctx->b_per_p == 0;
320  }
321 
322  if (ctx->gop_size == 1)
323  priv->dpb_frames = 0;
324  else
325  priv->dpb_frames = 1 + ctx->max_b_depth;
326 
327  if (avctx->level != FF_LEVEL_UNKNOWN) {
328  sps->level_idc = avctx->level;
329  } else {
330  const H264LevelDescriptor *level;
331  int framerate;
332 
333  if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
334  framerate = avctx->framerate.num / avctx->framerate.den;
335  else
336  framerate = 0;
337 
338  level = ff_h264_guess_level(sps->profile_idc,
339  avctx->bit_rate,
340  framerate,
341  priv->mb_width * 16,
342  priv->mb_height * 16,
343  priv->dpb_frames);
344  if (level) {
345  av_log(avctx, AV_LOG_VERBOSE, "Using level %s.\n", level->name);
346  if (level->constraint_set3_flag)
347  sps->constraint_set3_flag = 1;
348  sps->level_idc = level->level_idc;
349  } else {
350  av_log(avctx, AV_LOG_WARNING, "Stream will not conform "
351  "to any level: using level 6.2.\n");
352  sps->level_idc = 62;
353  }
354  }
355 
356  sps->seq_parameter_set_id = 0;
357  sps->chroma_format_idc = 1;
358 
359  sps->log2_max_frame_num_minus4 = 4;
360  sps->pic_order_cnt_type = 0;
362 
363  sps->max_num_ref_frames = priv->dpb_frames;
364 
365  sps->pic_width_in_mbs_minus1 = priv->mb_width - 1;
366  sps->pic_height_in_map_units_minus1 = priv->mb_height - 1;
367 
368  sps->frame_mbs_only_flag = 1;
369  sps->direct_8x8_inference_flag = 1;
370 
371  if (avctx->width != 16 * priv->mb_width ||
372  avctx->height != 16 * priv->mb_height) {
373  sps->frame_cropping_flag = 1;
374 
375  sps->frame_crop_left_offset = 0;
377  (16 * priv->mb_width - avctx->width) / 2;
378  sps->frame_crop_top_offset = 0;
380  (16 * priv->mb_height - avctx->height) / 2;
381  } else {
382  sps->frame_cropping_flag = 0;
383  }
384 
386 
387  if (avctx->sample_aspect_ratio.num != 0 &&
388  avctx->sample_aspect_ratio.den != 0) {
389  static const AVRational sar_idc[] = {
390  { 0, 0 },
391  { 1, 1 }, { 12, 11 }, { 10, 11 }, { 16, 11 },
392  { 40, 33 }, { 24, 11 }, { 20, 11 }, { 32, 11 },
393  { 80, 33 }, { 18, 11 }, { 15, 11 }, { 64, 33 },
394  { 160, 99 }, { 4, 3 }, { 3, 2 }, { 2, 1 },
395  };
396  int num, den, i;
397  av_reduce(&num, &den, avctx->sample_aspect_ratio.num,
398  avctx->sample_aspect_ratio.den, 65535);
399  for (i = 0; i < FF_ARRAY_ELEMS(sar_idc); i++) {
400  if (num == sar_idc[i].num &&
401  den == sar_idc[i].den) {
402  sps->vui.aspect_ratio_idc = i;
403  break;
404  }
405  }
406  if (i >= FF_ARRAY_ELEMS(sar_idc)) {
407  sps->vui.aspect_ratio_idc = 255;
408  sps->vui.sar_width = num;
409  sps->vui.sar_height = den;
410  }
412  }
413 
414  if (avctx->color_range != AVCOL_RANGE_UNSPECIFIED ||
416  avctx->color_trc != AVCOL_TRC_UNSPECIFIED ||
417  avctx->colorspace != AVCOL_SPC_UNSPECIFIED) {
419  sps->vui.video_format = 5; // Unspecified.
421  avctx->color_range == AVCOL_RANGE_JPEG;
422 
423  if (avctx->color_primaries != AVCOL_PRI_UNSPECIFIED ||
424  avctx->color_trc != AVCOL_TRC_UNSPECIFIED ||
425  avctx->colorspace != AVCOL_SPC_UNSPECIFIED) {
427  sps->vui.colour_primaries = avctx->color_primaries;
428  sps->vui.transfer_characteristics = avctx->color_trc;
429  sps->vui.matrix_coefficients = avctx->colorspace;
430  }
431  } else {
432  sps->vui.video_format = 5;
433  sps->vui.video_full_range_flag = 0;
434  sps->vui.colour_primaries = avctx->color_primaries;
435  sps->vui.transfer_characteristics = avctx->color_trc;
436  sps->vui.matrix_coefficients = avctx->colorspace;
437  }
438 
443  avctx->chroma_sample_location - 1;
444  }
445 
446  sps->vui.timing_info_present_flag = 1;
447  if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
448  sps->vui.num_units_in_tick = avctx->framerate.den;
449  sps->vui.time_scale = 2 * avctx->framerate.num;
450  sps->vui.fixed_frame_rate_flag = 1;
451  } else {
452  sps->vui.num_units_in_tick = avctx->time_base.num;
453  sps->vui.time_scale = 2 * avctx->time_base.den;
454  sps->vui.fixed_frame_rate_flag = 0;
455  }
456 
457  if (priv->sei & SEI_TIMING) {
458  H264RawHRD *hrd = &sps->vui.nal_hrd_parameters;
460 
462 
463  hrd->cpb_cnt_minus1 = 0;
464 
465  // Try to scale these to a sensible range so that the
466  // golomb encode of the value is not overlong.
467  hrd->bit_rate_scale =
468  av_clip_uintp2(av_log2(ctx->va_bit_rate) - 15 - 6, 4);
469  hrd->bit_rate_value_minus1[0] =
470  (ctx->va_bit_rate >> hrd->bit_rate_scale + 6) - 1;
471 
472  hrd->cpb_size_scale =
473  av_clip_uintp2(av_log2(ctx->hrd_params.buffer_size) - 15 - 4, 4);
474  hrd->cpb_size_value_minus1[0] =
475  (ctx->hrd_params.buffer_size >> hrd->cpb_size_scale + 4) - 1;
476 
477  // CBR mode as defined for the HRD cannot be achieved without filler
478  // data, so this flag cannot be set even with VAAPI CBR modes.
479  hrd->cbr_flag[0] = 0;
480 
484  hrd->time_offset_length = 0;
485 
487 
488  // This calculation can easily overflow 32 bits.
489  bp->nal.initial_cpb_removal_delay[0] = 90000 *
490  (uint64_t)ctx->hrd_params.initial_buffer_fullness /
491  ctx->hrd_params.buffer_size;
493  } else {
496  }
497 
503  sps->vui.max_dec_frame_buffering = ctx->max_b_depth + 1;
504 
505  pps->nal_unit_header.nal_ref_idc = 3;
507 
508  pps->pic_parameter_set_id = 0;
509  pps->seq_parameter_set_id = 0;
510 
515  if (!priv->coder && pps->entropy_coding_mode_flag)
516  pps->entropy_coding_mode_flag = 0;
517 
520 
521  pps->pic_init_qp_minus26 = priv->fixed_qp_idr - 26;
522 
526  pps->more_rbsp_data = 0;
527  } else {
528  pps->more_rbsp_data = 1;
529 
530  pps->transform_8x8_mode_flag = 1;
531  }
532 
533  *vseq = (VAEncSequenceParameterBufferH264) {
534  .seq_parameter_set_id = sps->seq_parameter_set_id,
535  .level_idc = sps->level_idc,
536  .intra_period = ctx->gop_size,
537  .intra_idr_period = ctx->gop_size,
538  .ip_period = ctx->b_per_p + 1,
539 
540  .bits_per_second = ctx->va_bit_rate,
541  .max_num_ref_frames = sps->max_num_ref_frames,
542  .picture_width_in_mbs = sps->pic_width_in_mbs_minus1 + 1,
543  .picture_height_in_mbs = sps->pic_height_in_map_units_minus1 + 1,
544 
545  .seq_fields.bits = {
546  .chroma_format_idc = sps->chroma_format_idc,
547  .frame_mbs_only_flag = sps->frame_mbs_only_flag,
548  .mb_adaptive_frame_field_flag = sps->mb_adaptive_frame_field_flag,
549  .seq_scaling_matrix_present_flag = sps->seq_scaling_matrix_present_flag,
550  .direct_8x8_inference_flag = sps->direct_8x8_inference_flag,
551  .log2_max_frame_num_minus4 = sps->log2_max_frame_num_minus4,
552  .pic_order_cnt_type = sps->pic_order_cnt_type,
553  .log2_max_pic_order_cnt_lsb_minus4 = sps->log2_max_pic_order_cnt_lsb_minus4,
554  .delta_pic_order_always_zero_flag = sps->delta_pic_order_always_zero_flag,
555  },
556 
557  .bit_depth_luma_minus8 = sps->bit_depth_luma_minus8,
558  .bit_depth_chroma_minus8 = sps->bit_depth_chroma_minus8,
559 
560  .frame_cropping_flag = sps->frame_cropping_flag,
561  .frame_crop_left_offset = sps->frame_crop_left_offset,
562  .frame_crop_right_offset = sps->frame_crop_right_offset,
563  .frame_crop_top_offset = sps->frame_crop_top_offset,
564  .frame_crop_bottom_offset = sps->frame_crop_bottom_offset,
565 
566  .vui_parameters_present_flag = sps->vui_parameters_present_flag,
567 
568  .vui_fields.bits = {
569  .aspect_ratio_info_present_flag = sps->vui.aspect_ratio_info_present_flag,
570  .timing_info_present_flag = sps->vui.timing_info_present_flag,
571  .bitstream_restriction_flag = sps->vui.bitstream_restriction_flag,
572  .log2_max_mv_length_horizontal = sps->vui.log2_max_mv_length_horizontal,
573  .log2_max_mv_length_vertical = sps->vui.log2_max_mv_length_vertical,
574  },
575 
576  .aspect_ratio_idc = sps->vui.aspect_ratio_idc,
577  .sar_width = sps->vui.sar_width,
578  .sar_height = sps->vui.sar_height,
579  .num_units_in_tick = sps->vui.num_units_in_tick,
580  .time_scale = sps->vui.time_scale,
581  };
582 
583  *vpic = (VAEncPictureParameterBufferH264) {
584  .CurrPic = {
585  .picture_id = VA_INVALID_ID,
586  .flags = VA_PICTURE_H264_INVALID,
587  },
588 
589  .coded_buf = VA_INVALID_ID,
590 
591  .pic_parameter_set_id = pps->pic_parameter_set_id,
592  .seq_parameter_set_id = pps->seq_parameter_set_id,
593 
594  .pic_init_qp = pps->pic_init_qp_minus26 + 26,
595  .num_ref_idx_l0_active_minus1 = pps->num_ref_idx_l0_default_active_minus1,
596  .num_ref_idx_l1_active_minus1 = pps->num_ref_idx_l1_default_active_minus1,
597 
598  .chroma_qp_index_offset = pps->chroma_qp_index_offset,
599  .second_chroma_qp_index_offset = pps->second_chroma_qp_index_offset,
600 
601  .pic_fields.bits = {
602  .entropy_coding_mode_flag = pps->entropy_coding_mode_flag,
603  .weighted_pred_flag = pps->weighted_pred_flag,
604  .weighted_bipred_idc = pps->weighted_bipred_idc,
605  .constrained_intra_pred_flag = pps->constrained_intra_pred_flag,
606  .transform_8x8_mode_flag = pps->transform_8x8_mode_flag,
607  .deblocking_filter_control_present_flag =
609  .redundant_pic_cnt_present_flag = pps->redundant_pic_cnt_present_flag,
610  .pic_order_present_flag =
612  .pic_scaling_matrix_present_flag = pps->pic_scaling_matrix_present_flag,
613  },
614  };
615 
616  return 0;
617 }
618 
620  VAAPIEncodePicture *pic)
621 {
622  VAAPIEncodeContext *ctx = avctx->priv_data;
623  VAAPIEncodeH264Context *priv = avctx->priv_data;
624  VAAPIEncodeH264Picture *hpic = pic->priv_data;
625  VAAPIEncodePicture *prev = pic->prev;
626  VAAPIEncodeH264Picture *hprev = prev ? prev->priv_data : NULL;
627  VAEncPictureParameterBufferH264 *vpic = pic->codec_picture_params;
628  int i;
629 
630  if (pic->type == PICTURE_TYPE_IDR) {
631  av_assert0(pic->display_order == pic->encode_order);
632 
633  hpic->frame_num = 0;
634  hpic->last_idr_frame = pic->display_order;
635  hpic->idr_pic_id = hprev ? hprev->idr_pic_id + 1 : 0;
636 
637  hpic->primary_pic_type = 0;
638  hpic->slice_type = 7;
639  } else {
640  av_assert0(prev);
641 
642  hpic->frame_num = hprev->frame_num + prev->is_reference;
643 
644  hpic->last_idr_frame = hprev->last_idr_frame;
645  hpic->idr_pic_id = hprev->idr_pic_id;
646 
647  if (pic->type == PICTURE_TYPE_I) {
648  hpic->slice_type = 7;
649  hpic->primary_pic_type = 0;
650  } else if (pic->type == PICTURE_TYPE_P) {
651  hpic->slice_type = 5;
652  hpic->primary_pic_type = 1;
653  } else {
654  hpic->slice_type = 6;
655  hpic->primary_pic_type = 2;
656  }
657  }
658  hpic->pic_order_cnt = pic->display_order - hpic->last_idr_frame;
659  hpic->dpb_delay = pic->display_order - pic->encode_order + ctx->max_b_depth;
660  hpic->cpb_delay = pic->encode_order - hpic->last_idr_frame;
661 
662  if (priv->aud) {
663  priv->aud_needed = 1;
664  priv->raw_aud = (H264RawAUD) {
665  .nal_unit_header = {
667  },
668  .primary_pic_type = hpic->primary_pic_type,
669  };
670  } else {
671  priv->aud_needed = 0;
672  }
673 
674  priv->sei_needed = 0;
675 
676  if (priv->sei & SEI_IDENTIFIER && pic->encode_order == 0)
677  priv->sei_needed |= SEI_IDENTIFIER;
678 #if !CONFIG_VAAPI_1
679  if (ctx->va_rc_mode == VA_RC_CBR)
680  priv->sei_cbr_workaround_needed = 1;
681 #endif
682 
683  if (priv->sei & SEI_TIMING) {
685  .cpb_removal_delay = 2 * hpic->cpb_delay,
686  .dpb_output_delay = 2 * hpic->dpb_delay,
687  };
688 
689  priv->sei_needed |= SEI_TIMING;
690  }
691 
692  if (priv->sei & SEI_RECOVERY_POINT && pic->type == PICTURE_TYPE_I) {
694  .recovery_frame_cnt = 0,
695  .exact_match_flag = 1,
696  .broken_link_flag = ctx->b_per_p > 0,
697  };
698 
700  }
701 
702  vpic->CurrPic = (VAPictureH264) {
703  .picture_id = pic->recon_surface,
704  .frame_idx = hpic->frame_num,
705  .flags = 0,
706  .TopFieldOrderCnt = hpic->pic_order_cnt,
707  .BottomFieldOrderCnt = hpic->pic_order_cnt,
708  };
709 
710  for (i = 0; i < pic->nb_refs; i++) {
711  VAAPIEncodePicture *ref = pic->refs[i];
713 
714  av_assert0(ref && ref->encode_order < pic->encode_order);
715  href = ref->priv_data;
716 
717  vpic->ReferenceFrames[i] = (VAPictureH264) {
718  .picture_id = ref->recon_surface,
719  .frame_idx = href->frame_num,
720  .flags = VA_PICTURE_H264_SHORT_TERM_REFERENCE,
721  .TopFieldOrderCnt = href->pic_order_cnt,
722  .BottomFieldOrderCnt = href->pic_order_cnt,
723  };
724  }
725  for (; i < FF_ARRAY_ELEMS(vpic->ReferenceFrames); i++) {
726  vpic->ReferenceFrames[i] = (VAPictureH264) {
727  .picture_id = VA_INVALID_ID,
728  .flags = VA_PICTURE_H264_INVALID,
729  };
730  }
731 
732  vpic->coded_buf = pic->output_buffer;
733 
734  vpic->frame_num = hpic->frame_num;
735 
736  vpic->pic_fields.bits.idr_pic_flag = (pic->type == PICTURE_TYPE_IDR);
737  vpic->pic_fields.bits.reference_pic_flag = (pic->type != PICTURE_TYPE_B);
738 
739  return 0;
740 }
741 
743  VAAPIEncodePicture *pic,
744  VAAPIEncodePicture **rpl0,
745  VAAPIEncodePicture **rpl1,
746  int *rpl_size)
747 {
748  VAAPIEncodePicture *prev;
749  VAAPIEncodeH264Picture *hp, *hn, *hc;
750  int i, j, n = 0;
751 
752  prev = pic->prev;
753  av_assert0(prev);
754  hp = pic->priv_data;
755 
756  for (i = 0; i < pic->prev->nb_dpb_pics; i++) {
757  hn = prev->dpb[i]->priv_data;
758  av_assert0(hn->frame_num < hp->frame_num);
759 
760  if (pic->type == PICTURE_TYPE_P) {
761  for (j = n; j > 0; j--) {
762  hc = rpl0[j - 1]->priv_data;
763  av_assert0(hc->frame_num != hn->frame_num);
764  if (hc->frame_num > hn->frame_num)
765  break;
766  rpl0[j] = rpl0[j - 1];
767  }
768  rpl0[j] = prev->dpb[i];
769 
770  } else if (pic->type == PICTURE_TYPE_B) {
771  for (j = n; j > 0; j--) {
772  hc = rpl0[j - 1]->priv_data;
774  if (hc->pic_order_cnt < hp->pic_order_cnt) {
775  if (hn->pic_order_cnt > hp->pic_order_cnt ||
776  hn->pic_order_cnt < hc->pic_order_cnt)
777  break;
778  } else {
779  if (hn->pic_order_cnt > hc->pic_order_cnt)
780  break;
781  }
782  rpl0[j] = rpl0[j - 1];
783  }
784  rpl0[j] = prev->dpb[i];
785 
786  for (j = n; j > 0; j--) {
787  hc = rpl1[j - 1]->priv_data;
789  if (hc->pic_order_cnt > hp->pic_order_cnt) {
790  if (hn->pic_order_cnt < hp->pic_order_cnt ||
791  hn->pic_order_cnt > hc->pic_order_cnt)
792  break;
793  } else {
794  if (hn->pic_order_cnt < hc->pic_order_cnt)
795  break;
796  }
797  rpl1[j] = rpl1[j - 1];
798  }
799  rpl1[j] = prev->dpb[i];
800  }
801 
802  ++n;
803  }
804 
805  if (pic->type == PICTURE_TYPE_B) {
806  for (i = 0; i < n; i++) {
807  if (rpl0[i] != rpl1[i])
808  break;
809  }
810  if (i == n)
811  FFSWAP(VAAPIEncodePicture*, rpl1[0], rpl1[1]);
812  }
813 
814  if (pic->type == PICTURE_TYPE_P ||
815  pic->type == PICTURE_TYPE_B) {
816  av_log(avctx, AV_LOG_DEBUG, "Default RefPicList0 for fn=%d/poc=%d:",
817  hp->frame_num, hp->pic_order_cnt);
818  for (i = 0; i < n; i++) {
819  hn = rpl0[i]->priv_data;
820  av_log(avctx, AV_LOG_DEBUG, " fn=%d/poc=%d",
821  hn->frame_num, hn->pic_order_cnt);
822  }
823  av_log(avctx, AV_LOG_DEBUG, "\n");
824  }
825  if (pic->type == PICTURE_TYPE_B) {
826  av_log(avctx, AV_LOG_DEBUG, "Default RefPicList1 for fn=%d/poc=%d:",
827  hp->frame_num, hp->pic_order_cnt);
828  for (i = 0; i < n; i++) {
829  hn = rpl1[i]->priv_data;
830  av_log(avctx, AV_LOG_DEBUG, " fn=%d/poc=%d",
831  hn->frame_num, hn->pic_order_cnt);
832  }
833  av_log(avctx, AV_LOG_DEBUG, "\n");
834  }
835 
836  *rpl_size = n;
837 }
838 
840  VAAPIEncodePicture *pic,
841  VAAPIEncodeSlice *slice)
842 {
843  VAAPIEncodeH264Context *priv = avctx->priv_data;
844  VAAPIEncodeH264Picture *hpic = pic->priv_data;
845  VAAPIEncodePicture *prev = pic->prev;
846  H264RawSPS *sps = &priv->raw_sps;
847  H264RawPPS *pps = &priv->raw_pps;
848  H264RawSliceHeader *sh = &priv->raw_slice.header;
849  VAEncPictureParameterBufferH264 *vpic = pic->codec_picture_params;
850  VAEncSliceParameterBufferH264 *vslice = slice->codec_slice_params;
851  int i, j;
852 
853  if (pic->type == PICTURE_TYPE_IDR) {
856  } else {
859  }
860 
861  sh->first_mb_in_slice = slice->block_start;
862  sh->slice_type = hpic->slice_type;
863 
865 
866  sh->frame_num = hpic->frame_num &
867  ((1 << (4 + sps->log2_max_frame_num_minus4)) - 1);
868  sh->idr_pic_id = hpic->idr_pic_id;
869  sh->pic_order_cnt_lsb = hpic->pic_order_cnt &
870  ((1 << (4 + sps->log2_max_pic_order_cnt_lsb_minus4)) - 1);
871 
873 
874  if (pic->type == PICTURE_TYPE_B)
875  sh->slice_qp_delta = priv->fixed_qp_b - (pps->pic_init_qp_minus26 + 26);
876  else if (pic->type == PICTURE_TYPE_P)
877  sh->slice_qp_delta = priv->fixed_qp_p - (pps->pic_init_qp_minus26 + 26);
878  else
879  sh->slice_qp_delta = priv->fixed_qp_idr - (pps->pic_init_qp_minus26 + 26);
880 
881  if (pic->is_reference && pic->type != PICTURE_TYPE_IDR) {
882  VAAPIEncodePicture *discard_list[MAX_DPB_SIZE];
883  int discard = 0, keep = 0;
884 
885  // Discard everything which is in the DPB of the previous frame but
886  // not in the DPB of this one.
887  for (i = 0; i < prev->nb_dpb_pics; i++) {
888  for (j = 0; j < pic->nb_dpb_pics; j++) {
889  if (prev->dpb[i] == pic->dpb[j])
890  break;
891  }
892  if (j == pic->nb_dpb_pics) {
893  discard_list[discard] = prev->dpb[i];
894  ++discard;
895  } else {
896  ++keep;
897  }
898  }
899  av_assert0(keep <= priv->dpb_frames);
900 
901  if (discard == 0) {
903  } else {
905  for (i = 0; i < discard; i++) {
906  VAAPIEncodeH264Picture *old = discard_list[i]->priv_data;
907  av_assert0(old->frame_num < hpic->frame_num);
910  hpic->frame_num - old->frame_num - 1;
911  }
913  }
914  }
915 
916  // If the intended references are not the first entries of RefPicListN
917  // by default, use ref-pic-list-modification to move them there.
918  if (pic->type == PICTURE_TYPE_P || pic->type == PICTURE_TYPE_B) {
919  VAAPIEncodePicture *def_l0[MAX_DPB_SIZE], *def_l1[MAX_DPB_SIZE];
921  int n;
922 
924  def_l0, def_l1, &n);
925 
926  if (pic->type == PICTURE_TYPE_P) {
927  int need_rplm = 0;
928  for (i = 0; i < pic->nb_refs; i++) {
929  av_assert0(pic->refs[i]);
930  if (pic->refs[i] != def_l0[i])
931  need_rplm = 1;
932  }
933 
934  sh->ref_pic_list_modification_flag_l0 = need_rplm;
935  if (need_rplm) {
936  int pic_num = hpic->frame_num;
937  for (i = 0; i < pic->nb_refs; i++) {
938  href = pic->refs[i]->priv_data;
939  av_assert0(href->frame_num != pic_num);
940  if (href->frame_num < pic_num) {
943  pic_num - href->frame_num - 1;
944  } else {
947  href->frame_num - pic_num - 1;
948  }
949  pic_num = href->frame_num;
950  }
952  }
953 
954  } else {
955  int need_rplm_l0 = 0, need_rplm_l1 = 0;
956  int n0 = 0, n1 = 0;
957  for (i = 0; i < pic->nb_refs; i++) {
958  av_assert0(pic->refs[i]);
959  href = pic->refs[i]->priv_data;
960  av_assert0(href->pic_order_cnt != hpic->pic_order_cnt);
961  if (href->pic_order_cnt < hpic->pic_order_cnt) {
962  if (pic->refs[i] != def_l0[n0])
963  need_rplm_l0 = 1;
964  ++n0;
965  } else {
966  if (pic->refs[i] != def_l1[n1])
967  need_rplm_l1 = 1;
968  ++n1;
969  }
970  }
971 
972  sh->ref_pic_list_modification_flag_l0 = need_rplm_l0;
973  if (need_rplm_l0) {
974  int pic_num = hpic->frame_num;
975  for (i = j = 0; i < pic->nb_refs; i++) {
976  href = pic->refs[i]->priv_data;
977  if (href->pic_order_cnt > hpic->pic_order_cnt)
978  continue;
979  av_assert0(href->frame_num != pic_num);
980  if (href->frame_num < pic_num) {
983  pic_num - href->frame_num - 1;
984  } else {
987  href->frame_num - pic_num - 1;
988  }
989  pic_num = href->frame_num;
990  ++j;
991  }
992  av_assert0(j == n0);
994  }
995 
996  sh->ref_pic_list_modification_flag_l1 = need_rplm_l1;
997  if (need_rplm_l1) {
998  int pic_num = hpic->frame_num;
999  for (i = j = 0; i < pic->nb_refs; i++) {
1000  href = pic->refs[i]->priv_data;
1001  if (href->pic_order_cnt < hpic->pic_order_cnt)
1002  continue;
1003  av_assert0(href->frame_num != pic_num);
1004  if (href->frame_num < pic_num) {
1007  pic_num - href->frame_num - 1;
1008  } else {
1011  href->frame_num - pic_num - 1;
1012  }
1013  pic_num = href->frame_num;
1014  ++j;
1015  }
1016  av_assert0(j == n1);
1018  }
1019  }
1020  }
1021 
1022  vslice->macroblock_address = slice->block_start;
1023  vslice->num_macroblocks = slice->block_size;
1024 
1025  vslice->macroblock_info = VA_INVALID_ID;
1026 
1027  vslice->slice_type = sh->slice_type % 5;
1028  vslice->pic_parameter_set_id = sh->pic_parameter_set_id;
1029  vslice->idr_pic_id = sh->idr_pic_id;
1030 
1031  vslice->pic_order_cnt_lsb = sh->pic_order_cnt_lsb;
1032 
1033  vslice->direct_spatial_mv_pred_flag = sh->direct_spatial_mv_pred_flag;
1034 
1035  for (i = 0; i < FF_ARRAY_ELEMS(vslice->RefPicList0); i++) {
1036  vslice->RefPicList0[i].picture_id = VA_INVALID_ID;
1037  vslice->RefPicList0[i].flags = VA_PICTURE_H264_INVALID;
1038  vslice->RefPicList1[i].picture_id = VA_INVALID_ID;
1039  vslice->RefPicList1[i].flags = VA_PICTURE_H264_INVALID;
1040  }
1041 
1042  av_assert0(pic->nb_refs <= 2);
1043  if (pic->nb_refs >= 1) {
1044  // Backward reference for P- or B-frame.
1045  av_assert0(pic->type == PICTURE_TYPE_P ||
1046  pic->type == PICTURE_TYPE_B);
1047  vslice->RefPicList0[0] = vpic->ReferenceFrames[0];
1048  }
1049  if (pic->nb_refs >= 2) {
1050  // Forward reference for B-frame.
1051  av_assert0(pic->type == PICTURE_TYPE_B);
1052  vslice->RefPicList1[0] = vpic->ReferenceFrames[1];
1053  }
1054 
1055  vslice->slice_qp_delta = sh->slice_qp_delta;
1056 
1057  return 0;
1058 }
1059 
1061 {
1062  VAAPIEncodeContext *ctx = avctx->priv_data;
1063  VAAPIEncodeH264Context *priv = avctx->priv_data;
1064  int err;
1065 
1066  err = ff_cbs_init(&priv->cbc, AV_CODEC_ID_H264, avctx);
1067  if (err < 0)
1068  return err;
1069 
1070  priv->mb_width = FFALIGN(avctx->width, 16) / 16;
1071  priv->mb_height = FFALIGN(avctx->height, 16) / 16;
1072 
1073  if (ctx->va_rc_mode == VA_RC_CQP) {
1074  priv->fixed_qp_p = av_clip(ctx->rc_quality, 1, 51);
1075  if (avctx->i_quant_factor > 0.0)
1076  priv->fixed_qp_idr =
1077  av_clip((avctx->i_quant_factor * priv->fixed_qp_p +
1078  avctx->i_quant_offset) + 0.5, 1, 51);
1079  else
1080  priv->fixed_qp_idr = priv->fixed_qp_p;
1081  if (avctx->b_quant_factor > 0.0)
1082  priv->fixed_qp_b =
1083  av_clip((avctx->b_quant_factor * priv->fixed_qp_p +
1084  avctx->b_quant_offset) + 0.5, 1, 51);
1085  else
1086  priv->fixed_qp_b = priv->fixed_qp_p;
1087 
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);
1091 
1092  } else {
1093  // These still need to be set for pic_init_qp/slice_qp_delta.
1094  priv->fixed_qp_idr = 26;
1095  priv->fixed_qp_p = 26;
1096  priv->fixed_qp_b = 26;
1097  }
1098 
1099  if (!ctx->rc_mode->hrd) {
1100  // Timing SEI requires a mode respecting HRD parameters.
1101  priv->sei &= ~SEI_TIMING;
1102  }
1103 
1104  if (priv->sei & SEI_IDENTIFIER) {
1105  const char *lavc = LIBAVCODEC_IDENT;
1106  const char *vaapi = VA_VERSION_S;
1107  const char *driver;
1108  int len;
1109 
1110  memcpy(priv->sei_identifier.uuid_iso_iec_11578,
1112  sizeof(priv->sei_identifier.uuid_iso_iec_11578));
1113 
1114  driver = vaQueryVendorString(ctx->hwctx->display);
1115  if (!driver)
1116  driver = "unknown driver";
1117 
1118  len = snprintf(NULL, 0, "%s / VAAPI %s / %s", lavc, vaapi, driver);
1119  if (len >= 0) {
1120  priv->sei_identifier_string = av_malloc(len + 1);
1121  if (!priv->sei_identifier_string)
1122  return AVERROR(ENOMEM);
1123 
1124  snprintf(priv->sei_identifier_string, len + 1,
1125  "%s / VAAPI %s / %s", lavc, vaapi, driver);
1126 
1128  priv->sei_identifier.data_length = len + 1;
1129  }
1130  }
1131 
1132  ctx->roi_quant_range = 51 + 6 * (ctx->profile->depth - 8);
1133 
1134  return 0;
1135 }
1136 
1138  { FF_PROFILE_H264_HIGH, 8, 3, 1, 1, VAProfileH264High },
1139  { FF_PROFILE_H264_MAIN, 8, 3, 1, 1, VAProfileH264Main },
1141  8, 3, 1, 1, VAProfileH264ConstrainedBaseline },
1142  { FF_PROFILE_UNKNOWN }
1143 };
1144 
1147 
1148  .flags = FLAG_SLICE_CONTROL |
1149  FLAG_B_PICTURES |
1152 
1153  .default_quality = 20,
1154 
1155  .configure = &vaapi_encode_h264_configure,
1156 
1157  .picture_priv_data_size = sizeof(VAAPIEncodeH264Picture),
1158 
1159  .sequence_params_size = sizeof(VAEncSequenceParameterBufferH264),
1160  .init_sequence_params = &vaapi_encode_h264_init_sequence_params,
1161 
1162  .picture_params_size = sizeof(VAEncPictureParameterBufferH264),
1163  .init_picture_params = &vaapi_encode_h264_init_picture_params,
1164 
1165  .slice_params_size = sizeof(VAEncSliceParameterBufferH264),
1166  .init_slice_params = &vaapi_encode_h264_init_slice_params,
1167 
1168  .sequence_header_type = VAEncPackedHeaderSequence,
1169  .write_sequence_header = &vaapi_encode_h264_write_sequence_header,
1170 
1171  .slice_header_type = VAEncPackedHeaderH264_Slice,
1172  .write_slice_header = &vaapi_encode_h264_write_slice_header,
1173 
1174  .write_extra_header = &vaapi_encode_h264_write_extra_header,
1175 };
1176 
1178 {
1179  VAAPIEncodeContext *ctx = avctx->priv_data;
1180  VAAPIEncodeH264Context *priv = avctx->priv_data;
1181 
1182  ctx->codec = &vaapi_encode_type_h264;
1183 
1184  if (avctx->profile == FF_PROFILE_UNKNOWN)
1185  avctx->profile = priv->profile;
1186  if (avctx->level == FF_LEVEL_UNKNOWN)
1187  avctx->level = priv->level;
1189  avctx->compression_level = priv->quality;
1190 
1191  // Reject unsupported profiles.
1192  switch (avctx->profile) {
1194  av_log(avctx, AV_LOG_WARNING, "H.264 baseline profile is not "
1195  "supported, using constrained baseline profile instead.\n");
1197  break;
1199  av_log(avctx, AV_LOG_ERROR, "H.264 extended profile "
1200  "is not supported.\n");
1201  return AVERROR_PATCHWELCOME;
1204  av_log(avctx, AV_LOG_ERROR, "H.264 10-bit profiles "
1205  "are not supported.\n");
1206  return AVERROR_PATCHWELCOME;
1213  av_log(avctx, AV_LOG_ERROR, "H.264 non-4:2:0 profiles "
1214  "are not supported.\n");
1215  return AVERROR_PATCHWELCOME;
1216  }
1217 
1218  if (avctx->level != FF_LEVEL_UNKNOWN && avctx->level & ~0xff) {
1219  av_log(avctx, AV_LOG_ERROR, "Invalid level %d: must fit "
1220  "in 8-bit unsigned integer.\n", avctx->level);
1221  return AVERROR(EINVAL);
1222  }
1223 
1224  ctx->desired_packed_headers =
1225  VA_ENC_PACKED_HEADER_SEQUENCE | // SPS and PPS.
1226  VA_ENC_PACKED_HEADER_SLICE | // Slice headers.
1227  VA_ENC_PACKED_HEADER_MISC; // SEI.
1228 
1229  ctx->surface_width = FFALIGN(avctx->width, 16);
1230  ctx->surface_height = FFALIGN(avctx->height, 16);
1231 
1232  ctx->slice_block_height = ctx->slice_block_width = 16;
1233 
1234  if (priv->qp > 0)
1235  ctx->explicit_qp = priv->qp;
1236 
1237  return ff_vaapi_encode_init(avctx);
1238 }
1239 
1241 {
1242  VAAPIEncodeH264Context *priv = avctx->priv_data;
1243 
1245  ff_cbs_close(&priv->cbc);
1247 
1248  return ff_vaapi_encode_close(avctx);
1249 }
1250 
1251 #define OFFSET(x) offsetof(VAAPIEncodeH264Context, x)
1252 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
1256 
1257  { "qp", "Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)",
1258  OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 52, FLAGS },
1259  { "quality", "Set encode quality (trades off against speed, higher is faster)",
1260  OFFSET(quality), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS },
1261  { "coder", "Entropy coder type",
1262  OFFSET(coder), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, FLAGS, "coder" },
1263  { "cavlc", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, INT_MIN, INT_MAX, FLAGS, "coder" },
1264  { "cabac", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, FLAGS, "coder" },
1265  { "vlc", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, INT_MIN, INT_MAX, FLAGS, "coder" },
1266  { "ac", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, FLAGS, "coder" },
1267 
1268  { "aud", "Include AUD",
1269  OFFSET(aud), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
1270 
1271  { "sei", "Set SEI to include",
1274  0, INT_MAX, FLAGS, "sei" },
1275  { "identifier", "Include encoder version identifier",
1276  0, AV_OPT_TYPE_CONST, { .i64 = SEI_IDENTIFIER },
1277  INT_MIN, INT_MAX, FLAGS, "sei" },
1278  { "timing", "Include timing parameters (buffering_period and pic_timing)",
1279  0, AV_OPT_TYPE_CONST, { .i64 = SEI_TIMING },
1280  INT_MIN, INT_MAX, FLAGS, "sei" },
1281  { "recovery_point", "Include recovery points where appropriate",
1282  0, AV_OPT_TYPE_CONST, { .i64 = SEI_RECOVERY_POINT },
1283  INT_MIN, INT_MAX, FLAGS, "sei" },
1284 
1285  { "profile", "Set profile (profile_idc and constraint_set*_flag)",
1287  { .i64 = FF_PROFILE_UNKNOWN }, FF_PROFILE_UNKNOWN, 0xffff, FLAGS, "profile" },
1288 
1289 #define PROFILE(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
1290  { .i64 = value }, 0, 0, FLAGS, "profile"
1291  { PROFILE("constrained_baseline", FF_PROFILE_H264_CONSTRAINED_BASELINE) },
1292  { PROFILE("main", FF_PROFILE_H264_MAIN) },
1293  { PROFILE("high", FF_PROFILE_H264_HIGH) },
1294 #undef PROFILE
1295 
1296  { "level", "Set level (level_idc)",
1298  { .i64 = FF_LEVEL_UNKNOWN }, FF_LEVEL_UNKNOWN, 0xff, FLAGS, "level" },
1299 
1300 #define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
1301  { .i64 = value }, 0, 0, FLAGS, "level"
1302  { LEVEL("1", 10) },
1303  { LEVEL("1.1", 11) },
1304  { LEVEL("1.2", 12) },
1305  { LEVEL("1.3", 13) },
1306  { LEVEL("2", 20) },
1307  { LEVEL("2.1", 21) },
1308  { LEVEL("2.2", 22) },
1309  { LEVEL("3", 30) },
1310  { LEVEL("3.1", 31) },
1311  { LEVEL("3.2", 32) },
1312  { LEVEL("4", 40) },
1313  { LEVEL("4.1", 41) },
1314  { LEVEL("4.2", 42) },
1315  { LEVEL("5", 50) },
1316  { LEVEL("5.1", 51) },
1317  { LEVEL("5.2", 52) },
1318  { LEVEL("6", 60) },
1319  { LEVEL("6.1", 61) },
1320  { LEVEL("6.2", 62) },
1321 #undef LEVEL
1322 
1323  { NULL },
1324 };
1325 
1327  { "b", "0" },
1328  { "bf", "2" },
1329  { "g", "120" },
1330  { "i_qfactor", "1" },
1331  { "i_qoffset", "0" },
1332  { "b_qfactor", "6/5" },
1333  { "b_qoffset", "0" },
1334  { "qmin", "-1" },
1335  { "qmax", "-1" },
1336  { NULL },
1337 };
1338 
1340  .class_name = "h264_vaapi",
1341  .item_name = av_default_item_name,
1342  .option = vaapi_encode_h264_options,
1343  .version = LIBAVUTIL_VERSION_INT,
1344 };
1345 
1347  .name = "h264_vaapi",
1348  .long_name = NULL_IF_CONFIG_SMALL("H.264/AVC (VAAPI)"),
1349  .type = AVMEDIA_TYPE_VIDEO,
1350  .id = AV_CODEC_ID_H264,
1351  .priv_data_size = sizeof(VAAPIEncodeH264Context),
1353  .receive_packet = &ff_vaapi_encode_receive_packet,
1354  .close = &vaapi_encode_h264_close,
1355  .priv_class = &vaapi_encode_h264_class,
1356  .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE,
1357  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
1358  .defaults = vaapi_encode_h264_defaults,
1359  .pix_fmts = (const enum AVPixelFormat[]) {
1362  },
1363  .hw_configs = ff_vaapi_encode_hw_configs,
1364  .wrapper_name = "vaapi",
1365 };
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: internal.h:48
#define FF_PROFILE_H264_MAIN
Definition: avcodec.h:1900
H264RawNALUnitHeader nal_unit_header
Definition: cbs_h264.h:181
uint8_t frame_cropping_flag
Definition: cbs_h264.h:156
uint8_t deblocking_filter_control_present_flag
Definition: cbs_h264.h:211
uint32_t payload_type
Definition: cbs_h264.h:322
#define NULL
Definition: coverity.c:32
AVRational framerate
Definition: avcodec.h:2069
static const VAAPIEncodeType vaapi_encode_type_h264
#define FF_PROFILE_H264_CAVLC_444
Definition: avcodec.h:1912
uint8_t bit_depth_chroma_minus8
Definition: cbs_h264.h:129
#define FF_COMPRESSION_DEFAULT
Definition: avcodec.h:599
uint8_t aspect_ratio_idc
Definition: cbs_h264.h:69
static av_cold int vaapi_encode_h264_configure(AVCodecContext *avctx)
uint8_t video_format
Definition: cbs_h264.h:77
AVOption.
Definition: opt.h:248
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:100
union H264RawSEIPayload::@28 payload
static void vaapi_encode_h264_default_ref_pic_list(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodePicture **rpl0, VAAPIEncodePicture **rpl1, int *rpl_size)
uint8_t bit_rate_scale
Definition: cbs_h264.h:54
uint16_t recovery_frame_cnt
Definition: cbs_h264.h:293
uint8_t dpb_output_delay_length_minus1
Definition: cbs_h264.h:63
uint8_t initial_cpb_removal_delay_length_minus1
Definition: cbs_h264.h:61
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:200
int64_t bit_rate
the average bitrate
Definition: avcodec.h:576
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
uint8_t chroma_sample_loc_type_bottom_field
Definition: cbs_h264.h:86
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
uint8_t constraint_set3_flag
Definition: h264_levels.h:28
#define AV_CODEC_CAP_HARDWARE
Codec is backed by a hardware implementation.
Definition: codec.h:150
int ff_cbs_init(CodedBitstreamContext **ctx_ptr, enum AVCodecID codec_id, void *log_ctx)
Create and initialise a new context for the given codec.
Definition: cbs.c:74
H264RawNALUnitHeader nal_unit_header
Definition: cbs_h264.h:345
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:1161
H264RawSEIRecoveryPoint recovery_point
Definition: cbs_h264.h:331
int num
Numerator.
Definition: rational.h:59
uint8_t log2_max_frame_num_minus4
Definition: cbs_h264.h:137
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
int av_log2(unsigned v)
Definition: intmath.c:26
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
Definition: avcodec.h:905
uint16_t pic_order_cnt_lsb
Definition: cbs_h264.h:367
uint8_t time_offset_length
Definition: cbs_h264.h:64
GLint GLenum type
Definition: opengl_enc.c:104
uint8_t low_delay_hrd_flag
Definition: cbs_h264.h:97
void * codec_sequence_params
Definition: vaapi_encode.h:274
#define FLAGS
#define OFFSET(x)
uint8_t max_dec_frame_buffering
Definition: cbs_h264.h:108
int profile
profile
Definition: avcodec.h:1859
uint8_t fixed_frame_rate_flag
Definition: cbs_h264.h:91
H264RawVUI vui
Definition: cbs_h264.h:163
AVCodec.
Definition: codec.h:190
int framerate
Definition: h264_levels.c:65
struct H264RawSliceHeader::@30 rplm_l0[H264_MAX_RPLM_COUNT]
float i_quant_offset
qscale offset between P and I-frames
Definition: avcodec.h:838
uint32_t first_mb_in_slice
Definition: cbs_h264.h:354
static const AVClass vaapi_encode_h264_class
#define FF_PROFILE_H264_HIGH_444_PREDICTIVE
Definition: avcodec.h:1910
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:649
struct H264RawSliceHeader::@30 rplm_l1[H264_MAX_RPLM_COUNT]
uint8_t weighted_pred_flag
Definition: cbs_h264.h:204
uint8_t constraint_set4_flag
Definition: cbs_h264.h:119
#define FF_LEVEL_UNKNOWN
Definition: avcodec.h:1983
H264RawHRD nal_hrd_parameters
Definition: cbs_h264.h:94
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
#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:75
static int vaapi_encode_h264_write_extra_header(AVCodecContext *avctx, VAAPIEncodePicture *pic, int index, int *type, char *data, size_t *data_len)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
int8_t slice_qp_delta
Definition: cbs_h264.h:417
struct H264RawSliceHeader::@31 mmco[H264_MAX_MMCO_COUNT]
static const AVOption vaapi_encode_h264_options[]
H264RawSEIRecoveryPoint sei_recovery_point
#define FF_PROFILE_H264_BASELINE
Definition: avcodec.h:1898
uint8_t
#define av_cold
Definition: attributes.h:88
#define av_malloc(s)
AVOptions.
uint16_t frame_crop_top_offset
Definition: cbs_h264.h:159
uint16_t pic_width_in_mbs_minus1
Definition: cbs_h264.h:149
int dpb_frames
Definition: h264_levels.c:159
static const AVCodecDefault vaapi_encode_h264_defaults[]
const VAAPIEncodeRCMode * rc_mode
Definition: vaapi_encode.h:220
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:795
H264RawNALUnitHeader nal_unit_header
Definition: cbs_h264.h:352
static const uint8_t vaapi_encode_h264_sei_identifier_uuid[16]
uint32_t num_units_in_tick
Definition: cbs_h264.h:89
unregistered user data
Definition: h264_sei.h:34
uint8_t mb_adaptive_frame_field_flag
Definition: cbs_h264.h:153
uint8_t transform_8x8_mode_flag
Definition: cbs_h264.h:217
uint8_t constrained_intra_pred_flag
Definition: cbs_h264.h:212
uint32_t cpb_size_value_minus1[H264_MAX_CPB_CNT]
Definition: cbs_h264.h:58
uint16_t frame_crop_left_offset
Definition: cbs_h264.h:157
static int vaapi_encode_h264_init_picture_params(AVCodecContext *avctx, VAAPIEncodePicture *pic)
static float hn(int n, EqParameter *param, float fs)
static av_cold int vaapi_encode_h264_init(AVCodecContext *avctx)
struct VAAPIEncodePicture * prev
Definition: vaapi_encode.h:119
#define AVERROR_EOF
End of file.
Definition: error.h:55
#define FF_PROFILE_H264_EXTENDED
Definition: avcodec.h:1901
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:210
VASurfaceID recon_surface
Definition: vaapi_encode.h:94
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:35
static const uint8_t header[24]
Definition: sdr2.c:67
H264RawNALUnitHeader nal_unit_header
Definition: cbs_h264.h:228
uint16_t idr_pic_id
Definition: cbs_h264.h:365
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
Definition: avcodec.h:1168
#define FFALIGN(x, a)
Definition: macros.h:48
uint8_t ref_pic_list_modification_flag_l0
Definition: cbs_h264.h:378
int8_t second_chroma_qp_index_offset
Definition: cbs_h264.h:224
#define av_log(a,...)
void ff_cbs_fragment_reset(CodedBitstreamFragment *frag)
Free the units contained in a fragment as well as the fragment&#39;s own data buffer, but not the units a...
Definition: cbs.c:141
uint8_t cpb_size_scale
Definition: cbs_h264.h:55
uint8_t nal_hrd_parameters_present_flag
Definition: cbs_h264.h:93
uint8_t bit_depth_luma_minus8
Definition: cbs_h264.h:128
size_t data_size
The number of bytes in the bitstream.
Definition: cbs.h:129
H.264 common definitions.
uint8_t pic_scaling_matrix_present_flag
Definition: cbs_h264.h:219
unsigned int va_rc_mode
Definition: vaapi_encode.h:230
uint8_t chroma_sample_loc_type_top_field
Definition: cbs_h264.h:85
uint8_t modification_of_pic_nums_idc
Definition: cbs_h264.h:381
buffering period (H.264, D.1.1)
Definition: h264_sei.h:29
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
uint8_t aspect_ratio_info_present_flag
Definition: cbs_h264.h:68
uint8_t max_num_ref_frames
Definition: cbs_h264.h:146
uint8_t weighted_bipred_idc
Definition: cbs_h264.h:205
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:153
uint8_t transfer_characteristics
Definition: cbs_h264.h:81
static int vaapi_encode_h264_write_access_unit(AVCodecContext *avctx, char *data, size_t *data_len, CodedBitstreamFragment *au)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:215
CodedBitstreamContext * cbc
const AVCodecHWConfigInternal * ff_vaapi_encode_hw_configs[]
Definition: vaapi_encode.c:31
#define FF_PROFILE_H264_HIGH_422
Definition: avcodec.h:1906
#define FF_PROFILE_H264_HIGH
Definition: avcodec.h:1902
uint16_t sar_width
Definition: cbs_h264.h:70
uint32_t initial_cpb_removal_delay_offset[H264_MAX_CPB_CNT]
Definition: cbs_h264.h:237
uint8_t slice_type
Definition: cbs_h264.h:355
uint8_t num_ref_idx_l1_default_active_minus1
Definition: cbs_h264.h:202
simple assert() macros that are a bit more flexible than ISO C assert().
const char * name
Name of the codec implementation.
Definition: codec.h:197
uint8_t frame_mbs_only_flag
Definition: cbs_h264.h:152
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:831
uint8_t ref_pic_list_modification_flag_l1
Definition: cbs_h264.h:379
static const AVCodecDefault defaults[]
Definition: amfenc_h264.c:361
unsigned int va_bit_rate
Definition: vaapi_encode.h:232
uint8_t seq_parameter_set_id
Definition: cbs_h264.h:124
uint8_t seq_scaling_matrix_present_flag
Definition: cbs_h264.h:132
static int vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx)
void * codec_picture_params
Definition: vaapi_encode.h:103
size_t data_bit_padding
The number of bits which should be ignored in the final byte.
Definition: cbs.h:133
H264RawSEIPicTiming pic_timing
Definition: cbs_h264.h:326
#define fail()
Definition: checkasm.h:123
uint8_t timing_info_present_flag
Definition: cbs_h264.h:88
uint8_t more_rbsp_data
Definition: cbs_h264.h:214
H264RawSEIPicTiming sei_pic_timing
uint8_t video_full_range_flag
Definition: cbs_h264.h:78
uint8_t seq_parameter_set_id
Definition: cbs_h264.h:184
#define LEVEL(name, value)
H264RawSEIUserDataUnregistered user_data_unregistered
Definition: cbs_h264.h:330
common internal API header
uint8_t adaptive_ref_pic_marking_mode_flag
Definition: cbs_h264.h:406
AVCodec ff_h264_vaapi_encoder
uint8_t colour_primaries
Definition: cbs_h264.h:80
picture timing
Definition: h264_sei.h:30
static int vaapi_encode_h264_write_sequence_header(AVCodecContext *avctx, char *data, size_t *data_len)
uint16_t sar_height
Definition: cbs_h264.h:71
uint16_t frame_crop_bottom_offset
Definition: cbs_h264.h:160
int width
picture width / height.
Definition: avcodec.h:699
uint8_t vui_parameters_present_flag
Definition: cbs_h264.h:162
const VAAPIEncodeProfile * profile
Definition: vaapi_encode.h:217
#define FF_PROFILE_UNKNOWN
Definition: avcodec.h:1860
const VAAPIEncodeProfile * profiles
Definition: vaapi_encode.h:369
av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
uint32_t cpb_removal_delay
Definition: cbs_h264.h:259
AVFormatContext * ctx
Definition: movenc.c:48
uint8_t colour_description_present_flag
Definition: cbs_h264.h:79
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:1140
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about quality
static const VAAPIEncodeProfile vaapi_encode_h264_profiles[]
uint8_t video_signal_type_present_flag
Definition: cbs_h264.h:76
int level
level
Definition: avcodec.h:1982
void * codec_picture_params
Definition: vaapi_encode.h:278
static int vaapi_encode_h264_write_slice_header(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice, char *data, size_t *data_len)
static int vaapi_encode_h264_add_nal(AVCodecContext *avctx, CodedBitstreamFragment *au, void *nal_unit)
int8_t chroma_qp_index_offset
Definition: cbs_h264.h:209
int ff_vaapi_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
uint8_t constraint_set5_flag
Definition: cbs_h264.h:120
uint8_t pic_parameter_set_id
Definition: cbs_h264.h:357
uint8_t chroma_format_idc
Definition: cbs_h264.h:126
uint8_t * data
Pointer to the bitstream form of this fragment.
Definition: cbs.h:122
#define FF_ARRAY_ELEMS(a)
uint8_t profile_idc
Definition: cbs_h264.h:114
int32_t abs_diff_pic_num_minus1
Definition: cbs_h264.h:382
the normal 2^n-1 "JPEG" YUV ranges
Definition: pixfmt.h:538
int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Write the content of the fragment to its own internal buffer.
Definition: cbs.c:336
VADisplay display
The VADisplay handle, to be filled by the user.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
struct VAAPIEncodePicture * refs[MAX_PICTURE_REFERENCES]
Definition: vaapi_encode.h:116
uint32_t bit_rate_value_minus1[H264_MAX_CPB_CNT]
Definition: cbs_h264.h:57
uint8_t cpb_cnt_minus1
Definition: cbs_h264.h:53
H264RawNALUnitHeader nal_unit_header
Definition: cbs_h264.h:112
uint8_t chroma_loc_info_present_flag
Definition: cbs_h264.h:84
uint8_t cbr_flag[H264_MAX_CPB_CNT]
Definition: cbs_h264.h:59
const struct VAAPIEncodeType * codec
Definition: vaapi_encode.h:179
Libavcodec external API header.
#define VAAPI_ENCODE_RC_OPTIONS
Definition: vaapi_encode.h:463
#define FF_PROFILE_H264_HIGH_422_INTRA
Definition: avcodec.h:1907
int compression_level
Definition: avcodec.h:598
uint8_t bottom_field_pic_order_in_frame_present_flag
Definition: cbs_h264.h:187
uint8_t entropy_coding_mode_flag
Definition: cbs_h264.h:186
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:116
VAAPIEncodeContext common
main external API structure.
Definition: avcodec.h:526
#define FF_PROFILE_H264_HIGH_10_INTRA
Definition: avcodec.h:1904
static int FUNC() aud(CodedBitstreamContext *ctx, RWContext *rw, H264RawAUD *current)
uint8_t pic_order_cnt_type
Definition: cbs_h264.h:138
Describe the class of an AVClass context structure.
Definition: log.h:67
static int FUNC() pps(CodedBitstreamContext *ctx, RWContext *rw, H264RawPPS *current)
Context structure for coded bitstream operations.
Definition: cbs.h:168
uint8_t matrix_coefficients
Definition: cbs_h264.h:82
uint8_t num_ref_idx_l0_default_active_minus1
Definition: cbs_h264.h:201
int index
Definition: gxfenc.c:89
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:1154
Rational number (pair of numerator and denominator).
Definition: rational.h:58
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:1147
uint16_t frame_num
Definition: cbs_h264.h:361
int ff_cbs_insert_unit_content(CodedBitstreamFragment *frag, int position, CodedBitstreamUnitType type, void *content, AVBufferRef *content_buf)
Insert a new unit into a fragment with the given content.
Definition: cbs.c:715
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
recovery point (frame # to decoder sync)
Definition: h264_sei.h:35
#define FF_PROFILE_H264_HIGH_444
Definition: avcodec.h:1909
uint8_t log2_max_mv_length_horizontal
Definition: cbs_h264.h:105
uint8_t direct_spatial_mv_pred_flag
Definition: cbs_h264.h:372
void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
Definition: cbs.c:115
float b_quant_offset
qscale offset between IP and B-frames
Definition: avcodec.h:808
#define snprintf
Definition: snprintf.h:34
H264RawSEIBufferingPeriod buffering_period
Definition: cbs_h264.h:325
H264RawSEIPayload payload[H264_MAX_SEI_PAYLOADS]
Definition: cbs_h264.h:347
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:270
mfxU16 profile
Definition: qsvenc.c:45
CodedBitstreamFragment current_access_unit
#define VAAPI_ENCODE_COMMON_OPTIONS
Definition: vaapi_encode.h:445
uint8_t level
Definition: svq3.c:209
uint8_t direct_8x8_inference_flag
Definition: cbs_h264.h:154
static int vaapi_encode_h264_init_slice_params(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice)
uint32_t initial_cpb_removal_delay[H264_MAX_CPB_CNT]
Definition: cbs_h264.h:236
VAEncMiscParameterHRD hrd_params
Definition: vaapi_encode.h:267
common internal api header.
common internal and external API header
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:107
uint8_t redundant_pic_cnt_present_flag
Definition: cbs_h264.h:216
uint8_t memory_management_control_operation
Definition: cbs_h264.h:408
uint8_t cpb_removal_delay_length_minus1
Definition: cbs_h264.h:62
uint8_t motion_vectors_over_pic_boundaries_flag
Definition: cbs_h264.h:102
uint32_t time_scale
Definition: cbs_h264.h:90
static int FUNC() sei(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEI *current)
uint8_t bitstream_restriction_flag
Definition: cbs_h264.h:101
uint8_t level_idc
Definition: cbs_h264.h:122
uint16_t frame_crop_right_offset
Definition: cbs_h264.h:158
int den
Denominator.
Definition: rational.h:60
uint8_t pic_parameter_set_id
Definition: cbs_h264.h:183
uint8_t max_num_reorder_frames
Definition: cbs_h264.h:107
H264RawSEIUserDataUnregistered sei_identifier
void * priv_data
Definition: avcodec.h:553
#define PROFILE(name, value)
uint8_t log2_max_mv_length_vertical
Definition: cbs_h264.h:106
H264RawSliceHeader header
Definition: cbs_h264.h:430
uint8_t log2_max_pic_order_cnt_lsb_minus4
Definition: cbs_h264.h:139
int len
const char * name
Definition: h264_levels.h:26
struct H264RawSEIBufferingPeriod::@27 nal
static av_cold int vaapi_encode_h264_close(AVCodecContext *avctx)
void * codec_slice_params
Definition: vaapi_encode.h:67
uint8_t delta_pic_order_always_zero_flag
Definition: cbs_h264.h:140
H264RawSEIBufferingPeriod sei_buffering_period
#define FF_PROFILE_H264_HIGH_444_INTRA
Definition: avcodec.h:1911
void ff_cbs_fragment_free(CodedBitstreamFragment *frag)
Free the units array of a fragment in addition to what ff_cbs_fragment_reset does.
Definition: cbs.c:155
int8_t pic_init_qp_minus26
Definition: cbs_h264.h:207
#define LIBAVCODEC_IDENT
Definition: version.h:42
unsigned int desired_packed_headers
Definition: vaapi_encode.h:201
uint8_t nal_ref_idc
Definition: cbs_h264.h:41
#define av_freep(p)
#define FFSWAP(type, a, b)
Definition: common.h:99
uint8_t constraint_set1_flag
Definition: cbs_h264.h:116
uint16_t pic_height_in_map_units_minus1
Definition: cbs_h264.h:150
#define FF_PROFILE_H264_CONSTRAINED_BASELINE
Definition: avcodec.h:1899
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Frame references ownership and permissions
VABufferID output_buffer
Definition: vaapi_encode.h:100
#define FF_PROFILE_H264_HIGH_10
Definition: avcodec.h:1903
int32_t difference_of_pic_nums_minus1
Definition: cbs_h264.h:409
uint8_t nal_unit_type
Definition: cbs_h264.h:42
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
struct VAAPIEncodePicture * dpb[MAX_DPB_SIZE]
Definition: vaapi_encode.h:112
uint8_t payload_count
Definition: cbs_h264.h:348
av_cold int ff_vaapi_encode_close(AVCodecContext *avctx)
int i
Definition: input.c:407
const H264LevelDescriptor * ff_h264_guess_level(int profile_idc, int64_t bitrate, int framerate, int width, int height, int max_dec_frame_buffering)
Guess the level of a stream from some parameters.
Definition: h264_levels.c:90
AVVAAPIDeviceContext * hwctx
Definition: vaapi_encode.h:245
uint8_t constraint_set3_flag
Definition: cbs_h264.h:118