24 #include "config_components.h"
27 #include <sys/types.h>
28 #include <mfx/mfxvideo.h>
52 { MFX_PROFILE_AVC_BASELINE,
"avc baseline" },
53 { MFX_PROFILE_AVC_MAIN,
"avc main" },
54 { MFX_PROFILE_AVC_EXTENDED,
"avc extended" },
55 { MFX_PROFILE_AVC_HIGH,
"avc high" },
56 #if QSV_VERSION_ATLEAST(1, 15)
57 { MFX_PROFILE_AVC_HIGH_422,
"avc high 422" },
59 #if QSV_VERSION_ATLEAST(1, 4)
60 { MFX_PROFILE_AVC_CONSTRAINED_BASELINE,
"avc constrained baseline" },
61 { MFX_PROFILE_AVC_CONSTRAINED_HIGH,
"avc constrained high" },
62 { MFX_PROFILE_AVC_PROGRESSIVE_HIGH,
"avc progressive high" },
67 { MFX_PROFILE_MPEG2_SIMPLE,
"mpeg2 simple" },
68 { MFX_PROFILE_MPEG2_MAIN,
"mpeg2 main" },
69 { MFX_PROFILE_MPEG2_HIGH,
"mpeg2 high" },
73 #if QSV_VERSION_ATLEAST(1, 8)
74 { MFX_PROFILE_HEVC_MAIN,
"hevc main" },
75 { MFX_PROFILE_HEVC_MAIN10,
"hevc main10" },
76 { MFX_PROFILE_HEVC_MAINSP,
"hevc mainsp" },
77 { MFX_PROFILE_HEVC_REXT,
"hevc rext" },
79 #if QSV_VERSION_ATLEAST(1, 32)
80 { MFX_PROFILE_HEVC_SCC,
"hevc scc" },
85 #if QSV_VERSION_ATLEAST(1, 19)
86 { MFX_PROFILE_VP9_0,
"vp9 0" },
87 { MFX_PROFILE_VP9_1,
"vp9 1" },
88 { MFX_PROFILE_VP9_2,
"vp9 2" },
89 { MFX_PROFILE_VP9_3,
"vp9 3" },
129 for (
i = 0;
i < num_profiles;
i++)
136 static const struct {
140 { MFX_RATECONTROL_CBR,
"CBR" },
141 { MFX_RATECONTROL_VBR,
"VBR" },
142 { MFX_RATECONTROL_CQP,
"CQP" },
144 { MFX_RATECONTROL_AVBR,
"AVBR" },
147 { MFX_RATECONTROL_LA,
"LA" },
150 { MFX_RATECONTROL_ICQ,
"ICQ" },
151 { MFX_RATECONTROL_LA_ICQ,
"LA_ICQ" },
154 { MFX_RATECONTROL_VCM,
"VCM" },
156 #if QSV_VERSION_ATLEAST(1, 10)
157 { MFX_RATECONTROL_LA_EXT,
"LA_EXT" },
160 { MFX_RATECONTROL_LA_HRD,
"LA_HRD" },
163 { MFX_RATECONTROL_QVBR,
"QVBR" },
178 if (
val == MFX_CODINGOPTION_ON)
180 else if (
val == MFX_CODINGOPTION_OFF)
186 mfxExtBuffer **coding_opts)
190 mfxExtCodingOption *co = (mfxExtCodingOption*)coding_opts[0];
192 mfxExtCodingOption2 *co2 = (mfxExtCodingOption2*)coding_opts[1];
195 mfxExtCodingOption3 *co3 = (mfxExtCodingOption3*)coding_opts[2];
197 #if QSV_HAVE_EXT_HEVC_TILES
198 mfxExtHEVCTiles *exthevctiles = (mfxExtHEVCTiles *)coding_opts[3 +
QSV_HAVE_CO_VPS];
205 info->GopPicSize,
info->GopRefDist);
206 if (
info->GopOptFlag & MFX_GOP_CLOSED)
208 if (
info->GopOptFlag & MFX_GOP_STRICT)
215 if (
info->RateControlMethod == MFX_RATECONTROL_CBR ||
216 info->RateControlMethod == MFX_RATECONTROL_VBR
218 ||
info->RateControlMethod == MFX_RATECONTROL_VCM
222 "BufferSizeInKB: %"PRIu16
"; InitialDelayInKB: %"PRIu16
"; TargetKbps: %"PRIu16
"; MaxKbps: %"PRIu16
"; BRCParamMultiplier: %"PRIu16
"\n",
223 info->BufferSizeInKB,
info->InitialDelayInKB,
info->TargetKbps,
info->MaxKbps,
info->BRCParamMultiplier);
229 }
else if (
info->RateControlMethod == MFX_RATECONTROL_CQP) {
234 else if (
info->RateControlMethod == MFX_RATECONTROL_AVBR) {
236 "TargetKbps: %"PRIu16
"; Accuracy: %"PRIu16
"; Convergence: %"PRIu16
"; BRCParamMultiplier: %"PRIu16
"\n",
237 info->TargetKbps,
info->Accuracy,
info->Convergence,
info->BRCParamMultiplier);
241 else if (
info->RateControlMethod == MFX_RATECONTROL_LA
243 ||
info->RateControlMethod == MFX_RATECONTROL_LA_HRD
247 "TargetKbps: %"PRIu16
"; LookAheadDepth: %"PRIu16
"; BRCParamMultiplier: %"PRIu16
"\n",
248 info->TargetKbps, co2->LookAheadDepth,
info->BRCParamMultiplier);
252 else if (
info->RateControlMethod == MFX_RATECONTROL_ICQ) {
254 }
else if (
info->RateControlMethod == MFX_RATECONTROL_LA_ICQ) {
256 info->ICQQuality, co2->LookAheadDepth);
260 else if (
info->RateControlMethod == MFX_RATECONTROL_QVBR) {
270 #if QSV_HAVE_EXT_HEVC_TILES
273 exthevctiles->NumTileColumns, exthevctiles->NumTileRows);
278 "RecoveryPointSEI: %s IntRefType: %"PRIu16
"; IntRefCycleSize: %"PRIu16
"; IntRefQPDelta: %"PRId16
"\n",
279 print_threestate(co->RecoveryPointSEI), co2->IntRefType, co2->IntRefCycleSize, co2->IntRefQPDelta);
282 #if QSV_HAVE_MAX_SLICE_SIZE
288 "BitrateLimit: %s; MBBRC: %s; ExtBRC: %s\n",
294 if (co2->Trellis & MFX_TRELLIS_OFF) {
296 }
else if (!co2->Trellis) {
310 #if QSV_VERSION_ATLEAST(1, 8)
312 "RepeatPPS: %s; NumMbPerSlice: %"PRIu16
"; LookAheadDS: ",
314 switch (co2->LookAheadDS) {
324 switch (co2->BRefType) {
331 switch (co3->PRefType) {
340 #if QSV_VERSION_ATLEAST(1, 9)
342 "MinQPI: %"PRIu8
"; MaxQPI: %"PRIu8
"; MinQPP: %"PRIu8
"; MaxQPP: %"PRIu8
"; MinQPB: %"PRIu8
"; MaxQPB: %"PRIu8
"\n",
343 co2->MinQPI, co2->MaxQPI, co2->MinQPP, co2->MaxQPP, co2->MinQPB, co2->MaxQPB);
354 co->CAVLC == MFX_CODINGOPTION_ON ?
"CAVLC" :
"CABAC", co->MaxDecFrameBuffering);
356 "NalHrdConformance: %s; SingleSeiNalUnit: %s; VuiVclHrdParameters: %s VuiNalHrdParameters: %s\n",
361 "NalHrdConformance: %s; VuiNalHrdParameters: %s\n",
366 info->FrameInfo.FrameRateExtD,
info->FrameInfo.FrameRateExtN);
368 #if QSV_HAVE_DISABLEDEBLOCKIDC
372 #if QSV_VERSION_ATLEAST(1, 26)
376 #if QSV_VERSION_ATLEAST(1, 16)
379 #if QSV_VERSION_ATLEAST(1, 23)
382 #if QSV_VERSION_ATLEAST(1, 19)
389 mfxExtBuffer **coding_opts)
392 #if QSV_HAVE_EXT_VP9_PARAM
393 mfxExtVP9Param *vp9_param = (mfxExtVP9Param *)coding_opts[0];
396 mfxExtCodingOption2 *co2 = (mfxExtCodingOption2*)coding_opts[1];
403 info->GopPicSize,
info->GopRefDist);
404 if (
info->GopOptFlag & MFX_GOP_CLOSED)
406 if (
info->GopOptFlag & MFX_GOP_STRICT)
413 if (
info->RateControlMethod == MFX_RATECONTROL_CBR ||
414 info->RateControlMethod == MFX_RATECONTROL_VBR) {
416 "BufferSizeInKB: %"PRIu16
"; InitialDelayInKB: %"PRIu16
"; TargetKbps: %"PRIu16
"; MaxKbps: %"PRIu16
"; BRCParamMultiplier: %"PRIu16
"\n",
417 info->BufferSizeInKB,
info->InitialDelayInKB,
info->TargetKbps,
info->MaxKbps,
info->BRCParamMultiplier);
418 }
else if (
info->RateControlMethod == MFX_RATECONTROL_CQP) {
423 else if (
info->RateControlMethod == MFX_RATECONTROL_ICQ) {
435 "IntRefType: %"PRIu16
"; IntRefCycleSize: %"PRIu16
"; IntRefQPDelta: %"PRId16
"\n",
436 co2->IntRefType, co2->IntRefCycleSize, co2->IntRefQPDelta);
442 "BitrateLimit: %s; MBBRC: %s; ExtBRC: %s\n",
450 #if QSV_VERSION_ATLEAST(1, 9)
452 "MinQPI: %"PRIu8
"; MaxQPI: %"PRIu8
"; MinQPP: %"PRIu8
"; MaxQPP: %"PRIu8
"; MinQPB: %"PRIu8
"; MaxQPB: %"PRIu8
"\n",
453 co2->MinQPI, co2->MaxQPI, co2->MinQPP, co2->MaxQPP, co2->MinQPB, co2->MaxQPB);
458 info->FrameInfo.FrameRateExtD,
info->FrameInfo.FrameRateExtN);
460 #if QSV_HAVE_EXT_VP9_PARAM
475 info->FrameInfo.FrameRateExtD,
info->FrameInfo.FrameRateExtN);
485 int want_vcm = q->
vcm;
489 "Lookahead ratecontrol mode requested, but is not supported by this SDK version\n");
494 "VCM ratecontrol mode requested, but is not supported by this SDK version\n");
498 if (want_la + want_qscale + want_vcm > 1) {
500 "More than one of: { constant qscale, lookahead, VCM } requested, "
501 "only one of them can be used at a time.\n");
507 "ICQ ratecontrol mode requested, but is not supported by this SDK version\n");
513 rc_desc =
"constant quantization parameter (CQP)";
518 rc_desc =
"video conferencing mode (VCM)";
524 rc_desc =
"VBR with lookahead (LA)";
528 rc_mode = MFX_RATECONTROL_LA_ICQ;
529 rc_desc =
"intelligent constant quality with lookahead (LA_ICQ)";
537 rc_desc =
"intelligent constant quality (ICQ)";
542 rc_desc =
"constant bitrate (CBR)";
546 rc_mode = MFX_RATECONTROL_AVBR;
547 rc_desc =
"average variable bitrate (AVBR)";
552 rc_mode = MFX_RATECONTROL_QVBR;
553 rc_desc =
"constant quality with VBR algorithm (QVBR)";
558 rc_desc =
"variable bitrate (VBR)";
569 mfxVideoParam param_out = { .mfx.CodecId = q->
param.mfx.CodecId };
572 #define UNMATCH(x) (param_out.mfx.x != q->param.mfx.x)
581 if (
UNMATCH(RateControlMethod))
610 if (avctx->
level > 0)
622 q->
param.mfx.FrameInfo.CropX = 0;
623 q->
param.mfx.FrameInfo.CropY = 0;
628 q->
param.mfx.FrameInfo.ChromaFormat = MFX_CHROMAFORMAT_YUV420 +
629 !
desc->log2_chroma_w + !
desc->log2_chroma_h;
630 q->
param.mfx.FrameInfo.BitDepthLuma =
desc->comp[0].depth;
631 q->
param.mfx.FrameInfo.BitDepthChroma =
desc->comp[0].depth;
632 q->
param.mfx.FrameInfo.Shift =
desc->comp[0].depth > 8;
640 q->
param.mfx.FrameInfo.Width = frames_hwctx->surfaces[0].Info.Width;
641 q->
param.mfx.FrameInfo.Height = frames_hwctx->surfaces[0].Info.Height;
652 q->
param.mfx.Interleaved = 1;
654 q->
param.mfx.RestartInterval = 0;
671 int target_bitrate_kbps, max_bitrate_kbps, brc_param_multiplier;
672 int buffer_size_in_kilobytes, initial_delay_in_kilobytes;
680 if (avctx->
level > 0)
688 "valid range is 0-%d, using %d instead\n",
689 MFX_TARGETUSAGE_BEST_SPEED, MFX_TARGETUSAGE_BEST_SPEED);
696 q->
param.mfx.LowPower = MFX_CODINGOPTION_ON;
699 "not supported with this MSDK version.\n");
701 q->
param.mfx.LowPower = MFX_CODINGOPTION_OFF;
704 q->
param.mfx.LowPower = MFX_CODINGOPTION_UNKNOWN;
706 q->
param.mfx.LowPower = MFX_CODINGOPTION_OFF;
713 MFX_GOP_CLOSED : MFX_GOP_STRICT;
717 q->
param.mfx.EncodedOrder = 0;
718 q->
param.mfx.BufferSizeInKB = 0;
728 q->
param.mfx.FrameInfo.CropX = 0;
729 q->
param.mfx.FrameInfo.CropY = 0;
734 q->
param.mfx.FrameInfo.ChromaFormat = MFX_CHROMAFORMAT_YUV420 +
735 !
desc->log2_chroma_w + !
desc->log2_chroma_h;
736 q->
param.mfx.FrameInfo.BitDepthLuma =
desc->comp[0].depth;
737 q->
param.mfx.FrameInfo.BitDepthChroma =
desc->comp[0].depth;
738 q->
param.mfx.FrameInfo.Shift =
desc->comp[0].depth > 8;
750 q->
param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_FIELD_TFF;
754 q->
param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
765 q->
param.mfx.FrameInfo.Width = frames_hwctx->surfaces[0].Info.Width;
766 q->
param.mfx.FrameInfo.Height = frames_hwctx->surfaces[0].Info.Height;
784 target_bitrate_kbps = avctx->
bit_rate / 1000;
786 brc_param_multiplier = (
FFMAX(
FFMAX3(target_bitrate_kbps, max_bitrate_kbps, buffer_size_in_kilobytes),
787 initial_delay_in_kilobytes) + 0x10000) / 0x10000;
789 switch (q->
param.mfx.RateControlMethod) {
790 case MFX_RATECONTROL_CBR:
791 case MFX_RATECONTROL_VBR:
798 case MFX_RATECONTROL_VCM:
801 case MFX_RATECONTROL_QVBR:
803 q->
param.mfx.BufferSizeInKB = buffer_size_in_kilobytes / brc_param_multiplier;
804 q->
param.mfx.InitialDelayInKB = initial_delay_in_kilobytes / brc_param_multiplier;
805 q->
param.mfx.TargetKbps = target_bitrate_kbps / brc_param_multiplier;
806 q->
param.mfx.MaxKbps = max_bitrate_kbps / brc_param_multiplier;
807 q->
param.mfx.BRCParamMultiplier = brc_param_multiplier;
809 if (q->
param.mfx.RateControlMethod == MFX_RATECONTROL_QVBR)
813 case MFX_RATECONTROL_CQP:
822 case MFX_RATECONTROL_AVBR:
823 q->
param.mfx.TargetKbps = target_bitrate_kbps / brc_param_multiplier;
826 q->
param.mfx.BRCParamMultiplier = brc_param_multiplier;
830 case MFX_RATECONTROL_LA:
831 q->
param.mfx.TargetKbps = target_bitrate_kbps / brc_param_multiplier;
833 q->
param.mfx.BRCParamMultiplier = brc_param_multiplier;
836 case MFX_RATECONTROL_LA_ICQ:
838 case MFX_RATECONTROL_ICQ:
850 q->
extco.Header.BufferId = MFX_EXTBUFF_CODING_OPTION;
854 MFX_CODINGOPTION_ON : MFX_CODINGOPTION_UNKNOWN;
857 q->
extco.RateDistortionOpt = q->
rdo > 0 ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
860 q->
extco.CAVLC = q->
cavlc ? MFX_CODINGOPTION_ON
861 : MFX_CODINGOPTION_UNKNOWN;
865 MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
872 q->
extco.AUDelimiter = q->
aud ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
876 MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
881 q->
extco.AUDelimiter = q->
aud ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
889 q->extco2.BitrateLimit = q->
bitrate_limit ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
893 q->extco2.Trellis = (avctx->
trellis == 0) ? MFX_TRELLIS_OFF : (MFX_TRELLIS_I | MFX_TRELLIS_P | MFX_TRELLIS_B);
895 q->extco2.Trellis = MFX_TRELLIS_UNKNOWN;
898 #if QSV_VERSION_ATLEAST(1, 8)
900 q->extco2.RepeatPPS = q->
repeat_pps ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
903 q->extco2.AdaptiveI = q->
adaptive_i ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
905 q->extco2.AdaptiveB = q->
adaptive_b ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
911 q->extco2.ExtBRC = q->
extbrc ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
920 #if QSV_HAVE_MAX_SLICE_SIZE
924 #if QSV_HAVE_DISABLEDEBLOCKIDC
925 q->extco2.DisableDeblockingIdc = q->
dblk_idc;
928 #if QSV_VERSION_ATLEAST(1, 8)
930 q->extco2.BRefType = q->
b_strategy ? MFX_B_REF_PYRAMID : MFX_B_REF_OFF;
932 #if QSV_VERSION_ATLEAST(1, 9)
934 av_log(avctx,
AV_LOG_ERROR,
"qmin and or qmax are set but invalid, please make sure min <= max\n");
937 if (avctx->
qmin >= 0) {
938 q->extco2.MinQPI = avctx->
qmin > 51 ? 51 : avctx->
qmin;
939 q->extco2.MinQPP = q->extco2.MinQPB = q->extco2.MinQPI;
941 if (avctx->
qmax >= 0) {
942 q->extco2.MaxQPI = avctx->
qmax > 51 ? 51 : avctx->
qmax;
943 q->extco2.MaxQPP = q->extco2.MaxQPB = q->extco2.MaxQPI;
947 q->extco2.MBBRC = q->
mbbrc ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
949 q->extco2.Header.BufferId = MFX_EXTBUFF_CODING_OPTION2;
950 q->extco2.Header.BufferSz =
sizeof(q->extco2);
959 q->extmfp.Header.BufferId = MFX_EXTBUFF_MULTI_FRAME_PARAM;
960 q->extmfp.Header.BufferSz =
sizeof(q->extmfp);
962 q->extmfp.MFMode = q->mfmode;
969 q->extco3.Header.BufferId = MFX_EXTBUFF_CODING_OPTION3;
970 q->extco3.Header.BufferSz =
sizeof(q->extco3);
977 q->extco3.PRefType = MFX_P_REF_DEFAULT;
980 q->extco3.PRefType = MFX_P_REF_SIMPLE;
983 q->extco3.PRefType = MFX_P_REF_PYRAMID;
986 q->extco3.PRefType = MFX_P_REF_DEFAULT;
988 "invalid p_strategy, set to default\n");
991 if (q->extco3.PRefType == MFX_P_REF_PYRAMID &&
994 "Please set max_b_frames(-bf) to 0 to enable P-pyramid\n");
997 #if QSV_VERSION_ATLEAST(1, 16)
1001 #if QSV_VERSION_ATLEAST(1, 23)
1003 q->extco3.LowDelayBRC = q->
low_delay_brc ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
1005 #if QSV_VERSION_ATLEAST(1, 19)
1014 #if QSV_VERSION_ATLEAST(1, 26)
1016 q->extco3.TransformSkip = q->
transform_skip ? MFX_CODINGOPTION_ON :
1017 MFX_CODINGOPTION_OFF;
1019 q->extco3.TransformSkip = MFX_CODINGOPTION_UNKNOWN;
1022 q->extco3.GPB = q->
gpb ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
1029 #if QSV_HAVE_EXT_VP9_PARAM
1031 q->extvp9param.Header.BufferId = MFX_EXTBUFF_VP9_PARAM;
1032 q->extvp9param.Header.BufferSz =
sizeof(q->extvp9param);
1033 q->extvp9param.WriteIVFHeaders = MFX_CODINGOPTION_OFF;
1034 #if QSV_HAVE_EXT_VP9_TILES
1035 q->extvp9param.NumTileColumns = q->
tile_cols;
1036 q->extvp9param.NumTileRows = q->
tile_rows;
1042 #if QSV_HAVE_EXT_HEVC_TILES
1044 q->exthevctiles.Header.BufferId = MFX_EXTBUFF_HEVC_TILES;
1045 q->exthevctiles.Header.BufferSz =
sizeof(q->exthevctiles);
1046 q->exthevctiles.NumTileColumns = q->
tile_cols;
1047 q->exthevctiles.NumTileRows = q->
tile_rows;
1053 q->
extvsi.ColourDescriptionPresent = 0;
1058 q->
extvsi.ColourDescriptionPresent = 1;
1064 if (q->
extvsi.VideoFullRange || q->
extvsi.ColourDescriptionPresent) {
1065 q->
extvsi.Header.BufferId = MFX_EXTBUFF_VIDEO_SIGNAL_INFO;
1072 "some encoding parameters are not supported by the QSV "
1073 "runtime. Please double check the input parameters.\n");
1087 "Error calling GetVideoParam");
1103 #if QSV_HAVE_EXT_VP9_PARAM
1104 mfxExtVP9Param vp9_extend_buf = {
1105 .Header.BufferId = MFX_EXTBUFF_VP9_PARAM,
1106 .Header.BufferSz =
sizeof(vp9_extend_buf),
1111 mfxExtCodingOption2 co2 = {
1112 .Header.BufferId = MFX_EXTBUFF_CODING_OPTION2,
1113 .Header.BufferSz =
sizeof(co2),
1118 mfxExtCodingOption3 co3 = {
1119 .Header.BufferId = MFX_EXTBUFF_CODING_OPTION3,
1120 .Header.BufferSz =
sizeof(co3),
1124 mfxExtBuffer *ext_buffers[] = {
1125 #if QSV_HAVE_EXT_VP9_PARAM
1126 (mfxExtBuffer*)&vp9_extend_buf,
1129 (mfxExtBuffer*)&co2,
1132 (mfxExtBuffer*)&co3,
1136 q->
param.ExtParam = ext_buffers;
1142 "Error calling GetVideoParam");
1155 uint8_t sps_buf[128];
1156 uint8_t pps_buf[128];
1158 mfxExtCodingOptionSPSPPS extradata = {
1159 .Header.BufferId = MFX_EXTBUFF_CODING_OPTION_SPSPPS,
1160 .Header.BufferSz =
sizeof(extradata),
1161 .SPSBuffer = sps_buf, .SPSBufSize =
sizeof(sps_buf),
1162 .PPSBuffer = pps_buf, .PPSBufSize =
sizeof(pps_buf)
1165 mfxExtCodingOption co = {
1166 .Header.BufferId = MFX_EXTBUFF_CODING_OPTION,
1167 .Header.BufferSz =
sizeof(co),
1170 mfxExtCodingOption2 co2 = {
1171 .Header.BufferId = MFX_EXTBUFF_CODING_OPTION2,
1172 .Header.BufferSz =
sizeof(co2),
1176 mfxExtCodingOption3 co3 = {
1177 .Header.BufferId = MFX_EXTBUFF_CODING_OPTION3,
1178 .Header.BufferSz =
sizeof(co3),
1183 uint8_t vps_buf[128];
1184 mfxExtCodingOptionVPS extradata_vps = {
1185 .Header.BufferId = MFX_EXTBUFF_CODING_OPTION_VPS,
1186 .Header.BufferSz =
sizeof(extradata_vps),
1187 .VPSBuffer = vps_buf,
1188 .VPSBufSize =
sizeof(vps_buf),
1192 #if QSV_HAVE_EXT_HEVC_TILES
1193 mfxExtHEVCTiles hevc_tile_buf = {
1194 .Header.BufferId = MFX_EXTBUFF_HEVC_TILES,
1195 .Header.BufferSz =
sizeof(hevc_tile_buf),
1202 int ret, ext_buf_num = 0, extradata_offset = 0;
1204 ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&extradata;
1205 ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&co;
1207 ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&co2;
1210 ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&co3;
1215 ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&extradata_vps;
1217 #if QSV_HAVE_EXT_HEVC_TILES
1219 ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&hevc_tile_buf;
1222 q->
param.ExtParam = ext_buffers;
1223 q->
param.NumExtParam = ext_buf_num;
1228 "Error calling GetVideoParam");
1232 if (!extradata.SPSBufSize || (need_pps && !extradata.PPSBufSize)
1234 || (q->
hevc_vps && !extradata_vps.VPSBufSize)
1241 avctx->
extradata_size = extradata.SPSBufSize + need_pps * extradata.PPSBufSize;
1252 memcpy(avctx->
extradata, vps_buf, extradata_vps.VPSBufSize);
1253 extradata_offset += extradata_vps.VPSBufSize;
1257 memcpy(avctx->
extradata + extradata_offset, sps_buf, extradata.SPSBufSize);
1258 extradata_offset += extradata.SPSBufSize;
1260 memcpy(avctx->
extradata + extradata_offset, pps_buf, extradata.PPSBufSize);
1261 extradata_offset += extradata.PPSBufSize;
1281 mfxFrameSurface1 *surfaces;
1295 for (
i = 0;
i < nb_surfaces;
i++) {
1296 surfaces[
i].Info = q->
req.Info;
1300 q->
opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
1329 q->
param.IOPattern == MFX_IOPATTERN_IN_OPAQUE_MEMORY,
1360 int opaque_alloc = 0;
1381 if (frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME)
1382 iopattern = MFX_IOPATTERN_IN_OPAQUE_MEMORY;
1383 else if (frames_hwctx->frame_type &
1384 (MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET | MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET))
1385 iopattern = MFX_IOPATTERN_IN_VIDEO_MEMORY;
1390 iopattern = MFX_IOPATTERN_IN_SYSTEM_MEMORY;
1391 q->
param.IOPattern = iopattern;
1401 "Error querying mfx version");
1435 if (j < qsv->nb_ext_buffers)
1446 if (
ret == MFX_WRN_PARTIAL_ACCELERATION) {
1448 }
else if (
ret < 0) {
1450 "Error querying encoder params");
1456 "Error querying (IOSurf) the encoding parameters");
1467 "Error initializing the encoder");
1470 "Warning in encoder initialization");
1500 enc_ctrl->NumPayload = 0;
1537 last = &
frame->next;
1545 if (!
frame->frame) {
1616 !
frame->interlaced_frame ? MFX_PICSTRUCT_PROGRESSIVE :
1617 frame->top_field_first ? MFX_PICSTRUCT_FIELD_TFF :
1618 MFX_PICSTRUCT_FIELD_BFF;
1619 if (
frame->repeat_pict == 1)
1620 qf->
surface.Info.PicStruct |= MFX_PICSTRUCT_FIELD_REPEATED;
1621 else if (
frame->repeat_pict == 2)
1622 qf->
surface.Info.PicStruct |= MFX_PICSTRUCT_FRAME_DOUBLING;
1623 else if (
frame->repeat_pict == 4)
1624 qf->
surface.Info.PicStruct |= MFX_PICSTRUCT_FRAME_TRIPLING;
1641 if (q->
param.mfx.CodecId == MFX_CODEC_AVC) {
1642 if (q->
param.mfx.CodecProfile == MFX_PROFILE_AVC_BASELINE ||
1643 q->
param.mfx.CodecLevel < MFX_LEVEL_AVC_21 ||
1644 q->
param.mfx.CodecLevel > MFX_LEVEL_AVC_41)
1646 "Interlaced coding is supported"
1647 " at Main/High Profile Level 2.2-4.0\n");
1655 #if QSV_VERSION_ATLEAST(1, 26)
1656 mfxExtAVCEncodedFrameInfo *enc_info =
NULL;
1657 mfxExtBuffer **enc_buf =
NULL;
1660 mfxFrameSurface1 *surf =
NULL;
1662 mfxEncodeCtrl* enc_ctrl =
NULL;
1677 enc_ctrl->FrameType = MFX_FRAMETYPE_I | MFX_FRAMETYPE_REF;
1679 enc_ctrl->FrameType |= MFX_FRAMETYPE_IDR;
1695 #if QSV_VERSION_ATLEAST(1, 26)
1701 enc_info->Header.BufferId = MFX_EXTBUFF_ENCODED_FRAME_INFO;
1702 enc_info->Header.BufferSz =
sizeof (*enc_info);
1703 pkt.bs->NumExtParam = 1;
1704 enc_buf =
av_mallocz(
sizeof(mfxExtBuffer *));
1707 enc_buf[0] = (mfxExtBuffer *)enc_info;
1709 pkt.bs->ExtParam = enc_buf;
1722 ret = MFXVideoENCODE_EncodeFrameAsync(q->
session, enc_ctrl, surf,
pkt.bs,
pkt.sync);
1723 if (
ret == MFX_WRN_DEVICE_BUSY)
1725 }
while (
ret == MFX_WRN_DEVICE_BUSY ||
ret == MFX_WRN_IN_EXECUTION);
1731 ret = (
ret == MFX_ERR_MORE_DATA) ?
1736 if (
ret == MFX_WRN_INCOMPATIBLE_VIDEO_PARAM &&
frame &&
frame->interlaced_frame)
1748 #if QSV_VERSION_ATLEAST(1, 26)
1774 #if QSV_VERSION_ATLEAST(1, 26)
1775 mfxExtAVCEncodedFrameInfo *enc_info;
1776 mfxExtBuffer **enc_buf;
1784 }
while (
ret == MFX_WRN_IN_EXECUTION);
1790 if (qpkt.
bs->FrameType & MFX_FRAMETYPE_IDR || qpkt.
bs->FrameType & MFX_FRAMETYPE_xIDR) {
1793 }
else if (qpkt.
bs->FrameType & MFX_FRAMETYPE_I || qpkt.
bs->FrameType & MFX_FRAMETYPE_xI)
1795 else if (qpkt.
bs->FrameType & MFX_FRAMETYPE_P || qpkt.
bs->FrameType & MFX_FRAMETYPE_xP)
1797 else if (qpkt.
bs->FrameType & MFX_FRAMETYPE_B || qpkt.
bs->FrameType & MFX_FRAMETYPE_xB)
1799 else if (qpkt.
bs->FrameType == MFX_FRAMETYPE_UNKNOWN) {
1807 #if QSV_VERSION_ATLEAST(1, 26)
1809 enc_buf = qpkt.
bs->ExtParam;
1810 enc_info = (mfxExtAVCEncodedFrameInfo *)(*enc_buf);
1833 MFXVideoENCODE_Close(q->
session);
1853 #if QSV_VERSION_ATLEAST(1, 26)
1855 mfxExtBuffer **enc_buf =
pkt.bs->ExtParam;
1856 mfxExtAVCEncodedFrameInfo *enc_info = (mfxExtAVCEncodedFrameInfo *)(*enc_buf);