You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1084 lines
38KB

  1. /*
  2. * This file is part of Libav.
  3. *
  4. * Libav 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. * Libav 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 Libav; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include <string.h>
  19. #include <va/va.h>
  20. #include <va/va_enc_h264.h>
  21. #include "libavutil/avassert.h"
  22. #include "libavutil/common.h"
  23. #include "libavutil/internal.h"
  24. #include "libavutil/opt.h"
  25. #include "avcodec.h"
  26. #include "cbs.h"
  27. #include "cbs_h264.h"
  28. #include "h264.h"
  29. #include "h264_sei.h"
  30. #include "internal.h"
  31. #include "vaapi_encode.h"
  32. enum {
  33. SEI_TIMING = 0x01,
  34. SEI_IDENTIFIER = 0x02,
  35. SEI_RECOVERY_POINT = 0x04,
  36. };
  37. // Random (version 4) ISO 11578 UUID.
  38. static const uint8_t vaapi_encode_h264_sei_identifier_uuid[16] = {
  39. 0x59, 0x94, 0x8b, 0x28, 0x11, 0xec, 0x45, 0xaf,
  40. 0x96, 0x75, 0x19, 0xd4, 0x1f, 0xea, 0xa9, 0x4d,
  41. };
  42. typedef struct VAAPIEncodeH264Context {
  43. int mb_width;
  44. int mb_height;
  45. int fixed_qp_idr;
  46. int fixed_qp_p;
  47. int fixed_qp_b;
  48. H264RawAUD aud;
  49. H264RawSPS sps;
  50. H264RawPPS pps;
  51. H264RawSEI sei;
  52. H264RawSlice slice;
  53. H264RawSEIBufferingPeriod buffering_period;
  54. H264RawSEIPicTiming pic_timing;
  55. H264RawSEIRecoveryPoint recovery_point;
  56. H264RawSEIUserDataUnregistered identifier;
  57. char *identifier_string;
  58. int frame_num;
  59. int pic_order_cnt;
  60. int next_frame_num;
  61. int64_t last_idr_frame;
  62. int64_t idr_pic_count;
  63. int primary_pic_type;
  64. int slice_type;
  65. int cpb_delay;
  66. int dpb_delay;
  67. CodedBitstreamContext cbc;
  68. CodedBitstreamFragment current_access_unit;
  69. int aud_needed;
  70. int sei_needed;
  71. int sei_cbr_workaround_needed;
  72. } VAAPIEncodeH264Context;
  73. typedef struct VAAPIEncodeH264Options {
  74. int qp;
  75. int quality;
  76. int low_power;
  77. int aud;
  78. int sei;
  79. int profile;
  80. int level;
  81. } VAAPIEncodeH264Options;
  82. static int vaapi_encode_h264_write_access_unit(AVCodecContext *avctx,
  83. char *data, size_t *data_len,
  84. CodedBitstreamFragment *au)
  85. {
  86. VAAPIEncodeContext *ctx = avctx->priv_data;
  87. VAAPIEncodeH264Context *priv = ctx->priv_data;
  88. int err;
  89. err = ff_cbs_write_fragment_data(&priv->cbc, au);
  90. if (err < 0) {
  91. av_log(avctx, AV_LOG_ERROR, "Failed to write packed header.\n");
  92. return err;
  93. }
  94. if (*data_len < 8 * au->data_size - au->data_bit_padding) {
  95. av_log(avctx, AV_LOG_ERROR, "Access unit too large: "
  96. "%zu < %zu.\n", *data_len,
  97. 8 * au->data_size - au->data_bit_padding);
  98. return AVERROR(ENOSPC);
  99. }
  100. memcpy(data, au->data, au->data_size);
  101. *data_len = 8 * au->data_size - au->data_bit_padding;
  102. return 0;
  103. }
  104. static int vaapi_encode_h264_add_nal(AVCodecContext *avctx,
  105. CodedBitstreamFragment *au,
  106. void *nal_unit)
  107. {
  108. VAAPIEncodeContext *ctx = avctx->priv_data;
  109. VAAPIEncodeH264Context *priv = ctx->priv_data;
  110. H264RawNALUnitHeader *header = nal_unit;
  111. int err;
  112. err = ff_cbs_insert_unit_content(&priv->cbc, au, -1,
  113. header->nal_unit_type, nal_unit);
  114. if (err < 0) {
  115. av_log(avctx, AV_LOG_ERROR, "Failed to add NAL unit: "
  116. "type = %d.\n", header->nal_unit_type);
  117. return err;
  118. }
  119. return 0;
  120. }
  121. static int vaapi_encode_h264_write_sequence_header(AVCodecContext *avctx,
  122. char *data, size_t *data_len)
  123. {
  124. VAAPIEncodeContext *ctx = avctx->priv_data;
  125. VAAPIEncodeH264Context *priv = ctx->priv_data;
  126. CodedBitstreamFragment *au = &priv->current_access_unit;
  127. int err;
  128. if (priv->aud_needed) {
  129. err = vaapi_encode_h264_add_nal(avctx, au, &priv->aud);
  130. if (err < 0)
  131. goto fail;
  132. priv->aud_needed = 0;
  133. }
  134. err = vaapi_encode_h264_add_nal(avctx, au, &priv->sps);
  135. if (err < 0)
  136. goto fail;
  137. err = vaapi_encode_h264_add_nal(avctx, au, &priv->pps);
  138. if (err < 0)
  139. goto fail;
  140. err = vaapi_encode_h264_write_access_unit(avctx, data, data_len, au);
  141. fail:
  142. ff_cbs_fragment_uninit(&priv->cbc, au);
  143. return err;
  144. }
  145. static int vaapi_encode_h264_write_slice_header(AVCodecContext *avctx,
  146. VAAPIEncodePicture *pic,
  147. VAAPIEncodeSlice *slice,
  148. char *data, size_t *data_len)
  149. {
  150. VAAPIEncodeContext *ctx = avctx->priv_data;
  151. VAAPIEncodeH264Context *priv = ctx->priv_data;
  152. CodedBitstreamFragment *au = &priv->current_access_unit;
  153. int err;
  154. if (priv->aud_needed) {
  155. err = vaapi_encode_h264_add_nal(avctx, au, &priv->aud);
  156. if (err < 0)
  157. goto fail;
  158. priv->aud_needed = 0;
  159. }
  160. err = vaapi_encode_h264_add_nal(avctx, au, &priv->slice);
  161. if (err < 0)
  162. goto fail;
  163. err = vaapi_encode_h264_write_access_unit(avctx, data, data_len, au);
  164. fail:
  165. ff_cbs_fragment_uninit(&priv->cbc, au);
  166. return err;
  167. }
  168. static int vaapi_encode_h264_write_extra_header(AVCodecContext *avctx,
  169. VAAPIEncodePicture *pic,
  170. int index, int *type,
  171. char *data, size_t *data_len)
  172. {
  173. VAAPIEncodeContext *ctx = avctx->priv_data;
  174. VAAPIEncodeH264Context *priv = ctx->priv_data;
  175. VAAPIEncodeH264Options *opt = ctx->codec_options;
  176. CodedBitstreamFragment *au = &priv->current_access_unit;
  177. int err, i;
  178. if (priv->sei_needed) {
  179. if (priv->aud_needed) {
  180. err = vaapi_encode_h264_add_nal(avctx, au, &priv->aud);
  181. if (err < 0)
  182. goto fail;
  183. priv->aud_needed = 0;
  184. }
  185. memset(&priv->sei, 0, sizeof(priv->sei));
  186. priv->sei.nal_unit_header.nal_unit_type = H264_NAL_SEI;
  187. i = 0;
  188. if (pic->encode_order == 0 && opt->sei & SEI_IDENTIFIER) {
  189. priv->sei.payload[i].payload_type = H264_SEI_TYPE_USER_DATA_UNREGISTERED;
  190. priv->sei.payload[i].payload.user_data_unregistered = priv->identifier;
  191. ++i;
  192. }
  193. if (opt->sei & SEI_TIMING) {
  194. if (pic->type == PICTURE_TYPE_IDR) {
  195. priv->sei.payload[i].payload_type = H264_SEI_TYPE_BUFFERING_PERIOD;
  196. priv->sei.payload[i].payload.buffering_period = priv->buffering_period;
  197. ++i;
  198. }
  199. priv->sei.payload[i].payload_type = H264_SEI_TYPE_PIC_TIMING;
  200. priv->sei.payload[i].payload.pic_timing = priv->pic_timing;
  201. ++i;
  202. }
  203. if (opt->sei & SEI_RECOVERY_POINT && pic->type == PICTURE_TYPE_I) {
  204. priv->sei.payload[i].payload_type = H264_SEI_TYPE_RECOVERY_POINT;
  205. priv->sei.payload[i].payload.recovery_point = priv->recovery_point;
  206. ++i;
  207. }
  208. priv->sei.payload_count = i;
  209. av_assert0(priv->sei.payload_count > 0);
  210. err = vaapi_encode_h264_add_nal(avctx, au, &priv->sei);
  211. if (err < 0)
  212. goto fail;
  213. priv->sei_needed = 0;
  214. err = vaapi_encode_h264_write_access_unit(avctx, data, data_len, au);
  215. if (err < 0)
  216. goto fail;
  217. ff_cbs_fragment_uninit(&priv->cbc, au);
  218. *type = VAEncPackedHeaderRawData;
  219. return 0;
  220. #if !HAVE_VAAPI_1
  221. } else if (priv->sei_cbr_workaround_needed) {
  222. // Insert a zero-length header using the old SEI type. This is
  223. // required to avoid triggering broken behaviour on Intel platforms
  224. // in CBR mode where an invalid SEI message is generated by the
  225. // driver and inserted into the stream.
  226. *data_len = 0;
  227. *type = VAEncPackedHeaderH264_SEI;
  228. priv->sei_cbr_workaround_needed = 0;
  229. return 0;
  230. #endif
  231. } else {
  232. return AVERROR_EOF;
  233. }
  234. fail:
  235. ff_cbs_fragment_uninit(&priv->cbc, au);
  236. return err;
  237. }
  238. static int vaapi_encode_h264_init_sequence_params(AVCodecContext *avctx)
  239. {
  240. VAAPIEncodeContext *ctx = avctx->priv_data;
  241. VAAPIEncodeH264Context *priv = ctx->priv_data;
  242. VAAPIEncodeH264Options *opt = ctx->codec_options;
  243. H264RawSPS *sps = &priv->sps;
  244. H264RawPPS *pps = &priv->pps;
  245. VAEncSequenceParameterBufferH264 *vseq = ctx->codec_sequence_params;
  246. VAEncPictureParameterBufferH264 *vpic = ctx->codec_picture_params;
  247. memset(&priv->current_access_unit, 0,
  248. sizeof(priv->current_access_unit));
  249. memset(sps, 0, sizeof(*sps));
  250. memset(pps, 0, sizeof(*pps));
  251. sps->nal_unit_header.nal_ref_idc = 3;
  252. sps->nal_unit_header.nal_unit_type = H264_NAL_SPS;
  253. sps->profile_idc = avctx->profile & 0xff;
  254. sps->constraint_set1_flag =
  255. !!(avctx->profile & FF_PROFILE_H264_CONSTRAINED);
  256. sps->constraint_set3_flag =
  257. !!(avctx->profile & FF_PROFILE_H264_INTRA);
  258. sps->level_idc = avctx->level;
  259. sps->seq_parameter_set_id = 0;
  260. sps->chroma_format_idc = 1;
  261. sps->log2_max_frame_num_minus4 = 4;
  262. sps->pic_order_cnt_type = 0;
  263. sps->log2_max_pic_order_cnt_lsb_minus4 =
  264. av_clip(av_log2(ctx->b_per_p + 1) - 2, 0, 12);
  265. sps->max_num_ref_frames =
  266. (avctx->profile & FF_PROFILE_H264_INTRA) ? 0 :
  267. 1 + (ctx->b_per_p > 0);
  268. sps->pic_width_in_mbs_minus1 = priv->mb_width - 1;
  269. sps->pic_height_in_map_units_minus1 = priv->mb_height - 1;
  270. sps->frame_mbs_only_flag = 1;
  271. sps->direct_8x8_inference_flag = 1;
  272. if (avctx->width != 16 * priv->mb_width ||
  273. avctx->height != 16 * priv->mb_height) {
  274. sps->frame_cropping_flag = 1;
  275. sps->frame_crop_left_offset = 0;
  276. sps->frame_crop_right_offset =
  277. (16 * priv->mb_width - avctx->width) / 2;
  278. sps->frame_crop_top_offset = 0;
  279. sps->frame_crop_bottom_offset =
  280. (16 * priv->mb_height - avctx->height) / 2;
  281. } else {
  282. sps->frame_cropping_flag = 0;
  283. }
  284. sps->vui_parameters_present_flag = 1;
  285. if (avctx->sample_aspect_ratio.num != 0 &&
  286. avctx->sample_aspect_ratio.den != 0) {
  287. static const AVRational sar_idc[] = {
  288. { 0, 0 },
  289. { 1, 1 }, { 12, 11 }, { 10, 11 }, { 16, 11 },
  290. { 40, 33 }, { 24, 11 }, { 20, 11 }, { 32, 11 },
  291. { 80, 33 }, { 18, 11 }, { 15, 11 }, { 64, 33 },
  292. { 160, 99 }, { 4, 3 }, { 3, 2 }, { 2, 1 },
  293. };
  294. int i;
  295. for (i = 0; i < FF_ARRAY_ELEMS(sar_idc); i++) {
  296. if (avctx->sample_aspect_ratio.num == sar_idc[i].num &&
  297. avctx->sample_aspect_ratio.den == sar_idc[i].den) {
  298. sps->vui.aspect_ratio_idc = i;
  299. break;
  300. }
  301. }
  302. if (i >= FF_ARRAY_ELEMS(sar_idc)) {
  303. sps->vui.aspect_ratio_idc = 255;
  304. sps->vui.sar_width = avctx->sample_aspect_ratio.num;
  305. sps->vui.sar_height = avctx->sample_aspect_ratio.den;
  306. }
  307. sps->vui.aspect_ratio_info_present_flag = 1;
  308. }
  309. if (avctx->color_range != AVCOL_RANGE_UNSPECIFIED ||
  310. avctx->color_primaries != AVCOL_PRI_UNSPECIFIED ||
  311. avctx->color_trc != AVCOL_TRC_UNSPECIFIED ||
  312. avctx->colorspace != AVCOL_SPC_UNSPECIFIED) {
  313. sps->vui.video_signal_type_present_flag = 1;
  314. sps->vui.video_format = 5; // Unspecified.
  315. sps->vui.video_full_range_flag =
  316. avctx->color_range == AVCOL_RANGE_JPEG;
  317. if (avctx->color_primaries != AVCOL_PRI_UNSPECIFIED ||
  318. avctx->color_trc != AVCOL_TRC_UNSPECIFIED ||
  319. avctx->colorspace != AVCOL_SPC_UNSPECIFIED) {
  320. sps->vui.colour_description_present_flag = 1;
  321. sps->vui.colour_primaries = avctx->color_primaries;
  322. sps->vui.transfer_characteristics = avctx->color_trc;
  323. sps->vui.matrix_coefficients = avctx->colorspace;
  324. }
  325. } else {
  326. sps->vui.video_format = 5;
  327. sps->vui.video_full_range_flag = 0;
  328. sps->vui.colour_primaries = avctx->color_primaries;
  329. sps->vui.transfer_characteristics = avctx->color_trc;
  330. sps->vui.matrix_coefficients = avctx->colorspace;
  331. }
  332. if (avctx->chroma_sample_location != AVCHROMA_LOC_UNSPECIFIED) {
  333. sps->vui.chroma_loc_info_present_flag = 1;
  334. sps->vui.chroma_sample_loc_type_top_field =
  335. sps->vui.chroma_sample_loc_type_bottom_field =
  336. avctx->chroma_sample_location - 1;
  337. }
  338. sps->vui.timing_info_present_flag = 1;
  339. if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
  340. sps->vui.num_units_in_tick = avctx->framerate.den;
  341. sps->vui.time_scale = 2 * avctx->framerate.num;
  342. sps->vui.fixed_frame_rate_flag = 1;
  343. } else {
  344. sps->vui.num_units_in_tick = avctx->time_base.num;
  345. sps->vui.time_scale = 2 * avctx->time_base.den;
  346. sps->vui.fixed_frame_rate_flag = 0;
  347. }
  348. if (opt->sei & SEI_TIMING) {
  349. H264RawHRD *hrd = &sps->vui.nal_hrd_parameters;
  350. sps->vui.nal_hrd_parameters_present_flag = 1;
  351. hrd->cpb_cnt_minus1 = 0;
  352. // Try to scale these to a sensible range so that the
  353. // golomb encode of the value is not overlong.
  354. hrd->bit_rate_scale =
  355. av_clip_uintp2(av_log2(avctx->bit_rate) - 15 - 6, 4);
  356. hrd->bit_rate_value_minus1[0] =
  357. (avctx->bit_rate >> hrd->bit_rate_scale + 6) - 1;
  358. hrd->cpb_size_scale =
  359. av_clip_uintp2(av_log2(ctx->hrd_params.hrd.buffer_size) - 15 - 4, 4);
  360. hrd->cpb_size_value_minus1[0] =
  361. (ctx->hrd_params.hrd.buffer_size >> hrd->cpb_size_scale + 4) - 1;
  362. // CBR mode as defined for the HRD cannot be achieved without filler
  363. // data, so this flag cannot be set even with VAAPI CBR modes.
  364. hrd->cbr_flag[0] = 0;
  365. hrd->initial_cpb_removal_delay_length_minus1 = 23;
  366. hrd->cpb_removal_delay_length_minus1 = 23;
  367. hrd->dpb_output_delay_length_minus1 = 7;
  368. hrd->time_offset_length = 0;
  369. priv->buffering_period.seq_parameter_set_id = sps->seq_parameter_set_id;
  370. // This calculation can easily overflow 32 bits.
  371. priv->buffering_period.nal.initial_cpb_removal_delay[0] = 90000 *
  372. (uint64_t)ctx->hrd_params.hrd.initial_buffer_fullness /
  373. ctx->hrd_params.hrd.buffer_size;
  374. priv->buffering_period.nal.initial_cpb_removal_delay_offset[0] = 0;
  375. } else {
  376. sps->vui.nal_hrd_parameters_present_flag = 0;
  377. sps->vui.low_delay_hrd_flag = 1 - sps->vui.fixed_frame_rate_flag;
  378. }
  379. sps->vui.bitstream_restriction_flag = 1;
  380. sps->vui.motion_vectors_over_pic_boundaries_flag = 1;
  381. sps->vui.log2_max_mv_length_horizontal = 16;
  382. sps->vui.log2_max_mv_length_vertical = 16;
  383. sps->vui.max_num_reorder_frames = (ctx->b_per_p > 0);
  384. sps->vui.max_dec_frame_buffering = sps->max_num_ref_frames;
  385. pps->nal_unit_header.nal_ref_idc = 3;
  386. pps->nal_unit_header.nal_unit_type = H264_NAL_PPS;
  387. pps->pic_parameter_set_id = 0;
  388. pps->seq_parameter_set_id = 0;
  389. pps->entropy_coding_mode_flag =
  390. !(sps->profile_idc == FF_PROFILE_H264_BASELINE ||
  391. sps->profile_idc == FF_PROFILE_H264_EXTENDED ||
  392. sps->profile_idc == FF_PROFILE_H264_CAVLC_444);
  393. pps->num_ref_idx_l0_default_active_minus1 = 0;
  394. pps->num_ref_idx_l1_default_active_minus1 = 0;
  395. pps->pic_init_qp_minus26 = priv->fixed_qp_idr - 26;
  396. if (sps->profile_idc == FF_PROFILE_H264_BASELINE ||
  397. sps->profile_idc == FF_PROFILE_H264_EXTENDED ||
  398. sps->profile_idc == FF_PROFILE_H264_MAIN) {
  399. pps->more_rbsp_data = 0;
  400. } else {
  401. pps->more_rbsp_data = 1;
  402. pps->transform_8x8_mode_flag = 1;
  403. }
  404. *vseq = (VAEncSequenceParameterBufferH264) {
  405. .seq_parameter_set_id = sps->seq_parameter_set_id,
  406. .level_idc = sps->level_idc,
  407. .intra_period = avctx->gop_size,
  408. .intra_idr_period = avctx->gop_size,
  409. .ip_period = ctx->b_per_p + 1,
  410. .bits_per_second = avctx->bit_rate,
  411. .max_num_ref_frames = sps->max_num_ref_frames,
  412. .picture_width_in_mbs = sps->pic_width_in_mbs_minus1 + 1,
  413. .picture_height_in_mbs = sps->pic_height_in_map_units_minus1 + 1,
  414. .seq_fields.bits = {
  415. .chroma_format_idc = sps->chroma_format_idc,
  416. .frame_mbs_only_flag = sps->frame_mbs_only_flag,
  417. .mb_adaptive_frame_field_flag = sps->mb_adaptive_frame_field_flag,
  418. .seq_scaling_matrix_present_flag = sps->seq_scaling_matrix_present_flag,
  419. .direct_8x8_inference_flag = sps->direct_8x8_inference_flag,
  420. .log2_max_frame_num_minus4 = sps->log2_max_frame_num_minus4,
  421. .pic_order_cnt_type = sps->pic_order_cnt_type,
  422. .log2_max_pic_order_cnt_lsb_minus4 = sps->log2_max_pic_order_cnt_lsb_minus4,
  423. .delta_pic_order_always_zero_flag = sps->delta_pic_order_always_zero_flag,
  424. },
  425. .bit_depth_luma_minus8 = sps->bit_depth_luma_minus8,
  426. .bit_depth_chroma_minus8 = sps->bit_depth_chroma_minus8,
  427. .frame_cropping_flag = sps->frame_cropping_flag,
  428. .frame_crop_left_offset = sps->frame_crop_left_offset,
  429. .frame_crop_right_offset = sps->frame_crop_right_offset,
  430. .frame_crop_top_offset = sps->frame_crop_top_offset,
  431. .frame_crop_bottom_offset = sps->frame_crop_bottom_offset,
  432. .vui_parameters_present_flag = sps->vui_parameters_present_flag,
  433. .vui_fields.bits = {
  434. .aspect_ratio_info_present_flag = sps->vui.aspect_ratio_info_present_flag,
  435. .timing_info_present_flag = sps->vui.timing_info_present_flag,
  436. .bitstream_restriction_flag = sps->vui.bitstream_restriction_flag,
  437. .log2_max_mv_length_horizontal = sps->vui.log2_max_mv_length_horizontal,
  438. .log2_max_mv_length_vertical = sps->vui.log2_max_mv_length_vertical,
  439. },
  440. .aspect_ratio_idc = sps->vui.aspect_ratio_idc,
  441. .sar_width = sps->vui.sar_width,
  442. .sar_height = sps->vui.sar_height,
  443. .num_units_in_tick = sps->vui.num_units_in_tick,
  444. .time_scale = sps->vui.time_scale,
  445. };
  446. *vpic = (VAEncPictureParameterBufferH264) {
  447. .CurrPic = {
  448. .picture_id = VA_INVALID_ID,
  449. .flags = VA_PICTURE_H264_INVALID,
  450. },
  451. .coded_buf = VA_INVALID_ID,
  452. .pic_parameter_set_id = pps->pic_parameter_set_id,
  453. .seq_parameter_set_id = pps->seq_parameter_set_id,
  454. .pic_init_qp = pps->pic_init_qp_minus26 + 26,
  455. .num_ref_idx_l0_active_minus1 = pps->num_ref_idx_l0_default_active_minus1,
  456. .num_ref_idx_l1_active_minus1 = pps->num_ref_idx_l1_default_active_minus1,
  457. .chroma_qp_index_offset = pps->chroma_qp_index_offset,
  458. .second_chroma_qp_index_offset = pps->second_chroma_qp_index_offset,
  459. .pic_fields.bits = {
  460. .entropy_coding_mode_flag = pps->entropy_coding_mode_flag,
  461. .weighted_pred_flag = pps->weighted_pred_flag,
  462. .weighted_bipred_idc = pps->weighted_bipred_idc,
  463. .constrained_intra_pred_flag = pps->constrained_intra_pred_flag,
  464. .transform_8x8_mode_flag = pps->transform_8x8_mode_flag,
  465. .deblocking_filter_control_present_flag =
  466. pps->deblocking_filter_control_present_flag,
  467. .redundant_pic_cnt_present_flag = pps->redundant_pic_cnt_present_flag,
  468. .pic_order_present_flag =
  469. pps->bottom_field_pic_order_in_frame_present_flag,
  470. .pic_scaling_matrix_present_flag = pps->pic_scaling_matrix_present_flag,
  471. },
  472. };
  473. return 0;
  474. }
  475. static int vaapi_encode_h264_init_picture_params(AVCodecContext *avctx,
  476. VAAPIEncodePicture *pic)
  477. {
  478. VAAPIEncodeContext *ctx = avctx->priv_data;
  479. VAAPIEncodeH264Context *priv = ctx->priv_data;
  480. VAAPIEncodeH264Options *opt = ctx->codec_options;
  481. H264RawSPS *sps = &priv->sps;
  482. VAEncPictureParameterBufferH264 *vpic = pic->codec_picture_params;
  483. int i;
  484. memset(&priv->current_access_unit, 0,
  485. sizeof(priv->current_access_unit));
  486. if (pic->type == PICTURE_TYPE_IDR) {
  487. av_assert0(pic->display_order == pic->encode_order);
  488. priv->frame_num = 0;
  489. priv->next_frame_num = 1;
  490. priv->cpb_delay = 0;
  491. priv->last_idr_frame = pic->display_order;
  492. ++priv->idr_pic_count;
  493. priv->slice_type = 7;
  494. priv->primary_pic_type = 0;
  495. } else {
  496. priv->frame_num = priv->next_frame_num;
  497. if (pic->type != PICTURE_TYPE_B) {
  498. // Reference picture, so frame_num advances.
  499. priv->next_frame_num = (priv->frame_num + 1) &
  500. ((1 << (4 + sps->log2_max_frame_num_minus4)) - 1);
  501. }
  502. ++priv->cpb_delay;
  503. if (pic->type == PICTURE_TYPE_I) {
  504. priv->slice_type = 7;
  505. priv->primary_pic_type = 0;
  506. } else if (pic->type == PICTURE_TYPE_P) {
  507. priv->slice_type = 5;
  508. priv->primary_pic_type = 1;
  509. } else {
  510. priv->slice_type = 6;
  511. priv->primary_pic_type = 2;
  512. }
  513. }
  514. priv->pic_order_cnt = pic->display_order - priv->last_idr_frame;
  515. priv->dpb_delay = pic->display_order - pic->encode_order + 1;
  516. if (opt->aud) {
  517. priv->aud_needed = 1;
  518. priv->aud.nal_unit_header.nal_unit_type = H264_NAL_AUD;
  519. priv->aud.primary_pic_type = priv->primary_pic_type;
  520. } else {
  521. priv->aud_needed = 0;
  522. }
  523. if (opt->sei & SEI_IDENTIFIER && pic->encode_order == 0)
  524. priv->sei_needed = 1;
  525. #if !HAVE_VAAPI_1
  526. if (ctx->va_rc_mode == VA_RC_CBR)
  527. priv->sei_cbr_workaround_needed = 1;
  528. #endif
  529. if (opt->sei & SEI_TIMING) {
  530. memset(&priv->pic_timing, 0, sizeof(priv->pic_timing));
  531. priv->pic_timing.cpb_removal_delay = 2 * priv->cpb_delay;
  532. priv->pic_timing.dpb_output_delay = 2 * priv->dpb_delay;
  533. priv->sei_needed = 1;
  534. }
  535. if (opt->sei & SEI_RECOVERY_POINT && pic->type == PICTURE_TYPE_I) {
  536. priv->recovery_point.recovery_frame_cnt = 0;
  537. priv->recovery_point.exact_match_flag = 1;
  538. priv->recovery_point.broken_link_flag = ctx->b_per_p > 0;
  539. priv->sei_needed = 1;
  540. }
  541. vpic->CurrPic = (VAPictureH264) {
  542. .picture_id = pic->recon_surface,
  543. .frame_idx = priv->frame_num,
  544. .flags = 0,
  545. .TopFieldOrderCnt = priv->pic_order_cnt,
  546. .BottomFieldOrderCnt = priv->pic_order_cnt,
  547. };
  548. for (i = 0; i < pic->nb_refs; i++) {
  549. VAAPIEncodePicture *ref = pic->refs[i];
  550. unsigned int frame_num = (ref->encode_order - priv->last_idr_frame) &
  551. ((1 << (4 + sps->log2_max_frame_num_minus4)) - 1);
  552. unsigned int pic_order_cnt = ref->display_order - priv->last_idr_frame;
  553. av_assert0(ref && ref->encode_order < pic->encode_order);
  554. vpic->ReferenceFrames[i] = (VAPictureH264) {
  555. .picture_id = ref->recon_surface,
  556. .frame_idx = frame_num,
  557. .flags = VA_PICTURE_H264_SHORT_TERM_REFERENCE,
  558. .TopFieldOrderCnt = pic_order_cnt,
  559. .BottomFieldOrderCnt = pic_order_cnt,
  560. };
  561. }
  562. for (; i < FF_ARRAY_ELEMS(vpic->ReferenceFrames); i++) {
  563. vpic->ReferenceFrames[i] = (VAPictureH264) {
  564. .picture_id = VA_INVALID_ID,
  565. .flags = VA_PICTURE_H264_INVALID,
  566. };
  567. }
  568. vpic->coded_buf = pic->output_buffer;
  569. vpic->frame_num = priv->frame_num;
  570. vpic->pic_fields.bits.idr_pic_flag = (pic->type == PICTURE_TYPE_IDR);
  571. vpic->pic_fields.bits.reference_pic_flag = (pic->type != PICTURE_TYPE_B);
  572. pic->nb_slices = 1;
  573. return 0;
  574. }
  575. static int vaapi_encode_h264_init_slice_params(AVCodecContext *avctx,
  576. VAAPIEncodePicture *pic,
  577. VAAPIEncodeSlice *slice)
  578. {
  579. VAAPIEncodeContext *ctx = avctx->priv_data;
  580. VAAPIEncodeH264Context *priv = ctx->priv_data;
  581. H264RawSPS *sps = &priv->sps;
  582. H264RawPPS *pps = &priv->pps;
  583. H264RawSliceHeader *sh = &priv->slice.header;
  584. VAEncPictureParameterBufferH264 *vpic = pic->codec_picture_params;
  585. VAEncSliceParameterBufferH264 *vslice = slice->codec_slice_params;
  586. int i;
  587. if (pic->type == PICTURE_TYPE_IDR) {
  588. sh->nal_unit_header.nal_unit_type = H264_NAL_IDR_SLICE;
  589. sh->nal_unit_header.nal_ref_idc = 3;
  590. } else {
  591. sh->nal_unit_header.nal_unit_type = H264_NAL_SLICE;
  592. sh->nal_unit_header.nal_ref_idc = pic->type != PICTURE_TYPE_B;
  593. }
  594. // Only one slice per frame.
  595. sh->first_mb_in_slice = 0;
  596. sh->slice_type = priv->slice_type;
  597. sh->pic_parameter_set_id = pps->pic_parameter_set_id;
  598. sh->frame_num = priv->frame_num;
  599. sh->idr_pic_id = priv->idr_pic_count;
  600. sh->pic_order_cnt_lsb = priv->pic_order_cnt &
  601. ((1 << (4 + sps->log2_max_pic_order_cnt_lsb_minus4)) - 1);
  602. sh->direct_spatial_mv_pred_flag = 1;
  603. if (pic->type == PICTURE_TYPE_B)
  604. sh->slice_qp_delta = priv->fixed_qp_b - (pps->pic_init_qp_minus26 + 26);
  605. else if (pic->type == PICTURE_TYPE_P)
  606. sh->slice_qp_delta = priv->fixed_qp_p - (pps->pic_init_qp_minus26 + 26);
  607. else
  608. sh->slice_qp_delta = priv->fixed_qp_idr - (pps->pic_init_qp_minus26 + 26);
  609. vslice->macroblock_address = sh->first_mb_in_slice;
  610. vslice->num_macroblocks = priv->mb_width * priv->mb_height;
  611. vslice->macroblock_info = VA_INVALID_ID;
  612. vslice->slice_type = sh->slice_type % 5;
  613. vslice->pic_parameter_set_id = sh->pic_parameter_set_id;
  614. vslice->idr_pic_id = sh->idr_pic_id;
  615. vslice->pic_order_cnt_lsb = sh->pic_order_cnt_lsb;
  616. vslice->direct_spatial_mv_pred_flag = sh->direct_spatial_mv_pred_flag;
  617. for (i = 0; i < FF_ARRAY_ELEMS(vslice->RefPicList0); i++) {
  618. vslice->RefPicList0[i].picture_id = VA_INVALID_ID;
  619. vslice->RefPicList0[i].flags = VA_PICTURE_H264_INVALID;
  620. vslice->RefPicList1[i].picture_id = VA_INVALID_ID;
  621. vslice->RefPicList1[i].flags = VA_PICTURE_H264_INVALID;
  622. }
  623. av_assert0(pic->nb_refs <= 2);
  624. if (pic->nb_refs >= 1) {
  625. // Backward reference for P- or B-frame.
  626. av_assert0(pic->type == PICTURE_TYPE_P ||
  627. pic->type == PICTURE_TYPE_B);
  628. vslice->RefPicList0[0] = vpic->ReferenceFrames[0];
  629. }
  630. if (pic->nb_refs >= 2) {
  631. // Forward reference for B-frame.
  632. av_assert0(pic->type == PICTURE_TYPE_B);
  633. vslice->RefPicList1[0] = vpic->ReferenceFrames[1];
  634. }
  635. vslice->slice_qp_delta = sh->slice_qp_delta;
  636. return 0;
  637. }
  638. static av_cold int vaapi_encode_h264_configure(AVCodecContext *avctx)
  639. {
  640. VAAPIEncodeContext *ctx = avctx->priv_data;
  641. VAAPIEncodeH264Context *priv = ctx->priv_data;
  642. VAAPIEncodeH264Options *opt = ctx->codec_options;
  643. int err;
  644. err = ff_cbs_init(&priv->cbc, AV_CODEC_ID_H264, avctx);
  645. if (err < 0)
  646. return err;
  647. priv->mb_width = FFALIGN(avctx->width, 16) / 16;
  648. priv->mb_height = FFALIGN(avctx->height, 16) / 16;
  649. if (ctx->va_rc_mode == VA_RC_CQP) {
  650. priv->fixed_qp_p = opt->qp;
  651. if (avctx->i_quant_factor > 0.0)
  652. priv->fixed_qp_idr = (int)((priv->fixed_qp_p * avctx->i_quant_factor +
  653. avctx->i_quant_offset) + 0.5);
  654. else
  655. priv->fixed_qp_idr = priv->fixed_qp_p;
  656. if (avctx->b_quant_factor > 0.0)
  657. priv->fixed_qp_b = (int)((priv->fixed_qp_p * avctx->b_quant_factor +
  658. avctx->b_quant_offset) + 0.5);
  659. else
  660. priv->fixed_qp_b = priv->fixed_qp_p;
  661. opt->sei &= ~SEI_TIMING;
  662. av_log(avctx, AV_LOG_DEBUG, "Using fixed QP = "
  663. "%d / %d / %d for IDR- / P- / B-frames.\n",
  664. priv->fixed_qp_idr, priv->fixed_qp_p, priv->fixed_qp_b);
  665. } else if (ctx->va_rc_mode == VA_RC_CBR ||
  666. ctx->va_rc_mode == VA_RC_VBR) {
  667. // These still need to be set for pic_init_qp/slice_qp_delta.
  668. priv->fixed_qp_idr = 26;
  669. priv->fixed_qp_p = 26;
  670. priv->fixed_qp_b = 26;
  671. av_log(avctx, AV_LOG_DEBUG, "Using %s-bitrate = %d bps.\n",
  672. ctx->va_rc_mode == VA_RC_CBR ? "constant" : "variable",
  673. avctx->bit_rate);
  674. } else {
  675. av_assert0(0 && "Invalid RC mode.");
  676. }
  677. if (avctx->compression_level == FF_COMPRESSION_DEFAULT)
  678. avctx->compression_level = opt->quality;
  679. if (opt->sei & SEI_IDENTIFIER) {
  680. const char *lavc = LIBAVCODEC_IDENT;
  681. const char *vaapi = VA_VERSION_S;
  682. const char *driver;
  683. int len;
  684. memcpy(priv->identifier.uuid_iso_iec_11578,
  685. vaapi_encode_h264_sei_identifier_uuid,
  686. sizeof(priv->identifier.uuid_iso_iec_11578));
  687. driver = vaQueryVendorString(ctx->hwctx->display);
  688. if (!driver)
  689. driver = "unknown driver";
  690. len = snprintf(NULL, 0, "%s / VAAPI %s / %s", lavc, vaapi, driver);
  691. if (len >= 0) {
  692. priv->identifier_string = av_malloc(len + 1);
  693. if (!priv->identifier_string)
  694. return AVERROR(ENOMEM);
  695. snprintf(priv->identifier_string, len + 1,
  696. "%s / VAAPI %s / %s", lavc, vaapi, driver);
  697. priv->identifier.data = priv->identifier_string;
  698. priv->identifier.data_length = len + 1;
  699. }
  700. }
  701. return 0;
  702. }
  703. static const VAAPIEncodeType vaapi_encode_type_h264 = {
  704. .priv_data_size = sizeof(VAAPIEncodeH264Context),
  705. .configure = &vaapi_encode_h264_configure,
  706. .sequence_params_size = sizeof(VAEncSequenceParameterBufferH264),
  707. .init_sequence_params = &vaapi_encode_h264_init_sequence_params,
  708. .picture_params_size = sizeof(VAEncPictureParameterBufferH264),
  709. .init_picture_params = &vaapi_encode_h264_init_picture_params,
  710. .slice_params_size = sizeof(VAEncSliceParameterBufferH264),
  711. .init_slice_params = &vaapi_encode_h264_init_slice_params,
  712. .sequence_header_type = VAEncPackedHeaderSequence,
  713. .write_sequence_header = &vaapi_encode_h264_write_sequence_header,
  714. .slice_header_type = VAEncPackedHeaderH264_Slice,
  715. .write_slice_header = &vaapi_encode_h264_write_slice_header,
  716. .write_extra_header = &vaapi_encode_h264_write_extra_header,
  717. };
  718. static av_cold int vaapi_encode_h264_init(AVCodecContext *avctx)
  719. {
  720. VAAPIEncodeContext *ctx = avctx->priv_data;
  721. VAAPIEncodeH264Options *opt =
  722. (VAAPIEncodeH264Options*)ctx->codec_options_data;
  723. ctx->codec = &vaapi_encode_type_h264;
  724. if (avctx->profile == FF_PROFILE_UNKNOWN)
  725. avctx->profile = opt->profile;
  726. if (avctx->level == FF_LEVEL_UNKNOWN)
  727. avctx->level = opt->level;
  728. switch (avctx->profile) {
  729. case FF_PROFILE_H264_BASELINE:
  730. av_log(avctx, AV_LOG_WARNING, "H.264 baseline profile is not "
  731. "supported, using constrained baseline profile instead.\n");
  732. avctx->profile = FF_PROFILE_H264_CONSTRAINED_BASELINE;
  733. case FF_PROFILE_H264_CONSTRAINED_BASELINE:
  734. ctx->va_profile = VAProfileH264ConstrainedBaseline;
  735. break;
  736. case FF_PROFILE_H264_MAIN:
  737. ctx->va_profile = VAProfileH264Main;
  738. break;
  739. case FF_PROFILE_H264_EXTENDED:
  740. av_log(avctx, AV_LOG_ERROR, "H.264 extended profile "
  741. "is not supported.\n");
  742. return AVERROR_PATCHWELCOME;
  743. case FF_PROFILE_UNKNOWN:
  744. case FF_PROFILE_H264_HIGH:
  745. ctx->va_profile = VAProfileH264High;
  746. break;
  747. case FF_PROFILE_H264_HIGH_10:
  748. case FF_PROFILE_H264_HIGH_10_INTRA:
  749. av_log(avctx, AV_LOG_ERROR, "H.264 10-bit profiles "
  750. "are not supported.\n");
  751. return AVERROR_PATCHWELCOME;
  752. case FF_PROFILE_H264_HIGH_422:
  753. case FF_PROFILE_H264_HIGH_422_INTRA:
  754. case FF_PROFILE_H264_HIGH_444:
  755. case FF_PROFILE_H264_HIGH_444_PREDICTIVE:
  756. case FF_PROFILE_H264_HIGH_444_INTRA:
  757. case FF_PROFILE_H264_CAVLC_444:
  758. av_log(avctx, AV_LOG_ERROR, "H.264 non-4:2:0 profiles "
  759. "are not supported.\n");
  760. return AVERROR_PATCHWELCOME;
  761. default:
  762. av_log(avctx, AV_LOG_ERROR, "Unknown H.264 profile %d.\n",
  763. avctx->profile);
  764. return AVERROR(EINVAL);
  765. }
  766. if (opt->low_power) {
  767. #if VA_CHECK_VERSION(0, 39, 2)
  768. ctx->va_entrypoint = VAEntrypointEncSliceLP;
  769. #else
  770. av_log(avctx, AV_LOG_ERROR, "Low-power encoding is not "
  771. "supported with this VAAPI version.\n");
  772. return AVERROR(EINVAL);
  773. #endif
  774. } else {
  775. ctx->va_entrypoint = VAEntrypointEncSlice;
  776. }
  777. // Only 8-bit encode is supported.
  778. ctx->va_rt_format = VA_RT_FORMAT_YUV420;
  779. if (avctx->bit_rate > 0) {
  780. if (avctx->rc_max_rate == avctx->bit_rate)
  781. ctx->va_rc_mode = VA_RC_CBR;
  782. else
  783. ctx->va_rc_mode = VA_RC_VBR;
  784. } else
  785. ctx->va_rc_mode = VA_RC_CQP;
  786. ctx->va_packed_headers =
  787. VA_ENC_PACKED_HEADER_SEQUENCE | // SPS and PPS.
  788. VA_ENC_PACKED_HEADER_SLICE | // Slice headers.
  789. VA_ENC_PACKED_HEADER_MISC; // SEI.
  790. ctx->surface_width = FFALIGN(avctx->width, 16);
  791. ctx->surface_height = FFALIGN(avctx->height, 16);
  792. return ff_vaapi_encode_init(avctx);
  793. }
  794. static av_cold int vaapi_encode_h264_close(AVCodecContext *avctx)
  795. {
  796. VAAPIEncodeContext *ctx = avctx->priv_data;
  797. VAAPIEncodeH264Context *priv = ctx->priv_data;
  798. if (priv) {
  799. ff_cbs_close(&priv->cbc);
  800. av_freep(&priv->identifier_string);
  801. }
  802. return ff_vaapi_encode_close(avctx);
  803. }
  804. #define OFFSET(x) (offsetof(VAAPIEncodeContext, codec_options_data) + \
  805. offsetof(VAAPIEncodeH264Options, x))
  806. #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
  807. static const AVOption vaapi_encode_h264_options[] = {
  808. { "qp", "Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)",
  809. OFFSET(qp), AV_OPT_TYPE_INT, { .i64 = 20 }, 0, 52, FLAGS },
  810. { "quality", "Set encode quality (trades off against speed, higher is faster)",
  811. OFFSET(quality), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 8, FLAGS },
  812. { "low_power", "Use low-power encoding mode (experimental: only supported "
  813. "on some platforms, does not support all features)",
  814. OFFSET(low_power), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, FLAGS },
  815. { "aud", "Include AUD",
  816. OFFSET(aud), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, FLAGS },
  817. { "sei", "Set SEI to include",
  818. OFFSET(sei), AV_OPT_TYPE_FLAGS,
  819. { .i64 = SEI_IDENTIFIER | SEI_TIMING | SEI_RECOVERY_POINT },
  820. 0, INT_MAX, FLAGS, "sei" },
  821. { "identifier", "Include encoder version identifier",
  822. 0, AV_OPT_TYPE_CONST, { .i64 = SEI_IDENTIFIER },
  823. INT_MIN, INT_MAX, FLAGS, "sei" },
  824. { "timing", "Include timing parameters (buffering_period and pic_timing)",
  825. 0, AV_OPT_TYPE_CONST, { .i64 = SEI_TIMING },
  826. INT_MIN, INT_MAX, FLAGS, "sei" },
  827. { "recovery_point", "Include recovery points where appropriate",
  828. 0, AV_OPT_TYPE_CONST, { .i64 = SEI_RECOVERY_POINT },
  829. INT_MIN, INT_MAX, FLAGS, "sei" },
  830. { "profile", "Set profile (profile_idc and constraint_set*_flag)",
  831. OFFSET(profile), AV_OPT_TYPE_INT,
  832. { .i64 = FF_PROFILE_H264_HIGH }, 0x0000, 0xffff, FLAGS, "profile" },
  833. #define PROFILE(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
  834. { .i64 = value }, 0, 0, FLAGS, "profile"
  835. { PROFILE("constrained_baseline", FF_PROFILE_H264_CONSTRAINED_BASELINE) },
  836. { PROFILE("main", FF_PROFILE_H264_MAIN) },
  837. { PROFILE("high", FF_PROFILE_H264_HIGH) },
  838. #undef PROFILE
  839. { "level", "Set level (level_idc)",
  840. OFFSET(level), AV_OPT_TYPE_INT,
  841. { .i64 = 51 }, 0x00, 0xff, FLAGS, "level" },
  842. #define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
  843. { .i64 = value }, 0, 0, FLAGS, "level"
  844. { LEVEL("1", 10) },
  845. { LEVEL("1.1", 11) },
  846. { LEVEL("1.2", 12) },
  847. { LEVEL("1.3", 13) },
  848. { LEVEL("2", 20) },
  849. { LEVEL("2.1", 21) },
  850. { LEVEL("2.2", 22) },
  851. { LEVEL("3", 30) },
  852. { LEVEL("3.1", 31) },
  853. { LEVEL("3.2", 32) },
  854. { LEVEL("4", 40) },
  855. { LEVEL("4.1", 41) },
  856. { LEVEL("4.2", 42) },
  857. { LEVEL("5", 50) },
  858. { LEVEL("5.1", 51) },
  859. { LEVEL("5.2", 52) },
  860. { LEVEL("6", 60) },
  861. { LEVEL("6.1", 61) },
  862. { LEVEL("6.2", 62) },
  863. #undef LEVEL
  864. { NULL },
  865. };
  866. static const AVCodecDefault vaapi_encode_h264_defaults[] = {
  867. { "b", "0" },
  868. { "bf", "2" },
  869. { "g", "120" },
  870. { "i_qfactor", "1.0" },
  871. { "i_qoffset", "0.0" },
  872. { "b_qfactor", "1.2" },
  873. { "b_qoffset", "0.0" },
  874. { "qmin", "0" },
  875. { NULL },
  876. };
  877. static const AVClass vaapi_encode_h264_class = {
  878. .class_name = "h264_vaapi",
  879. .item_name = av_default_item_name,
  880. .option = vaapi_encode_h264_options,
  881. .version = LIBAVUTIL_VERSION_INT,
  882. };
  883. AVCodec ff_h264_vaapi_encoder = {
  884. .name = "h264_vaapi",
  885. .long_name = NULL_IF_CONFIG_SMALL("H.264/AVC (VAAPI)"),
  886. .type = AVMEDIA_TYPE_VIDEO,
  887. .id = AV_CODEC_ID_H264,
  888. .priv_data_size = (sizeof(VAAPIEncodeContext) +
  889. sizeof(VAAPIEncodeH264Options)),
  890. .init = &vaapi_encode_h264_init,
  891. .encode2 = &ff_vaapi_encode2,
  892. .close = &vaapi_encode_h264_close,
  893. .priv_class = &vaapi_encode_h264_class,
  894. .capabilities = AV_CODEC_CAP_DELAY,
  895. .defaults = vaapi_encode_h264_defaults,
  896. .pix_fmts = (const enum AVPixelFormat[]) {
  897. AV_PIX_FMT_VAAPI,
  898. AV_PIX_FMT_NONE,
  899. },
  900. };