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/pixdesc.h"
27 #include "libavutil/internal.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 "h264_levels.h"
37 #include "h264_sei.h"
38 #include "h2645data.h"
39 #include "vaapi_encode.h"
40 #include "version.h"
41 
42 enum {
43  SEI_TIMING = 0x01,
46  SEI_A53_CC = 0x08,
47 };
48 
49 // Random (version 4) ISO 11578 UUID.
50 static 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 
55 typedef struct VAAPIEncodeH264Picture {
56  int frame_num;
58 
60  uint16_t idr_pic_id;
61 
64 
65  int cpb_delay;
66  int dpb_delay;
68 
69 typedef struct VAAPIEncodeH264Context {
71 
72  // User options.
73  int qp;
74  int quality;
75  int coder;
76  int aud;
77  int sei;
78  int profile;
79  int level;
80 
81  // Derived settings.
82  int mb_width;
83  int mb_height;
84 
88 
90 
91  // Writer structures.
94 
99 
107 
112 
113 
115  char *data, size_t *data_len,
117 {
118  VAAPIEncodeH264Context *priv = avctx->priv_data;
119  int err;
120 
121  err = ff_cbs_write_fragment_data(priv->cbc, au);
122  if (err < 0) {
123  av_log(avctx, AV_LOG_ERROR, "Failed to write packed header.\n");
124  return err;
125  }
126 
127  if (*data_len < 8 * au->data_size - au->data_bit_padding) {
128  av_log(avctx, AV_LOG_ERROR, "Access unit too large: "
129  "%zu < %zu.\n", *data_len,
130  8 * au->data_size - au->data_bit_padding);
131  return AVERROR(ENOSPC);
132  }
133 
134  memcpy(data, au->data, au->data_size);
135  *data_len = 8 * au->data_size - au->data_bit_padding;
136 
137  return 0;
138 }
139 
142  void *nal_unit)
143 {
144  H264RawNALUnitHeader *header = nal_unit;
145  int err;
146 
147  err = ff_cbs_insert_unit_content(au, -1,
148  header->nal_unit_type, nal_unit, NULL);
149  if (err < 0) {
150  av_log(avctx, AV_LOG_ERROR, "Failed to add NAL unit: "
151  "type = %d.\n", header->nal_unit_type);
152  return err;
153  }
154 
155  return 0;
156 }
157 
159  char *data, size_t *data_len)
160 {
161  VAAPIEncodeH264Context *priv = avctx->priv_data;
163  int err;
164 
165  if (priv->aud_needed) {
166  err = vaapi_encode_h264_add_nal(avctx, au, &priv->raw_aud);
167  if (err < 0)
168  goto fail;
169  priv->aud_needed = 0;
170  }
171 
172  err = vaapi_encode_h264_add_nal(avctx, au, &priv->raw_sps);
173  if (err < 0)
174  goto fail;
175 
176  err = vaapi_encode_h264_add_nal(avctx, au, &priv->raw_pps);
177  if (err < 0)
178  goto fail;
179 
180  err = vaapi_encode_h264_write_access_unit(avctx, data, data_len, au);
181 fail:
183  return err;
184 }
185 
187  VAAPIEncodePicture *pic,
188  VAAPIEncodeSlice *slice,
189  char *data, size_t *data_len)
190 {
191  VAAPIEncodeH264Context *priv = avctx->priv_data;
193  int err;
194 
195  if (priv->aud_needed) {
196  err = vaapi_encode_h264_add_nal(avctx, au, &priv->raw_aud);
197  if (err < 0)
198  goto fail;
199  priv->aud_needed = 0;
200  }
201 
202  err = vaapi_encode_h264_add_nal(avctx, au, &priv->raw_slice);
203  if (err < 0)
204  goto fail;
205 
206  err = vaapi_encode_h264_write_access_unit(avctx, data, data_len, au);
207 fail:
209  return err;
210 }
211 
213  VAAPIEncodePicture *pic,
214  int index, int *type,
215  char *data, size_t *data_len)
216 {
217  VAAPIEncodeH264Context *priv = avctx->priv_data;
219  int err;
220 
221  if (priv->sei_needed) {
222  if (priv->aud_needed) {
223  err = vaapi_encode_h264_add_nal(avctx, au, &priv->raw_aud);
224  if (err < 0)
225  goto fail;
226  priv->aud_needed = 0;
227  }
228 
229  if (priv->sei_needed & SEI_IDENTIFIER) {
230  err = ff_cbs_sei_add_message(priv->cbc, au, 1,
232  &priv->sei_identifier, NULL);
233  if (err < 0)
234  goto fail;
235  }
236  if (priv->sei_needed & SEI_TIMING) {
237  if (pic->type == PICTURE_TYPE_IDR) {
238  err = ff_cbs_sei_add_message(priv->cbc, au, 1,
240  &priv->sei_buffering_period, NULL);
241  if (err < 0)
242  goto fail;
243  }
244  err = ff_cbs_sei_add_message(priv->cbc, au, 1,
246  &priv->sei_pic_timing, NULL);
247  if (err < 0)
248  goto fail;
249  }
250  if (priv->sei_needed & SEI_RECOVERY_POINT) {
251  err = ff_cbs_sei_add_message(priv->cbc, au, 1,
253  &priv->sei_recovery_point, NULL);
254  if (err < 0)
255  goto fail;
256  }
257  if (priv->sei_needed & SEI_A53_CC) {
258  err = ff_cbs_sei_add_message(priv->cbc, au, 1,
260  &priv->sei_a53cc, NULL);
261  if (err < 0)
262  goto fail;
263  }
264 
265  priv->sei_needed = 0;
266 
267  err = vaapi_encode_h264_write_access_unit(avctx, data, data_len, au);
268  if (err < 0)
269  goto fail;
270 
272 
273  *type = VAEncPackedHeaderRawData;
274  return 0;
275 
276 #if !CONFIG_VAAPI_1
277  } else if (priv->sei_cbr_workaround_needed) {
278  // Insert a zero-length header using the old SEI type. This is
279  // required to avoid triggering broken behaviour on Intel platforms
280  // in CBR mode where an invalid SEI message is generated by the
281  // driver and inserted into the stream.
282  *data_len = 0;
283  *type = VAEncPackedHeaderH264_SEI;
284  priv->sei_cbr_workaround_needed = 0;
285  return 0;
286 #endif
287 
288  } else {
289  return AVERROR_EOF;
290  }
291 
292 fail:
294  return err;
295 }
296 
298 {
299  VAAPIEncodeContext *ctx = avctx->priv_data;
300  VAAPIEncodeH264Context *priv = avctx->priv_data;
301  H264RawSPS *sps = &priv->raw_sps;
302  H264RawPPS *pps = &priv->raw_pps;
303  VAEncSequenceParameterBufferH264 *vseq = ctx->codec_sequence_params;
304  VAEncPictureParameterBufferH264 *vpic = ctx->codec_picture_params;
305  const AVPixFmtDescriptor *desc;
306  int bit_depth;
307 
308  memset(sps, 0, sizeof(*sps));
309  memset(pps, 0, sizeof(*pps));
310 
312  av_assert0(desc);
313  if (desc->nb_components == 1 || desc->log2_chroma_w != 1 || desc->log2_chroma_h != 1) {
314  av_log(avctx, AV_LOG_ERROR, "Chroma format of input pixel format "
315  "%s is not supported.\n", desc->name);
316  return AVERROR(EINVAL);
317  }
318  bit_depth = desc->comp[0].depth;
319 
320  sps->nal_unit_header.nal_ref_idc = 3;
321  sps->nal_unit_header.nal_unit_type = H264_NAL_SPS;
322 
323  sps->profile_idc = avctx->profile & 0xff;
324 
326  avctx->profile == AV_PROFILE_H264_MAIN)
327  sps->constraint_set1_flag = 1;
328 
329  if (avctx->profile == AV_PROFILE_H264_HIGH || avctx->profile == AV_PROFILE_H264_HIGH_10)
330  sps->constraint_set3_flag = ctx->gop_size == 1;
331 
332  if (avctx->profile == AV_PROFILE_H264_MAIN ||
334  sps->constraint_set4_flag = 1;
335  sps->constraint_set5_flag = ctx->b_per_p == 0;
336  }
337 
338  if (ctx->gop_size == 1)
339  priv->dpb_frames = 0;
340  else
341  priv->dpb_frames = 1 + ctx->max_b_depth;
342 
343  if (avctx->level != AV_LEVEL_UNKNOWN) {
344  sps->level_idc = avctx->level;
345  } else {
346  const H264LevelDescriptor *level;
347  int framerate;
348 
349  if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
350  framerate = avctx->framerate.num / avctx->framerate.den;
351  else
352  framerate = 0;
353 
354  level = ff_h264_guess_level(sps->profile_idc,
355  avctx->bit_rate,
356  framerate,
357  priv->mb_width * 16,
358  priv->mb_height * 16,
359  priv->dpb_frames);
360  if (level) {
361  av_log(avctx, AV_LOG_VERBOSE, "Using level %s.\n", level->name);
362  if (level->constraint_set3_flag)
363  sps->constraint_set3_flag = 1;
364  sps->level_idc = level->level_idc;
365  } else {
366  av_log(avctx, AV_LOG_WARNING, "Stream will not conform "
367  "to any level: using level 6.2.\n");
368  sps->level_idc = 62;
369  }
370  }
371 
372  sps->seq_parameter_set_id = 0;
373  sps->chroma_format_idc = 1;
374  sps->bit_depth_luma_minus8 = bit_depth - 8;
375  sps->bit_depth_chroma_minus8 = bit_depth - 8;
376 
377  sps->log2_max_frame_num_minus4 = 4;
378  sps->pic_order_cnt_type = ctx->max_b_depth ? 0 : 2;
379  if (sps->pic_order_cnt_type == 0) {
380  sps->log2_max_pic_order_cnt_lsb_minus4 = 4;
381  }
382 
383  sps->max_num_ref_frames = priv->dpb_frames;
384 
385  sps->pic_width_in_mbs_minus1 = priv->mb_width - 1;
386  sps->pic_height_in_map_units_minus1 = priv->mb_height - 1;
387 
388  sps->frame_mbs_only_flag = 1;
389  sps->direct_8x8_inference_flag = 1;
390 
391  if (avctx->width != 16 * priv->mb_width ||
392  avctx->height != 16 * priv->mb_height) {
393  sps->frame_cropping_flag = 1;
394 
395  sps->frame_crop_left_offset = 0;
396  sps->frame_crop_right_offset =
397  (16 * priv->mb_width - avctx->width) / 2;
398  sps->frame_crop_top_offset = 0;
399  sps->frame_crop_bottom_offset =
400  (16 * priv->mb_height - avctx->height) / 2;
401  } else {
402  sps->frame_cropping_flag = 0;
403  }
404 
405  sps->vui_parameters_present_flag = 1;
406 
407  if (avctx->sample_aspect_ratio.num != 0 &&
408  avctx->sample_aspect_ratio.den != 0) {
409  int num, den, i;
410  av_reduce(&num, &den, avctx->sample_aspect_ratio.num,
411  avctx->sample_aspect_ratio.den, 65535);
412  for (i = 0; i < FF_ARRAY_ELEMS(ff_h2645_pixel_aspect); i++) {
413  if (num == ff_h2645_pixel_aspect[i].num &&
414  den == ff_h2645_pixel_aspect[i].den) {
415  sps->vui.aspect_ratio_idc = i;
416  break;
417  }
418  }
420  sps->vui.aspect_ratio_idc = 255;
421  sps->vui.sar_width = num;
422  sps->vui.sar_height = den;
423  }
424  sps->vui.aspect_ratio_info_present_flag = 1;
425  }
426 
427  // Unspecified video format, from table E-2.
428  sps->vui.video_format = 5;
429  sps->vui.video_full_range_flag =
430  avctx->color_range == AVCOL_RANGE_JPEG;
431  sps->vui.colour_primaries = avctx->color_primaries;
432  sps->vui.transfer_characteristics = avctx->color_trc;
433  sps->vui.matrix_coefficients = avctx->colorspace;
434  if (avctx->color_primaries != AVCOL_PRI_UNSPECIFIED ||
435  avctx->color_trc != AVCOL_TRC_UNSPECIFIED ||
437  sps->vui.colour_description_present_flag = 1;
438  if (avctx->color_range != AVCOL_RANGE_UNSPECIFIED ||
439  sps->vui.colour_description_present_flag)
440  sps->vui.video_signal_type_present_flag = 1;
441 
443  sps->vui.chroma_loc_info_present_flag = 1;
444  sps->vui.chroma_sample_loc_type_top_field =
445  sps->vui.chroma_sample_loc_type_bottom_field =
446  avctx->chroma_sample_location - 1;
447  }
448 
449  sps->vui.timing_info_present_flag = 1;
450  if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
451  sps->vui.num_units_in_tick = avctx->framerate.den;
452  sps->vui.time_scale = 2 * avctx->framerate.num;
453  sps->vui.fixed_frame_rate_flag = 1;
454  } else {
455  sps->vui.num_units_in_tick = avctx->time_base.num;
456  sps->vui.time_scale = 2 * avctx->time_base.den;
457  sps->vui.fixed_frame_rate_flag = 0;
458  }
459 
460  if (priv->sei & SEI_TIMING) {
461  H264RawHRD *hrd = &sps->vui.nal_hrd_parameters;
463 
464  sps->vui.nal_hrd_parameters_present_flag = 1;
465 
466  hrd->cpb_cnt_minus1 = 0;
467 
468  // Try to scale these to a sensible range so that the
469  // golomb encode of the value is not overlong.
470  hrd->bit_rate_scale =
471  av_clip_uintp2(av_log2(ctx->va_bit_rate) - 15 - 6, 4);
472  hrd->bit_rate_value_minus1[0] =
473  (ctx->va_bit_rate >> hrd->bit_rate_scale + 6) - 1;
474 
475  hrd->cpb_size_scale =
476  av_clip_uintp2(av_log2(ctx->hrd_params.buffer_size) - 15 - 4, 4);
477  hrd->cpb_size_value_minus1[0] =
478  (ctx->hrd_params.buffer_size >> hrd->cpb_size_scale + 4) - 1;
479 
480  // CBR mode as defined for the HRD cannot be achieved without filler
481  // data, so this flag cannot be set even with VAAPI CBR modes.
482  hrd->cbr_flag[0] = 0;
483 
487  hrd->time_offset_length = 0;
488 
489  bp->seq_parameter_set_id = sps->seq_parameter_set_id;
490 
491  // This calculation can easily overflow 32 bits.
492  bp->nal.initial_cpb_removal_delay[0] = 90000 *
493  (uint64_t)ctx->hrd_params.initial_buffer_fullness /
494  ctx->hrd_params.buffer_size;
496  } else {
497  sps->vui.nal_hrd_parameters_present_flag = 0;
498  sps->vui.low_delay_hrd_flag = 1 - sps->vui.fixed_frame_rate_flag;
499  }
500 
501  sps->vui.bitstream_restriction_flag = 1;
502  sps->vui.motion_vectors_over_pic_boundaries_flag = 1;
503  sps->vui.log2_max_mv_length_horizontal = 15;
504  sps->vui.log2_max_mv_length_vertical = 15;
505  sps->vui.max_num_reorder_frames = ctx->max_b_depth;
506  sps->vui.max_dec_frame_buffering = ctx->max_b_depth + 1;
507 
508  pps->nal_unit_header.nal_ref_idc = 3;
509  pps->nal_unit_header.nal_unit_type = H264_NAL_PPS;
510 
511  pps->pic_parameter_set_id = 0;
512  pps->seq_parameter_set_id = 0;
513 
514  pps->entropy_coding_mode_flag =
515  !(sps->profile_idc == AV_PROFILE_H264_BASELINE ||
516  sps->profile_idc == AV_PROFILE_H264_EXTENDED ||
517  sps->profile_idc == AV_PROFILE_H264_CAVLC_444);
518  if (!priv->coder && pps->entropy_coding_mode_flag)
519  pps->entropy_coding_mode_flag = 0;
520 
521  pps->num_ref_idx_l0_default_active_minus1 = 0;
522  pps->num_ref_idx_l1_default_active_minus1 = 0;
523 
524  pps->pic_init_qp_minus26 = priv->fixed_qp_idr - 26;
525 
526  if (sps->profile_idc == AV_PROFILE_H264_BASELINE ||
527  sps->profile_idc == AV_PROFILE_H264_EXTENDED ||
528  sps->profile_idc == AV_PROFILE_H264_MAIN) {
529  pps->more_rbsp_data = 0;
530  } else {
531  pps->more_rbsp_data = 1;
532 
533  pps->transform_8x8_mode_flag = 1;
534  }
535 
536  *vseq = (VAEncSequenceParameterBufferH264) {
537  .seq_parameter_set_id = sps->seq_parameter_set_id,
538  .level_idc = sps->level_idc,
539  .intra_period = ctx->gop_size,
540  .intra_idr_period = ctx->gop_size,
541  .ip_period = ctx->b_per_p + 1,
542 
543  .bits_per_second = ctx->va_bit_rate,
544  .max_num_ref_frames = sps->max_num_ref_frames,
545  .picture_width_in_mbs = sps->pic_width_in_mbs_minus1 + 1,
546  .picture_height_in_mbs = sps->pic_height_in_map_units_minus1 + 1,
547 
548  .seq_fields.bits = {
549  .chroma_format_idc = sps->chroma_format_idc,
550  .frame_mbs_only_flag = sps->frame_mbs_only_flag,
551  .mb_adaptive_frame_field_flag = sps->mb_adaptive_frame_field_flag,
552  .seq_scaling_matrix_present_flag = sps->seq_scaling_matrix_present_flag,
553  .direct_8x8_inference_flag = sps->direct_8x8_inference_flag,
554  .log2_max_frame_num_minus4 = sps->log2_max_frame_num_minus4,
555  .pic_order_cnt_type = sps->pic_order_cnt_type,
556  .log2_max_pic_order_cnt_lsb_minus4 = sps->log2_max_pic_order_cnt_lsb_minus4,
557  .delta_pic_order_always_zero_flag = sps->delta_pic_order_always_zero_flag,
558  },
559 
560  .bit_depth_luma_minus8 = sps->bit_depth_luma_minus8,
561  .bit_depth_chroma_minus8 = sps->bit_depth_chroma_minus8,
562 
563  .frame_cropping_flag = sps->frame_cropping_flag,
564  .frame_crop_left_offset = sps->frame_crop_left_offset,
565  .frame_crop_right_offset = sps->frame_crop_right_offset,
566  .frame_crop_top_offset = sps->frame_crop_top_offset,
567  .frame_crop_bottom_offset = sps->frame_crop_bottom_offset,
568 
569  .vui_parameters_present_flag = sps->vui_parameters_present_flag,
570 
571  .vui_fields.bits = {
572  .aspect_ratio_info_present_flag = sps->vui.aspect_ratio_info_present_flag,
573  .timing_info_present_flag = sps->vui.timing_info_present_flag,
574  .bitstream_restriction_flag = sps->vui.bitstream_restriction_flag,
575  .log2_max_mv_length_horizontal = sps->vui.log2_max_mv_length_horizontal,
576  .log2_max_mv_length_vertical = sps->vui.log2_max_mv_length_vertical,
577  },
578 
579  .aspect_ratio_idc = sps->vui.aspect_ratio_idc,
580  .sar_width = sps->vui.sar_width,
581  .sar_height = sps->vui.sar_height,
582  .num_units_in_tick = sps->vui.num_units_in_tick,
583  .time_scale = sps->vui.time_scale,
584  };
585 
586  *vpic = (VAEncPictureParameterBufferH264) {
587  .CurrPic = {
588  .picture_id = VA_INVALID_ID,
589  .flags = VA_PICTURE_H264_INVALID,
590  },
591 
592  .coded_buf = VA_INVALID_ID,
593 
594  .pic_parameter_set_id = pps->pic_parameter_set_id,
595  .seq_parameter_set_id = pps->seq_parameter_set_id,
596 
597  .pic_init_qp = pps->pic_init_qp_minus26 + 26,
598  .num_ref_idx_l0_active_minus1 = pps->num_ref_idx_l0_default_active_minus1,
599  .num_ref_idx_l1_active_minus1 = pps->num_ref_idx_l1_default_active_minus1,
600 
601  .chroma_qp_index_offset = pps->chroma_qp_index_offset,
602  .second_chroma_qp_index_offset = pps->second_chroma_qp_index_offset,
603 
604  .pic_fields.bits = {
605  .entropy_coding_mode_flag = pps->entropy_coding_mode_flag,
606  .weighted_pred_flag = pps->weighted_pred_flag,
607  .weighted_bipred_idc = pps->weighted_bipred_idc,
608  .constrained_intra_pred_flag = pps->constrained_intra_pred_flag,
609  .transform_8x8_mode_flag = pps->transform_8x8_mode_flag,
610  .deblocking_filter_control_present_flag =
611  pps->deblocking_filter_control_present_flag,
612  .redundant_pic_cnt_present_flag = pps->redundant_pic_cnt_present_flag,
613  .pic_order_present_flag =
614  pps->bottom_field_pic_order_in_frame_present_flag,
615  .pic_scaling_matrix_present_flag = pps->pic_scaling_matrix_present_flag,
616  },
617  };
618 
619  return 0;
620 }
621 
623  VAAPIEncodePicture *pic)
624 {
625  VAAPIEncodeContext *ctx = avctx->priv_data;
626  VAAPIEncodeH264Context *priv = avctx->priv_data;
627  VAAPIEncodeH264Picture *hpic = pic->priv_data;
628  VAAPIEncodePicture *prev = pic->prev;
629  VAAPIEncodeH264Picture *hprev = prev ? prev->priv_data : NULL;
630  VAEncPictureParameterBufferH264 *vpic = pic->codec_picture_params;
631  int i, j = 0;
632 
633  if (pic->type == PICTURE_TYPE_IDR) {
634  av_assert0(pic->display_order == pic->encode_order);
635 
636  hpic->frame_num = 0;
637  hpic->last_idr_frame = pic->display_order;
638  hpic->idr_pic_id = hprev ? hprev->idr_pic_id + 1 : 0;
639 
640  hpic->primary_pic_type = 0;
641  hpic->slice_type = 7;
642  } else {
643  av_assert0(prev);
644 
645  hpic->frame_num = hprev->frame_num + prev->is_reference;
646 
647  hpic->last_idr_frame = hprev->last_idr_frame;
648  hpic->idr_pic_id = hprev->idr_pic_id;
649 
650  if (pic->type == PICTURE_TYPE_I) {
651  hpic->slice_type = 7;
652  hpic->primary_pic_type = 0;
653  } else if (pic->type == PICTURE_TYPE_P) {
654  hpic->slice_type = 5;
655  hpic->primary_pic_type = 1;
656  } else {
657  hpic->slice_type = 6;
658  hpic->primary_pic_type = 2;
659  }
660  }
661  hpic->pic_order_cnt = pic->display_order - hpic->last_idr_frame;
662  if (priv->raw_sps.pic_order_cnt_type == 2) {
663  hpic->pic_order_cnt *= 2;
664  }
665 
666  hpic->dpb_delay = pic->display_order - pic->encode_order + ctx->max_b_depth;
667  hpic->cpb_delay = pic->encode_order - hpic->last_idr_frame;
668 
669  if (priv->aud) {
670  priv->aud_needed = 1;
671  priv->raw_aud = (H264RawAUD) {
672  .nal_unit_header = {
674  },
675  .primary_pic_type = hpic->primary_pic_type,
676  };
677  } else {
678  priv->aud_needed = 0;
679  }
680 
681  priv->sei_needed = 0;
682 
683  if (priv->sei & SEI_IDENTIFIER && pic->encode_order == 0)
684  priv->sei_needed |= SEI_IDENTIFIER;
685 #if !CONFIG_VAAPI_1
686  if (ctx->va_rc_mode == VA_RC_CBR)
687  priv->sei_cbr_workaround_needed = 1;
688 #endif
689 
690  if (priv->sei & SEI_TIMING) {
692  .cpb_removal_delay = 2 * hpic->cpb_delay,
693  .dpb_output_delay = 2 * hpic->dpb_delay,
694  };
695 
696  priv->sei_needed |= SEI_TIMING;
697  }
698 
699  if (priv->sei & SEI_RECOVERY_POINT && pic->type == PICTURE_TYPE_I) {
701  .recovery_frame_cnt = 0,
702  .exact_match_flag = 1,
703  .broken_link_flag = ctx->b_per_p > 0,
704  };
705 
707  }
708 
709  if (priv->sei & SEI_A53_CC) {
710  int err;
711  size_t sei_a53cc_len;
712  av_freep(&priv->sei_a53cc_data);
713  err = ff_alloc_a53_sei(pic->input_image, 0, &priv->sei_a53cc_data, &sei_a53cc_len);
714  if (err < 0)
715  return err;
716  if (priv->sei_a53cc_data != NULL) {
717  priv->sei_a53cc.itu_t_t35_country_code = 181;
718  priv->sei_a53cc.data = (uint8_t *)priv->sei_a53cc_data + 1;
719  priv->sei_a53cc.data_length = sei_a53cc_len - 1;
720 
721  priv->sei_needed |= SEI_A53_CC;
722  }
723  }
724 
725  vpic->CurrPic = (VAPictureH264) {
726  .picture_id = pic->recon_surface,
727  .frame_idx = hpic->frame_num,
728  .flags = 0,
729  .TopFieldOrderCnt = hpic->pic_order_cnt,
730  .BottomFieldOrderCnt = hpic->pic_order_cnt,
731  };
732  for (int k = 0; k < MAX_REFERENCE_LIST_NUM; k++) {
733  for (i = 0; i < pic->nb_refs[k]; i++) {
734  VAAPIEncodePicture *ref = pic->refs[k][i];
736 
737  av_assert0(ref && ref->encode_order < pic->encode_order);
738  href = ref->priv_data;
739 
740  vpic->ReferenceFrames[j++] = (VAPictureH264) {
741  .picture_id = ref->recon_surface,
742  .frame_idx = href->frame_num,
743  .flags = VA_PICTURE_H264_SHORT_TERM_REFERENCE,
744  .TopFieldOrderCnt = href->pic_order_cnt,
745  .BottomFieldOrderCnt = href->pic_order_cnt,
746  };
747  }
748  }
749 
750  for (; j < FF_ARRAY_ELEMS(vpic->ReferenceFrames); j++) {
751  vpic->ReferenceFrames[j] = (VAPictureH264) {
752  .picture_id = VA_INVALID_ID,
753  .flags = VA_PICTURE_H264_INVALID,
754  };
755  }
756 
757  vpic->coded_buf = pic->output_buffer;
758 
759  vpic->frame_num = hpic->frame_num;
760 
761  vpic->pic_fields.bits.idr_pic_flag = (pic->type == PICTURE_TYPE_IDR);
762  vpic->pic_fields.bits.reference_pic_flag = (pic->type != PICTURE_TYPE_B);
763 
764  return 0;
765 }
766 
768  VAAPIEncodePicture *pic,
769  VAAPIEncodePicture **rpl0,
770  VAAPIEncodePicture **rpl1,
771  int *rpl_size)
772 {
773  VAAPIEncodePicture *prev;
774  VAAPIEncodeH264Picture *hp, *hn, *hc;
775  int i, j, n = 0;
776 
777  prev = pic->prev;
778  av_assert0(prev);
779  hp = pic->priv_data;
780 
781  for (i = 0; i < pic->prev->nb_dpb_pics; i++) {
782  hn = prev->dpb[i]->priv_data;
783  av_assert0(hn->frame_num < hp->frame_num);
784 
785  if (pic->type == PICTURE_TYPE_P) {
786  for (j = n; j > 0; j--) {
787  hc = rpl0[j - 1]->priv_data;
788  av_assert0(hc->frame_num != hn->frame_num);
789  if (hc->frame_num > hn->frame_num)
790  break;
791  rpl0[j] = rpl0[j - 1];
792  }
793  rpl0[j] = prev->dpb[i];
794 
795  } else if (pic->type == PICTURE_TYPE_B) {
796  for (j = n; j > 0; j--) {
797  hc = rpl0[j - 1]->priv_data;
799  if (hc->pic_order_cnt < hp->pic_order_cnt) {
800  if (hn->pic_order_cnt > hp->pic_order_cnt ||
801  hn->pic_order_cnt < hc->pic_order_cnt)
802  break;
803  } else {
804  if (hn->pic_order_cnt > hc->pic_order_cnt)
805  break;
806  }
807  rpl0[j] = rpl0[j - 1];
808  }
809  rpl0[j] = prev->dpb[i];
810 
811  for (j = n; j > 0; j--) {
812  hc = rpl1[j - 1]->priv_data;
814  if (hc->pic_order_cnt > hp->pic_order_cnt) {
815  if (hn->pic_order_cnt < hp->pic_order_cnt ||
816  hn->pic_order_cnt > hc->pic_order_cnt)
817  break;
818  } else {
819  if (hn->pic_order_cnt < hc->pic_order_cnt)
820  break;
821  }
822  rpl1[j] = rpl1[j - 1];
823  }
824  rpl1[j] = prev->dpb[i];
825  }
826 
827  ++n;
828  }
829 
830  if (pic->type == PICTURE_TYPE_B) {
831  for (i = 0; i < n; i++) {
832  if (rpl0[i] != rpl1[i])
833  break;
834  }
835  if (i == n)
836  FFSWAP(VAAPIEncodePicture*, rpl1[0], rpl1[1]);
837  }
838 
839  if (pic->type == PICTURE_TYPE_P ||
840  pic->type == PICTURE_TYPE_B) {
841  av_log(avctx, AV_LOG_DEBUG, "Default RefPicList0 for fn=%d/poc=%d:",
842  hp->frame_num, hp->pic_order_cnt);
843  for (i = 0; i < n; i++) {
844  hn = rpl0[i]->priv_data;
845  av_log(avctx, AV_LOG_DEBUG, " fn=%d/poc=%d",
846  hn->frame_num, hn->pic_order_cnt);
847  }
848  av_log(avctx, AV_LOG_DEBUG, "\n");
849  }
850  if (pic->type == PICTURE_TYPE_B) {
851  av_log(avctx, AV_LOG_DEBUG, "Default RefPicList1 for fn=%d/poc=%d:",
852  hp->frame_num, hp->pic_order_cnt);
853  for (i = 0; i < n; i++) {
854  hn = rpl1[i]->priv_data;
855  av_log(avctx, AV_LOG_DEBUG, " fn=%d/poc=%d",
856  hn->frame_num, hn->pic_order_cnt);
857  }
858  av_log(avctx, AV_LOG_DEBUG, "\n");
859  }
860 
861  *rpl_size = n;
862 }
863 
865  VAAPIEncodePicture *pic,
866  VAAPIEncodeSlice *slice)
867 {
868  VAAPIEncodeH264Context *priv = avctx->priv_data;
869  VAAPIEncodeH264Picture *hpic = pic->priv_data;
870  VAAPIEncodePicture *prev = pic->prev;
871  H264RawSPS *sps = &priv->raw_sps;
872  H264RawPPS *pps = &priv->raw_pps;
873  H264RawSliceHeader *sh = &priv->raw_slice.header;
874  VAEncPictureParameterBufferH264 *vpic = pic->codec_picture_params;
875  VAEncSliceParameterBufferH264 *vslice = slice->codec_slice_params;
876  int i, j;
877 
878  if (pic->type == PICTURE_TYPE_IDR) {
881  } else {
884  }
885 
886  sh->first_mb_in_slice = slice->block_start;
887  sh->slice_type = hpic->slice_type;
888 
889  sh->pic_parameter_set_id = pps->pic_parameter_set_id;
890 
891  sh->frame_num = hpic->frame_num &
892  ((1 << (4 + sps->log2_max_frame_num_minus4)) - 1);
893  sh->idr_pic_id = hpic->idr_pic_id;
894  sh->pic_order_cnt_lsb = hpic->pic_order_cnt &
895  ((1 << (4 + sps->log2_max_pic_order_cnt_lsb_minus4)) - 1);
896 
898 
899  if (pic->type == PICTURE_TYPE_B)
900  sh->slice_qp_delta = priv->fixed_qp_b - (pps->pic_init_qp_minus26 + 26);
901  else if (pic->type == PICTURE_TYPE_P)
902  sh->slice_qp_delta = priv->fixed_qp_p - (pps->pic_init_qp_minus26 + 26);
903  else
904  sh->slice_qp_delta = priv->fixed_qp_idr - (pps->pic_init_qp_minus26 + 26);
905 
906  if (pic->is_reference && pic->type != PICTURE_TYPE_IDR) {
907  VAAPIEncodePicture *discard_list[MAX_DPB_SIZE];
908  int discard = 0, keep = 0;
909 
910  // Discard everything which is in the DPB of the previous frame but
911  // not in the DPB of this one.
912  for (i = 0; i < prev->nb_dpb_pics; i++) {
913  for (j = 0; j < pic->nb_dpb_pics; j++) {
914  if (prev->dpb[i] == pic->dpb[j])
915  break;
916  }
917  if (j == pic->nb_dpb_pics) {
918  discard_list[discard] = prev->dpb[i];
919  ++discard;
920  } else {
921  ++keep;
922  }
923  }
924  av_assert0(keep <= priv->dpb_frames);
925 
926  if (discard == 0) {
928  } else {
930  for (i = 0; i < discard; i++) {
931  VAAPIEncodeH264Picture *old = discard_list[i]->priv_data;
932  av_assert0(old->frame_num < hpic->frame_num);
935  hpic->frame_num - old->frame_num - 1;
936  }
938  }
939  }
940 
941  // If the intended references are not the first entries of RefPicListN
942  // by default, use ref-pic-list-modification to move them there.
943  if (pic->type == PICTURE_TYPE_P || pic->type == PICTURE_TYPE_B) {
944  VAAPIEncodePicture *def_l0[MAX_DPB_SIZE], *def_l1[MAX_DPB_SIZE];
946  int n;
947 
949  def_l0, def_l1, &n);
950 
951  if (pic->type == PICTURE_TYPE_P) {
952  int need_rplm = 0;
953  for (i = 0; i < pic->nb_refs[0]; i++) {
954  av_assert0(pic->refs[0][i]);
955  if (pic->refs[0][i] != def_l0[i])
956  need_rplm = 1;
957  }
958 
959  sh->ref_pic_list_modification_flag_l0 = need_rplm;
960  if (need_rplm) {
961  int pic_num = hpic->frame_num;
962  for (i = 0; i < pic->nb_refs[0]; i++) {
963  href = pic->refs[0][i]->priv_data;
964  av_assert0(href->frame_num != pic_num);
965  if (href->frame_num < pic_num) {
968  pic_num - href->frame_num - 1;
969  } else {
972  href->frame_num - pic_num - 1;
973  }
974  pic_num = href->frame_num;
975  }
977  }
978 
979  } else {
980  int need_rplm_l0 = 0, need_rplm_l1 = 0;
981  int n0 = 0, n1 = 0;
982  for (i = 0; i < pic->nb_refs[0]; i++) {
983  av_assert0(pic->refs[0][i]);
984  href = pic->refs[0][i]->priv_data;
985  av_assert0(href->pic_order_cnt < hpic->pic_order_cnt);
986  if (pic->refs[0][i] != def_l0[n0])
987  need_rplm_l0 = 1;
988  ++n0;
989  }
990 
991  for (i = 0; i < pic->nb_refs[1]; i++) {
992  av_assert0(pic->refs[1][i]);
993  href = pic->refs[1][i]->priv_data;
994  av_assert0(href->pic_order_cnt > hpic->pic_order_cnt);
995  if (pic->refs[1][i] != def_l1[n1])
996  need_rplm_l1 = 1;
997  ++n1;
998  }
999 
1000  sh->ref_pic_list_modification_flag_l0 = need_rplm_l0;
1001  if (need_rplm_l0) {
1002  int pic_num = hpic->frame_num;
1003  for (i = j = 0; i < pic->nb_refs[0]; i++) {
1004  href = pic->refs[0][i]->priv_data;
1005  av_assert0(href->frame_num != pic_num);
1006  if (href->frame_num < pic_num) {
1009  pic_num - href->frame_num - 1;
1010  } else {
1013  href->frame_num - pic_num - 1;
1014  }
1015  pic_num = href->frame_num;
1016  ++j;
1017  }
1018  av_assert0(j == n0);
1020  }
1021 
1022  sh->ref_pic_list_modification_flag_l1 = need_rplm_l1;
1023  if (need_rplm_l1) {
1024  int pic_num = hpic->frame_num;
1025  for (i = j = 0; i < pic->nb_refs[1]; i++) {
1026  href = pic->refs[1][i]->priv_data;
1027  av_assert0(href->frame_num != pic_num);
1028  if (href->frame_num < pic_num) {
1031  pic_num - href->frame_num - 1;
1032  } else {
1035  href->frame_num - pic_num - 1;
1036  }
1037  pic_num = href->frame_num;
1038  ++j;
1039  }
1040  av_assert0(j == n1);
1042  }
1043  }
1044  }
1045 
1046  vslice->macroblock_address = slice->block_start;
1047  vslice->num_macroblocks = slice->block_size;
1048 
1049  vslice->macroblock_info = VA_INVALID_ID;
1050 
1051  vslice->slice_type = sh->slice_type % 5;
1052  vslice->pic_parameter_set_id = sh->pic_parameter_set_id;
1053  vslice->idr_pic_id = sh->idr_pic_id;
1054 
1055  vslice->pic_order_cnt_lsb = sh->pic_order_cnt_lsb;
1056 
1057  vslice->direct_spatial_mv_pred_flag = sh->direct_spatial_mv_pred_flag;
1058 
1059  for (i = 0; i < FF_ARRAY_ELEMS(vslice->RefPicList0); i++) {
1060  vslice->RefPicList0[i].picture_id = VA_INVALID_ID;
1061  vslice->RefPicList0[i].flags = VA_PICTURE_H264_INVALID;
1062  vslice->RefPicList1[i].picture_id = VA_INVALID_ID;
1063  vslice->RefPicList1[i].flags = VA_PICTURE_H264_INVALID;
1064  }
1065 
1066  if (pic->nb_refs[0]) {
1067  // Backward reference for P- or B-frame.
1068  av_assert0(pic->type == PICTURE_TYPE_P ||
1069  pic->type == PICTURE_TYPE_B);
1070  vslice->RefPicList0[0] = vpic->ReferenceFrames[0];
1071  }
1072  if (pic->nb_refs[1]) {
1073  // Forward reference for B-frame.
1074  av_assert0(pic->type == PICTURE_TYPE_B);
1075  vslice->RefPicList1[0] = vpic->ReferenceFrames[1];
1076  }
1077 
1078  vslice->slice_qp_delta = sh->slice_qp_delta;
1079 
1080  return 0;
1081 }
1082 
1084 {
1085  VAAPIEncodeContext *ctx = avctx->priv_data;
1086  VAAPIEncodeH264Context *priv = avctx->priv_data;
1087  int err;
1088 
1089  err = ff_cbs_init(&priv->cbc, AV_CODEC_ID_H264, avctx);
1090  if (err < 0)
1091  return err;
1092 
1093  priv->mb_width = FFALIGN(avctx->width, 16) / 16;
1094  priv->mb_height = FFALIGN(avctx->height, 16) / 16;
1095 
1096  if (ctx->va_rc_mode == VA_RC_CQP) {
1097  priv->fixed_qp_p = av_clip(ctx->rc_quality, 1, 51);
1098  if (avctx->i_quant_factor > 0.0)
1099  priv->fixed_qp_idr =
1100  av_clip((avctx->i_quant_factor * priv->fixed_qp_p +
1101  avctx->i_quant_offset) + 0.5, 1, 51);
1102  else
1103  priv->fixed_qp_idr = priv->fixed_qp_p;
1104  if (avctx->b_quant_factor > 0.0)
1105  priv->fixed_qp_b =
1106  av_clip((avctx->b_quant_factor * priv->fixed_qp_p +
1107  avctx->b_quant_offset) + 0.5, 1, 51);
1108  else
1109  priv->fixed_qp_b = priv->fixed_qp_p;
1110 
1111  av_log(avctx, AV_LOG_DEBUG, "Using fixed QP = "
1112  "%d / %d / %d for IDR- / P- / B-frames.\n",
1113  priv->fixed_qp_idr, priv->fixed_qp_p, priv->fixed_qp_b);
1114 
1115  } else {
1116  // These still need to be set for pic_init_qp/slice_qp_delta.
1117  priv->fixed_qp_idr = 26;
1118  priv->fixed_qp_p = 26;
1119  priv->fixed_qp_b = 26;
1120  }
1121 
1122  if (!ctx->rc_mode->hrd) {
1123  // Timing SEI requires a mode respecting HRD parameters.
1124  priv->sei &= ~SEI_TIMING;
1125  }
1126 
1127  if (priv->sei & SEI_IDENTIFIER) {
1128  const char *lavc = LIBAVCODEC_IDENT;
1129  const char *vaapi = VA_VERSION_S;
1130  const char *driver;
1131  int len;
1132 
1133  memcpy(priv->sei_identifier.uuid_iso_iec_11578,
1135  sizeof(priv->sei_identifier.uuid_iso_iec_11578));
1136 
1137  driver = vaQueryVendorString(ctx->hwctx->display);
1138  if (!driver)
1139  driver = "unknown driver";
1140 
1141  len = snprintf(NULL, 0, "%s / VAAPI %s / %s", lavc, vaapi, driver);
1142  if (len >= 0) {
1143  priv->sei_identifier_string = av_malloc(len + 1);
1144  if (!priv->sei_identifier_string)
1145  return AVERROR(ENOMEM);
1146 
1147  snprintf(priv->sei_identifier_string, len + 1,
1148  "%s / VAAPI %s / %s", lavc, vaapi, driver);
1149 
1151  priv->sei_identifier.data_length = len + 1;
1152  }
1153  }
1154 
1155  ctx->roi_quant_range = 51 + 6 * (ctx->profile->depth - 8);
1156 
1157  return 0;
1158 }
1159 
1161 #if VA_CHECK_VERSION(1, 18, 0)
1162  { AV_PROFILE_H264_HIGH_10, 10, 3, 1, 1, VAProfileH264High10 },
1163 #endif
1164  { AV_PROFILE_H264_HIGH, 8, 3, 1, 1, VAProfileH264High },
1165  { AV_PROFILE_H264_MAIN, 8, 3, 1, 1, VAProfileH264Main },
1167  8, 3, 1, 1, VAProfileH264ConstrainedBaseline },
1168  { AV_PROFILE_UNKNOWN }
1169 };
1170 
1173 
1174  .flags = FLAG_SLICE_CONTROL |
1175  FLAG_B_PICTURES |
1178 
1179  .default_quality = 20,
1180 
1181  .configure = &vaapi_encode_h264_configure,
1182 
1183  .picture_priv_data_size = sizeof(VAAPIEncodeH264Picture),
1184 
1185  .sequence_params_size = sizeof(VAEncSequenceParameterBufferH264),
1186  .init_sequence_params = &vaapi_encode_h264_init_sequence_params,
1187 
1188  .picture_params_size = sizeof(VAEncPictureParameterBufferH264),
1189  .init_picture_params = &vaapi_encode_h264_init_picture_params,
1190 
1191  .slice_params_size = sizeof(VAEncSliceParameterBufferH264),
1192  .init_slice_params = &vaapi_encode_h264_init_slice_params,
1193 
1194  .sequence_header_type = VAEncPackedHeaderSequence,
1195  .write_sequence_header = &vaapi_encode_h264_write_sequence_header,
1196 
1197  .slice_header_type = VAEncPackedHeaderH264_Slice,
1198  .write_slice_header = &vaapi_encode_h264_write_slice_header,
1199 
1200  .write_extra_header = &vaapi_encode_h264_write_extra_header,
1201 };
1202 
1204 {
1205  VAAPIEncodeContext *ctx = avctx->priv_data;
1206  VAAPIEncodeH264Context *priv = avctx->priv_data;
1207 
1208  ctx->codec = &vaapi_encode_type_h264;
1209 
1210  if (avctx->profile == AV_PROFILE_UNKNOWN)
1211  avctx->profile = priv->profile;
1212  if (avctx->level == AV_LEVEL_UNKNOWN)
1213  avctx->level = priv->level;
1215  avctx->compression_level = priv->quality;
1216 
1217  // Reject unsupported profiles.
1218  switch (avctx->profile) {
1220  av_log(avctx, AV_LOG_WARNING, "H.264 baseline profile is not "
1221  "supported, using constrained baseline profile instead.\n");
1223  break;
1225  av_log(avctx, AV_LOG_ERROR, "H.264 extended profile "
1226  "is not supported.\n");
1227  return AVERROR_PATCHWELCOME;
1229  av_log(avctx, AV_LOG_ERROR, "H.264 high 10 intra profile "
1230  "is not supported.\n");
1231  return AVERROR_PATCHWELCOME;
1238  av_log(avctx, AV_LOG_ERROR, "H.264 non-4:2:0 profiles "
1239  "are not supported.\n");
1240  return AVERROR_PATCHWELCOME;
1241  }
1242 
1243  if (avctx->level != AV_LEVEL_UNKNOWN && avctx->level & ~0xff) {
1244  av_log(avctx, AV_LOG_ERROR, "Invalid level %d: must fit "
1245  "in 8-bit unsigned integer.\n", avctx->level);
1246  return AVERROR(EINVAL);
1247  }
1248 
1249  ctx->desired_packed_headers =
1250  VA_ENC_PACKED_HEADER_SEQUENCE | // SPS and PPS.
1251  VA_ENC_PACKED_HEADER_SLICE | // Slice headers.
1252  VA_ENC_PACKED_HEADER_MISC; // SEI.
1253 
1254  ctx->surface_width = FFALIGN(avctx->width, 16);
1255  ctx->surface_height = FFALIGN(avctx->height, 16);
1256 
1257  ctx->slice_block_height = ctx->slice_block_width = 16;
1258 
1259  if (priv->qp > 0)
1260  ctx->explicit_qp = priv->qp;
1261 
1262  return ff_vaapi_encode_init(avctx);
1263 }
1264 
1266 {
1267  VAAPIEncodeH264Context *priv = avctx->priv_data;
1268 
1270  ff_cbs_close(&priv->cbc);
1272  av_freep(&priv->sei_a53cc_data);
1273 
1274  return ff_vaapi_encode_close(avctx);
1275 }
1276 
1277 #define OFFSET(x) offsetof(VAAPIEncodeH264Context, x)
1278 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
1282 
1283  { "qp", "Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)",
1284  OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 52, FLAGS },
1285  { "quality", "Set encode quality (trades off against speed, higher is faster)",
1286  OFFSET(quality), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS },
1287  { "coder", "Entropy coder type",
1288  OFFSET(coder), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, FLAGS, .unit = "coder" },
1289  { "cavlc", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, INT_MIN, INT_MAX, FLAGS, .unit = "coder" },
1290  { "cabac", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, FLAGS, .unit = "coder" },
1291  { "vlc", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, INT_MIN, INT_MAX, FLAGS, .unit = "coder" },
1292  { "ac", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, FLAGS, .unit = "coder" },
1293 
1294  { "aud", "Include AUD",
1295  OFFSET(aud), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
1296 
1297  { "sei", "Set SEI to include",
1300  0, INT_MAX, FLAGS, .unit = "sei" },
1301  { "identifier", "Include encoder version identifier",
1302  0, AV_OPT_TYPE_CONST, { .i64 = SEI_IDENTIFIER },
1303  INT_MIN, INT_MAX, FLAGS, .unit = "sei" },
1304  { "timing", "Include timing parameters (buffering_period and pic_timing)",
1305  0, AV_OPT_TYPE_CONST, { .i64 = SEI_TIMING },
1306  INT_MIN, INT_MAX, FLAGS, .unit = "sei" },
1307  { "recovery_point", "Include recovery points where appropriate",
1308  0, AV_OPT_TYPE_CONST, { .i64 = SEI_RECOVERY_POINT },
1309  INT_MIN, INT_MAX, FLAGS, .unit = "sei" },
1310  { "a53_cc", "Include A/53 caption data",
1311  0, AV_OPT_TYPE_CONST, { .i64 = SEI_A53_CC },
1312  INT_MIN, INT_MAX, FLAGS, .unit = "sei" },
1313 
1314  { "profile", "Set profile (profile_idc and constraint_set*_flag)",
1316  { .i64 = AV_PROFILE_UNKNOWN }, AV_PROFILE_UNKNOWN, 0xffff, FLAGS, .unit = "profile" },
1317 
1318 #define PROFILE(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
1319  { .i64 = value }, 0, 0, FLAGS, .unit = "profile"
1320  { PROFILE("constrained_baseline", AV_PROFILE_H264_CONSTRAINED_BASELINE) },
1321  { PROFILE("main", AV_PROFILE_H264_MAIN) },
1322  { PROFILE("high", AV_PROFILE_H264_HIGH) },
1323  { PROFILE("high10", AV_PROFILE_H264_HIGH_10) },
1324 #undef PROFILE
1325 
1326  { "level", "Set level (level_idc)",
1328  { .i64 = AV_LEVEL_UNKNOWN }, AV_LEVEL_UNKNOWN, 0xff, FLAGS, .unit = "level" },
1329 
1330 #define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
1331  { .i64 = value }, 0, 0, FLAGS, .unit = "level"
1332  { LEVEL("1", 10) },
1333  { LEVEL("1.1", 11) },
1334  { LEVEL("1.2", 12) },
1335  { LEVEL("1.3", 13) },
1336  { LEVEL("2", 20) },
1337  { LEVEL("2.1", 21) },
1338  { LEVEL("2.2", 22) },
1339  { LEVEL("3", 30) },
1340  { LEVEL("3.1", 31) },
1341  { LEVEL("3.2", 32) },
1342  { LEVEL("4", 40) },
1343  { LEVEL("4.1", 41) },
1344  { LEVEL("4.2", 42) },
1345  { LEVEL("5", 50) },
1346  { LEVEL("5.1", 51) },
1347  { LEVEL("5.2", 52) },
1348  { LEVEL("6", 60) },
1349  { LEVEL("6.1", 61) },
1350  { LEVEL("6.2", 62) },
1351 #undef LEVEL
1352 
1353  { NULL },
1354 };
1355 
1357  { "b", "0" },
1358  { "bf", "2" },
1359  { "g", "120" },
1360  { "i_qfactor", "1" },
1361  { "i_qoffset", "0" },
1362  { "b_qfactor", "6/5" },
1363  { "b_qoffset", "0" },
1364  { "qmin", "-1" },
1365  { "qmax", "-1" },
1366  { NULL },
1367 };
1368 
1370  .class_name = "h264_vaapi",
1371  .item_name = av_default_item_name,
1372  .option = vaapi_encode_h264_options,
1373  .version = LIBAVUTIL_VERSION_INT,
1374 };
1375 
1377  .p.name = "h264_vaapi",
1378  CODEC_LONG_NAME("H.264/AVC (VAAPI)"),
1379  .p.type = AVMEDIA_TYPE_VIDEO,
1380  .p.id = AV_CODEC_ID_H264,
1381  .priv_data_size = sizeof(VAAPIEncodeH264Context),
1384  .close = &vaapi_encode_h264_close,
1385  .p.priv_class = &vaapi_encode_h264_class,
1386  .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE |
1388  .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE |
1390  .defaults = vaapi_encode_h264_defaults,
1391  .p.pix_fmts = (const enum AVPixelFormat[]) {
1394  },
1395  .hw_configs = ff_vaapi_encode_hw_configs,
1396  .p.wrapper_name = "vaapi",
1397 };
FLAGS
#define FLAGS
Definition: vaapi_encode_h264.c:1278
H264_NAL_PPS
@ H264_NAL_PPS
Definition: h264.h:42
VAAPIEncodeH264Context::sei_identifier_string
char * sei_identifier_string
Definition: vaapi_encode_h264.c:104
ff_alloc_a53_sei
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:25
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
VAAPIEncodeSlice::codec_slice_params
void * codec_slice_params
Definition: vaapi_encode.h:70
OFFSET
#define OFFSET(x)
Definition: vaapi_encode_h264.c:1277
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
level
uint8_t level
Definition: svq3.c:204
AV_PROFILE_H264_HIGH_10_INTRA
#define AV_PROFILE_H264_HIGH_10_INTRA
Definition: defs.h:115
H264_NAL_SLICE
@ H264_NAL_SLICE
Definition: h264.h:35
av_clip
#define av_clip
Definition: common.h:98
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:42
AVERROR
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
SEI_IDENTIFIER
@ SEI_IDENTIFIER
Definition: vaapi_encode_h264.c:44
opt.h
LIBAVCODEC_IDENT
#define LIBAVCODEC_IDENT
Definition: version.h:43
AVCodecContext::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:685
SEIRawUserDataRegistered
Definition: cbs_sei.h:33
VAAPIEncodeH264Picture
Definition: vaapi_encode_h264.c:55
h264_levels.h
ff_cbs_fragment_free
av_cold 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:185
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2962
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
AV_CODEC_CAP_HARDWARE
#define AV_CODEC_CAP_HARDWARE
Codec is backed by a hardware implementation.
Definition: codec.h:145
av_clip_uintp2
#define av_clip_uintp2
Definition: common.h:122
AV_PROFILE_H264_MAIN
#define AV_PROFILE_H264_MAIN
Definition: defs.h:111
ff_cbs_sei_add_message
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:268
cbs_h264.h
dpb_frames
int dpb_frames
Definition: h264_levels.c:163
ff_cbs_insert_unit_content
int ff_cbs_insert_unit_content(CodedBitstreamFragment *frag, int position, CodedBitstreamUnitType type, void *content, void *content_ref)
Insert a new unit into a fragment with the given content.
Definition: cbs.c:782
int64_t
long long int64_t
Definition: coverity.c:34
vaapi_encode_h264_sei_identifier_uuid
static const uint8_t vaapi_encode_h264_sei_identifier_uuid[16]
Definition: vaapi_encode_h264.c:50
FLAG_B_PICTURES
@ FLAG_B_PICTURES
Definition: vaapi_encode.h:408
pixdesc.h
AVCodecContext::color_trc
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:678
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:683
ff_cbs_fragment_reset
void ff_cbs_fragment_reset(CodedBitstreamFragment *frag)
Free the units contained in a fragment as well as the fragment's own data buffer, but not the units a...
Definition: cbs.c:171
vaapi_encode_h264_class
static const AVClass vaapi_encode_h264_class
Definition: vaapi_encode_h264.c:1369
CodedBitstreamContext
Context structure for coded bitstream operations.
Definition: cbs.h:219
VAAPIEncodeSlice
Definition: vaapi_encode.h:64
H264RawHRD::dpb_output_delay_length_minus1
uint8_t dpb_output_delay_length_minus1
Definition: cbs_h264.h:54
VAAPIEncodeH264Context::aud
int aud
Definition: vaapi_encode_h264.c:76
AVOption
AVOption.
Definition: opt.h:346
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:583
data
const char data[16]
Definition: mxf.c:148
H264RawHRD
Definition: cbs_h264.h:43
AVCodecContext::b_quant_offset
float b_quant_offset
qscale offset between IP and B-frames
Definition: avcodec.h:811
VAAPIEncodeSlice::block_start
int block_start
Definition: vaapi_encode.h:68
FF_CODEC_CAP_NOT_INIT_THREADSAFE
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
Definition: codec_internal.h:34
VAAPIEncodeH264Context::sei_a53cc
SEIRawUserDataRegistered sei_a53cc
Definition: vaapi_encode_h264.c:105
FFCodec
Definition: codec_internal.h:127
vaapi_encode_h264_init_picture_params
static int vaapi_encode_h264_init_picture_params(AVCodecContext *avctx, VAAPIEncodePicture *pic)
Definition: vaapi_encode_h264.c:622
version.h
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
VAAPIEncodeH264Context::sei_recovery_point
H264RawSEIRecoveryPoint sei_recovery_point
Definition: vaapi_encode_h264.c:102
ff_vaapi_encode_close
av_cold int ff_vaapi_encode_close(AVCodecContext *avctx)
Definition: vaapi_encode.c:2982
FLAG_B_PICTURE_REFERENCES
@ FLAG_B_PICTURE_REFERENCES
Definition: vaapi_encode.h:410
cbs.h
PICTURE_TYPE_IDR
@ PICTURE_TYPE_IDR
Definition: vaapi_encode.h:58
H264LevelDescriptor
Definition: h264_levels.h:25
VAAPIEncodeH264Context::mb_height
int mb_height
Definition: vaapi_encode_h264.c:83
FF_COMPRESSION_DEFAULT
#define FF_COMPRESSION_DEFAULT
Definition: avcodec.h:1246
bit_depth
static void bit_depth(AudioStatsContext *s, const uint64_t *const mask, uint8_t *depth)
Definition: af_astats.c:245
H264RawHRD::cpb_size_scale
uint8_t cpb_size_scale
Definition: cbs_h264.h:46
quality
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about quality
Definition: rate_distortion.txt:12
H264RawSliceHeader::nal_unit_header
H264RawNALUnitHeader nal_unit_header
Definition: cbs_h264.h:311
ff_cbs_close
av_cold void ff_cbs_close(CodedBitstreamContext **ctx_ptr)
Close a context and free all internal state.
Definition: cbs.c:141
SEI_A53_CC
@ SEI_A53_CC
Definition: vaapi_encode_h264.c:46
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
H264RawSliceHeader::direct_spatial_mv_pred_flag
uint8_t direct_spatial_mv_pred_flag
Definition: cbs_h264.h:331
VAAPIEncodePicture::refs
struct VAAPIEncodePicture * refs[MAX_REFERENCE_LIST_NUM][MAX_PICTURE_REFERENCES]
Definition: vaapi_encode.h:125
AV_PROFILE_H264_EXTENDED
#define AV_PROFILE_H264_EXTENDED
Definition: defs.h:112
MAX_DPB_SIZE
@ MAX_DPB_SIZE
Definition: vaapi_encode.h:43
AVCodecContext::framerate
AVRational framerate
Definition: avcodec.h:560
H264RawSEIRecoveryPoint::recovery_frame_cnt
uint16_t recovery_frame_cnt
Definition: cbs_h264.h:269
VAAPIEncodePicture::nb_refs
int nb_refs[MAX_REFERENCE_LIST_NUM]
Definition: vaapi_encode.h:124
VAAPIEncodeH264Context::level
int level
Definition: vaapi_encode_h264.c:79
H264RawHRD::bit_rate_scale
uint8_t bit_rate_scale
Definition: cbs_h264.h:45
H264RawSEIPicTiming
Definition: cbs_h264.h:249
AVCodecContext::i_quant_factor
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:820
FFCodecDefault
Definition: codec_internal.h:97
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
VAAPIEncodeH264Picture::pic_order_cnt
int pic_order_cnt
Definition: vaapi_encode_h264.c:57
ff_h264_guess_level
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:79
vaapi_encode.h
SEIRawUserDataUnregistered::data
uint8_t * data
RefStruct reference.
Definition: cbs_sei.h:42
fail
#define fail()
Definition: checkasm.h:179
H264RawHRD::cpb_size_value_minus1
uint32_t cpb_size_value_minus1[H264_MAX_CPB_CNT]
Definition: cbs_h264.h:49
VAAPIEncodePicture
Definition: vaapi_encode.h:73
VAAPIEncodeH264Context
Definition: vaapi_encode_h264.c:69
SEIRawUserDataUnregistered
Definition: cbs_sei.h:40
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
H264RawSliceHeader::pic_order_cnt_lsb
uint16_t pic_order_cnt_lsb
Definition: cbs_h264.h:326
av_reduce
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
AVRational::num
int num
Numerator.
Definition: rational.h:59
avassert.h
H264RawSliceHeader::first_mb_in_slice
uint32_t first_mb_in_slice
Definition: cbs_h264.h:313
SEIRawUserDataRegistered::itu_t_t35_country_code
uint8_t itu_t_t35_country_code
Definition: cbs_sei.h:34
AVCodecContext::color_primaries
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:671
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
H264_NAL_SPS
@ H264_NAL_SPS
Definition: h264.h:41
AV_PROFILE_UNKNOWN
#define AV_PROFILE_UNKNOWN
Definition: defs.h:65
LEVEL
#define LEVEL(name, value)
VAAPIEncodePicture::codec_picture_params
void * codec_picture_params
Definition: vaapi_encode.h:111
CodedBitstreamFragment
Coded bitstream fragment structure, combining one or more units.
Definition: cbs.h:122
H264RawSEIBufferingPeriod::initial_cpb_removal_delay
uint32_t initial_cpb_removal_delay[H264_MAX_CPB_CNT]
Definition: cbs_h264.h:227
FLAG_SLICE_CONTROL
@ FLAG_SLICE_CONTROL
Definition: vaapi_encode.h:402
vaapi_encode_h264_init
static av_cold int vaapi_encode_h264_init(AVCodecContext *avctx)
Definition: vaapi_encode_h264.c:1203
VAAPIEncodeH264Context::fixed_qp_idr
int fixed_qp_idr
Definition: vaapi_encode_h264.c:85
H264RawSliceHeader::slice_qp_delta
int8_t slice_qp_delta
Definition: cbs_h264.h:376
PICTURE_TYPE_I
@ PICTURE_TYPE_I
Definition: vaapi_encode.h:59
CodedBitstreamFragment::data_size
size_t data_size
The number of bytes in the bitstream.
Definition: cbs.h:135
VAAPIEncodeH264Context::quality
int quality
Definition: vaapi_encode_h264.c:74
MAX_REFERENCE_LIST_NUM
@ MAX_REFERENCE_LIST_NUM
Definition: vaapi_encode.h:52
H264RawNALUnitHeader::nal_unit_type
uint8_t nal_unit_type
Definition: cbs_h264.h:33
AV_PROFILE_H264_HIGH_10
#define AV_PROFILE_H264_HIGH_10
Definition: defs.h:114
H264RawSliceHeader::frame_num
uint16_t frame_num
Definition: cbs_h264.h:320
AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
#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:159
H264RawAUD::nal_unit_header
H264RawNALUnitHeader nal_unit_header
Definition: cbs_h264.h:219
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
SEIRawUserDataUnregistered::data_length
size_t data_length
Definition: cbs_sei.h:43
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
VAAPIEncodeH264Picture::cpb_delay
int cpb_delay
Definition: vaapi_encode_h264.c:65
ctx
AVFormatContext * ctx
Definition: movenc.c:48
vaapi_encode_h264_write_extra_header
static int vaapi_encode_h264_write_extra_header(AVCodecContext *avctx, VAAPIEncodePicture *pic, int index, int *type, char *data, size_t *data_len)
Definition: vaapi_encode_h264.c:212
SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35
@ SEI_TYPE_USER_DATA_REGISTERED_ITU_T_T35
Definition: sei.h:34
vaapi_encode_h264_options
static const AVOption vaapi_encode_h264_options[]
Definition: vaapi_encode_h264.c:1279
AV_PROFILE_H264_HIGH_422_INTRA
#define AV_PROFILE_H264_HIGH_422_INTRA
Definition: defs.h:118
ff_vaapi_encode_receive_packet
int ff_vaapi_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
Definition: vaapi_encode.c:1396
VAAPIEncodeH264Context::fixed_qp_b
int fixed_qp_b
Definition: vaapi_encode_h264.c:87
VAAPIEncodeH264Context::sei_pic_timing
H264RawSEIPicTiming sei_pic_timing
Definition: vaapi_encode_h264.c:101
CodedBitstreamFragment::data_bit_padding
size_t data_bit_padding
The number of bits which should be ignored in the final byte.
Definition: cbs.h:139
VAAPIEncodeH264Context::coder
int coder
Definition: vaapi_encode_h264.c:75
h2645data.h
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:558
VAAPIEncodeType
Definition: vaapi_encode.h:419
AV_CODEC_ID_H264
@ AV_CODEC_ID_H264
Definition: codec_id.h:79
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
AV_PROFILE_H264_HIGH_422
#define AV_PROFILE_H264_HIGH_422
Definition: defs.h:117
H264RawSliceHeader::adaptive_ref_pic_marking_mode_flag
uint8_t adaptive_ref_pic_marking_mode_flag
Definition: cbs_h264.h:365
VAAPIEncodeContext
Definition: vaapi_encode.h:195
VAAPIEncodePicture::prev
struct VAAPIEncodePicture * prev
Definition: vaapi_encode.h:128
framerate
float framerate
Definition: av1_levels.c:29
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
NULL
#define NULL
Definition: coverity.c:32
VAAPIEncodeH264Context::cbc
CodedBitstreamContext * cbc
Definition: vaapi_encode_h264.c:92
VAAPIEncodeH264Picture::dpb_delay
int dpb_delay
Definition: vaapi_encode_h264.c:66
AVHWFramesContext::sw_format
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition: hwcontext.h:210
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:695
VAAPIEncodeH264Context::sei
int sei
Definition: vaapi_encode_h264.c:77
VAAPIEncodePicture::dpb
struct VAAPIEncodePicture * dpb[MAX_DPB_SIZE]
Definition: vaapi_encode.h:120
AV_LEVEL_UNKNOWN
#define AV_LEVEL_UNKNOWN
Definition: defs.h:196
VAAPIEncodeType::profiles
const VAAPIEncodeProfile * profiles
Definition: vaapi_encode.h:422
FF_CODEC_RECEIVE_PACKET_CB
#define FF_CODEC_RECEIVE_PACKET_CB(func)
Definition: codec_internal.h:302
AVCodecContext::bit_rate
int64_t bit_rate
the average bitrate
Definition: avcodec.h:495
H264RawNALUnitHeader
Definition: cbs_h264.h:31
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
VAAPIEncodeH264Context::raw_slice
H264RawSlice raw_slice
Definition: vaapi_encode_h264.c:98
VAAPIEncodeH264Context::fixed_qp_p
int fixed_qp_p
Definition: vaapi_encode_h264.c:86
H264RawSEIBufferingPeriod::nal
struct H264RawSEIBufferingPeriod::@42 nal
vaapi_encode_h264_profiles
static const VAAPIEncodeProfile vaapi_encode_h264_profiles[]
Definition: vaapi_encode_h264.c:1160
vaapi_encode_h264_add_nal
static int vaapi_encode_h264_add_nal(AVCodecContext *avctx, CodedBitstreamFragment *au, void *nal_unit)
Definition: vaapi_encode_h264.c:140
sei
static int FUNC() sei(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEI *current)
Definition: cbs_h264_syntax_template.c:824
AVCodecContext::level
int level
Encoding level descriptor.
Definition: avcodec.h:1783
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:649
index
int index
Definition: gxfenc.c:89
AVCodecContext::time_base
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avcodec.h:544
aud
static int FUNC() aud(CodedBitstreamContext *ctx, RWContext *rw, H264RawAUD *current)
Definition: cbs_h264_syntax_template.c:841
VAAPIEncodeH264Context::raw_sps
H264RawSPS raw_sps
Definition: vaapi_encode_h264.c:96
vaapi_encode_h264_write_access_unit
static int vaapi_encode_h264_write_access_unit(AVCodecContext *avctx, char *data, size_t *data_len, CodedBitstreamFragment *au)
Definition: vaapi_encode_h264.c:114
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:365
H264RawSliceHeader::difference_of_pic_nums_minus1
int32_t difference_of_pic_nums_minus1
Definition: cbs_h264.h:368
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
VAAPIEncodePicture::type
int type
Definition: vaapi_encode.h:92
hn
static float hn(int n, EqParameter *param, float fs)
Definition: af_superequalizer.c:91
pps
static int FUNC() pps(CodedBitstreamContext *ctx, RWContext *rw, H264RawPPS *current)
Definition: cbs_h264_syntax_template.c:404
codec_internal.h
H264RawNALUnitHeader::nal_ref_idc
uint8_t nal_ref_idc
Definition: cbs_h264.h:32
VAAPI_ENCODE_RC_OPTIONS
#define VAAPI_ENCODE_RC_OPTIONS
Definition: vaapi_encode.h:532
H264RawSliceHeader::slice_type
uint8_t slice_type
Definition: cbs_h264.h:314
AV_PROFILE_H264_CAVLC_444
#define AV_PROFILE_H264_CAVLC_444
Definition: defs.h:123
SEIRawUserDataRegistered::data
uint8_t * data
RefStruct reference.
Definition: cbs_sei.h:36
vaapi_encode_h264_init_sequence_params
static int vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx)
Definition: vaapi_encode_h264.c:297
CodedBitstreamFragment::data
uint8_t * data
Pointer to the bitstream form of this fragment.
Definition: cbs.h:128
vaapi_encode_h264_write_slice_header
static int vaapi_encode_h264_write_slice_header(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice, char *data, size_t *data_len)
Definition: vaapi_encode_h264.c:186
AVCHROMA_LOC_UNSPECIFIED
@ AVCHROMA_LOC_UNSPECIFIED
Definition: pixfmt.h:703
VAAPIEncodeH264Context::mb_width
int mb_width
Definition: vaapi_encode_h264.c:82
VAAPIEncodeH264Context::common
VAAPIEncodeContext common
Definition: vaapi_encode_h264.c:70
header
static const uint8_t header[24]
Definition: sdr2.c:68
vaapi_encode_h264_init_slice_params
static int vaapi_encode_h264_init_slice_params(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice)
Definition: vaapi_encode_h264.c:864
VAAPI_ENCODE_COMMON_OPTIONS
#define VAAPI_ENCODE_COMMON_OPTIONS
Definition: vaapi_encode.h:505
VAAPIEncodePicture::recon_surface
VASurfaceID recon_surface
Definition: vaapi_encode.h:101
VAAPIEncodePicture::output_buffer
VABufferID output_buffer
Definition: vaapi_encode.h:108
VAAPIEncodePicture::priv_data
void * priv_data
Definition: vaapi_encode.h:110
SEIRawUserDataRegistered::data_length
size_t data_length
Definition: cbs_sei.h:37
H264_NAL_IDR_SLICE
@ H264_NAL_IDR_SLICE
Definition: h264.h:39
VAAPIEncodePicture::display_order
int64_t display_order
Definition: vaapi_encode.h:76
AV_PIX_FMT_VAAPI
@ AV_PIX_FMT_VAAPI
Hardware acceleration through VA-API, data[3] contains a VASurfaceID.
Definition: pixfmt.h:126
VAAPIEncodePicture::nb_dpb_pics
int nb_dpb_pics
Definition: vaapi_encode.h:119
vaapi_encode_h264_write_sequence_header
static int vaapi_encode_h264_write_sequence_header(AVCodecContext *avctx, char *data, size_t *data_len)
Definition: vaapi_encode_h264.c:158
AVCodecContext::b_quant_factor
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:804
H264RawSliceHeader::rplm_l1
struct H264RawSliceHeader::@43 rplm_l1[H264_MAX_RPLM_COUNT]
VAAPIEncodeH264Picture::slice_type
int slice_type
Definition: vaapi_encode_h264.c:63
H264RawSliceHeader
Definition: cbs_h264.h:310
H264RawSEIBufferingPeriod::initial_cpb_removal_delay_offset
uint32_t initial_cpb_removal_delay_offset[H264_MAX_CPB_CNT]
Definition: cbs_h264.h:228
h264_sei.h
H264RawSlice::header
H264RawSliceHeader header
Definition: cbs_h264.h:389
H264RawSliceHeader::idr_pic_id
uint16_t idr_pic_id
Definition: cbs_h264.h:324
PICTURE_TYPE_B
@ PICTURE_TYPE_B
Definition: vaapi_encode.h:61
FLAG_NON_IDR_KEY_PICTURES
@ FLAG_NON_IDR_KEY_PICTURES
Definition: vaapi_encode.h:413
H264RawHRD::cpb_cnt_minus1
uint8_t cpb_cnt_minus1
Definition: cbs_h264.h:44
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
VAAPIEncodeH264Context::raw_aud
H264RawAUD raw_aud
Definition: vaapi_encode_h264.c:95
VAAPIEncodeH264Context::aud_needed
int aud_needed
Definition: vaapi_encode_h264.c:108
H264_NAL_AUD
@ H264_NAL_AUD
Definition: h264.h:43
H264RawHRD::cbr_flag
uint8_t cbr_flag[H264_MAX_CPB_CNT]
Definition: cbs_h264.h:50
internal.h
VAAPIEncodeContext::input_frames
AVHWFramesContext * input_frames
Definition: vaapi_encode.h:275
common.h
VAAPIEncodeH264Context::sei_needed
int sei_needed
Definition: vaapi_encode_h264.c:109
SEI_TYPE_PIC_TIMING
@ SEI_TYPE_PIC_TIMING
Definition: sei.h:31
VAAPIEncodeH264Context::sei_a53cc_data
void * sei_a53cc_data
Definition: vaapi_encode_h264.c:106
VAAPIEncodeH264Context::sei_cbr_workaround_needed
int sei_cbr_workaround_needed
Definition: vaapi_encode_h264.c:110
vaapi_encode_h264_close
static av_cold int vaapi_encode_h264_close(AVCodecContext *avctx)
Definition: vaapi_encode_h264.c:1265
H264RawSPS::pic_order_cnt_type
uint8_t pic_order_cnt_type
Definition: cbs_h264.h:129
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
ff_h2645_pixel_aspect
const AVRational ff_h2645_pixel_aspect[]
Definition: h2645data.c:21
AVCodecContext::chroma_sample_location
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
Definition: avcodec.h:702
len
int len
Definition: vorbis_enc_data.h:426
profile
int profile
Definition: mxfenc.c:2226
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:612
H264RawSliceHeader::ref_pic_list_modification_flag_l0
uint8_t ref_pic_list_modification_flag_l0
Definition: cbs_h264.h:337
AVCodecContext::height
int height
Definition: avcodec.h:618
VAAPIEncodeH264Context::qp
int qp
Definition: vaapi_encode_h264.c:73
H264RawSliceHeader::mmco
struct H264RawSliceHeader::@44 mmco[H264_MAX_MMCO_COUNT]
ff_cbs_write_fragment_data
int ff_cbs_write_fragment_data(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag)
Write the content of the fragment to its own internal buffer.
Definition: cbs.c:408
H264RawSliceHeader::rplm_l0
struct H264RawSliceHeader::@43 rplm_l0[H264_MAX_RPLM_COUNT]
VAAPIEncodeH264Picture::primary_pic_type
int primary_pic_type
Definition: vaapi_encode_h264.c:62
avcodec.h
H264RawSliceHeader::memory_management_control_operation
uint8_t memory_management_control_operation
Definition: cbs_h264.h:367
ff_vaapi_encode_hw_configs
const AVCodecHWConfigInternal *const ff_vaapi_encode_hw_configs[]
Definition: vaapi_encode.c:35
AV_PROFILE_H264_HIGH_444_PREDICTIVE
#define AV_PROFILE_H264_HIGH_444_PREDICTIVE
Definition: defs.h:121
ff_vaapi_encode_init
av_cold int ff_vaapi_encode_init(AVCodecContext *avctx)
Definition: vaapi_encode.c:2773
VAAPIEncodeH264Context::dpb_frames
int dpb_frames
Definition: vaapi_encode_h264.c:89
FFSWAP
#define FFSWAP(type, a, b)
Definition: macros.h:52
AVClass::class_name
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:71
VAAPIEncodeH264Context::sei_identifier
SEIRawUserDataUnregistered sei_identifier
Definition: vaapi_encode_h264.c:103
VAAPIEncodeH264Picture::frame_num
int frame_num
Definition: vaapi_encode_h264.c:56
VAAPIEncodeH264Picture::idr_pic_id
uint16_t idr_pic_id
Definition: vaapi_encode_h264.c:60
atsc_a53.h
VAAPIEncodeH264Picture::last_idr_frame
int64_t last_idr_frame
Definition: vaapi_encode_h264.c:59
AV_PROFILE_H264_BASELINE
#define AV_PROFILE_H264_BASELINE
Definition: defs.h:109
sps
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
Definition: cbs_h264_syntax_template.c:260
H264RawSEIBufferingPeriod::seq_parameter_set_id
uint8_t seq_parameter_set_id
Definition: cbs_h264.h:225
H264RawHRD::bit_rate_value_minus1
uint32_t bit_rate_value_minus1[H264_MAX_CPB_CNT]
Definition: cbs_h264.h:48
ff_h264_vaapi_encoder
const FFCodec ff_h264_vaapi_encoder
Definition: vaapi_encode_h264.c:1376
H264RawHRD::cpb_removal_delay_length_minus1
uint8_t cpb_removal_delay_length_minus1
Definition: cbs_h264.h:53
VAAPIEncodeH264Context::current_access_unit
CodedBitstreamFragment current_access_unit
Definition: vaapi_encode_h264.c:93
AVCodecContext
main external API structure.
Definition: avcodec.h:445
H264RawAUD
Definition: cbs_h264.h:218
AV_PROFILE_H264_HIGH
#define AV_PROFILE_H264_HIGH
Definition: defs.h:113
VAAPIEncodeH264Context::raw_pps
H264RawPPS raw_pps
Definition: vaapi_encode_h264.c:97
SEI_TYPE_BUFFERING_PERIOD
@ SEI_TYPE_BUFFERING_PERIOD
Definition: sei.h:30
SEI_TYPE_USER_DATA_UNREGISTERED
@ SEI_TYPE_USER_DATA_UNREGISTERED
Definition: sei.h:35
AVRational::den
int den
Denominator.
Definition: rational.h:60
VAAPIEncodePicture::is_reference
int is_reference
Definition: vaapi_encode.h:114
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:235
AVCodecContext::profile
int profile
profile
Definition: avcodec.h:1639
AVCodecContext::i_quant_offset
float i_quant_offset
qscale offset between P and I-frames
Definition: avcodec.h:827
H264RawSliceHeader::ref_pic_list_modification_flag_l1
uint8_t ref_pic_list_modification_flag_l1
Definition: cbs_h264.h:338
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:112
AV_CODEC_CAP_DELAY
#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:76
AV_PROFILE_H264_CONSTRAINED_BASELINE
#define AV_PROFILE_H264_CONSTRAINED_BASELINE
Definition: defs.h:110
SEI_TYPE_RECOVERY_POINT
@ SEI_TYPE_RECOVERY_POINT
Definition: sei.h:36
SEI_RECOVERY_POINT
@ SEI_RECOVERY_POINT
Definition: vaapi_encode_h264.c:45
desc
const char * desc
Definition: libsvtav1.c:75
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
VAAPIEncodeH264Context::sei_buffering_period
H264RawSEIBufferingPeriod sei_buffering_period
Definition: vaapi_encode_h264.c:100
AV_PROFILE_H264_HIGH_444
#define AV_PROFILE_H264_HIGH_444
Definition: defs.h:120
H264RawSEIRecoveryPoint
Definition: cbs_h264.h:268
AV_PROFILE_H264_HIGH_444_INTRA
#define AV_PROFILE_H264_HIGH_444_INTRA
Definition: defs.h:122
H264RawSEIPicTiming::cpb_removal_delay
uint32_t cpb_removal_delay
Definition: cbs_h264.h:250
vaapi_encode_type_h264
static const VAAPIEncodeType vaapi_encode_type_h264
Definition: vaapi_encode_h264.c:1171
vaapi_encode_h264_configure
static av_cold int vaapi_encode_h264_configure(AVCodecContext *avctx)
Definition: vaapi_encode_h264.c:1083
VAAPIEncodePicture::input_image
AVFrame * input_image
Definition: vaapi_encode.h:97
VAAPIEncodeSlice::block_size
int block_size
Definition: vaapi_encode.h:69
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
ff_cbs_init
av_cold 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:89
H264RawSliceHeader::modification_of_pic_nums_idc
uint8_t modification_of_pic_nums_idc
Definition: cbs_h264.h:340
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:472
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:251
VAAPIEncodePicture::encode_order
int64_t encode_order
Definition: vaapi_encode.h:77
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
vaapi_encode_h264_defaults
static const FFCodecDefault vaapi_encode_h264_defaults[]
Definition: vaapi_encode_h264.c:1356
PROFILE
#define PROFILE(name, value)
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:618
AV_OPT_TYPE_FLAGS
@ AV_OPT_TYPE_FLAGS
Definition: opt.h:234
h264.h
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
SEIRawUserDataUnregistered::uuid_iso_iec_11578
uint8_t uuid_iso_iec_11578[16]
Definition: cbs_sei.h:41
H264RawHRD::initial_cpb_removal_delay_length_minus1
uint8_t initial_cpb_removal_delay_length_minus1
Definition: cbs_h264.h:52
H264RawSEIBufferingPeriod
Definition: cbs_h264.h:224
VAAPIEncodeH264Context::profile
int profile
Definition: vaapi_encode_h264.c:78
PICTURE_TYPE_P
@ PICTURE_TYPE_P
Definition: vaapi_encode.h:60
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:244
snprintf
#define snprintf
Definition: snprintf.h:34
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
H264RawSliceHeader::pic_parameter_set_id
uint8_t pic_parameter_set_id
Definition: cbs_h264.h:316
AVCodecContext::sample_aspect_ratio
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:642
VAAPIEncodeProfile
Definition: vaapi_encode.h:150
H264RawSliceHeader::abs_diff_pic_num_minus1
int32_t abs_diff_pic_num_minus1
Definition: cbs_h264.h:341
AVCodecContext::compression_level
int compression_level
Definition: avcodec.h:1245
H264RawSlice
Definition: cbs_h264.h:388
H264RawHRD::time_offset_length
uint8_t time_offset_length
Definition: cbs_h264.h:55
vaapi_encode_h264_default_ref_pic_list
static void vaapi_encode_h264_default_ref_pic_list(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodePicture **rpl0, VAAPIEncodePicture **rpl1, int *rpl_size)
Definition: vaapi_encode_h264.c:767
SEI_TIMING
@ SEI_TIMING
Definition: vaapi_encode_h264.c:43
H264RawSPS
Definition: cbs_h264.h:102
H264RawPPS
Definition: cbs_h264.h:171