25 #include <sys/types.h>
26 #include <mfx/mfxvideo.h>
50 { MFX_PROFILE_AVC_BASELINE,
"avc baseline" },
51 { MFX_PROFILE_AVC_MAIN,
"avc main" },
52 { MFX_PROFILE_AVC_EXTENDED,
"avc extended" },
53 { MFX_PROFILE_AVC_HIGH,
"avc high" },
54 #if QSV_VERSION_ATLEAST(1, 15)
55 { MFX_PROFILE_AVC_HIGH_422,
"avc high 422" },
57 #if QSV_VERSION_ATLEAST(1, 4)
58 { MFX_PROFILE_AVC_CONSTRAINED_BASELINE,
"avc constrained baseline" },
59 { MFX_PROFILE_AVC_CONSTRAINED_HIGH,
"avc constrained high" },
60 { MFX_PROFILE_AVC_PROGRESSIVE_HIGH,
"avc progressive high" },
65 { MFX_PROFILE_MPEG2_SIMPLE,
"mpeg2 simple" },
66 { MFX_PROFILE_MPEG2_MAIN,
"mpeg2 main" },
67 { MFX_PROFILE_MPEG2_HIGH,
"mpeg2 high" },
71 #if QSV_VERSION_ATLEAST(1, 8)
72 { MFX_PROFILE_HEVC_MAIN,
"hevc main" },
73 { MFX_PROFILE_HEVC_MAIN10,
"hevc main10" },
74 { MFX_PROFILE_HEVC_MAINSP,
"hevc mainsp" },
75 { MFX_PROFILE_HEVC_REXT,
"hevc rext" },
80 #if QSV_VERSION_ATLEAST(1, 19)
81 { MFX_PROFILE_VP9_0,
"vp9 0" },
82 { MFX_PROFILE_VP9_1,
"vp9 1" },
83 { MFX_PROFILE_VP9_2,
"vp9 2" },
84 { MFX_PROFILE_VP9_3,
"vp9 3" },
118 for (
i = 0;
i < num_profiles;
i++)
125 static const struct {
129 { MFX_RATECONTROL_CBR,
"CBR" },
130 { MFX_RATECONTROL_VBR,
"VBR" },
131 { MFX_RATECONTROL_CQP,
"CQP" },
133 { MFX_RATECONTROL_AVBR,
"AVBR" },
136 { MFX_RATECONTROL_LA,
"LA" },
139 { MFX_RATECONTROL_ICQ,
"ICQ" },
140 { MFX_RATECONTROL_LA_ICQ,
"LA_ICQ" },
143 { MFX_RATECONTROL_VCM,
"VCM" },
145 #if QSV_VERSION_ATLEAST(1, 10)
146 { MFX_RATECONTROL_LA_EXT,
"LA_EXT" },
149 { MFX_RATECONTROL_LA_HRD,
"LA_HRD" },
152 { MFX_RATECONTROL_QVBR,
"QVBR" },
167 if (
val == MFX_CODINGOPTION_ON)
169 else if (
val == MFX_CODINGOPTION_OFF)
175 mfxExtBuffer **coding_opts)
179 mfxExtCodingOption *co = (mfxExtCodingOption*)coding_opts[0];
181 mfxExtCodingOption2 *co2 = (mfxExtCodingOption2*)coding_opts[1];
184 mfxExtCodingOption3 *co3 = (mfxExtCodingOption3*)coding_opts[2];
186 #if QSV_HAVE_EXT_HEVC_TILES
187 mfxExtHEVCTiles *exthevctiles = (mfxExtHEVCTiles *)coding_opts[3 +
QSV_HAVE_CO_VPS];
194 info->GopPicSize,
info->GopRefDist);
195 if (
info->GopOptFlag & MFX_GOP_CLOSED)
197 if (
info->GopOptFlag & MFX_GOP_STRICT)
204 if (
info->RateControlMethod == MFX_RATECONTROL_CBR ||
205 info->RateControlMethod == MFX_RATECONTROL_VBR
207 ||
info->RateControlMethod == MFX_RATECONTROL_VCM
211 "BufferSizeInKB: %"PRIu16
"; InitialDelayInKB: %"PRIu16
"; TargetKbps: %"PRIu16
"; MaxKbps: %"PRIu16
"; BRCParamMultiplier: %"PRIu16
"\n",
212 info->BufferSizeInKB,
info->InitialDelayInKB,
info->TargetKbps,
info->MaxKbps,
info->BRCParamMultiplier);
218 }
else if (
info->RateControlMethod == MFX_RATECONTROL_CQP) {
223 else if (
info->RateControlMethod == MFX_RATECONTROL_AVBR) {
225 "TargetKbps: %"PRIu16
"; Accuracy: %"PRIu16
"; Convergence: %"PRIu16
"; BRCParamMultiplier: %"PRIu16
"\n",
226 info->TargetKbps,
info->Accuracy,
info->Convergence,
info->BRCParamMultiplier);
230 else if (
info->RateControlMethod == MFX_RATECONTROL_LA
232 ||
info->RateControlMethod == MFX_RATECONTROL_LA_HRD
236 "TargetKbps: %"PRIu16
"; LookAheadDepth: %"PRIu16
"; BRCParamMultiplier: %"PRIu16
"\n",
237 info->TargetKbps, co2->LookAheadDepth,
info->BRCParamMultiplier);
241 else if (
info->RateControlMethod == MFX_RATECONTROL_ICQ) {
243 }
else if (
info->RateControlMethod == MFX_RATECONTROL_LA_ICQ) {
245 info->ICQQuality, co2->LookAheadDepth);
249 else if (
info->RateControlMethod == MFX_RATECONTROL_QVBR) {
259 #if QSV_HAVE_EXT_HEVC_TILES
262 exthevctiles->NumTileColumns, exthevctiles->NumTileRows);
267 "RecoveryPointSEI: %s IntRefType: %"PRIu16
"; IntRefCycleSize: %"PRIu16
"; IntRefQPDelta: %"PRId16
"\n",
268 print_threestate(co->RecoveryPointSEI), co2->IntRefType, co2->IntRefCycleSize, co2->IntRefQPDelta);
271 #if QSV_HAVE_MAX_SLICE_SIZE
277 "BitrateLimit: %s; MBBRC: %s; ExtBRC: %s\n",
283 if (co2->Trellis & MFX_TRELLIS_OFF) {
285 }
else if (!co2->Trellis) {
299 #if QSV_VERSION_ATLEAST(1, 8)
301 "RepeatPPS: %s; NumMbPerSlice: %"PRIu16
"; LookAheadDS: ",
303 switch (co2->LookAheadDS) {
313 switch (co2->BRefType) {
321 #if QSV_VERSION_ATLEAST(1, 9)
323 "MinQPI: %"PRIu8
"; MaxQPI: %"PRIu8
"; MinQPP: %"PRIu8
"; MaxQPP: %"PRIu8
"; MinQPB: %"PRIu8
"; MaxQPB: %"PRIu8
"\n",
324 co2->MinQPI, co2->MaxQPI, co2->MinQPP, co2->MaxQPP, co2->MinQPB, co2->MaxQPB);
335 co->CAVLC == MFX_CODINGOPTION_ON ?
"CAVLC" :
"CABAC", co->MaxDecFrameBuffering);
337 "NalHrdConformance: %s; SingleSeiNalUnit: %s; VuiVclHrdParameters: %s VuiNalHrdParameters: %s\n",
342 "NalHrdConformance: %s; VuiNalHrdParameters: %s\n",
347 info->FrameInfo.FrameRateExtD,
info->FrameInfo.FrameRateExtN);
352 mfxExtBuffer **coding_opts)
355 #if QSV_HAVE_EXT_VP9_PARAM
356 mfxExtVP9Param *vp9_param = (mfxExtVP9Param *)coding_opts[0];
359 mfxExtCodingOption2 *co2 = (mfxExtCodingOption2*)coding_opts[1];
366 info->GopPicSize,
info->GopRefDist);
367 if (
info->GopOptFlag & MFX_GOP_CLOSED)
369 if (
info->GopOptFlag & MFX_GOP_STRICT)
376 if (
info->RateControlMethod == MFX_RATECONTROL_CBR ||
377 info->RateControlMethod == MFX_RATECONTROL_VBR) {
379 "BufferSizeInKB: %"PRIu16
"; InitialDelayInKB: %"PRIu16
"; TargetKbps: %"PRIu16
"; MaxKbps: %"PRIu16
"; BRCParamMultiplier: %"PRIu16
"\n",
380 info->BufferSizeInKB,
info->InitialDelayInKB,
info->TargetKbps,
info->MaxKbps,
info->BRCParamMultiplier);
381 }
else if (
info->RateControlMethod == MFX_RATECONTROL_CQP) {
386 else if (
info->RateControlMethod == MFX_RATECONTROL_ICQ) {
398 "IntRefType: %"PRIu16
"; IntRefCycleSize: %"PRIu16
"; IntRefQPDelta: %"PRId16
"\n",
399 co2->IntRefType, co2->IntRefCycleSize, co2->IntRefQPDelta);
405 "BitrateLimit: %s; MBBRC: %s; ExtBRC: %s\n",
413 #if QSV_VERSION_ATLEAST(1, 9)
415 "MinQPI: %"PRIu8
"; MaxQPI: %"PRIu8
"; MinQPP: %"PRIu8
"; MaxQPP: %"PRIu8
"; MinQPB: %"PRIu8
"; MaxQPB: %"PRIu8
"\n",
416 co2->MinQPI, co2->MaxQPI, co2->MinQPP, co2->MaxQPP, co2->MinQPB, co2->MaxQPB);
421 info->FrameInfo.FrameRateExtD,
info->FrameInfo.FrameRateExtN);
423 #if QSV_HAVE_EXT_VP9_PARAM
438 info->FrameInfo.FrameRateExtD,
info->FrameInfo.FrameRateExtN);
448 int want_vcm = q->
vcm;
452 "Lookahead ratecontrol mode requested, but is not supported by this SDK version\n");
457 "VCM ratecontrol mode requested, but is not supported by this SDK version\n");
461 if (want_la + want_qscale + want_vcm > 1) {
463 "More than one of: { constant qscale, lookahead, VCM } requested, "
464 "only one of them can be used at a time.\n");
470 "ICQ ratecontrol mode requested, but is not supported by this SDK version\n");
476 rc_desc =
"constant quantization parameter (CQP)";
481 rc_desc =
"video conferencing mode (VCM)";
487 rc_desc =
"VBR with lookahead (LA)";
491 rc_mode = MFX_RATECONTROL_LA_ICQ;
492 rc_desc =
"intelligent constant quality with lookahead (LA_ICQ)";
500 rc_desc =
"intelligent constant quality (ICQ)";
505 rc_desc =
"constant bitrate (CBR)";
509 rc_mode = MFX_RATECONTROL_AVBR;
510 rc_desc =
"average variable bitrate (AVBR)";
515 rc_mode = MFX_RATECONTROL_QVBR;
516 rc_desc =
"constant quality with VBR algorithm (QVBR)";
521 rc_desc =
"variable bitrate (VBR)";
532 mfxVideoParam param_out = { .mfx.CodecId = q->
param.mfx.CodecId };
535 #define UNMATCH(x) (param_out.mfx.x != q->param.mfx.x)
544 if (
UNMATCH(RateControlMethod))
573 if (avctx->
level > 0)
583 q->
param.mfx.FrameInfo.CropX = 0;
584 q->
param.mfx.FrameInfo.CropY = 0;
589 q->
param.mfx.FrameInfo.ChromaFormat = MFX_CHROMAFORMAT_YUV420;
590 q->
param.mfx.FrameInfo.BitDepthLuma =
desc->comp[0].depth;
591 q->
param.mfx.FrameInfo.BitDepthChroma =
desc->comp[0].depth;
592 q->
param.mfx.FrameInfo.Shift =
desc->comp[0].depth > 8;
600 q->
param.mfx.FrameInfo.Width = frames_hwctx->surfaces[0].Info.Width;
601 q->
param.mfx.FrameInfo.Height = frames_hwctx->surfaces[0].Info.Height;
612 q->
param.mfx.Interleaved = 1;
614 q->
param.mfx.RestartInterval = 0;
631 int target_bitrate_kbps, max_bitrate_kbps, brc_param_multiplier;
632 int buffer_size_in_kilobytes, initial_delay_in_kilobytes;
640 if (avctx->
level > 0)
648 "valid range is 0-%d, using %d instead\n",
649 MFX_TARGETUSAGE_BEST_SPEED, MFX_TARGETUSAGE_BEST_SPEED);
656 q->
param.mfx.LowPower = MFX_CODINGOPTION_ON;
659 "not supported with this MSDK version.\n");
661 q->
param.mfx.LowPower = MFX_CODINGOPTION_OFF;
664 q->
param.mfx.LowPower = MFX_CODINGOPTION_UNKNOWN;
666 q->
param.mfx.LowPower = MFX_CODINGOPTION_OFF;
673 MFX_GOP_CLOSED : MFX_GOP_STRICT;
677 q->
param.mfx.EncodedOrder = 0;
678 q->
param.mfx.BufferSizeInKB = 0;
686 q->
param.mfx.FrameInfo.CropX = 0;
687 q->
param.mfx.FrameInfo.CropY = 0;
692 q->
param.mfx.FrameInfo.ChromaFormat = MFX_CHROMAFORMAT_YUV420 +
693 !
desc->log2_chroma_w + !
desc->log2_chroma_h;
694 q->
param.mfx.FrameInfo.BitDepthLuma =
desc->comp[0].depth;
695 q->
param.mfx.FrameInfo.BitDepthChroma =
desc->comp[0].depth;
696 q->
param.mfx.FrameInfo.Shift =
desc->comp[0].depth > 8;
708 q->
param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_FIELD_TFF;
712 q->
param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
723 q->
param.mfx.FrameInfo.Width = frames_hwctx->surfaces[0].Info.Width;
724 q->
param.mfx.FrameInfo.Height = frames_hwctx->surfaces[0].Info.Height;
742 target_bitrate_kbps = avctx->
bit_rate / 1000;
744 brc_param_multiplier = (
FFMAX(
FFMAX3(target_bitrate_kbps, max_bitrate_kbps, buffer_size_in_kilobytes),
745 initial_delay_in_kilobytes) + 0x10000) / 0x10000;
747 switch (q->
param.mfx.RateControlMethod) {
748 case MFX_RATECONTROL_CBR:
749 case MFX_RATECONTROL_VBR:
756 case MFX_RATECONTROL_VCM:
759 case MFX_RATECONTROL_QVBR:
761 q->
param.mfx.BufferSizeInKB = buffer_size_in_kilobytes / brc_param_multiplier;
762 q->
param.mfx.InitialDelayInKB = initial_delay_in_kilobytes / brc_param_multiplier;
763 q->
param.mfx.TargetKbps = target_bitrate_kbps / brc_param_multiplier;
764 q->
param.mfx.MaxKbps = max_bitrate_kbps / brc_param_multiplier;
765 q->
param.mfx.BRCParamMultiplier = brc_param_multiplier;
767 if (q->
param.mfx.RateControlMethod == MFX_RATECONTROL_QVBR)
771 case MFX_RATECONTROL_CQP:
780 case MFX_RATECONTROL_AVBR:
781 q->
param.mfx.TargetKbps = target_bitrate_kbps / brc_param_multiplier;
784 q->
param.mfx.BRCParamMultiplier = brc_param_multiplier;
788 case MFX_RATECONTROL_LA:
789 q->
param.mfx.TargetKbps = target_bitrate_kbps / brc_param_multiplier;
791 q->
param.mfx.BRCParamMultiplier = brc_param_multiplier;
794 case MFX_RATECONTROL_LA_ICQ:
796 case MFX_RATECONTROL_ICQ:
808 q->
extco.Header.BufferId = MFX_EXTBUFF_CODING_OPTION;
812 MFX_CODINGOPTION_ON : MFX_CODINGOPTION_UNKNOWN;
815 q->
extco.RateDistortionOpt = q->
rdo > 0 ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
818 q->
extco.CAVLC = q->
cavlc ? MFX_CODINGOPTION_ON
819 : MFX_CODINGOPTION_UNKNOWN;
823 MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
830 q->
extco.AUDelimiter = q->
aud ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
834 MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
839 q->
extco.AUDelimiter = q->
aud ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
854 q->extco2.BitrateLimit = q->
bitrate_limit ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
856 q->extco2.MBBRC = q->
mbbrc ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
860 #if QSV_HAVE_MAX_SLICE_SIZE
867 q->extco2.Trellis = (avctx->
trellis == 0) ? MFX_TRELLIS_OFF : (MFX_TRELLIS_I | MFX_TRELLIS_P | MFX_TRELLIS_B);
869 q->extco2.Trellis = MFX_TRELLIS_UNKNOWN;
872 #if QSV_VERSION_ATLEAST(1, 8)
874 q->extco2.RepeatPPS = q->
repeat_pps ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
877 q->extco2.BRefType = q->
b_strategy ? MFX_B_REF_PYRAMID : MFX_B_REF_OFF;
879 q->extco2.AdaptiveI = q->
adaptive_i ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
881 q->extco2.AdaptiveB = q->
adaptive_b ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
887 q->extco2.ExtBRC = q->
extbrc ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
889 #if QSV_VERSION_ATLEAST(1, 9)
891 av_log(avctx,
AV_LOG_ERROR,
"qmin and or qmax are set but invalid, please make sure min <= max\n");
894 if (avctx->
qmin >= 0) {
895 q->extco2.MinQPI = avctx->
qmin > 51 ? 51 : avctx->
qmin;
896 q->extco2.MinQPP = q->extco2.MinQPB = q->extco2.MinQPI;
898 if (avctx->
qmax >= 0) {
899 q->extco2.MaxQPI = avctx->
qmax > 51 ? 51 : avctx->
qmax;
900 q->extco2.MaxQPP = q->extco2.MaxQPB = q->extco2.MaxQPI;
903 q->extco2.Header.BufferId = MFX_EXTBUFF_CODING_OPTION2;
904 q->extco2.Header.BufferSz =
sizeof(q->extco2);
913 q->extmfp.Header.BufferId = MFX_EXTBUFF_MULTI_FRAME_PARAM;
914 q->extmfp.Header.BufferSz =
sizeof(q->extmfp);
916 q->extmfp.MFMode = q->mfmode;
923 q->extco3.Header.BufferId = MFX_EXTBUFF_CODING_OPTION3;
924 q->extco3.Header.BufferSz =
sizeof(q->extco3);
927 q->extco3.GPB = q->
gpb ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
933 #if QSV_HAVE_EXT_VP9_PARAM
935 q->extvp9param.Header.BufferId = MFX_EXTBUFF_VP9_PARAM;
936 q->extvp9param.Header.BufferSz =
sizeof(q->extvp9param);
937 q->extvp9param.WriteIVFHeaders = MFX_CODINGOPTION_OFF;
942 #if QSV_HAVE_EXT_HEVC_TILES
944 q->exthevctiles.Header.BufferId = MFX_EXTBUFF_HEVC_TILES;
945 q->exthevctiles.Header.BufferSz =
sizeof(q->exthevctiles);
946 q->exthevctiles.NumTileColumns = q->
tile_cols;
947 q->exthevctiles.NumTileRows = q->
tile_rows;
953 q->
extvsi.ColourDescriptionPresent = 0;
958 q->
extvsi.ColourDescriptionPresent = 1;
964 if (q->
extvsi.VideoFullRange || q->
extvsi.ColourDescriptionPresent) {
965 q->
extvsi.Header.BufferId = MFX_EXTBUFF_VIDEO_SIGNAL_INFO;
972 "some encoding parameters are not supported by the QSV "
973 "runtime. Please double check the input parameters.\n");
987 "Error calling GetVideoParam");
1003 #if QSV_HAVE_EXT_VP9_PARAM
1004 mfxExtVP9Param vp9_extend_buf = {
1005 .Header.BufferId = MFX_EXTBUFF_VP9_PARAM,
1006 .Header.BufferSz =
sizeof(vp9_extend_buf),
1011 mfxExtCodingOption2 co2 = {
1012 .Header.BufferId = MFX_EXTBUFF_CODING_OPTION2,
1013 .Header.BufferSz =
sizeof(co2),
1018 mfxExtCodingOption3 co3 = {
1019 .Header.BufferId = MFX_EXTBUFF_CODING_OPTION3,
1020 .Header.BufferSz =
sizeof(co3),
1024 mfxExtBuffer *ext_buffers[] = {
1025 #if QSV_HAVE_EXT_VP9_PARAM
1026 (mfxExtBuffer*)&vp9_extend_buf,
1029 (mfxExtBuffer*)&co2,
1032 (mfxExtBuffer*)&co3,
1036 q->
param.ExtParam = ext_buffers;
1042 "Error calling GetVideoParam");
1055 uint8_t sps_buf[128];
1056 uint8_t pps_buf[128];
1058 mfxExtCodingOptionSPSPPS extradata = {
1059 .Header.BufferId = MFX_EXTBUFF_CODING_OPTION_SPSPPS,
1060 .Header.BufferSz =
sizeof(extradata),
1061 .SPSBuffer = sps_buf, .SPSBufSize =
sizeof(sps_buf),
1062 .PPSBuffer = pps_buf, .PPSBufSize =
sizeof(pps_buf)
1065 mfxExtCodingOption co = {
1066 .Header.BufferId = MFX_EXTBUFF_CODING_OPTION,
1067 .Header.BufferSz =
sizeof(co),
1070 mfxExtCodingOption2 co2 = {
1071 .Header.BufferId = MFX_EXTBUFF_CODING_OPTION2,
1072 .Header.BufferSz =
sizeof(co2),
1076 mfxExtCodingOption3 co3 = {
1077 .Header.BufferId = MFX_EXTBUFF_CODING_OPTION3,
1078 .Header.BufferSz =
sizeof(co3),
1083 uint8_t vps_buf[128];
1084 mfxExtCodingOptionVPS extradata_vps = {
1085 .Header.BufferId = MFX_EXTBUFF_CODING_OPTION_VPS,
1086 .Header.BufferSz =
sizeof(extradata_vps),
1087 .VPSBuffer = vps_buf,
1088 .VPSBufSize =
sizeof(vps_buf),
1092 #if QSV_HAVE_EXT_HEVC_TILES
1093 mfxExtHEVCTiles hevc_tile_buf = {
1094 .Header.BufferId = MFX_EXTBUFF_HEVC_TILES,
1095 .Header.BufferSz =
sizeof(hevc_tile_buf),
1102 int ret, ext_buf_num = 0, extradata_offset = 0;
1104 ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&extradata;
1105 ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&co;
1107 ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&co2;
1110 ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&co3;
1115 ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&extradata_vps;
1117 #if QSV_HAVE_EXT_HEVC_TILES
1119 ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&hevc_tile_buf;
1122 q->
param.ExtParam = ext_buffers;
1123 q->
param.NumExtParam = ext_buf_num;
1128 "Error calling GetVideoParam");
1132 if (!extradata.SPSBufSize || (need_pps && !extradata.PPSBufSize)
1134 || (q->
hevc_vps && !extradata_vps.VPSBufSize)
1141 avctx->
extradata_size = extradata.SPSBufSize + need_pps * extradata.PPSBufSize;
1152 memcpy(avctx->
extradata, vps_buf, extradata_vps.VPSBufSize);
1153 extradata_offset += extradata_vps.VPSBufSize;
1157 memcpy(avctx->
extradata + extradata_offset, sps_buf, extradata.SPSBufSize);
1158 extradata_offset += extradata.SPSBufSize;
1160 memcpy(avctx->
extradata + extradata_offset, pps_buf, extradata.PPSBufSize);
1161 extradata_offset += extradata.PPSBufSize;
1181 mfxFrameSurface1 *surfaces;
1195 for (
i = 0;
i < nb_surfaces;
i++) {
1196 surfaces[
i].Info = q->
req.Info;
1200 q->
opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
1229 q->
param.IOPattern == MFX_IOPATTERN_IN_OPAQUE_MEMORY,
1259 return sizeof(
AVPacket) +
sizeof(mfxSyncPoint*) +
sizeof(mfxBitstream*);
1270 int opaque_alloc = 0;
1291 if (frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME)
1292 iopattern = MFX_IOPATTERN_IN_OPAQUE_MEMORY;
1293 else if (frames_hwctx->frame_type &
1294 (MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET | MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET))
1295 iopattern = MFX_IOPATTERN_IN_VIDEO_MEMORY;
1300 iopattern = MFX_IOPATTERN_IN_SYSTEM_MEMORY;
1301 q->
param.IOPattern = iopattern;
1311 "Error querying mfx version");
1345 if (j < qsv->nb_ext_buffers)
1356 if (
ret == MFX_WRN_PARTIAL_ACCELERATION) {
1358 }
else if (
ret < 0) {
1360 "Error querying encoder params");
1366 "Error querying (IOSurf) the encoding parameters");
1377 "Error initializing the encoder");
1380 "Warning in encoder initialization");
1410 enc_ctrl->NumPayload = 0;
1447 last = &
frame->next;
1455 if (!
frame->frame) {
1525 !
frame->interlaced_frame ? MFX_PICSTRUCT_PROGRESSIVE :
1526 frame->top_field_first ? MFX_PICSTRUCT_FIELD_TFF :
1527 MFX_PICSTRUCT_FIELD_BFF;
1528 if (
frame->repeat_pict == 1)
1529 qf->
surface.Info.PicStruct |= MFX_PICSTRUCT_FIELD_REPEATED;
1530 else if (
frame->repeat_pict == 2)
1531 qf->
surface.Info.PicStruct |= MFX_PICSTRUCT_FRAME_DOUBLING;
1532 else if (
frame->repeat_pict == 4)
1533 qf->
surface.Info.PicStruct |= MFX_PICSTRUCT_FRAME_TRIPLING;
1549 if (q->
param.mfx.CodecId == MFX_CODEC_AVC) {
1550 if (q->
param.mfx.CodecProfile == MFX_PROFILE_AVC_BASELINE ||
1551 q->
param.mfx.CodecLevel < MFX_LEVEL_AVC_21 ||
1552 q->
param.mfx.CodecLevel > MFX_LEVEL_AVC_41)
1554 "Interlaced coding is supported"
1555 " at Main/High Profile Level 2.2-4.0\n");
1563 mfxBitstream *bs =
NULL;
1564 #if QSV_VERSION_ATLEAST(1, 26)
1565 mfxExtAVCEncodedFrameInfo *enc_info =
NULL;
1566 mfxExtBuffer **enc_buf =
NULL;
1569 mfxFrameSurface1 *surf =
NULL;
1570 mfxSyncPoint *sync =
NULL;
1572 mfxEncodeCtrl* enc_ctrl =
NULL;
1587 enc_ctrl->FrameType = MFX_FRAMETYPE_I | MFX_FRAMETYPE_REF;
1589 enc_ctrl->FrameType |= MFX_FRAMETYPE_IDR;
1602 bs->Data = new_pkt.
data;
1603 bs->MaxLength = new_pkt.
size;
1605 #if QSV_VERSION_ATLEAST(1, 26)
1611 enc_info->Header.BufferId = MFX_EXTBUFF_ENCODED_FRAME_INFO;
1612 enc_info->Header.BufferSz =
sizeof (*enc_info);
1613 bs->NumExtParam = 1;
1614 enc_buf =
av_mallocz(
sizeof(mfxExtBuffer *));
1617 enc_buf[0] = (mfxExtBuffer *)enc_info;
1619 bs->ExtParam = enc_buf;
1632 ret = MFXVideoENCODE_EncodeFrameAsync(q->
session, enc_ctrl, surf, bs, sync);
1633 if (
ret == MFX_WRN_DEVICE_BUSY)
1635 }
while (
ret == MFX_WRN_DEVICE_BUSY ||
ret == MFX_WRN_IN_EXECUTION);
1641 ret = (
ret == MFX_ERR_MORE_DATA) ?
1646 if (
ret == MFX_WRN_INCOMPATIBLE_VIDEO_PARAM &&
frame->interlaced_frame)
1660 #if QSV_VERSION_ATLEAST(1, 26)
1688 #if QSV_VERSION_ATLEAST(1, 26)
1689 mfxExtAVCEncodedFrameInfo *enc_info;
1690 mfxExtBuffer **enc_buf;
1699 ret = MFXVideoCORE_SyncOperation(q->
session, *sync, 1000);
1700 }
while (
ret == MFX_WRN_IN_EXECUTION);
1704 new_pkt.
size = bs->DataLength;
1706 if (bs->FrameType & MFX_FRAMETYPE_IDR || bs->FrameType & MFX_FRAMETYPE_xIDR) {
1709 }
else if (bs->FrameType & MFX_FRAMETYPE_I || bs->FrameType & MFX_FRAMETYPE_xI)
1711 else if (bs->FrameType & MFX_FRAMETYPE_P || bs->FrameType & MFX_FRAMETYPE_xP)
1713 else if (bs->FrameType & MFX_FRAMETYPE_B || bs->FrameType & MFX_FRAMETYPE_xB)
1715 else if (bs->FrameType == MFX_FRAMETYPE_UNKNOWN) {
1723 #if QSV_VERSION_ATLEAST(1, 26)
1725 enc_buf = bs->ExtParam;
1726 enc_info = (mfxExtAVCEncodedFrameInfo *)(*bs->ExtParam);
1749 MFXVideoENCODE_Close(q->
session);
1775 #if QSV_VERSION_ATLEAST(1, 26)
1777 mfxExtBuffer **enc_buf = bs->ExtParam;
1778 mfxExtAVCEncodedFrameInfo *enc_info = (mfxExtAVCEncodedFrameInfo *)(*bs->ExtParam);