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 { MFX_PROFILE_AVC_HIGH_422,
"avc high 422" },
57 { MFX_PROFILE_AVC_CONSTRAINED_BASELINE,
"avc constrained baseline" },
58 { MFX_PROFILE_AVC_CONSTRAINED_HIGH,
"avc constrained high" },
59 { MFX_PROFILE_AVC_PROGRESSIVE_HIGH,
"avc progressive high" },
63 { MFX_PROFILE_MPEG2_SIMPLE,
"mpeg2 simple" },
64 { MFX_PROFILE_MPEG2_MAIN,
"mpeg2 main" },
65 { MFX_PROFILE_MPEG2_HIGH,
"mpeg2 high" },
69 { MFX_PROFILE_HEVC_MAIN,
"hevc main" },
70 { MFX_PROFILE_HEVC_MAIN10,
"hevc main10" },
71 { MFX_PROFILE_HEVC_MAINSP,
"hevc mainsp" },
72 { MFX_PROFILE_HEVC_REXT,
"hevc rext" },
73 #if QSV_VERSION_ATLEAST(1, 32)
74 { MFX_PROFILE_HEVC_SCC,
"hevc scc" },
79 { MFX_PROFILE_VP9_0,
"vp9 0" },
80 { MFX_PROFILE_VP9_1,
"vp9 1" },
81 { MFX_PROFILE_VP9_2,
"vp9 2" },
82 { MFX_PROFILE_VP9_3,
"vp9 3" },
121 for (
i = 0;
i < num_profiles;
i++)
128 static const struct {
132 { MFX_RATECONTROL_CBR,
"CBR" },
133 { MFX_RATECONTROL_VBR,
"VBR" },
134 { MFX_RATECONTROL_CQP,
"CQP" },
136 { MFX_RATECONTROL_AVBR,
"AVBR" },
138 { MFX_RATECONTROL_LA,
"LA" },
139 { MFX_RATECONTROL_ICQ,
"ICQ" },
140 { MFX_RATECONTROL_LA_ICQ,
"LA_ICQ" },
142 { MFX_RATECONTROL_VCM,
"VCM" },
144 { MFX_RATECONTROL_LA_EXT,
"LA_EXT" },
145 { MFX_RATECONTROL_LA_HRD,
"LA_HRD" },
146 { MFX_RATECONTROL_QVBR,
"QVBR" },
149 #define UPDATE_PARAM(a, b) \
168 if (
val == MFX_CODINGOPTION_ON)
170 else if (
val == MFX_CODINGOPTION_OFF)
176 mfxExtBuffer **coding_opts)
181 mfxExtCodingOption *co = (mfxExtCodingOption*)coding_opts[1];
182 mfxExtCodingOption2 *co2 =
NULL;
183 mfxExtCodingOption3 *co3 =
NULL;
184 mfxExtHEVCTiles *exthevctiles =
NULL;
187 co2 = (mfxExtCodingOption2*)coding_opts[q->
co2_idx];
190 co3 = (mfxExtCodingOption3*)coding_opts[q->
co3_idx];
199 info->GopPicSize,
info->GopRefDist);
200 if (
info->GopOptFlag & MFX_GOP_CLOSED)
202 if (
info->GopOptFlag & MFX_GOP_STRICT)
209 if (
info->RateControlMethod == MFX_RATECONTROL_CBR ||
210 info->RateControlMethod == MFX_RATECONTROL_VBR
212 ||
info->RateControlMethod == MFX_RATECONTROL_VCM
216 "BufferSizeInKB: %"PRIu16
"; InitialDelayInKB: %"PRIu16
"; TargetKbps: %"PRIu16
"; MaxKbps: %"PRIu16
"; BRCParamMultiplier: %"PRIu16
"\n",
217 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);
229 else if (
info->RateControlMethod == MFX_RATECONTROL_LA
230 ||
info->RateControlMethod == MFX_RATECONTROL_LA_HRD
233 "TargetKbps: %"PRIu16
"; BRCParamMultiplier: %"PRIu16
"\n",
234 info->TargetKbps,
info->BRCParamMultiplier);
235 }
else if (
info->RateControlMethod == MFX_RATECONTROL_ICQ ||
236 info->RateControlMethod == MFX_RATECONTROL_LA_ICQ)
248 co->CAVLC == MFX_CODINGOPTION_ON ?
"CAVLC" :
"CABAC", co->MaxDecFrameBuffering);
250 "NalHrdConformance: %s; SingleSeiNalUnit: %s; VuiVclHrdParameters: %s VuiNalHrdParameters: %s\n",
255 "NalHrdConformance: %s; VuiNalHrdParameters: %s\n",
260 info->FrameInfo.FrameRateExtD,
info->FrameInfo.FrameRateExtN);
264 (
info->RateControlMethod == MFX_RATECONTROL_LA) ||
265 (
info->RateControlMethod == MFX_RATECONTROL_LA_HRD) ||
266 (
info->RateControlMethod == MFX_RATECONTROL_LA_ICQ))
269 av_log(avctx,
AV_LOG_VERBOSE,
"IntRefType: %"PRIu16
"; IntRefCycleSize: %"PRIu16
"; IntRefQPDelta: %"PRId16
"\n",
270 co2->IntRefType, co2->IntRefCycleSize, co2->IntRefQPDelta);
277 "BitrateLimit: %s; MBBRC: %s; ExtBRC: %s\n",
282 if (co2->Trellis & MFX_TRELLIS_OFF) {
284 }
else if (!co2->Trellis) {
294 "RepeatPPS: %s; NumMbPerSlice: %"PRIu16
"; LookAheadDS: ",
296 switch (co2->LookAheadDS) {
306 switch (co2->BRefType) {
313 "MinQPI: %"PRIu8
"; MaxQPI: %"PRIu8
"; MinQPP: %"PRIu8
"; MaxQPP: %"PRIu8
"; MinQPB: %"PRIu8
"; MaxQPB: %"PRIu8
"\n",
314 co2->MinQPI, co2->MaxQPI, co2->MinQPP, co2->MaxQPP, co2->MinQPB, co2->MaxQPB);
319 if (
info->RateControlMethod == MFX_RATECONTROL_QVBR)
323 switch (co3->PRefType) {
343 exthevctiles->NumTileColumns, exthevctiles->NumTileRows);
348 mfxExtBuffer **coding_opts)
351 mfxExtVP9Param *vp9_param =
NULL;
352 mfxExtCodingOption2 *co2 =
NULL;
355 vp9_param = (mfxExtVP9Param *)coding_opts[q->
vp9_idx];
358 co2 = (mfxExtCodingOption2*)coding_opts[q->
co2_idx];
364 info->GopPicSize,
info->GopRefDist);
365 if (
info->GopOptFlag & MFX_GOP_CLOSED)
367 if (
info->GopOptFlag & MFX_GOP_STRICT)
374 if (
info->RateControlMethod == MFX_RATECONTROL_CBR ||
375 info->RateControlMethod == MFX_RATECONTROL_VBR) {
377 "BufferSizeInKB: %"PRIu16
"; InitialDelayInKB: %"PRIu16
"; TargetKbps: %"PRIu16
"; MaxKbps: %"PRIu16
"; BRCParamMultiplier: %"PRIu16
"\n",
378 info->BufferSizeInKB,
info->InitialDelayInKB,
info->TargetKbps,
info->MaxKbps,
info->BRCParamMultiplier);
379 }
else if (
info->RateControlMethod == MFX_RATECONTROL_CQP) {
383 else if (
info->RateControlMethod == MFX_RATECONTROL_ICQ) {
392 info->FrameInfo.FrameRateExtD,
info->FrameInfo.FrameRateExtN);
396 "IntRefType: %"PRIu16
"; IntRefCycleSize: %"PRIu16
"; IntRefQPDelta: %"PRId16
"\n",
397 co2->IntRefType, co2->IntRefCycleSize, co2->IntRefQPDelta);
403 "BitrateLimit: %s; MBBRC: %s; ExtBRC: %s\n",
410 "MinQPI: %"PRIu8
"; MaxQPI: %"PRIu8
"; MinQPP: %"PRIu8
"; MaxQPP: %"PRIu8
"; MinQPB: %"PRIu8
"; MaxQPB: %"PRIu8
"\n",
411 co2->MinQPI, co2->MaxQPI, co2->MinQPP, co2->MaxQPP, co2->MinQPB, co2->MaxQPB);
429 info->FrameInfo.FrameRateExtD,
info->FrameInfo.FrameRateExtN);
439 int want_vcm = q->
vcm;
443 "VCM ratecontrol mode requested, but is not supported by this SDK version\n");
447 if (want_la + want_qscale + want_vcm > 1) {
449 "More than one of: { constant qscale, lookahead, VCM } requested, "
450 "only one of them can be used at a time.\n");
456 rc_desc =
"constant quantization parameter (CQP)";
461 rc_desc =
"video conferencing mode (VCM)";
466 rc_desc =
"VBR with lookahead (LA)";
469 rc_mode = MFX_RATECONTROL_LA_ICQ;
470 rc_desc =
"intelligent constant quality with lookahead (LA_ICQ)";
475 rc_desc =
"intelligent constant quality (ICQ)";
479 rc_desc =
"constant bitrate (CBR)";
483 rc_mode = MFX_RATECONTROL_AVBR;
484 rc_desc =
"average variable bitrate (AVBR)";
488 rc_mode = MFX_RATECONTROL_QVBR;
489 rc_desc =
"constant quality with VBR algorithm (QVBR)";
493 rc_desc =
"variable bitrate (VBR)";
504 mfxVideoParam param_out = { .mfx.CodecId = q->
param.mfx.CodecId };
507 #define UNMATCH(x) (param_out.mfx.x != q->param.mfx.x)
516 if (
UNMATCH(RateControlMethod))
545 if (avctx->
level > 0)
557 q->
param.mfx.FrameInfo.CropX = 0;
558 q->
param.mfx.FrameInfo.CropY = 0;
563 q->
param.mfx.FrameInfo.ChromaFormat = MFX_CHROMAFORMAT_YUV420 +
564 !
desc->log2_chroma_w + !
desc->log2_chroma_h;
565 q->
param.mfx.FrameInfo.BitDepthLuma =
desc->comp[0].depth;
566 q->
param.mfx.FrameInfo.BitDepthChroma =
desc->comp[0].depth;
567 q->
param.mfx.FrameInfo.Shift =
desc->comp[0].depth > 8;
575 q->
param.mfx.FrameInfo.Width = frames_hwctx->surfaces[0].Info.Width;
576 q->
param.mfx.FrameInfo.Height = frames_hwctx->surfaces[0].Info.Height;
587 q->
param.mfx.Interleaved = 1;
589 q->
param.mfx.RestartInterval = 0;
606 int target_bitrate_kbps, max_bitrate_kbps, brc_param_multiplier;
607 int buffer_size_in_kilobytes, initial_delay_in_kilobytes;
615 if (avctx->
level > 0)
623 "valid range is 0-%d, using %d instead\n",
624 MFX_TARGETUSAGE_BEST_SPEED, MFX_TARGETUSAGE_BEST_SPEED);
630 q->
param.mfx.LowPower = MFX_CODINGOPTION_ON;
632 q->
param.mfx.LowPower = MFX_CODINGOPTION_UNKNOWN;
634 q->
param.mfx.LowPower = MFX_CODINGOPTION_OFF;
641 MFX_GOP_CLOSED : MFX_GOP_STRICT;
645 q->
param.mfx.EncodedOrder = 0;
646 q->
param.mfx.BufferSizeInKB = 0;
656 q->
param.mfx.FrameInfo.CropX = 0;
657 q->
param.mfx.FrameInfo.CropY = 0;
662 q->
param.mfx.FrameInfo.ChromaFormat = MFX_CHROMAFORMAT_YUV420 +
663 !
desc->log2_chroma_w + !
desc->log2_chroma_h;
664 q->
param.mfx.FrameInfo.BitDepthLuma =
desc->comp[0].depth;
665 q->
param.mfx.FrameInfo.BitDepthChroma =
desc->comp[0].depth;
666 q->
param.mfx.FrameInfo.Shift =
desc->comp[0].depth > 8;
678 q->
param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_FIELD_TFF;
682 q->
param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
693 q->
param.mfx.FrameInfo.Width = frames_hwctx->surfaces[0].Info.Width;
694 q->
param.mfx.FrameInfo.Height = frames_hwctx->surfaces[0].Info.Height;
712 target_bitrate_kbps = avctx->
bit_rate / 1000;
714 brc_param_multiplier = (
FFMAX(
FFMAX3(target_bitrate_kbps, max_bitrate_kbps, buffer_size_in_kilobytes),
715 initial_delay_in_kilobytes) + 0x10000) / 0x10000;
717 switch (q->
param.mfx.RateControlMethod) {
718 case MFX_RATECONTROL_CBR:
719 case MFX_RATECONTROL_VBR:
724 case MFX_RATECONTROL_VCM:
726 case MFX_RATECONTROL_QVBR:
727 q->
param.mfx.BufferSizeInKB = buffer_size_in_kilobytes / brc_param_multiplier;
728 q->
param.mfx.InitialDelayInKB = initial_delay_in_kilobytes / brc_param_multiplier;
729 q->
param.mfx.TargetKbps = target_bitrate_kbps / brc_param_multiplier;
730 q->
param.mfx.MaxKbps = max_bitrate_kbps / brc_param_multiplier;
731 q->
param.mfx.BRCParamMultiplier = brc_param_multiplier;
732 if (q->
param.mfx.RateControlMethod == MFX_RATECONTROL_QVBR)
735 case MFX_RATECONTROL_CQP:
744 case MFX_RATECONTROL_AVBR:
745 q->
param.mfx.TargetKbps = target_bitrate_kbps / brc_param_multiplier;
748 q->
param.mfx.BRCParamMultiplier = brc_param_multiplier;
751 case MFX_RATECONTROL_LA:
752 q->
param.mfx.TargetKbps = target_bitrate_kbps / brc_param_multiplier;
754 q->
param.mfx.BRCParamMultiplier = brc_param_multiplier;
756 case MFX_RATECONTROL_LA_ICQ:
758 case MFX_RATECONTROL_ICQ:
768 q->
extco.Header.BufferId = MFX_EXTBUFF_CODING_OPTION;
772 MFX_CODINGOPTION_ON : MFX_CODINGOPTION_UNKNOWN;
775 q->
extco.RateDistortionOpt = q->
rdo > 0 ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
778 q->
extco.CAVLC = q->
cavlc ? MFX_CODINGOPTION_ON
779 : MFX_CODINGOPTION_UNKNOWN;
783 MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
790 q->
extco.AUDelimiter = q->
aud ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
794 MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
799 q->
extco.AUDelimiter = q->
aud ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
809 q->
extco2.Trellis = (avctx->
trellis == 0) ? MFX_TRELLIS_OFF : (MFX_TRELLIS_I | MFX_TRELLIS_P | MFX_TRELLIS_B);
811 q->
extco2.Trellis = MFX_TRELLIS_UNKNOWN;
814 q->
extco2.RepeatPPS = q->
repeat_pps ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
817 q->
extco2.AdaptiveI = q->
adaptive_i ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
819 q->
extco2.AdaptiveB = q->
adaptive_b ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
824 q->
extco2.ExtBRC = q->
extbrc ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
844 "qmin and or qmax are set but invalid,"
845 " please make sure min <= max\n");
848 if (avctx->
qmin >= 0) {
852 if (avctx->
qmax >= 0) {
869 q->
extco2.MBBRC = q->
mbbrc ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
871 q->
extco2.Header.BufferId = MFX_EXTBUFF_CODING_OPTION2;
880 q->
extmfp.Header.BufferId = MFX_EXTBUFF_MULTI_FRAME_PARAM;
889 q->
extco3.Header.BufferId = MFX_EXTBUFF_CODING_OPTION3;
896 q->
extco3.PRefType = MFX_P_REF_DEFAULT;
899 q->
extco3.PRefType = MFX_P_REF_SIMPLE;
902 q->
extco3.PRefType = MFX_P_REF_PYRAMID;
905 q->
extco3.PRefType = MFX_P_REF_DEFAULT;
907 "invalid p_strategy, set to default\n");
910 if (q->
extco3.PRefType == MFX_P_REF_PYRAMID &&
913 "Please set max_b_frames(-bf) to 0 to enable P-pyramid\n");
928 MFX_CODINGOPTION_OFF;
930 q->
extco3.TransformSkip = MFX_CODINGOPTION_UNKNOWN;
931 q->
extco3.GPB = q->
gpb ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
937 q->
extvp9param.Header.BufferId = MFX_EXTBUFF_VP9_PARAM;
939 q->
extvp9param.WriteIVFHeaders = MFX_CODINGOPTION_OFF;
940 #if QSV_HAVE_EXT_VP9_TILES
948 q->
exthevctiles.Header.BufferId = MFX_EXTBUFF_HEVC_TILES;
956 q->
extvsi.ColourDescriptionPresent = 0;
961 q->
extvsi.ColourDescriptionPresent = 1;
967 if (q->
extvsi.VideoFullRange || q->
extvsi.ColourDescriptionPresent) {
968 q->
extvsi.Header.BufferId = MFX_EXTBUFF_VIDEO_SIGNAL_INFO;
975 "some encoding parameters are not supported by the QSV "
976 "runtime. Please double check the input parameters.\n");
990 "Error calling GetVideoParam");
1006 mfxExtVP9Param vp9_extend_buf = {
1007 .Header.BufferId = MFX_EXTBUFF_VP9_PARAM,
1008 .Header.BufferSz =
sizeof(vp9_extend_buf),
1011 mfxExtCodingOption2 co2 = {
1012 .Header.BufferId = MFX_EXTBUFF_CODING_OPTION2,
1013 .Header.BufferSz =
sizeof(co2),
1016 mfxExtCodingOption3 co3 = {
1017 .Header.BufferId = MFX_EXTBUFF_CODING_OPTION3,
1018 .Header.BufferSz =
sizeof(co3),
1021 mfxExtBuffer *ext_buffers[3];
1022 int ext_buf_num = 0;
1029 ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&co2;
1034 ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&co3;
1039 ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&vp9_extend_buf;
1042 q->
param.ExtParam = ext_buffers;
1043 q->
param.NumExtParam = ext_buf_num;
1048 "Error calling GetVideoParam");
1061 uint8_t sps_buf[128];
1062 uint8_t pps_buf[128];
1064 mfxExtCodingOptionSPSPPS extradata = {
1065 .Header.BufferId = MFX_EXTBUFF_CODING_OPTION_SPSPPS,
1066 .Header.BufferSz =
sizeof(extradata),
1067 .SPSBuffer = sps_buf, .SPSBufSize =
sizeof(sps_buf),
1068 .PPSBuffer = pps_buf, .PPSBufSize =
sizeof(pps_buf)
1071 mfxExtCodingOption co = {
1072 .Header.BufferId = MFX_EXTBUFF_CODING_OPTION,
1073 .Header.BufferSz =
sizeof(co),
1075 mfxExtCodingOption2 co2 = {
1076 .Header.BufferId = MFX_EXTBUFF_CODING_OPTION2,
1077 .Header.BufferSz =
sizeof(co2),
1079 mfxExtCodingOption3 co3 = {
1080 .Header.BufferId = MFX_EXTBUFF_CODING_OPTION3,
1081 .Header.BufferSz =
sizeof(co3),
1084 uint8_t vps_buf[128];
1085 mfxExtCodingOptionVPS extradata_vps = {
1086 .Header.BufferId = MFX_EXTBUFF_CODING_OPTION_VPS,
1087 .Header.BufferSz =
sizeof(extradata_vps),
1088 .VPSBuffer = vps_buf,
1089 .VPSBufSize =
sizeof(vps_buf),
1092 mfxExtHEVCTiles hevc_tile_buf = {
1093 .Header.BufferId = MFX_EXTBUFF_HEVC_TILES,
1094 .Header.BufferSz =
sizeof(hevc_tile_buf),
1097 mfxExtBuffer *ext_buffers[6];
1100 int ret, ext_buf_num = 0, extradata_offset = 0;
1103 ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&extradata;
1104 ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&co;
1109 ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&co2;
1114 ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&co3;
1119 ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&extradata_vps;
1122 ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&hevc_tile_buf;
1125 q->
param.ExtParam = ext_buffers;
1126 q->
param.NumExtParam = ext_buf_num;
1131 "Error calling GetVideoParam");
1135 if (!extradata.SPSBufSize || (need_pps && !extradata.PPSBufSize)
1136 || (q->
hevc_vps && !extradata_vps.VPSBufSize)
1142 avctx->
extradata_size = extradata.SPSBufSize + need_pps * extradata.PPSBufSize;
1150 memcpy(avctx->
extradata, vps_buf, extradata_vps.VPSBufSize);
1151 extradata_offset += extradata_vps.VPSBufSize;
1154 memcpy(avctx->
extradata + extradata_offset, sps_buf, extradata.SPSBufSize);
1155 extradata_offset += extradata.SPSBufSize;
1157 memcpy(avctx->
extradata + extradata_offset, pps_buf, extradata.PPSBufSize);
1158 extradata_offset += extradata.PPSBufSize;
1178 mfxFrameSurface1 *surfaces;
1192 for (
i = 0;
i < nb_surfaces;
i++) {
1193 surfaces[
i].Info = q->
req.Info;
1197 q->
opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
1226 q->
param.IOPattern == MFX_IOPATTERN_IN_OPAQUE_MEMORY,
1257 int opaque_alloc = 0;
1278 if (frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME)
1279 iopattern = MFX_IOPATTERN_IN_OPAQUE_MEMORY;
1280 else if (frames_hwctx->frame_type &
1281 (MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET | MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET))
1282 iopattern = MFX_IOPATTERN_IN_VIDEO_MEMORY;
1287 iopattern = MFX_IOPATTERN_IN_SYSTEM_MEMORY;
1288 q->
param.IOPattern = iopattern;
1298 "Error querying mfx version");
1332 if (j < qsv->nb_ext_buffers)
1343 if (
ret == MFX_WRN_PARTIAL_ACCELERATION) {
1345 }
else if (
ret < 0) {
1347 "Error querying encoder params");
1353 "Error querying (IOSurf) the encoding parameters");
1364 "Error initializing the encoder");
1367 "Warning in encoder initialization");
1397 enc_ctrl->NumPayload = 0;
1406 if (enc_ctrl->ExtParam[
i])
1409 enc_ctrl->NumExtParam = 0;
1448 last = &
frame->next;
1456 if (!
frame->frame) {
1528 !
frame->interlaced_frame ? MFX_PICSTRUCT_PROGRESSIVE :
1529 frame->top_field_first ? MFX_PICSTRUCT_FIELD_TFF :
1530 MFX_PICSTRUCT_FIELD_BFF;
1531 if (
frame->repeat_pict == 1)
1532 qf->
surface.Info.PicStruct |= MFX_PICSTRUCT_FIELD_REPEATED;
1533 else if (
frame->repeat_pict == 2)
1534 qf->
surface.Info.PicStruct |= MFX_PICSTRUCT_FRAME_DOUBLING;
1535 else if (
frame->repeat_pict == 4)
1536 qf->
surface.Info.PicStruct |= MFX_PICSTRUCT_FRAME_TRIPLING;
1553 if (q->
param.mfx.CodecId == MFX_CODEC_AVC) {
1554 if (q->
param.mfx.CodecProfile == MFX_PROFILE_AVC_BASELINE ||
1555 q->
param.mfx.CodecLevel < MFX_LEVEL_AVC_21 ||
1556 q->
param.mfx.CodecLevel > MFX_LEVEL_AVC_41)
1558 "Interlaced coding is supported"
1559 " at Main/High Profile Level 2.2-4.0\n");
1564 mfxEncodeCtrl *enc_ctrl)
1580 mfxExtEncoderROI *enc_roi =
NULL;
1587 if (!roi_size || sd->
size % roi_size) {
1591 nb_roi = sd->
size / roi_size;
1594 "supported by driver (%d > %d).\n",
1602 enc_roi->Header.BufferId = MFX_EXTBUFF_ENCODER_ROI;
1603 enc_roi->Header.BufferSz =
sizeof(*enc_roi);
1604 enc_roi->NumROI = nb_roi;
1605 enc_roi->ROIMode = MFX_ROI_MODE_QP_DELTA;
1606 for (
i = 0;
i < nb_roi;
i++) {
1612 enc_roi->ROI[
i].DeltaQP =
1616 enc_roi->ROI[
i].DeltaQP);
1618 enc_ctrl->ExtParam[enc_ctrl->NumExtParam] = (mfxExtBuffer *)enc_roi;
1619 enc_ctrl->NumExtParam++;
1627 int updated = 0, qp = 0, new_qp;
1635 if (entry && q->
param.mfx.RateControlMethod == MFX_RATECONTROL_CQP) {
1636 qp = strtol(entry->
value, &tail, 10);
1641 if (qp < 0 || qp > 51) {
1654 "using fixed qp = %d/%d/%d for idr/p/b frames\n",
1663 int needReset = 0,
ret = 0;
1685 if (j < qsv->nb_ext_buffers)
1705 mfxExtAVCEncodedFrameInfo *enc_info =
NULL;
1706 mfxExtBuffer **enc_buf =
NULL;
1708 mfxFrameSurface1 *surf =
NULL;
1710 mfxEncodeCtrl* enc_ctrl =
NULL;
1725 enc_ctrl->FrameType = MFX_FRAMETYPE_I | MFX_FRAMETYPE_REF;
1727 enc_ctrl->FrameType |= MFX_FRAMETYPE_IDR;
1748 enc_info->Header.BufferId = MFX_EXTBUFF_ENCODED_FRAME_INFO;
1749 enc_info->Header.BufferSz =
sizeof (*enc_info);
1750 pkt.bs->NumExtParam = 1;
1751 enc_buf =
av_mallocz(
sizeof(mfxExtBuffer *));
1754 enc_buf[0] = (mfxExtBuffer *)enc_info;
1756 pkt.bs->ExtParam = enc_buf;
1776 ret = MFXVideoENCODE_EncodeFrameAsync(q->
session, enc_ctrl, surf,
pkt.bs,
pkt.sync);
1777 if (
ret == MFX_WRN_DEVICE_BUSY)
1779 }
while (
ret == MFX_WRN_DEVICE_BUSY ||
ret == MFX_WRN_IN_EXECUTION);
1785 ret = (
ret == MFX_ERR_MORE_DATA) ?
1790 if (
ret == MFX_WRN_INCOMPATIBLE_VIDEO_PARAM &&
frame &&
frame->interlaced_frame)
1830 mfxExtAVCEncodedFrameInfo *enc_info;
1831 mfxExtBuffer **enc_buf;
1838 }
while (
ret == MFX_WRN_IN_EXECUTION);
1844 if (qpkt.
bs->FrameType & MFX_FRAMETYPE_IDR || qpkt.
bs->FrameType & MFX_FRAMETYPE_xIDR) {
1847 }
else if (qpkt.
bs->FrameType & MFX_FRAMETYPE_I || qpkt.
bs->FrameType & MFX_FRAMETYPE_xI)
1849 else if (qpkt.
bs->FrameType & MFX_FRAMETYPE_P || qpkt.
bs->FrameType & MFX_FRAMETYPE_xP)
1851 else if (qpkt.
bs->FrameType & MFX_FRAMETYPE_B || qpkt.
bs->FrameType & MFX_FRAMETYPE_xB)
1853 else if (qpkt.
bs->FrameType == MFX_FRAMETYPE_UNKNOWN) {
1862 enc_buf = qpkt.
bs->ExtParam;
1863 enc_info = (mfxExtAVCEncodedFrameInfo *)(*enc_buf);
1885 MFXVideoENCODE_Close(q->
session);
1907 mfxExtBuffer **enc_buf =
pkt.bs->ExtParam;
1908 mfxExtAVCEncodedFrameInfo *enc_info = (mfxExtAVCEncodedFrameInfo *)(*enc_buf);