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