51 { MFX_PROFILE_AVC_BASELINE,
"avc baseline" },
52 { MFX_PROFILE_AVC_MAIN,
"avc main" },
53 { MFX_PROFILE_AVC_EXTENDED,
"avc extended" },
54 { MFX_PROFILE_AVC_HIGH,
"avc high" },
55 { MFX_PROFILE_AVC_HIGH_422,
"avc high 422" },
56 { MFX_PROFILE_AVC_CONSTRAINED_BASELINE,
"avc constrained baseline" },
57 { MFX_PROFILE_AVC_CONSTRAINED_HIGH,
"avc constrained high" },
58 { MFX_PROFILE_AVC_PROGRESSIVE_HIGH,
"avc progressive high" },
62 { MFX_PROFILE_MPEG2_SIMPLE,
"mpeg2 simple" },
63 { MFX_PROFILE_MPEG2_MAIN,
"mpeg2 main" },
64 { MFX_PROFILE_MPEG2_HIGH,
"mpeg2 high" },
68 { MFX_PROFILE_HEVC_MAIN,
"hevc main" },
69 { MFX_PROFILE_HEVC_MAIN10,
"hevc main10" },
70 { MFX_PROFILE_HEVC_MAINSP,
"hevc mainsp" },
71 { MFX_PROFILE_HEVC_REXT,
"hevc rext" },
72#if QSV_VERSION_ATLEAST(1, 32)
73 { MFX_PROFILE_HEVC_SCC,
"hevc scc" },
78 { MFX_PROFILE_VP9_0,
"vp9 0" },
79 { MFX_PROFILE_VP9_1,
"vp9 1" },
80 { MFX_PROFILE_VP9_2,
"vp9 2" },
81 { MFX_PROFILE_VP9_3,
"vp9 3" },
85#if QSV_VERSION_ATLEAST(1, 34)
86 { MFX_PROFILE_AV1_MAIN,
"av1 main" },
87 { MFX_PROFILE_AV1_HIGH,
"av1 high" },
88 { MFX_PROFILE_AV1_PRO,
"av1 professional" },
133 for (
i = 0;
i < num_profiles;
i++)
144 { MFX_RATECONTROL_CBR,
"CBR" },
145 { MFX_RATECONTROL_VBR,
"VBR" },
146 { MFX_RATECONTROL_CQP,
"CQP" },
148 { MFX_RATECONTROL_AVBR,
"AVBR" },
150 { MFX_RATECONTROL_LA,
"LA" },
151 { MFX_RATECONTROL_ICQ,
"ICQ" },
152 { MFX_RATECONTROL_LA_ICQ,
"LA_ICQ" },
154 { MFX_RATECONTROL_VCM,
"VCM" },
157 { MFX_RATECONTROL_LA_EXT,
"LA_EXT" },
159 { MFX_RATECONTROL_LA_HRD,
"LA_HRD" },
160 { MFX_RATECONTROL_QVBR,
"QVBR" },
163#define UPDATE_PARAM(a, b) \
171#define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl))
184 if (
val == MFX_CODINGOPTION_ON)
186 else if (
val == MFX_CODINGOPTION_OFF)
192 mfxExtBuffer **coding_opts)
194 mfxInfoMFX *info = &q->
param.mfx;
197 mfxExtCodingOption *co = (mfxExtCodingOption*)coding_opts[1];
198 mfxExtCodingOption2 *co2 =
NULL;
199 mfxExtCodingOption3 *co3 =
NULL;
200 mfxExtHEVCTiles *exthevctiles =
NULL;
202 mfxExtHyperModeParam *exthypermodeparam =
NULL;
205 const char *tmp_str =
NULL;
208 co2 = (mfxExtCodingOption2*)coding_opts[q->
co2_idx];
211 co3 = (mfxExtCodingOption3*)coding_opts[q->
co3_idx];
225 "GopPicSize: %"PRIu16
"; GopRefDist: %"PRIu16
"; GopOptFlag:%s%s; IdrInterval: %"PRIu16
"\n",
226 info->GopPicSize, info->GopRefDist,
227 info->GopOptFlag & MFX_GOP_CLOSED ?
" closed" :
"",
228 info->GopOptFlag & MFX_GOP_STRICT ?
" strict" :
"",
234 if (info->RateControlMethod == MFX_RATECONTROL_CBR ||
235 info->RateControlMethod == MFX_RATECONTROL_VBR
237 || info->RateControlMethod == MFX_RATECONTROL_VCM
241 "BufferSizeInKB: %"PRIu16
"; InitialDelayInKB: %"PRIu16
"; TargetKbps: %"PRIu16
"; MaxKbps: %"PRIu16
"; BRCParamMultiplier: %"PRIu16
"\n",
242 info->BufferSizeInKB, info->InitialDelayInKB, info->TargetKbps, info->MaxKbps, info->BRCParamMultiplier);
243 }
else if (info->RateControlMethod == MFX_RATECONTROL_CQP) {
245 info->QPI, info->QPP, info->QPB);
248 else if (info->RateControlMethod == MFX_RATECONTROL_AVBR) {
250 "TargetKbps: %"PRIu16
"; Accuracy: %"PRIu16
"; Convergence: %"PRIu16
"; BRCParamMultiplier: %"PRIu16
"\n",
251 info->TargetKbps, info->Accuracy, info->Convergence, info->BRCParamMultiplier);
254 else if (info->RateControlMethod == MFX_RATECONTROL_LA
255 || info->RateControlMethod == MFX_RATECONTROL_LA_HRD
258 "TargetKbps: %"PRIu16
"; BRCParamMultiplier: %"PRIu16
"\n",
259 info->TargetKbps, info->BRCParamMultiplier);
260 }
else if (info->RateControlMethod == MFX_RATECONTROL_ICQ ||
261 info->RateControlMethod == MFX_RATECONTROL_LA_ICQ)
264 info->NumSlice, info->NumRefFrame);
273 co->CAVLC == MFX_CODINGOPTION_ON ?
"CAVLC" :
"CABAC", co->MaxDecFrameBuffering);
275 "NalHrdConformance: %s; SingleSeiNalUnit: %s; VuiVclHrdParameters: %s VuiNalHrdParameters: %s\n",
280 "NalHrdConformance: %s; VuiNalHrdParameters: %s\n",
285 info->FrameInfo.FrameRateExtD, info->FrameInfo.FrameRateExtN);
289 (info->RateControlMethod == MFX_RATECONTROL_LA) ||
290 (info->RateControlMethod == MFX_RATECONTROL_LA_HRD) ||
291 (info->RateControlMethod == MFX_RATECONTROL_LA_ICQ))
294 av_log(avctx,
AV_LOG_VERBOSE,
"IntRefType: %"PRIu16
"; IntRefCycleSize: %"PRIu16
"; IntRefQPDelta: %"PRId16
"\n",
295 co2->IntRefType, co2->IntRefCycleSize, co2->IntRefQPDelta);
298 co2->MaxFrameSize, co2->MaxSliceSize);
301 "BitrateLimit: %s; MBBRC: %s; ExtBRC: %s\n",
305 if (co2->Trellis & MFX_TRELLIS_OFF) {
307 }
else if (!co2->Trellis) {
310 char trellis_type[4];
312 if (co2->Trellis & MFX_TRELLIS_I) trellis_type[
i++] =
'I';
313 if (co2->Trellis & MFX_TRELLIS_P) trellis_type[
i++] =
'P';
314 if (co2->Trellis & MFX_TRELLIS_B) trellis_type[
i++] =
'B';
319 switch (co2->LookAheadDS) {
320 case MFX_LOOKAHEAD_DS_OFF: tmp_str =
"off";
break;
321 case MFX_LOOKAHEAD_DS_2x: tmp_str =
"2x";
break;
322 case MFX_LOOKAHEAD_DS_4x: tmp_str =
"4x";
break;
323 default: tmp_str =
"unknown";
break;
326 "RepeatPPS: %s; NumMbPerSlice: %"PRIu16
"; LookAheadDS: %s\n",
329 switch (co2->BRefType) {
330 case MFX_B_REF_OFF: tmp_str =
"off";
break;
331 case MFX_B_REF_PYRAMID: tmp_str =
"pyramid";
break;
332 default: tmp_str =
"auto";
break;
335 "AdaptiveI: %s; AdaptiveB: %s; BRefType:%s\n",
339 "MinQPI: %"PRIu8
"; MaxQPI: %"PRIu8
"; MinQPP: %"PRIu8
"; MaxQPP: %"PRIu8
"; MinQPB: %"PRIu8
"; MaxQPB: %"PRIu8
"\n",
340 co2->MinQPI, co2->MaxQPI, co2->MinQPP, co2->MaxQPP, co2->MinQPB, co2->MaxQPB);
343 switch (co2->SkipFrame) {
344 case MFX_SKIPFRAME_NO_SKIP:
347 case MFX_SKIPFRAME_INSERT_DUMMY:
350 case MFX_SKIPFRAME_INSERT_NOTHING:
353 case MFX_SKIPFRAME_BRC_ONLY:
361 if (info->RateControlMethod == MFX_RATECONTROL_QVBR)
364 switch (co3->PRefType) {
384 exthevctiles->NumTileColumns, exthevctiles->NumTileRows);
388 if (exthypermodeparam) {
391 if (exthypermodeparam->Mode == MFX_HYPERMODE_OFF)
393 if (exthypermodeparam->Mode == MFX_HYPERMODE_ON)
395 if (exthypermodeparam->Mode == MFX_HYPERMODE_ADAPTIVE)
404 mfxExtBuffer **coding_opts)
406 mfxInfoMFX *info = &q->
param.mfx;
407 mfxExtVP9Param *vp9_param =
NULL;
408 mfxExtCodingOption2 *co2 =
NULL;
411 vp9_param = (mfxExtVP9Param *)coding_opts[q->
vp9_idx];
414 co2 = (mfxExtCodingOption2*)coding_opts[q->
co2_idx];
420 "GopPicSize: %"PRIu16
"; GopRefDist: %"PRIu16
"; GopOptFlag:%s%s; IdrInterval: %"PRIu16
"\n",
421 info->GopPicSize, info->GopRefDist,
422 info->GopOptFlag & MFX_GOP_CLOSED ?
" closed" :
"",
423 info->GopOptFlag & MFX_GOP_STRICT ?
" strict" :
"",
429 if (info->RateControlMethod == MFX_RATECONTROL_CBR ||
430 info->RateControlMethod == MFX_RATECONTROL_VBR) {
432 "BufferSizeInKB: %"PRIu16
"; InitialDelayInKB: %"PRIu16
"; TargetKbps: %"PRIu16
"; MaxKbps: %"PRIu16
"; BRCParamMultiplier: %"PRIu16
"\n",
433 info->BufferSizeInKB, info->InitialDelayInKB, info->TargetKbps, info->MaxKbps, info->BRCParamMultiplier);
434 }
else if (info->RateControlMethod == MFX_RATECONTROL_CQP) {
436 info->QPI, info->QPP, info->QPB);
438 else if (info->RateControlMethod == MFX_RATECONTROL_ICQ) {
442 av_log(avctx,
AV_LOG_VERBOSE,
"Unsupported ratecontrol method: %d \n", info->RateControlMethod);
447 info->FrameInfo.FrameRateExtD, info->FrameInfo.FrameRateExtN);
451 "IntRefType: %"PRIu16
"; IntRefCycleSize: %"PRIu16
"; IntRefQPDelta: %"PRId16
"\n",
452 co2->IntRefType, co2->IntRefCycleSize, co2->IntRefQPDelta);
457 "BitrateLimit: %s; MBBRC: %s; ExtBRC: %s\n",
464 "MinQPI: %"PRIu8
"; MaxQPI: %"PRIu8
"; MinQPP: %"PRIu8
"; MaxQPP: %"PRIu8
"; MinQPB: %"PRIu8
"; MaxQPB: %"PRIu8
"\n",
465 co2->MinQPI, co2->MaxQPI, co2->MinQPP, co2->MaxQPP, co2->MinQPB, co2->MaxQPB);
476 mfxInfoMFX *info = &q->
param.mfx;
483 info->FrameInfo.FrameRateExtD, info->FrameInfo.FrameRateExtN);
486#if QSV_HAVE_EXT_AV1_PARAM
488 mfxExtBuffer **coding_opts)
490 mfxInfoMFX *info = &q->
param.mfx;
491 mfxExtAV1TileParam *av1_tile_param = (mfxExtAV1TileParam *)coding_opts[0];
492 mfxExtAV1BitstreamParam *av1_bs_param = (mfxExtAV1BitstreamParam *)coding_opts[1];
493 mfxExtCodingOption2 *co2 = (mfxExtCodingOption2*)coding_opts[2];
494 mfxExtCodingOption3 *co3 = (mfxExtCodingOption3*)coding_opts[3];
500 "GopPicSize: %"PRIu16
"; GopRefDist: %"PRIu16
"; GopOptFlag:%s%s; IdrInterval: %"PRIu16
"\n",
501 info->GopPicSize, info->GopRefDist,
502 info->GopOptFlag & MFX_GOP_CLOSED ?
" closed" :
"",
503 info->GopOptFlag & MFX_GOP_STRICT ?
" strict" :
"",
509 if (info->RateControlMethod == MFX_RATECONTROL_CBR ||
510 info->RateControlMethod == MFX_RATECONTROL_VBR)
512 "BufferSizeInKB: %"PRIu16
"; InitialDelayInKB: %"PRIu16
"; TargetKbps: %"PRIu16
"; MaxKbps: %"PRIu16
"; BRCParamMultiplier: %"PRIu16
"\n",
513 info->BufferSizeInKB, info->InitialDelayInKB, info->TargetKbps, info->MaxKbps, info->BRCParamMultiplier);
514 else if (info->RateControlMethod == MFX_RATECONTROL_CQP)
516 info->QPI, info->QPP, info->QPB);
517 else if (info->RateControlMethod == MFX_RATECONTROL_ICQ)
520 av_log(avctx,
AV_LOG_VERBOSE,
"Unsupported ratecontrol method: %d \n", info->RateControlMethod);
525 "IntRefType: %"PRIu16
"; IntRefCycleSize: %"PRIu16
526 "; IntRefQPDelta: %"PRId16
"; IntRefCycleDist: %"PRId16
"\n",
527 co2->IntRefType, co2->IntRefCycleSize,
528 co2->IntRefQPDelta, co3->IntRefCycleDist);
533 "BitrateLimit: %s; MBBRC: %s; ExtBRC: %s\n",
539 switch (co2->BRefType) {
545 switch (co3->PRefType) {
553 "MinQPI: %"PRIu8
"; MaxQPI: %"PRIu8
"; MinQPP: %"PRIu8
"; MaxQPP: %"PRIu8
"; MinQPB: %"PRIu8
"; MaxQPB: %"PRIu8
"\n",
554 co2->MinQPI, co2->MaxQPI, co2->MinQPP, co2->MaxQPP, co2->MinQPB, co2->MaxQPB);
557 info->FrameInfo.FrameRateExtD, info->FrameInfo.FrameRateExtN);
560 "NumTileRows: %"PRIu16
"; NumTileColumns: %"PRIu16
"; NumTileGroups: %"PRIu16
"\n",
561 av1_tile_param->NumTileRows, av1_tile_param->NumTileColumns, av1_tile_param->NumTileGroups);
577 int want_vcm = q->
vcm;
581 "VCM ratecontrol mode requested, but is not supported by this SDK version\n");
585 if (want_la + want_qscale + want_vcm > 1) {
587 "More than one of: { constant qscale, lookahead, VCM } requested, "
588 "only one of them can be used at a time.\n");
594 rc_desc =
"constant quantization parameter (CQP)";
599 rc_desc =
"video conferencing mode (VCM)";
603 "setting bitrate. Please use the b option to set the desired "
604 "bitrate.\n", rc_desc);
611 rc_desc =
"VBR with lookahead (LA)";
614 rc_mode = MFX_RATECONTROL_LA_ICQ;
615 rc_desc =
"intelligent constant quality with lookahead (LA_ICQ)";
618 "setting bitrate. Please use the b option to set the desired "
619 "bitrate.\n", rc_desc);
625 rc_desc =
"intelligent constant quality (ICQ)";
630 rc_desc =
"constant bitrate (CBR)";
637 rc_mode = MFX_RATECONTROL_AVBR;
638 rc_desc =
"average variable bitrate (AVBR)";
642 rc_mode = MFX_RATECONTROL_QVBR;
643 rc_desc =
"constant quality with VBR algorithm (QVBR)";
646 rc_desc =
"variable bitrate (VBR)";
650 rc_desc =
"constant quantization parameter (CQP)";
656 "parameter (CQP) by default. Please use the global_quality "
657 "option and other options for a quality-based mode or the b "
658 "option and other options for a bitrate-based mode if the "
659 "default is not the desired choice.\n");
670 mfxVideoParam param_out = { .mfx.CodecId = q->
param.mfx.CodecId };
673#define UNMATCH(x) (param_out.mfx.x != q->param.mfx.x)
675 ret = MFXVideoENCODE_Query(q->
session, &q->
param, ¶m_out);
682 if (
UNMATCH(RateControlMethod))
717 q->
param.mfx.CodecId = ret;
719 if (avctx->
level > 0)
731 q->
param.mfx.FrameInfo.CropX = 0;
732 q->
param.mfx.FrameInfo.CropY = 0;
737 q->
param.mfx.FrameInfo.ChromaFormat = MFX_CHROMAFORMAT_YUV420 +
738 !
desc->log2_chroma_w + !
desc->log2_chroma_h;
739 q->
param.mfx.FrameInfo.BitDepthLuma =
desc->comp[0].depth;
740 q->
param.mfx.FrameInfo.BitDepthChroma =
desc->comp[0].depth;
749 q->
param.mfx.FrameInfo.Width = info->Width;
750 q->
param.mfx.FrameInfo.Height = info->Height;
761 q->
param.mfx.Interleaved = 1;
763 q->
param.mfx.RestartInterval = 0;
780 int target_bitrate_kbps, max_bitrate_kbps, brc_param_multiplier;
781 int buffer_size_in_kilobytes, initial_delay_in_kilobytes;
787 q->
param.mfx.CodecId = ret;
789 if (avctx->
level > 0) {
800 "valid range is 0-%d, using %d instead\n",
801 MFX_TARGETUSAGE_BEST_SPEED, MFX_TARGETUSAGE_BEST_SPEED);
807 q->
param.mfx.LowPower = MFX_CODINGOPTION_ON;
809 q->
param.mfx.LowPower = MFX_CODINGOPTION_UNKNOWN;
811 q->
param.mfx.LowPower = MFX_CODINGOPTION_OFF;
824 q->
param.mfx.EncodedOrder = 0;
825 q->
param.mfx.BufferSizeInKB = 0;
835 q->
param.mfx.FrameInfo.CropX = 0;
836 q->
param.mfx.FrameInfo.CropY = 0;
841 q->
param.mfx.FrameInfo.ChromaFormat = MFX_CHROMAFORMAT_YUV420 +
842 !
desc->log2_chroma_w + !
desc->log2_chroma_h;
843 q->
param.mfx.FrameInfo.BitDepthLuma =
desc->comp[0].depth;
844 q->
param.mfx.FrameInfo.BitDepthChroma =
desc->comp[0].depth;
856 q->
param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_FIELD_TFF;
860 q->
param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
874 q->
param.mfx.FrameInfo.Width = info->Width;
875 q->
param.mfx.FrameInfo.Height = info->Height;
894 target_bitrate_kbps = avctx->
bit_rate / 1000;
896 brc_param_multiplier = (
FFMAX(
FFMAX3(target_bitrate_kbps, max_bitrate_kbps, buffer_size_in_kilobytes),
897 initial_delay_in_kilobytes) + 0x10000) / 0x10000;
903 switch (q->
param.mfx.RateControlMethod) {
904 case MFX_RATECONTROL_CBR:
905 case MFX_RATECONTROL_VBR:
911 case MFX_RATECONTROL_VCM:
913 case MFX_RATECONTROL_QVBR:
914 q->
param.mfx.BufferSizeInKB = buffer_size_in_kilobytes / brc_param_multiplier;
915 q->
param.mfx.InitialDelayInKB = initial_delay_in_kilobytes / brc_param_multiplier;
916 q->
param.mfx.TargetKbps = target_bitrate_kbps / brc_param_multiplier;
917 q->
param.mfx.MaxKbps = max_bitrate_kbps / brc_param_multiplier;
918 q->
param.mfx.BRCParamMultiplier = brc_param_multiplier;
919 if (q->
param.mfx.RateControlMethod == MFX_RATECONTROL_QVBR)
922 case MFX_RATECONTROL_CQP:
941 case MFX_RATECONTROL_AVBR:
942 q->
param.mfx.TargetKbps = target_bitrate_kbps / brc_param_multiplier;
945 q->
param.mfx.BRCParamMultiplier = brc_param_multiplier;
948 case MFX_RATECONTROL_LA:
949 q->
param.mfx.TargetKbps = target_bitrate_kbps / brc_param_multiplier;
951 q->
param.mfx.BRCParamMultiplier = brc_param_multiplier;
953 case MFX_RATECONTROL_LA_ICQ:
956 case MFX_RATECONTROL_ICQ:
966 q->
extco.Header.BufferId = MFX_EXTBUFF_CODING_OPTION;
970 MFX_CODINGOPTION_ON : MFX_CODINGOPTION_UNKNOWN;
974 q->
extco.RateDistortionOpt = q->
rdo > 0 ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
977 q->
extco.CAVLC = q->
cavlc ? MFX_CODINGOPTION_ON
978 : MFX_CODINGOPTION_UNKNOWN;
982 MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
989 q->
extco.AUDelimiter = q->
aud ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
993 MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
998 q->
extco.AUDelimiter = q->
aud ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
1008 q->
extco2.Trellis = (avctx->
trellis == 0) ? MFX_TRELLIS_OFF : (MFX_TRELLIS_I | MFX_TRELLIS_P | MFX_TRELLIS_B);
1010 q->
extco2.Trellis = MFX_TRELLIS_UNKNOWN;
1013 q->
extco2.RepeatPPS = q->
repeat_pps ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
1018 q->
extco2.ExtBRC = q->
extbrc ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
1038 q->
extco2.AdaptiveI = q->
adaptive_i ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
1040 q->
extco2.AdaptiveB = q->
adaptive_b ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
1046 "qmin and or qmax are set but invalid,"
1047 " please make sure min <= max\n");
1050 if (avctx->
qmin >= 0) {
1055 if (avctx->
qmax >= 0) {
1079 q->
extco2.MBBRC = q->
mbbrc ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
1083 q->
extco2.Header.BufferId = MFX_EXTBUFF_CODING_OPTION2;
1089 q->
extco2.ExtBRC = q->
extbrc ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
1093 q->
extco2.AdaptiveI = q->
adaptive_i ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
1095 q->
extco2.AdaptiveB = q->
adaptive_b ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
1099 q->
extco2.Header.BufferId = MFX_EXTBUFF_CODING_OPTION2;
1108 q->extmfp.Header.BufferId = MFX_EXTBUFF_MULTI_FRAME_PARAM;
1109 q->extmfp.Header.BufferSz =
sizeof(q->extmfp);
1111 q->extmfp.MFMode = q->mfmode;
1117 q->
extco3.Header.BufferId = MFX_EXTBUFF_CODING_OPTION3;
1124 q->
extco3.PRefType = MFX_P_REF_DEFAULT;
1127 q->
extco3.PRefType = MFX_P_REF_SIMPLE;
1130 q->
extco3.PRefType = MFX_P_REF_PYRAMID;
1133 q->
extco3.PRefType = MFX_P_REF_DEFAULT;
1135 "invalid p_strategy, set to default\n");
1138 if (q->
extco3.PRefType == MFX_P_REF_PYRAMID &&
1141 "Please set max_b_frames(-bf) to 0 to enable P-pyramid\n");
1154 (q->
profile == MFX_PROFILE_HEVC_REXT ||
1155 q->
profile == MFX_PROFILE_UNKNOWN))
1156 q->
extco3.TargetChromaFormatPlus1 = MFX_CHROMAFORMAT_YUV444 + 1;
1168 MFX_CODINGOPTION_OFF;
1170 q->
extco3.TransformSkip = MFX_CODINGOPTION_UNKNOWN;
1171 q->
extco3.GPB = q->
gpb ? MFX_CODINGOPTION_ON : MFX_CODINGOPTION_OFF;
1177 q->
extvp9param.Header.BufferId = MFX_EXTBUFF_VP9_PARAM;
1179 q->
extvp9param.WriteIVFHeaders = MFX_CODINGOPTION_OFF;
1180#if QSV_HAVE_EXT_VP9_TILES
1187#if QSV_HAVE_EXT_AV1_PARAM
1190 q->extav1tileparam.Header.BufferId = MFX_EXTBUFF_AV1_TILE_PARAM;
1191 q->extav1tileparam.Header.BufferSz =
sizeof(q->extav1tileparam);
1192 q->extav1tileparam.NumTileColumns = q->
tile_cols;
1193 q->extav1tileparam.NumTileRows = q->
tile_rows;
1196 q->extav1bsparam.Header.BufferId = MFX_EXTBUFF_AV1_BITSTREAM_PARAM;
1197 q->extav1bsparam.Header.BufferSz =
sizeof(q->extav1bsparam);
1198 q->extav1bsparam.WriteIVFHeaders = MFX_CODINGOPTION_OFF;
1202 "This version of runtime doesn't support AV1 encoding\n");
1209 q->
exthevctiles.Header.BufferId = MFX_EXTBUFF_HEVC_TILES;
1217 q->
extvsi.ColourDescriptionPresent = 0;
1222 q->
extvsi.ColourDescriptionPresent = 1;
1234 q->
extvsi.Header.BufferId = MFX_EXTBUFF_VIDEO_SIGNAL_INFO;
1243 MFXQueryIMPL(q->
session, &impl);
1249 if (q->
param.mfx.LowPower != MFX_CODINGOPTION_ON) {
1250 av_log(avctx,
AV_LOG_ERROR,
"Dual GFX mode supports only low-power encoding mode \n");
1253 if (q->
param.mfx.CodecId != MFX_CODEC_AVC && q->
param.mfx.CodecId != MFX_CODEC_HEVC) {
1255 "Supported: h264_qsv and hevc_qsv \n");
1258 if (q->
param.mfx.RateControlMethod != MFX_RATECONTROL_VBR &&
1259 q->
param.mfx.RateControlMethod != MFX_RATECONTROL_CQP &&
1260 q->
param.mfx.RateControlMethod != MFX_RATECONTROL_ICQ) {
1262 "Supported: VBR, CQP and ICQ \n");
1264 if ((q->
param.mfx.CodecId == MFX_CODEC_AVC && q->
param.mfx.IdrInterval != 0) ||
1265 (q->
param.mfx.CodecId == MFX_CODEC_HEVC && q->
param.mfx.IdrInterval != 1)) {
1266 av_log(avctx,
AV_LOG_WARNING,
"Dual GFX mode requires closed GOP for AVC and strict GOP for HEVC, -idr_interval 0 \n");
1268 if (q->
param.mfx.GopPicSize < 30) {
1269 av_log(avctx,
AV_LOG_WARNING,
"For better performance in dual GFX mode GopPicSize must be >= 30 \n");
1271 if (q->
param.AsyncDepth < 30) {
1272 av_log(avctx,
AV_LOG_WARNING,
"For better performance in dual GFX mode AsyncDepth must be >= 30 \n");
1275 q->exthypermodeparam.Header.BufferId = MFX_EXTBUFF_HYPER_MODE_PARAM;
1276 q->exthypermodeparam.Header.BufferSz =
sizeof(q->exthypermodeparam);
1277 q->exthypermodeparam.Mode = q->
dual_gfx;
1281 "This version of runtime doesn't support Hyper Encode\n");
1289 "some encoding parameters are not supported by the QSV "
1290 "runtime. Please double check the input parameters.\n");
1301 ret = MFXVideoENCODE_GetVideoParam(q->
session, &q->
param);
1304 "Error calling GetVideoParam");
1320 mfxExtVP9Param vp9_extend_buf = {
1321 .Header.BufferId = MFX_EXTBUFF_VP9_PARAM,
1322 .Header.BufferSz =
sizeof(vp9_extend_buf),
1325 mfxExtCodingOption2 co2 = {
1326 .Header.BufferId = MFX_EXTBUFF_CODING_OPTION2,
1327 .Header.BufferSz =
sizeof(co2),
1330 mfxExtCodingOption3 co3 = {
1331 .Header.BufferId = MFX_EXTBUFF_CODING_OPTION3,
1332 .Header.BufferSz =
sizeof(co3),
1335 mfxExtBuffer *ext_buffers[3];
1336 int ext_buf_num = 0;
1343 ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&co2;
1348 ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&co3;
1353 ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&vp9_extend_buf;
1356 q->
param.ExtParam = ext_buffers;
1357 q->
param.NumExtParam = ext_buf_num;
1359 ret = MFXVideoENCODE_GetVideoParam(q->
session, &q->
param);
1362 "Error calling GetVideoParam");
1373#if QSV_HAVE_EXT_AV1_PARAM
1375 mfxExtAV1TileParam av1_extend_tile_buf = {
1376 .Header.BufferId = MFX_EXTBUFF_AV1_TILE_PARAM,
1377 .Header.BufferSz =
sizeof(av1_extend_tile_buf),
1379 mfxExtAV1BitstreamParam av1_bs_param = {
1380 .Header.BufferId = MFX_EXTBUFF_AV1_BITSTREAM_PARAM,
1381 .Header.BufferSz =
sizeof(av1_bs_param),
1384 mfxExtCodingOption2 co2 = {
1385 .Header.BufferId = MFX_EXTBUFF_CODING_OPTION2,
1386 .Header.BufferSz =
sizeof(co2),
1389 mfxExtCodingOption3 co3 = {
1390 .Header.BufferId = MFX_EXTBUFF_CODING_OPTION3,
1391 .Header.BufferSz =
sizeof(co3),
1394 mfxExtBuffer *ext_buffers[] = {
1395 (mfxExtBuffer*)&av1_extend_tile_buf,
1396 (mfxExtBuffer*)&av1_bs_param,
1397 (mfxExtBuffer*)&co2,
1398 (mfxExtBuffer*)&co3,
1403 "This version of runtime doesn't support AV1 encoding\n");
1407 q->
param.ExtParam = ext_buffers;
1410 ret = MFXVideoENCODE_GetVideoParam(q->
session, &q->
param);
1413 "Error calling GetVideoParam");
1416 dump_video_av1_param(avctx, q, ext_buffers);
1425 uint8_t sps_buf[512];
1426 uint8_t pps_buf[128];
1428 mfxExtCodingOptionSPSPPS extradata = {
1429 .Header.BufferId = MFX_EXTBUFF_CODING_OPTION_SPSPPS,
1430 .Header.BufferSz =
sizeof(extradata),
1431 .SPSBuffer = sps_buf, .SPSBufSize =
sizeof(sps_buf),
1432 .PPSBuffer = pps_buf, .PPSBufSize =
sizeof(pps_buf)
1435 mfxExtCodingOption co = {
1436 .Header.BufferId = MFX_EXTBUFF_CODING_OPTION,
1437 .Header.BufferSz =
sizeof(co),
1439 mfxExtCodingOption2 co2 = {
1440 .Header.BufferId = MFX_EXTBUFF_CODING_OPTION2,
1441 .Header.BufferSz =
sizeof(co2),
1443 mfxExtCodingOption3 co3 = {
1444 .Header.BufferId = MFX_EXTBUFF_CODING_OPTION3,
1445 .Header.BufferSz =
sizeof(co3),
1448 uint8_t vps_buf[128];
1449 mfxExtCodingOptionVPS extradata_vps = {
1450 .Header.BufferId = MFX_EXTBUFF_CODING_OPTION_VPS,
1451 .Header.BufferSz =
sizeof(extradata_vps),
1452 .VPSBuffer = vps_buf,
1453 .VPSBufSize =
sizeof(vps_buf),
1456 mfxExtHEVCTiles hevc_tile_buf = {
1457 .Header.BufferId = MFX_EXTBUFF_HEVC_TILES,
1458 .Header.BufferSz =
sizeof(hevc_tile_buf),
1462 mfxExtHyperModeParam hyper_mode_param_buf = {
1463 .Header.BufferId = MFX_EXTBUFF_HYPER_MODE_PARAM,
1464 .Header.BufferSz =
sizeof(hyper_mode_param_buf),
1471 int ret, ext_buf_num = 0, extradata_offset = 0;
1474 ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&extradata;
1475 ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&co;
1480 ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&co2;
1485 ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&co3;
1490 ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&extradata_vps;
1493 ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&hevc_tile_buf;
1498 ext_buffers[ext_buf_num++] = (mfxExtBuffer*)&hyper_mode_param_buf;
1502 q->
param.ExtParam = ext_buffers;
1503 q->
param.NumExtParam = ext_buf_num;
1505 ret = MFXVideoENCODE_GetVideoParam(q->
session, &q->
param);
1508 "Error calling GetVideoParam");
1512 if (!extradata.SPSBufSize || (need_pps && !extradata.PPSBufSize)
1513 || (q->
hevc_vps && !extradata_vps.VPSBufSize)
1519 avctx->
extradata_size = extradata.SPSBufSize + need_pps * extradata.PPSBufSize;
1527 memcpy(avctx->
extradata, vps_buf, extradata_vps.VPSBufSize);
1528 extradata_offset += extradata_vps.VPSBufSize;
1531 memcpy(avctx->
extradata + extradata_offset, sps_buf, extradata.SPSBufSize);
1532 extradata_offset += extradata.SPSBufSize;
1534 memcpy(avctx->
extradata + extradata_offset, pps_buf, extradata.PPSBufSize);
1535 extradata_offset += extradata.PPSBufSize;
1556 mfxFrameSurface1 *surfaces;
1562 if (!q->opaque_alloc_buf)
1565 q->opaque_surfaces =
av_malloc_array(nb_surfaces,
sizeof(*q->opaque_surfaces));
1566 if (!q->opaque_surfaces)
1569 surfaces = (mfxFrameSurface1*)q->opaque_alloc_buf->data;
1570 for (
i = 0;
i < nb_surfaces;
i++) {
1571 surfaces[
i].Info = q->
req.Info;
1572 q->opaque_surfaces[
i] = surfaces +
i;
1575 q->opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
1576 q->opaque_alloc.Header.BufferSz =
sizeof(q->opaque_alloc);
1577 q->opaque_alloc.In.Surfaces = q->opaque_surfaces;
1578 q->opaque_alloc.In.NumSurface = nb_surfaces;
1579 q->opaque_alloc.In.Type = q->
req.Type;
1606 q->
param.IOPattern == MFX_IOPATTERN_IN_OPAQUE_MEMORY,
1640 int opaque_alloc = 0;
1643#if HAVE_STRUCT_MFXCONFIGINTERFACE
1644 mfxExtBuffer ext_buf;
1645 mfxConfigInterface *iface =
NULL;
1668 if (frames_hwctx->
frame_type & MFX_MEMTYPE_OPAQUE_FRAME)
1669 iopattern = MFX_IOPATTERN_IN_OPAQUE_MEMORY;
1671 (MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET | MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET))
1672 iopattern = MFX_IOPATTERN_IN_VIDEO_MEMORY;
1675 (MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET | MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET))
1676 iopattern = MFX_IOPATTERN_IN_VIDEO_MEMORY;
1682 iopattern = MFX_IOPATTERN_IN_SYSTEM_MEMORY;
1683 q->
param.IOPattern = iopattern;
1693 "Error querying mfx version");
1742#if HAVE_STRUCT_MFXCONFIGINTERFACE
1743 ret = MFXVideoCORE_GetHandle(q->
session, MFX_HANDLE_CONFIG_INTERFACE, (mfxHDL *)(&iface));
1746 "Error getting mfx config interface handle");
1749 const char *param_key = param->
key;
1750 const char *param_value = param->
value;
1751 mfxExtBuffer *new_ext_buf;
1757 for (
int i = 0;
i < 2;
i++) {
1758 ret = iface->SetParameter(iface, (mfxU8*)param_key, (mfxU8*)param_value, MFX_STRUCTURE_TYPE_VIDEO_PARAM, &q->
param, &ext_buf);
1759 if (ret == MFX_ERR_NONE) {
1761 }
else if (
i == 0 && ret == MFX_ERR_MORE_EXTBUFFER) {
1772 new_ext_buf = (mfxExtBuffer*)
av_mallocz(ext_buf.BufferSz);
1776 new_ext_buf->BufferId = ext_buf.BufferId;
1777 new_ext_buf->BufferSz = ext_buf.BufferSz;
1795 if (ret == MFX_WRN_PARTIAL_ACCELERATION) {
1797 }
else if (ret < 0) {
1799 "Error querying encoder params");
1805 "Error querying (IOSurf) the encoding parameters");
1809 ret = qsv_init_opaque_alloc(avctx, q);
1814 "however libmfx %d.%d doesn't support OPAQUE memory.\n",
1815 q->
ver.Major, q->
ver.Minor);
1823 "Error initializing the encoder");
1826 "Warning in encoder initialization");
1861 enc_ctrl->NumPayload = 0;
1862 enc_ctrl->NumExtParam = 0;
1900 last = &
frame->next;
1908 if (!
frame->frame) {
1925 int max_step[4], filled[4] = { 0 };
1931 for (
int i = 0;
i <
desc->nb_components;
i++) {
1933 int sheight, dheight, plane =
comp->plane;
1941 if (swidth < 0 || dwidth < 0) {
1949 sheight =
frame->height;
1958 if (new_w >
frame->width) {
1959 for (
int j = 0; j < sheight; j++) {
1960 void *line_ptr =
frame->data[plane] + j *
frame->linesize[plane] + swidth;
1964 new_w -
frame->width);
1969 for (
int j = sheight; j < dheight; j++)
1970 memcpy(
frame->data[plane] + j *
frame->linesize[plane],
1971 frame->data[plane] + (sheight - 1) *
frame->linesize[plane],
1985 switch (
frame->format) {
2001 frame->linesize[1] = 0;
2002 total_size =
frame->linesize[0] *
frame->height;
2011 frame->linesize[1] = 0;
2012 total_size =
frame->linesize[0] *
frame->height;
2103 MFX_PICSTRUCT_FIELD_BFF;
2104 if (
frame->repeat_pict == 1)
2105 qf->
surface.Info.PicStruct |= MFX_PICSTRUCT_FIELD_REPEATED;
2106 else if (
frame->repeat_pict == 2)
2107 qf->
surface.Info.PicStruct |= MFX_PICSTRUCT_FRAME_DOUBLING;
2108 else if (
frame->repeat_pict == 4)
2109 qf->
surface.Info.PicStruct |= MFX_PICSTRUCT_FRAME_TRIPLING;
2126 if (q->
param.mfx.CodecId == MFX_CODEC_AVC) {
2127 if (q->
param.mfx.CodecProfile == MFX_PROFILE_AVC_BASELINE ||
2128 q->
param.mfx.CodecLevel < MFX_LEVEL_AVC_21 ||
2129 q->
param.mfx.CodecLevel > MFX_LEVEL_AVC_41)
2131 "Interlaced coding is supported"
2132 " at Main/High Profile Level 2.2-4.0\n");
2137 mfxEncodeCtrl *enc_ctrl)
2153 mfxExtEncoderROI *enc_roi =
NULL;
2160 if (!roi_size || sd->
size % roi_size) {
2164 nb_roi = sd->
size / roi_size;
2167 "supported by driver (%d > %d).\n",
2175 enc_roi->Header.BufferId = MFX_EXTBUFF_ENCODER_ROI;
2176 enc_roi->Header.BufferSz =
sizeof(*enc_roi);
2177 enc_roi->NumROI = nb_roi;
2178 enc_roi->ROIMode = MFX_ROI_MODE_QP_DELTA;
2179 for (
i = 0;
i < nb_roi;
i++) {
2185 enc_roi->ROI[
i].DeltaQP =
2189 enc_roi->ROI[
i].DeltaQP);
2191 enc_ctrl->ExtParam[enc_ctrl->NumExtParam] = (mfxExtBuffer *)enc_roi;
2192 enc_ctrl->NumExtParam++;
2198 mfxEncodeCtrl *enc_ctrl)
2201 if (!
frame->metadata)
2204 if (!skip_frame_dict)
2206 enc_ctrl->SkipFrame = strtol(skip_frame_dict->
value,
NULL, 10);
2212 int updated = 0, new_qp = 0;
2217 if (q->
param.mfx.RateControlMethod == MFX_RATECONTROL_CQP) {
2233 "Reset qp = %d/%d/%d for idr/p/b frames\n",
2252 "Reset MaxFrameSize: %d;\n", q->
extco2.MaxFrameSize);
2266 q->
param.mfx.GopPicSize);
2287 q->
extco2.IntRefQPDelta =
2291 "Reset IntRefType: %d; IntRefCycleSize: %d; "
2292 "IntRefQPDelta: %d; IntRefCycleDist: %d\n",
2322 "qmin and or qmax are set but invalid,"
2323 " please make sure min <= max\n");
2333 if (avctx->
qmin >= 0) {
2337 if (avctx->
qmax >= 0) {
2355 "MinQPP: %d; MaxQPP: %d; "
2356 "MinQPB: %d; MaxQPB: %d\n",
2377 q->
extco3.LowDelayBRC = MFX_CODINGOPTION_UNKNOWN;
2403 q->
param.mfx.FrameInfo.FrameRateExtN,
2404 q->
param.mfx.FrameInfo.FrameRateExtD,
2405 (
double)q->
param.mfx.FrameInfo.FrameRateExtN / q->
param.mfx.FrameInfo.FrameRateExtD);
2413 int target_bitrate_kbps, max_bitrate_kbps, brc_param_multiplier;
2414 int buffer_size_in_kilobytes, initial_delay_in_kilobytes;
2425 target_bitrate_kbps = avctx->
bit_rate / 1000;
2427 brc_param_multiplier = (
FFMAX(
FFMAX3(target_bitrate_kbps, max_bitrate_kbps, buffer_size_in_kilobytes),
2428 initial_delay_in_kilobytes) + 0x10000) / 0x10000;
2430 q->
param.mfx.BufferSizeInKB = buffer_size_in_kilobytes / brc_param_multiplier;
2431 q->
param.mfx.InitialDelayInKB = initial_delay_in_kilobytes / brc_param_multiplier;
2432 q->
param.mfx.TargetKbps = target_bitrate_kbps / brc_param_multiplier;
2433 q->
param.mfx.MaxKbps = max_bitrate_kbps / brc_param_multiplier;
2434 q->
param.mfx.BRCParamMultiplier = brc_param_multiplier;
2436 "Reset BufferSizeInKB: %d; InitialDelayInKB: %d; "
2437 "TargetKbps: %d; MaxKbps: %d; BRCParamMultiplier: %d\n",
2438 q->
param.mfx.BufferSizeInKB, q->
param.mfx.InitialDelayInKB,
2439 q->
param.mfx.TargetKbps, q->
param.mfx.MaxKbps, q->
param.mfx.BRCParamMultiplier);
2455 MFX_CODINGOPTION_ON : MFX_CODINGOPTION_UNKNOWN;
2466 mfxExtAVCEncodedFrameInfo *enc_info =
NULL;
2467 mfxExtBuffer **enc_buf =
NULL;
2469 mfxFrameSurface1 *surf =
NULL;
2471 mfxEncodeCtrl* enc_ctrl =
NULL;
2486 enc_ctrl->FrameType = MFX_FRAMETYPE_I | MFX_FRAMETYPE_REF;
2488 enc_ctrl->FrameType |= MFX_FRAMETYPE_IDR;
2501 pkt.bs->Data =
pkt.pkt.data;
2502 pkt.bs->MaxLength =
pkt.pkt.size;
2509 enc_info->Header.BufferId = MFX_EXTBUFF_ENCODED_FRAME_INFO;
2510 enc_info->Header.BufferSz =
sizeof (*enc_info);
2511 pkt.bs->NumExtParam = 1;
2512 enc_buf =
av_mallocz(
sizeof(mfxExtBuffer *));
2515 enc_buf[0] = (mfxExtBuffer *)enc_info;
2517 pkt.bs->ExtParam = enc_buf;
2542 ret = MFXVideoENCODE_EncodeFrameAsync(q->
session, enc_ctrl, surf,
pkt.bs,
pkt.sync);
2543 if (ret == MFX_WRN_DEVICE_BUSY)
2545 }
while (ret == MFX_WRN_DEVICE_BUSY || ret == MFX_WRN_IN_EXECUTION);
2551 ret = (ret == MFX_ERR_MORE_DATA) ?
2585 int needReset = 0, ret = 0;
2618 if (j < qsv->nb_ext_buffers)
2628 while (ret !=
AVERROR(EAGAIN)) {
2630 if (ret < 0 && ret !=
AVERROR(EAGAIN))
2652 if (ret < 0 && ret !=
AVERROR(EAGAIN))
2658 mfxExtAVCEncodedFrameInfo *enc_info;
2659 mfxExtBuffer **enc_buf;
2665 ret = MFXVideoCORE_SyncOperation(q->
session, *qpkt.
sync, 1000);
2666 }
while (ret == MFX_WRN_IN_EXECUTION);
2672 if (qpkt.
bs->FrameType & MFX_FRAMETYPE_IDR || qpkt.
bs->FrameType & MFX_FRAMETYPE_xIDR) {
2675 }
else if (qpkt.
bs->FrameType & MFX_FRAMETYPE_I || qpkt.
bs->FrameType & MFX_FRAMETYPE_xI) {
2679 }
else if (qpkt.
bs->FrameType & MFX_FRAMETYPE_P || qpkt.
bs->FrameType & MFX_FRAMETYPE_xP)
2681 else if (qpkt.
bs->FrameType & MFX_FRAMETYPE_B || qpkt.
bs->FrameType & MFX_FRAMETYPE_xB)
2683 else if (qpkt.
bs->FrameType == MFX_FRAMETYPE_UNKNOWN && qpkt.
bs->DataLength) {
2692 enc_buf = qpkt.
bs->ExtParam;
2693 enc_info = (mfxExtAVCEncodedFrameInfo *)(*enc_buf);
2715 MFXVideoENCODE_Close(q->
session);
2736 mfxExtBuffer **enc_buf =
pkt.bs->ExtParam;
2737 mfxExtAVCEncodedFrameInfo *enc_info = (mfxExtAVCEncodedFrameInfo *)(*enc_buf);
static double val(void *priv, double ch)
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
#define FF_COMPRESSION_DEFAULT
#define i(width, name, range_min, range_max)
common internal and external API header
#define AV_CEIL_RSHIFT(a, b)
static __device__ float fabs(float a)
#define FF_COMPLIANCE_NORMAL
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
AVCPBProperties * ff_encode_add_cpb_side_data(AVCodecContext *avctx)
Add a CPB properties side data to an encoding context.
int ff_encode_add_stats_side_data(AVPacket *pkt, int quality, const int64_t error[], int error_count, enum AVPictureType pict_type)
#define AV_CODEC_FLAG_CLOSED_GOP
#define AV_CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT.
#define AV_CODEC_FLAG_QSCALE
Use fixed qscale.
AVCodecID
Identify the syntax and semantics of the bitstream.
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
AVBufferRef * av_buffer_allocz(size_t size)
Same as av_buffer_alloc(), except the returned buffer will be initialized to zero.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
AVBufferRef * av_buffer_alloc(size_t size)
Allocate an AVBuffer of the given size using av_malloc().
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key,...
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
AVFifo * av_fifo_alloc2(size_t nb_elems, size_t elem_size, unsigned int flags)
Allocate and initialize an AVFifo with a given element size.
void av_fifo_freep2(AVFifo **f)
Free an AVFifo and reset pointer to NULL.
#define AV_FIFO_FLAG_AUTO_GROW
Automatically resize the FIFO on writes, so that the data fits.
size_t av_fifo_can_read(const AVFifo *f)
int av_fifo_write(AVFifo *f, const void *buf, size_t nb_elems)
Write data into a FIFO.
int av_fifo_read(AVFifo *f, void *buf, size_t nb_elems)
Read data from a FIFO.
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
#define AV_FRAME_FLAG_TOP_FIELD_FIRST
A flag to mark frames where the top field is displayed first if the content is interlaced.
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
int av_frame_replace(AVFrame *dst, const AVFrame *src)
Ensure the destination frame refers to the same data described by the source frame,...
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
@ AV_FRAME_DATA_REGIONS_OF_INTEREST
Regions Of Interest, the data is an array of AVRegionOfInterest type, the number of array element is ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
Overlapping memcpy() implementation.
int av_image_get_linesize(enum AVPixelFormat pix_fmt, int width, int plane)
Compute the size of an image line with format pix_fmt and width width for the plane plane.
void av_image_fill_max_pixsteps(int max_pixsteps[4], int max_pixstep_comps[4], const AVPixFmtDescriptor *pixdesc)
Compute the max pixel step for each plane of an image with a format described by pixdesc.
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_NONE
Undefined.
@ AV_PICTURE_TYPE_P
Predicted.
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
#define HW_CONFIG_ENCODER_DEVICE(format, device_type_)
#define HW_CONFIG_ENCODER_FRAMES(format, device_type_)
An API-specific header for AV_HWDEVICE_TYPE_QSV.
static const AVProfile profiles[]
Memory handling functions.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
@ AVCOL_RANGE_JPEG
Full range content.
#define AV_PIX_FMT_X2RGB10
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
@ AV_PIX_FMT_VUYX
packed VUYX 4:4:4:4, 32bpp, Variant of VUYA where alpha channel is left undefined
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
@ AV_PIX_FMT_YUYV422
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
@ AV_PIX_FMT_QSV
HW acceleration through QSV, data[3] contains a pointer to the mfxFrameSurface1 structure.
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB), YZX and ST 428-1
int ff_qsv_map_frame_to_surface(const AVFrame *frame, mfxFrameSurface1 *surface)
int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id)
int ff_qsv_init_internal_session(AVCodecContext *avctx, QSVSession *qs, const char *load_plugins, int gpu_copy)
int ff_qsv_print_error(void *log_ctx, mfxStatus err, const char *error_string)
int ff_qsv_close_internal_session(QSVSession *qs)
int ff_qsv_init_session_frames(AVCodecContext *avctx, mfxSession *psession, QSVFramesContext *qsv_frames_ctx, const char *load_plugins, int opaque, int gpu_copy)
int ff_qsv_print_iopattern(void *log_ctx, int mfx_iopattern, const char *extra_string)
int ff_qsv_init_session_device(AVCodecContext *avctx, mfxSession *psession, AVBufferRef *device_ref, const char *load_plugins, int gpu_copy)
int ff_qsv_find_surface_idx(QSVFramesContext *ctx, QSVFrame *frame)
int ff_qsv_print_warning(void *log_ctx, mfxStatus err, const char *warning_string)
int ff_qsv_map_pixfmt(enum AVPixelFormat format, uint32_t *fourcc, uint16_t *shift)
#define QSV_MAX_ENC_EXTPARAM
#define QSV_MAX_ENC_PAYLOAD
#define QSV_RUNTIME_VERSION_ATLEAST(MFX_VERSION, MAJOR, MINOR)
static int update_low_delay_brc(AVCodecContext *avctx, QSVEncContext *q)
static int encode_frame(AVCodecContext *avctx, QSVEncContext *q, const AVFrame *frame)
static void dump_video_mjpeg_param(AVCodecContext *avctx, QSVEncContext *q)
static int init_video_param_jpeg(AVCodecContext *avctx, QSVEncContext *q)
static int update_pic_timing_sei(AVCodecContext *avctx, QSVEncContext *q)
static int select_rc_mode(AVCodecContext *avctx, QSVEncContext *q)
static const struct @275277033325226266023232267036105046332237111312 rc_names[]
static int qsvenc_fill_padding_area(AVFrame *frame, int new_w, int new_h)
static int qsv_retrieve_enc_av1_params(AVCodecContext *avctx, QSVEncContext *q)
static void free_encoder_ctrl(mfxEncodeCtrl *enc_ctrl)
static void dump_video_vp9_param(AVCodecContext *avctx, QSVEncContext *q, mfxExtBuffer **coding_opts)
static const char * print_profile(enum AVCodecID codec_id, mfxU16 profile)
static int check_enc_param(AVCodecContext *avctx, QSVEncContext *q)
int ff_qsv_enc_close(AVCodecContext *avctx, QSVEncContext *q)
static int init_video_param(AVCodecContext *avctx, QSVEncContext *q)
static int qsv_retrieve_enc_vp9_params(AVCodecContext *avctx, QSVEncContext *q)
int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q)
int ff_qsv_encode(AVCodecContext *avctx, QSVEncContext *q, AVPacket *pkt, const AVFrame *frame, int *got_packet)
static const struct profile_names av1_profiles[]
static int update_bitrate(AVCodecContext *avctx, QSVEncContext *q)
static void set_skip_frame_encode_ctrl(AVCodecContext *avctx, const AVFrame *frame, mfxEncodeCtrl *enc_ctrl)
static const char * print_ratecontrol(mfxU16 rc_mode)
static int qsvenc_get_continuous_buffer(AVFrame *frame)
static int qsv_retrieve_enc_jpeg_params(AVCodecContext *avctx, QSVEncContext *q)
static const struct profile_names mpeg2_profiles[]
static int update_parameters(AVCodecContext *avctx, QSVEncContext *q, const AVFrame *frame)
static int update_frame_rate(AVCodecContext *avctx, QSVEncContext *q)
static const struct profile_names avc_profiles[]
static int set_roi_encode_ctrl(AVCodecContext *avctx, const AVFrame *frame, mfxEncodeCtrl *enc_ctrl)
static int update_gop_size(AVCodecContext *avctx, QSVEncContext *q)
static int qsv_retrieve_enc_params(AVCodecContext *avctx, QSVEncContext *q)
static const struct profile_names hevc_profiles[]
static int qsvenc_init_session(AVCodecContext *avctx, QSVEncContext *q)
static int get_free_frame(QSVEncContext *q, QSVFrame **f)
static int update_qp(AVCodecContext *avctx, QSVEncContext *q)
static void clear_unused_frames(QSVEncContext *q)
#define MFX_IMPL_VIA_MASK(impl)
static void dump_video_param(AVCodecContext *avctx, QSVEncContext *q, mfxExtBuffer **coding_opts)
static int update_max_frame_size(AVCodecContext *avctx, QSVEncContext *q)
static void print_interlace_msg(AVCodecContext *avctx, QSVEncContext *q)
static int is_strict_gop(QSVEncContext *q)
const AVCodecHWConfigInternal *const ff_qsv_enc_hw_configs[]
static int update_rir(AVCodecContext *avctx, QSVEncContext *q)
static int submit_frame(QSVEncContext *q, const AVFrame *frame, QSVFrame **new_frame)
static const struct profile_names vp9_profiles[]
static const char * print_threestate(mfxU16 val)
#define UPDATE_PARAM(a, b)
static int update_min_max_qp(AVCodecContext *avctx, QSVEncContext *q)
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
#define FF_ARRAY_ELEMS(a)
uint8_t * data
The data buffer.
This structure describes the bitrate properties of an encoded bitstream.
int64_t avg_bitrate
Average bitrate of the stream, in bits per second.
int64_t max_bitrate
Maximum bitrate of the stream, in bits per second.
int64_t buffer_size
The size of the buffer to which the ratecontrol is applied, in bits.
int64_t min_bitrate
Minimum bitrate of the stream, in bits per second.
main external API structure.
int trellis
trellis RD quantization
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
int rc_buffer_size
decoder bitstream buffer size
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
int global_quality
Global quality for codecs which cannot change it per frame.
enum AVColorRange color_range
MPEG vs JPEG YUV range.
int strict_std_compliance
strictly follow the standard (MPEG-4, ...).
float b_quant_offset
qscale offset between IP and B-frames
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames.
int max_b_frames
maximum number of B-frames between non-B-frames Note: The output will be delayed by max_b_frames+1 re...
int qmin
minimum quantizer
float b_quant_factor
qscale factor between IP and B-frames If > 0 then the last P-frame quantizer will be used (q= lastp_q...
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
int level
Encoding level descriptor.
int64_t bit_rate
the average bitrate
int rc_initial_buffer_occupancy
Number of bits which should be loaded into the rc buffer before decoding starts.
enum AVColorSpace colorspace
YUV colorspace type.
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
int refs
number of reference frames
int64_t rc_max_rate
maximum bitrate
int qmax
maximum quantizer
void * hwaccel_context
Legacy hardware accelerator context.
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
int flags
AV_CODEC_FLAG_*.
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
int64_t rc_min_rate
minimum bitrate
AVBufferRef * hw_device_ctx
A reference to the AVHWDeviceContext describing the device which will be used by a hardware encoder/d...
float i_quant_factor
qscale factor between P- and I-frames If > 0 then the last P-frame quantizer will be used (q = lastp_...
float i_quant_offset
qscale offset between P and I-frames
int slices
Number of slices.
Structure to hold side data for an AVFrame.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
This struct describes a set or pool of "hardware" frames (i.e.
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
This structure stores compressed data.
int flags
A combination of AV_PKT_FLAG values.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
This struct is used for communicating QSV parameters between libavcodec and the caller.
int opaque_alloc
Encoding only.
int opaque_alloc_type
Encoding only, and only if opaque_alloc is set to non-zero.
int nb_opaque_surfaces
Encoding only, and only if opaque_alloc is set to non-zero.
mfxExtBuffer ** ext_buffers
Extra buffers to pass to encoder or decoder initialization.
int iopattern
The IO pattern to use.
mfxSession session
If non-NULL, the session to use for encoding or decoding.
AVBufferRef * opaque_surfaces
Encoding only, and only if opaque_alloc is set to non-zero.
This struct is allocated as AVHWFramesContext.hwctx.
mfxFrameSurface1 * surfaces
A pointer to a mfxFrameSurface1 struct.
int nb_surfaces
Number of frames in the pool.
int frame_type
A combination of MFX_MEMTYPE_* describing the frame pool.
mfxFrameInfo * info
A pointer to a mfxFrameInfo struct.
Rational number (pair of numerator and denominator).
Structure describing a single Region Of Interest.
uint32_t self_size
Must be set to the size of this data structure (that is, sizeof(AVRegionOfInterest)).
AVRational qoffset
Quantisation offset.
int top
Distance in pixels from the top edge of the frame to the top and bottom edges and from the left edge ...
AVDictionary * qsv_params
int old_int_ref_cycle_size
mfxExtCodingOption3 extco3
mfxExtVP9Param extvp9param
SetEncodeCtrlCB * set_encode_ctrl_cb
int look_ahead_downsampling
mfxExtBuffer * extparam_internal[5+(QSV_HAVE_MF *2)+(QSV_HAVE_EXT_AV1_PARAM *2)+QSV_HAVE_HE]
mfxExtBuffer ** extparam_str
int old_rc_initial_buffer_occupancy
QSVFramesContext frames_ctx
mfxExtVideoSignalInfo extvsi
int max_dec_frame_buffering
int exthypermodeparam_idx
mfxExtHEVCTiles exthevctiles
mfxExtCodingOption2 extco2
int old_int_ref_cycle_dist
mfxExtBuffer * extparam[QSV_MAX_ENC_EXTPARAM]
used for enc_ctrl.ExtParam
mfxPayload * payloads[QSV_MAX_ENC_PAYLOAD]
used for enc_ctrl.Payload
QSVMid * mids
The memory ids for the external frames.
AVBufferRef * hw_frames_ctx
#define av_malloc_array(a, b)
int av_usleep(unsigned usec)
Sleep for a period of time.
static const uint8_t quant[64]