63 { 10, D3D12_VIDEO_ENCODER_LEVELS_H264_1 },
64 { 11, D3D12_VIDEO_ENCODER_LEVELS_H264_11 },
65 { 12, D3D12_VIDEO_ENCODER_LEVELS_H264_12 },
66 { 13, D3D12_VIDEO_ENCODER_LEVELS_H264_13 },
67 { 20, D3D12_VIDEO_ENCODER_LEVELS_H264_2 },
68 { 21, D3D12_VIDEO_ENCODER_LEVELS_H264_21 },
69 { 22, D3D12_VIDEO_ENCODER_LEVELS_H264_22 },
70 { 30, D3D12_VIDEO_ENCODER_LEVELS_H264_3 },
71 { 31, D3D12_VIDEO_ENCODER_LEVELS_H264_31 },
72 { 32, D3D12_VIDEO_ENCODER_LEVELS_H264_32 },
73 { 40, D3D12_VIDEO_ENCODER_LEVELS_H264_4 },
74 { 41, D3D12_VIDEO_ENCODER_LEVELS_H264_41 },
75 { 42, D3D12_VIDEO_ENCODER_LEVELS_H264_42 },
76 { 50, D3D12_VIDEO_ENCODER_LEVELS_H264_5 },
77 { 51, D3D12_VIDEO_ENCODER_LEVELS_H264_51 },
78 { 52, D3D12_VIDEO_ENCODER_LEVELS_H264_52 },
79 { 60, D3D12_VIDEO_ENCODER_LEVELS_H264_6 },
80 { 61, D3D12_VIDEO_ENCODER_LEVELS_H264_61 },
81 { 62, D3D12_VIDEO_ENCODER_LEVELS_H264_62 },
84 static const D3D12_VIDEO_ENCODER_PROFILE_H264
profile_main = D3D12_VIDEO_ENCODER_PROFILE_H264_MAIN;
85 static const D3D12_VIDEO_ENCODER_PROFILE_H264
profile_high = D3D12_VIDEO_ENCODER_PROFILE_H264_HIGH;
86 static const D3D12_VIDEO_ENCODER_PROFILE_H264
profile_high_10 = D3D12_VIDEO_ENCODER_PROFILE_H264_HIGH_10;
88 #define D3D_PROFILE_DESC(name) \
89 { sizeof(D3D12_VIDEO_ENCODER_PROFILE_H264), { .pH264Profile = (D3D12_VIDEO_ENCODER_PROFILE_H264 *)&profile_ ## name } }
98 char *
data,
size_t *data_len,
104 err = ff_cbs_write_fragment_data(priv->
cbc, au);
112 "%zu < %zu.\n", *data_len,
130 err = ff_cbs_insert_unit_content(au, -1,
134 "type = %d.\n",
header->nal_unit_type);
142 char *
data,
size_t *data_len)
158 ff_cbs_fragment_reset(au);
170 D3D12_VIDEO_ENCODER_PROFILE_H264
profile = D3D12_VIDEO_ENCODER_PROFILE_H264_MAIN;
171 D3D12_VIDEO_ENCODER_LEVELS_H264
level = { 0 };
176 D3D12_FEATURE_DATA_VIDEO_ENCODER_SUPPORT support = {
178 .Codec = D3D12_VIDEO_ENCODER_CODEC_H264,
179 .InputFormat = hwctx->
format,
180 .RateControl =
ctx->rc,
181 .IntraRefresh = D3D12_VIDEO_ENCODER_INTRA_REFRESH_MODE_NONE,
182 .SubregionFrameEncoding = D3D12_VIDEO_ENCODER_FRAME_SUBREGION_LAYOUT_MODE_FULL_FRAME,
183 .ResolutionsListCount = 1,
184 .pResolutionList = &
ctx->resolution,
185 .CodecGopSequence =
ctx->gop,
187 .CodecConfiguration =
ctx->codec_conf,
188 .SuggestedProfile.DataSize =
sizeof(D3D12_VIDEO_ENCODER_PROFILE_H264),
189 .SuggestedProfile.pH264Profile = &
profile,
190 .SuggestedLevel.DataSize =
sizeof(D3D12_VIDEO_ENCODER_LEVELS_H264),
191 .SuggestedLevel.pH264LevelSetting = &
level,
192 .pResolutionDependentSupport = &
ctx->res_limits,
195 hr = ID3D12VideoDevice3_CheckFeatureSupport(
ctx->video_device3, D3D12_FEATURE_VIDEO_ENCODER_SUPPORT,
196 &support,
sizeof(support));
203 if (!(support.SupportFlags & D3D12_VIDEO_ENCODER_SUPPORT_FLAG_GENERAL_SUPPORT_OK)) {
205 support.ValidationFlags);
209 if (support.SupportFlags & D3D12_VIDEO_ENCODER_SUPPORT_FLAG_RECONSTRUCTED_FRAMES_REQUIRE_TEXTURE_ARRAYS) {
210 ctx->is_texture_array = 1;
211 av_log(avctx,
AV_LOG_DEBUG,
"D3D12 video encode on this device uses texture array mode.\n");
218 sps->pic_height_in_map_units_minus1 = ((base_ctx->
surface_height + 0x0F) >> 4) - 1;
230 ctx->gop.pH264GroupOfPictures->pic_order_cnt_type =
sps->pic_order_cnt_type;
234 ctx->gop.pH264GroupOfPictures->log2_max_frame_num_minus4 =
sps->log2_max_frame_num_minus4;
235 pps->deblocking_filter_control_present_flag = 1;
247 D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_H264 *
config;
248 D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_H264 h264_caps;
250 D3D12_FEATURE_DATA_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT codec_caps = {
252 .Codec = D3D12_VIDEO_ENCODER_CODEC_H264,
253 .Profile =
ctx->profile->d3d12_profile,
254 .CodecSupportLimits.DataSize =
sizeof(D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_H264),
257 codec_caps.CodecSupportLimits.pH264Support = &h264_caps;
258 hr = ID3D12VideoDevice3_CheckFeatureSupport(
ctx->video_device3, D3D12_FEATURE_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT,
259 &codec_caps,
sizeof(codec_caps));
260 if (!(SUCCEEDED(hr) && codec_caps.IsSupported))
263 ctx->codec_conf.DataSize =
sizeof(D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_H264);
265 if (!
ctx->codec_conf.pH264Config)
270 config->ConfigurationFlags = D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_H264_FLAG_NONE;
272 if (h264_caps.SupportFlags & D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_H264_FLAG_CABAC_ENCODING_SUPPORT) {
273 config->ConfigurationFlags |= D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_H264_FLAG_ENABLE_CABAC_ENCODING;
288 int fixed_qp_idr, fixed_qp_p, fixed_qp_b;
296 if (
ctx->rc.Mode == D3D12_VIDEO_ENCODER_RATE_CONTROL_MODE_CQP) {
297 D3D12_VIDEO_ENCODER_RATE_CONTROL_CQP *cqp_ctl;
303 fixed_qp_idr = fixed_qp_p;
308 fixed_qp_b = fixed_qp_p;
311 "%d / %d / %d for IDR- / P- / B-frames.\n",
312 fixed_qp_idr, fixed_qp_p, fixed_qp_b);
314 ctx->rc.ConfigParams.DataSize =
sizeof(D3D12_VIDEO_ENCODER_RATE_CONTROL_CQP);
319 cqp_ctl->ConstantQP_FullIntracodedFrame = fixed_qp_idr;
320 cqp_ctl->ConstantQP_InterPredictedFrame_PrevRefOnly = fixed_qp_p;
321 cqp_ctl->ConstantQP_InterPredictedFrame_BiDirectionalRef = fixed_qp_b;
323 ctx->rc.ConfigParams.pConfiguration_CQP = cqp_ctl;
328 ctx->gop.DataSize =
sizeof(D3D12_VIDEO_ENCODER_SEQUENCE_GOP_STRUCTURE_H264);
330 if (!
ctx->gop.pH264GroupOfPictures)
333 ctx->gop.pH264GroupOfPictures->GOPLength = base_ctx->
gop_size;
334 ctx->gop.pH264GroupOfPictures->PPicturePeriod = base_ctx->
b_per_p + 1;
345 ctx->level.DataSize =
sizeof(D3D12_VIDEO_ENCODER_LEVELS_H264);
347 if (!
ctx->level.pH264LevelSetting)
367 if (!pic->
pic_ctl.pH264PicData)
372 av_freep(&pic->
pic_ctl.pH264PicData->pReferenceFramesReconPictureDescriptors);
384 D3D12_VIDEO_ENCODER_REFERENCE_PICTURE_DESCRIPTOR_H264 *pd =
NULL;
385 UINT *ref_list0 =
NULL, *ref_list1 =
NULL;
388 pic->
pic_ctl.DataSize =
sizeof(D3D12_VIDEO_ENCODER_PICTURE_CONTROL_CODEC_DATA_H264);
390 if (!pic->
pic_ctl.pH264PicData)
403 switch(base_pic->
type) {
405 pic->
pic_ctl.pH264PicData->FrameType = D3D12_VIDEO_ENCODER_FRAME_TYPE_H264_IDR_FRAME;
406 pic->
pic_ctl.pH264PicData->idr_pic_id =
ctx->idr_pic_id;
409 pic->
pic_ctl.pH264PicData->FrameType = D3D12_VIDEO_ENCODER_FRAME_TYPE_H264_I_FRAME;
412 pic->
pic_ctl.pH264PicData->FrameType = D3D12_VIDEO_ENCODER_FRAME_TYPE_H264_P_FRAME;
415 pic->
pic_ctl.pH264PicData->FrameType = D3D12_VIDEO_ENCODER_FRAME_TYPE_H264_B_FRAME;
433 pic->
pic_ctl.pH264PicData->List0ReferenceFramesCount = base_pic->
nb_refs[0];
439 href =
ref->codec_priv;
442 pd[idx].ReconstructedPictureResourceIndex = idx;
453 pic->
pic_ctl.pH264PicData->List1ReferenceFramesCount = base_pic->
nb_refs[1];
459 href =
ref->codec_priv;
462 pd[idx].ReconstructedPictureResourceIndex = idx;
468 pic->
pic_ctl.pH264PicData->pList0ReferenceFrames = ref_list0;
469 pic->
pic_ctl.pH264PicData->pList1ReferenceFrames = ref_list1;
470 pic->
pic_ctl.pH264PicData->ReferenceFramesReconPictureDescriptorsCount = idx;
471 pic->
pic_ctl.pH264PicData->pReferenceFramesReconPictureDescriptors = pd;
479 .d3d12_codec = D3D12_VIDEO_ENCODER_CODEC_H264,
485 .default_quality = 25,
518 "in 8-bit unsigned integer.\n", avctx->
level);
523 ctx->explicit_qp = priv->
qp;
533 ff_cbs_close(&priv->
cbc);
539 if (priv->
common.
rc.ConfigParams.pConfiguration_CQP !=
NULL) {
546 #define OFFSET(x) offsetof(D3D12VAEncodeH264Context, x)
547 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
553 {
"qp",
"Constant QP (for P-frames; scaled by qfactor/qoffset for I/B)",
556 {
"profile",
"Set profile (general_profile_idc)",
560 #define PROFILE(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
561 { .i64 = value }, 0, 0, FLAGS, "profile"
567 {
"level",
"Set level (general_level_idc)",
571 #define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
572 { .i64 = value }, 0, 0, FLAGS, "level"
574 {
LEVEL(
"1.1", 11) },
575 {
LEVEL(
"1.2", 12) },
576 {
LEVEL(
"1.3", 13) },
578 {
LEVEL(
"2.1", 21) },
579 {
LEVEL(
"2.2", 22) },
581 {
LEVEL(
"3.1", 31) },
582 {
LEVEL(
"3.2", 32) },
584 {
LEVEL(
"4.1", 41) },
585 {
LEVEL(
"4.2", 42) },
587 {
LEVEL(
"5.1", 51) },
588 {
LEVEL(
"5.2", 52) },
590 {
LEVEL(
"6.1", 61) },
591 {
LEVEL(
"6.2", 62) },
614 .
p.
name =
"h264_d3d12va",
630 .p.wrapper_name =
"d3d12va",