| @@ -82,6 +82,14 @@ static const struct profile_names vp9_profiles[] = { · 81 unmodified lines |
| 82 | 82 | { MFX_PROFILE_VP9_3, "vp9 3" }, |
| 83 | 83 | }; |
| 84 | 84 | |
| 85 | +static const struct profile_names av1_profiles[] = { |
| 86 | +#if QSV_VERSION_ATLEAST(1, 34) |
| 87 | + { MFX_PROFILE_AV1_MAIN, "av1 main" }, |
| 88 | + { MFX_PROFILE_AV1_HIGH, "av1 high" }, |
| 89 | + { MFX_PROFILE_AV1_PRO, "av1 professional" }, |
| 90 | +#endif |
| 91 | +}; |
| 92 | + |
| 85 | 93 | typedef struct QSVPacket { |
| 86 | 94 | AVPacket pkt; |
| 87 | 95 | mfxSyncPoint *sync; |
| @@ -114,6 +122,11 @@ static const char *print_profile(enum AVCodecID codec_id, mfxU16 profile) · 26 unmodified lines |
| 114 | 122 | num_profiles = FF_ARRAY_ELEMS(vp9_profiles); |
| 115 | 123 | break; |
| 116 | 124 | |
| 125 | + case AV_CODEC_ID_AV1: |
| 126 | + profiles = av1_profiles; |
| 127 | + num_profiles = FF_ARRAY_ELEMS(av1_profiles); |
| 128 | + break; |
| 129 | + |
| 117 | 130 | default: |
| 118 | 131 | return "unknown"; |
| 119 | 132 | } |
| @@ -429,6 +442,88 @@ static void dump_video_mjpeg_param(AVCodecContext *avctx, QSVEncContext *q) · 309 unmodified lines |
| 429 | 442 | info->FrameInfo.FrameRateExtD, info->FrameInfo.FrameRateExtN); |
| 430 | 443 | } |
| 431 | 444 | |
| 445 | +#if QSV_HAVE_EXT_AV1_PARAM |
| 446 | +static void dump_video_av1_param(AVCodecContext *avctx, QSVEncContext *q, |
| 447 | + mfxExtBuffer **coding_opts) |
| 448 | +{ |
| 449 | + mfxInfoMFX *info = &q->param.mfx; |
| 450 | + mfxExtAV1TileParam *av1_tile_param = (mfxExtAV1TileParam *)coding_opts[0]; |
| 451 | + mfxExtAV1BitstreamParam *av1_bs_param = (mfxExtAV1BitstreamParam *)coding_opts[1]; |
| 452 | + mfxExtCodingOption2 *co2 = (mfxExtCodingOption2*)coding_opts[2]; |
| 453 | + mfxExtCodingOption3 *co3 = (mfxExtCodingOption3*)coding_opts[3]; |
| 454 | + |
| 455 | + av_log(avctx, AV_LOG_VERBOSE, "profile: %s; level: %"PRIu16"\n", |
| 456 | + print_profile(avctx->codec_id, info->CodecProfile), info->CodecLevel); |
| 457 | + |
| 458 | + av_log(avctx, AV_LOG_VERBOSE, |
| 459 | + "GopPicSize: %"PRIu16"; GopRefDist: %"PRIu16"; GopOptFlag:%s%s; IdrInterval: %"PRIu16"\n", |
| 460 | + info->GopPicSize, info->GopRefDist, |
| 461 | + info->GopOptFlag & MFX_GOP_CLOSED ? " closed" : "", |
| 462 | + info->GopOptFlag & MFX_GOP_STRICT ? " strict" : "", |
| 463 | + info->IdrInterval); |
| 464 | + |
| 465 | + av_log(avctx, AV_LOG_VERBOSE, "TargetUsage: %"PRIu16"; RateControlMethod: %s\n", |
| 466 | + info->TargetUsage, print_ratecontrol(info->RateControlMethod)); |
| 467 | + |
| 468 | + if (info->RateControlMethod == MFX_RATECONTROL_CBR || |
| 469 | + info->RateControlMethod == MFX_RATECONTROL_VBR) |
| 470 | + av_log(avctx, AV_LOG_VERBOSE, |
| 471 | + "BufferSizeInKB: %"PRIu16"; InitialDelayInKB: %"PRIu16"; TargetKbps: %"PRIu16"; MaxKbps: %"PRIu16"; BRCParamMultiplier: %"PRIu16"\n", |
| 472 | + info->BufferSizeInKB, info->InitialDelayInKB, info->TargetKbps, info->MaxKbps, info->BRCParamMultiplier); |
| 473 | + else if (info->RateControlMethod == MFX_RATECONTROL_CQP) |
| 474 | + av_log(avctx, AV_LOG_VERBOSE, "QPI: %"PRIu16"; QPP: %"PRIu16"; QPB: %"PRIu16"\n", |
| 475 | + info->QPI, info->QPP, info->QPB); |
| 476 | + else if (info->RateControlMethod == MFX_RATECONTROL_ICQ) |
| 477 | + av_log(avctx, AV_LOG_VERBOSE, "ICQQuality: %"PRIu16"\n", info->ICQQuality); |
| 478 | + else |
| 479 | + av_log(avctx, AV_LOG_VERBOSE, "Unsupported ratecontrol method: %d \n", info->RateControlMethod); |
| 480 | + |
| 481 | + av_log(avctx, AV_LOG_VERBOSE, "NumRefFrame: %"PRIu16"\n", info->NumRefFrame); |
| 482 | + |
| 483 | + av_log(avctx, AV_LOG_VERBOSE, |
| 484 | + "IntRefType: %"PRIu16"; IntRefCycleSize: %"PRIu16 |
| 485 | + "; IntRefQPDelta: %"PRId16"; IntRefCycleDist: %"PRId16"\n", |
| 486 | + co2->IntRefType, co2->IntRefCycleSize, |
| 487 | + co2->IntRefQPDelta, co3->IntRefCycleDist); |
| 488 | + |
| 489 | + av_log(avctx, AV_LOG_VERBOSE, "MaxFrameSize: %d;\n", co2->MaxFrameSize); |
| 490 | + |
| 491 | + av_log(avctx, AV_LOG_VERBOSE, |
| 492 | + "BitrateLimit: %s; MBBRC: %s; ExtBRC: %s\n", |
| 493 | + print_threestate(co2->BitrateLimit), print_threestate(co2->MBBRC), |
| 494 | + print_threestate(co2->ExtBRC)); |
| 495 | + |
| 496 | + av_log(avctx, AV_LOG_VERBOSE, "VDENC: %s\n", print_threestate(info->LowPower)); |
| 497 | + |
| 498 | + switch (co2->BRefType) { |
| 499 | + case MFX_B_REF_OFF: av_log(avctx, AV_LOG_VERBOSE, "BRefType: off\n"); break; |
| 500 | + case MFX_B_REF_PYRAMID: av_log(avctx, AV_LOG_VERBOSE, "BRefType: pyramid\n"); break; |
| 501 | + default: av_log(avctx, AV_LOG_VERBOSE, "BRefType: auto\n"); break; |
| 502 | + } |
| 503 | + |
| 504 | + switch (co3->PRefType) { |
| 505 | + case MFX_P_REF_DEFAULT: av_log(avctx, AV_LOG_VERBOSE, "PRefType: default\n"); break; |
| 506 | + case MFX_P_REF_SIMPLE: av_log(avctx, AV_LOG_VERBOSE, "PRefType: simple\n"); break; |
| 507 | + case MFX_P_REF_PYRAMID: av_log(avctx, AV_LOG_VERBOSE, "PRefType: pyramid\n"); break; |
| 508 | + default: av_log(avctx, AV_LOG_VERBOSE, "PRefType: unknown\n"); break; |
| 509 | + } |
| 510 | + |
| 511 | + av_log(avctx, AV_LOG_VERBOSE, |
| 512 | + "MinQPI: %"PRIu8"; MaxQPI: %"PRIu8"; MinQPP: %"PRIu8"; MaxQPP: %"PRIu8"; MinQPB: %"PRIu8"; MaxQPB: %"PRIu8"\n", |
| 513 | + co2->MinQPI, co2->MaxQPI, co2->MinQPP, co2->MaxQPP, co2->MinQPB, co2->MaxQPB); |
| 514 | + |
| 515 | + av_log(avctx, AV_LOG_VERBOSE, "FrameRateExtD: %"PRIu32"; FrameRateExtN: %"PRIu32" \n", |
| 516 | + info->FrameInfo.FrameRateExtD, info->FrameInfo.FrameRateExtN); |
| 517 | + |
| 518 | + av_log(avctx, AV_LOG_VERBOSE, |
| 519 | + "NumTileRows: %"PRIu16"; NumTileColumns: %"PRIu16"; NumTileGroups: %"PRIu16"\n", |
| 520 | + av1_tile_param->NumTileRows, av1_tile_param->NumTileColumns, av1_tile_param->NumTileGroups); |
| 521 | + |
| 522 | + av_log(avctx, AV_LOG_VERBOSE, "WriteIVFHeaders: %s \n", |
| 523 | + print_threestate(av1_bs_param->WriteIVFHeaders)); |
| 524 | +} |
| 525 | +#endif |
| 526 | + |
| 432 | 527 | static int select_rc_mode(AVCodecContext *avctx, QSVEncContext *q) |
| 433 | 528 | { |
| 434 | 529 | const char *rc_desc; |
| @@ -741,10 +836,15 @@ static int init_video_param(AVCodecContext *avctx, QSVEncContext *q) · 306 unmodified lines |
| 741 | 836 | break; |
| 742 | 837 | case MFX_RATECONTROL_CQP: |
| 743 | 838 | quant = avctx->global_quality / FF_QP2LAMBDA; |
| 744 | | − |
| 745 | | − q->param.mfx.QPI = av_clip(quant * fabs(avctx->i_quant_factor) + avctx->i_quant_offset, 0, 51); |
| 746 | | − q->param.mfx.QPP = av_clip(quant, 0, 51); |
| 747 | | − q->param.mfx.QPB = av_clip(quant * fabs(avctx->b_quant_factor) + avctx->b_quant_offset, 0, 51); |
| 839 | + if (avctx->codec_id == AV_CODEC_ID_AV1) { |
| 840 | + q->param.mfx.QPI = av_clip_uintp2(quant * fabs(avctx->i_quant_factor) + avctx->i_quant_offset, 8); |
| 841 | + q->param.mfx.QPP = av_clip_uintp2(quant, 8); |
| 842 | + q->param.mfx.QPB = av_clip_uintp2(quant * fabs(avctx->b_quant_factor) + avctx->b_quant_offset, 8); |
| 843 | + } else { |
| 844 | + q->param.mfx.QPI = av_clip(quant * fabs(avctx->i_quant_factor) + avctx->i_quant_offset, 0, 51); |
| 845 | + q->param.mfx.QPP = av_clip(quant, 0, 51); |
| 846 | + q->param.mfx.QPB = av_clip(quant * fabs(avctx->b_quant_factor) + avctx->b_quant_offset, 0, 51); |
| 847 | + } |
| 748 | 848 | q->old_global_quality = avctx->global_quality; |
| 749 | 849 | q->old_i_quant_factor = avctx->i_quant_factor; |
| 750 | 850 | q->old_i_quant_offset = avctx->i_quant_offset; |
| @@ -895,6 +995,20 @@ static int init_video_param(AVCodecContext *avctx, QSVEncContext *q) · 144 unmodified lines |
| 895 | 995 | q->extco2.Header.BufferId = MFX_EXTBUFF_CODING_OPTION2; |
| 896 | 996 | q->extco2.Header.BufferSz = sizeof(q->extco2); |
| 897 | 997 | |
| 998 | + q->extparam_internal[q->nb_extparam_internal++] = (mfxExtBuffer *)&q->extco2; |
| 999 | + } else if (avctx->codec_id == AV_CODEC_ID_AV1) { |
| 1000 | + if (q->extbrc >= 0) |
| 1001 | + q->extco2.ExtBRC = q->extbrc ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF; |
| 1002 | + if (q->b_strategy >= 0) |
| 1003 | + q->extco2.BRefType = q->b_strategy ? MFX_B_REF_PYRAMID : MFX_B_REF_OFF; |
| 1004 | + if (q->adaptive_i >= 0) |
| 1005 | + q->extco2.AdaptiveI = q->adaptive_i ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF; |
| 1006 | + if (q->adaptive_b >= 0) |
| 1007 | + q->extco2.AdaptiveB = q->adaptive_b ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF; |
| 1008 | + |
| 1009 | + q->extco2.Header.BufferId = MFX_EXTBUFF_CODING_OPTION2; |
| 1010 | + q->extco2.Header.BufferSz = sizeof(q->extco2); |
| 1011 | + |
| 898 | 1012 | q->extparam_internal[q->nb_extparam_internal++] = (mfxExtBuffer *)&q->extco2; |
| 899 | 1013 | } |
| 900 | 1014 | |
| @@ -972,6 +1086,27 @@ static int init_video_param(AVCodecContext *avctx, QSVEncContext *q) · 71 unmodified lines |
| 972 | 1086 | q->extparam_internal[q->nb_extparam_internal++] = (mfxExtBuffer *)&q->extvp9param; |
| 973 | 1087 | } |
| 974 | 1088 | |
| 1089 | +#if QSV_HAVE_EXT_AV1_PARAM |
| 1090 | + if (avctx->codec_id == AV_CODEC_ID_AV1) { |
| 1091 | + if (QSV_RUNTIME_VERSION_ATLEAST(q->ver, 2, 5)) { |
| 1092 | + q->extav1tileparam.Header.BufferId = MFX_EXTBUFF_AV1_TILE_PARAM; |
| 1093 | + q->extav1tileparam.Header.BufferSz = sizeof(q->extav1tileparam); |
| 1094 | + q->extav1tileparam.NumTileColumns = q->tile_cols; |
| 1095 | + q->extav1tileparam.NumTileRows = q->tile_rows; |
| 1096 | + q->extparam_internal[q->nb_extparam_internal++] = (mfxExtBuffer *)&q->extav1tileparam; |
| 1097 | + |
| 1098 | + q->extav1bsparam.Header.BufferId = MFX_EXTBUFF_AV1_BITSTREAM_PARAM; |
| 1099 | + q->extav1bsparam.Header.BufferSz = sizeof(q->extav1bsparam); |
| 1100 | + q->extav1bsparam.WriteIVFHeaders = MFX_CODINGOPTION_OFF; |
| 1101 | + q->extparam_internal[q->nb_extparam_internal++] = (mfxExtBuffer *)&q->extav1bsparam; |
| 1102 | + } else { |
| 1103 | + av_log(avctx, AV_LOG_ERROR, |
| 1104 | + "This version of runtime doesn't support AV1 encoding\n"); |
| 1105 | + return AVERROR_UNKNOWN; |
| 1106 | + } |
| 1107 | + } |
| 1108 | +#endif |
| 1109 | + |
| 975 | 1110 | if (avctx->codec_id == AV_CODEC_ID_HEVC) { |
| 976 | 1111 | q->exthevctiles.Header.BufferId = MFX_EXTBUFF_HEVC_TILES; |
| 977 | 1112 | q->exthevctiles.Header.BufferSz = sizeof(q->exthevctiles); |
| @@ -1082,6 +1217,56 @@ static int qsv_retrieve_enc_vp9_params(AVCodecContext *avctx, QSVEncContext *q) · 104 unmodified lines |
| 1082 | 1217 | return 0; |
| 1083 | 1218 | } |
| 1084 | 1219 | |
| 1220 | +static int qsv_retrieve_enc_av1_params(AVCodecContext *avctx, QSVEncContext *q) |
| 1221 | +{ |
| 1222 | +#if QSV_HAVE_EXT_AV1_PARAM |
| 1223 | + int ret = 0; |
| 1224 | + mfxExtAV1TileParam av1_extend_tile_buf = { |
| 1225 | + .Header.BufferId = MFX_EXTBUFF_AV1_TILE_PARAM, |
| 1226 | + .Header.BufferSz = sizeof(av1_extend_tile_buf), |
| 1227 | + }; |
| 1228 | + mfxExtAV1BitstreamParam av1_bs_param = { |
| 1229 | + .Header.BufferId = MFX_EXTBUFF_AV1_BITSTREAM_PARAM, |
| 1230 | + .Header.BufferSz = sizeof(av1_bs_param), |
| 1231 | + }; |
| 1232 | + |
| 1233 | + mfxExtCodingOption2 co2 = { |
| 1234 | + .Header.BufferId = MFX_EXTBUFF_CODING_OPTION2, |
| 1235 | + .Header.BufferSz = sizeof(co2), |
| 1236 | + }; |
| 1237 | + |
| 1238 | + mfxExtCodingOption3 co3 = { |
| 1239 | + .Header.BufferId = MFX_EXTBUFF_CODING_OPTION3, |
| 1240 | + .Header.BufferSz = sizeof(co3), |
| 1241 | + }; |
| 1242 | + |
| 1243 | + mfxExtBuffer *ext_buffers[] = { |
| 1244 | + (mfxExtBuffer*)&av1_extend_tile_buf, |
| 1245 | + (mfxExtBuffer*)&av1_bs_param, |
| 1246 | + (mfxExtBuffer*)&co2, |
| 1247 | + (mfxExtBuffer*)&co3, |
| 1248 | + }; |
| 1249 | + |
| 1250 | + if (!QSV_RUNTIME_VERSION_ATLEAST(q->ver, 2, 5)) { |
| 1251 | + av_log(avctx, AV_LOG_ERROR, |
| 1252 | + "This version of runtime doesn't support AV1 encoding\n"); |
| 1253 | + return AVERROR_UNKNOWN; |
| 1254 | + } |
| 1255 | + |
| 1256 | + q->param.ExtParam = ext_buffers; |
| 1257 | + q->param.NumExtParam = FF_ARRAY_ELEMS(ext_buffers); |
| 1258 | + |
| 1259 | + ret = MFXVideoENCODE_GetVideoParam(q->session, &q->param); |
| 1260 | + if (ret < 0) |
| 1261 | + return ff_qsv_print_error(avctx, ret, |
| 1262 | + "Error calling GetVideoParam"); |
| 1263 | + |
| 1264 | + q->packet_size = q->param.mfx.BufferSizeInKB * q->param.mfx.BRCParamMultiplier * 1000; |
| 1265 | + dump_video_av1_param(avctx, q, ext_buffers); |
| 1266 | +#endif |
| 1267 | + return 0; |
| 1268 | +} |
| 1269 | + |
| 1085 | 1270 | static int qsv_retrieve_enc_params(AVCodecContext *avctx, QSVEncContext *q) |
| 1086 | 1271 | { |
| 1087 | 1272 | AVCPBProperties *cpb_props; |
| @@ -1420,6 +1605,9 @@ int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q) · 332 unmodified lines |
| 1420 | 1605 | case AV_CODEC_ID_VP9: |
| 1421 | 1606 | ret = qsv_retrieve_enc_vp9_params(avctx, q); |
| 1422 | 1607 | break; |
| 1608 | + case AV_CODEC_ID_AV1: |
| 1609 | + ret = qsv_retrieve_enc_av1_params(avctx, q); |
| 1610 | + break; |
| 1423 | 1611 | default: |
| 1424 | 1612 | ret = qsv_retrieve_enc_params(avctx, q); |
| 1425 | 1613 | break; |