24 #include <AMF/components/PreAnalysis.h>
26 #define OFFSET(x) offsetof(AmfContext, x)
27 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
30 {
"usage",
"Set the encoding usage",
OFFSET(
usage),
AV_OPT_TYPE_INT, {.i64 = -1 }, -1, AMF_VIDEO_ENCODER_HEVC_USAGE_LOW_LATENCY_HIGH_QUALITY,
VE, .unit =
"usage" },
31 {
"transcoding",
"Generic Transcoding", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_VIDEO_ENCODER_HEVC_USAGE_TRANSCODING }, 0, 0,
VE, .unit =
"usage" },
32 {
"ultralowlatency",
"Ultra low latency usecase", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_VIDEO_ENCODER_HEVC_USAGE_ULTRA_LOW_LATENCY }, 0, 0,
VE, .unit =
"usage" },
33 {
"lowlatency",
"Low latency usecase", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_VIDEO_ENCODER_HEVC_USAGE_LOW_LATENCY }, 0, 0,
VE, .unit =
"usage" },
34 {
"webcam",
"Webcam", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_VIDEO_ENCODER_HEVC_USAGE_WEBCAM }, 0, 0,
VE, .unit =
"usage" },
35 {
"high_quality",
"High quality usecase", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_VIDEO_ENCODER_HEVC_USAGE_HIGH_QUALITY }, 0, 0,
VE, .unit =
"usage" },
36 {
"lowlatency_high_quality",
"Low latency yet high quality usecase", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_VIDEO_ENCODER_HEVC_USAGE_LOW_LATENCY_HIGH_QUALITY }, 0, 0,
VE, .unit =
"usage" },
38 {
"profile",
"Set the profile",
OFFSET(
profile),
AV_OPT_TYPE_INT,{ .i64 = -1 }, -1, AMF_VIDEO_ENCODER_HEVC_PROFILE_MAIN_10,
VE, .unit =
"profile" },
39 {
"main",
"", 0,
AV_OPT_TYPE_CONST,{ .i64 = AMF_VIDEO_ENCODER_HEVC_PROFILE_MAIN }, 0, 0,
VE, .unit =
"profile" },
40 {
"main10",
"", 0,
AV_OPT_TYPE_CONST,{ .i64 = AMF_VIDEO_ENCODER_HEVC_PROFILE_MAIN_10 }, 0, 0,
VE, .unit =
"profile" },
42 {
"profile_tier",
"Set the profile tier (default main)",
OFFSET(
tier),
AV_OPT_TYPE_INT,{ .i64 = -1 }, -1, AMF_VIDEO_ENCODER_HEVC_TIER_HIGH,
VE, .unit =
"tier" },
43 {
"main",
"", 0,
AV_OPT_TYPE_CONST, { .i64 = AMF_VIDEO_ENCODER_HEVC_TIER_MAIN }, 0, 0,
VE, .unit =
"tier" },
44 {
"high",
"", 0,
AV_OPT_TYPE_CONST, { .i64 = AMF_VIDEO_ENCODER_HEVC_TIER_HIGH }, 0, 0,
VE, .unit =
"tier" },
46 {
"level",
"Set the encoding level (default auto)",
OFFSET(
level),
AV_OPT_TYPE_INT,{ .i64 = 0 }, 0, AMF_LEVEL_6_2,
VE, .unit =
"level" },
62 {
"quality",
"Set the encoding quality preset",
OFFSET(
quality),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, AMF_VIDEO_ENCODER_HEVC_QUALITY_PRESET_SPEED,
VE, .unit =
"quality" },
63 {
"preset",
"Set the encoding quality preset",
OFFSET(
quality),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, AMF_VIDEO_ENCODER_HEVC_QUALITY_PRESET_SPEED,
VE, .unit =
"quality" },
64 {
"quality",
"", 0,
AV_OPT_TYPE_CONST, { .i64 = AMF_VIDEO_ENCODER_HEVC_QUALITY_PRESET_QUALITY }, 0, 0,
VE, .unit =
"quality" },
65 {
"balanced",
"", 0,
AV_OPT_TYPE_CONST, { .i64 = AMF_VIDEO_ENCODER_HEVC_QUALITY_PRESET_BALANCED }, 0, 0,
VE, .unit =
"quality" },
66 {
"speed",
"", 0,
AV_OPT_TYPE_CONST, { .i64 = AMF_VIDEO_ENCODER_HEVC_QUALITY_PRESET_SPEED }, 0, 0,
VE, .unit =
"quality" },
70 {
"rc",
"Set the rate control mode",
OFFSET(rate_control_mode),
AV_OPT_TYPE_INT, { .i64 = AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_UNKNOWN }, AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_UNKNOWN, AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_HIGH_QUALITY_CBR,
VE, .unit =
"rc" },
71 {
"cqp",
"Constant Quantization Parameter", 0,
AV_OPT_TYPE_CONST, { .i64 = AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_CONSTANT_QP }, 0, 0,
VE, .unit =
"rc" },
72 {
"cbr",
"Constant Bitrate", 0,
AV_OPT_TYPE_CONST, { .i64 = AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_CBR }, 0, 0,
VE, .unit =
"rc" },
73 {
"vbr_peak",
"Peak Contrained Variable Bitrate", 0,
AV_OPT_TYPE_CONST, { .i64 = AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_PEAK_CONSTRAINED_VBR }, 0, 0,
VE, .unit =
"rc" },
74 {
"vbr_latency",
"Latency Constrained Variable Bitrate", 0,
AV_OPT_TYPE_CONST, { .i64 = AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_LATENCY_CONSTRAINED_VBR }, 0, 0,
VE, .unit =
"rc" },
75 {
"qvbr",
"Quality Variable Bitrate", 0,
AV_OPT_TYPE_CONST, { .i64 = AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_QUALITY_VBR }, 0, 0,
VE, .unit =
"rc" },
76 {
"hqvbr",
"High Quality Variable Bitrate", 0,
AV_OPT_TYPE_CONST, { .i64 = AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_HIGH_QUALITY_VBR }, 0, 0,
VE, .unit =
"rc" },
77 {
"hqcbr",
"High Quality Constant Bitrate", 0,
AV_OPT_TYPE_CONST, { .i64 = AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_HIGH_QUALITY_CBR }, 0, 0,
VE, .unit =
"rc" },
79 {
"qvbr_quality_level",
"Sets the QVBR quality level",
OFFSET(qvbr_quality_level),
AV_OPT_TYPE_INT, {.i64 = -1 }, -1, 51,
VE },
81 {
"header_insertion_mode",
"Set header insertion mode",
OFFSET(header_insertion_mode),
AV_OPT_TYPE_INT,{ .i64 = -1 }, -1, AMF_VIDEO_ENCODER_HEVC_HEADER_INSERTION_MODE_IDR_ALIGNED,
VE, .unit =
"hdrmode" },
82 {
"none",
"", 0,
AV_OPT_TYPE_CONST, { .i64 = AMF_VIDEO_ENCODER_HEVC_HEADER_INSERTION_MODE_NONE }, 0, 0,
VE, .unit =
"hdrmode" },
83 {
"gop",
"", 0,
AV_OPT_TYPE_CONST, { .i64 = AMF_VIDEO_ENCODER_HEVC_HEADER_INSERTION_MODE_GOP_ALIGNED }, 0, 0,
VE, .unit =
"hdrmode" },
84 {
"idr",
"", 0,
AV_OPT_TYPE_CONST, { .i64 = AMF_VIDEO_ENCODER_HEVC_HEADER_INSERTION_MODE_IDR_ALIGNED }, 0, 0,
VE, .unit =
"hdrmode" },
86 {
"high_motion_quality_boost_enable",
"Enable High motion quality boost mode",
OFFSET(hw_high_motion_quality_boost),
AV_OPT_TYPE_BOOL, {.i64 = -1 }, -1, 1,
VE },
87 {
"gops_per_idr",
"GOPs per IDR 0-no IDR will be inserted",
OFFSET(gops_per_idr),
AV_OPT_TYPE_INT, { .i64 = 1 }, 0, INT_MAX,
VE },
92 {
"max_au_size",
"Maximum Access Unit Size for rate control (in bits)",
OFFSET(max_au_size),
AV_OPT_TYPE_INT,{ .i64 = -1 }, -1, INT_MAX,
VE},
93 {
"min_qp_i",
"min quantization parameter for I-frame",
OFFSET(min_qp_i),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 51,
VE },
94 {
"max_qp_i",
"max quantization parameter for I-frame",
OFFSET(max_qp_i),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 51,
VE },
95 {
"min_qp_p",
"min quantization parameter for P-frame",
OFFSET(min_qp_p),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 51,
VE },
96 {
"max_qp_p",
"max quantization parameter for P-frame",
OFFSET(max_qp_p),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 51,
VE },
107 {
"log_to_dbg",
"Enable AMF logging to debug output",
OFFSET(log_to_dbg),
AV_OPT_TYPE_BOOL,{ .i64 = 0 }, 0, 1,
VE },
112 {
"pa_activity_type",
"Set the type of activity analysis",
OFFSET(pa_activity_type),
AV_OPT_TYPE_INT, {.i64 = -1 }, -1, AMF_PA_ACTIVITY_YUV,
VE, .unit =
"activity_type" },
113 {
"y",
"activity y", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_PA_ACTIVITY_Y }, 0, 0,
VE, .unit =
"activity_type" },
114 {
"yuv",
"activity yuv", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_PA_ACTIVITY_YUV }, 0, 0,
VE, .unit =
"activity_type" },
116 {
"pa_scene_change_detection_enable",
"Enable scene change detection",
OFFSET(pa_scene_change_detection),
AV_OPT_TYPE_BOOL, {.i64 = -1 }, -1, 1,
VE },
118 {
"pa_scene_change_detection_sensitivity",
"Set the sensitivity of scene change detection",
OFFSET(pa_scene_change_detection_sensitivity),
AV_OPT_TYPE_INT, {.i64 = -1 }, -1, AMF_PA_SCENE_CHANGE_DETECTION_SENSITIVITY_HIGH,
VE, .unit =
"scene_change_sensitivity" },
119 {
"low",
"low scene change dectection sensitivity", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_PA_SCENE_CHANGE_DETECTION_SENSITIVITY_LOW }, 0, 0,
VE, .unit =
"scene_change_sensitivity" },
120 {
"medium",
"medium scene change dectection sensitivity", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_PA_SCENE_CHANGE_DETECTION_SENSITIVITY_MEDIUM }, 0, 0,
VE, .unit =
"scene_change_sensitivity" },
121 {
"high",
"high scene change dectection sensitivity", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_PA_SCENE_CHANGE_DETECTION_SENSITIVITY_HIGH }, 0, 0,
VE, .unit =
"scene_change_sensitivity" },
123 {
"pa_static_scene_detection_enable",
"Enable static scene detection",
OFFSET(pa_static_scene_detection),
AV_OPT_TYPE_BOOL, {.i64 = -1 }, -1, 1,
VE },
125 {
"pa_static_scene_detection_sensitivity",
"Set the sensitivity of static scene detection",
OFFSET(pa_static_scene_detection_sensitivity),
AV_OPT_TYPE_INT, {.i64 = -1 }, -1, AMF_PA_STATIC_SCENE_DETECTION_SENSITIVITY_HIGH,
VE , .unit =
"static_scene_sensitivity" },
126 {
"low",
"low static scene dectection sensitivity", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_PA_STATIC_SCENE_DETECTION_SENSITIVITY_LOW }, 0, 0,
VE, .unit =
"static_scene_sensitivity" },
127 {
"medium",
"medium static scene dectection sensitivity", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_PA_STATIC_SCENE_DETECTION_SENSITIVITY_MEDIUM }, 0, 0,
VE, .unit =
"static_scene_sensitivity" },
128 {
"high",
"high static scene dectection sensitivity", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_PA_STATIC_SCENE_DETECTION_SENSITIVITY_HIGH }, 0, 0,
VE, .unit =
"static_scene_sensitivity" },
130 {
"pa_initial_qp_after_scene_change",
"The QP value that is used immediately after a scene change",
OFFSET(pa_initial_qp),
AV_OPT_TYPE_INT, {.i64 = -1 }, -1, 51,
VE },
131 {
"pa_max_qp_before_force_skip",
"The QP threshold to allow a skip frame",
OFFSET(pa_max_qp),
AV_OPT_TYPE_INT, {.i64 = -1 }, -1, 51,
VE },
133 {
"pa_caq_strength",
"Content Adaptive Quantization strength",
OFFSET(pa_caq_strength),
AV_OPT_TYPE_INT, {.i64 = -1 }, -1, AMF_PA_CAQ_STRENGTH_HIGH,
VE , .unit =
"caq_strength" },
134 {
"low",
"low Content Adaptive Quantization strength", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_PA_CAQ_STRENGTH_LOW }, 0, 0,
VE, .unit =
"caq_strength" },
135 {
"medium",
"medium Content Adaptive Quantization strength", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_PA_CAQ_STRENGTH_MEDIUM }, 0, 0,
VE, .unit =
"caq_strength" },
136 {
"high",
"high Content Adaptive Quantization strength", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_PA_CAQ_STRENGTH_HIGH }, 0, 0,
VE, .unit =
"caq_strength" },
138 {
"pa_frame_sad_enable",
"Enable Frame SAD algorithm",
OFFSET(pa_frame_sad),
AV_OPT_TYPE_BOOL, {.i64 = -1 }, -1, 1,
VE },
139 {
"pa_ltr_enable",
"Enable long term reference frame management",
OFFSET(pa_ltr),
AV_OPT_TYPE_BOOL, {.i64 = -1 }, -1, 1,
VE },
142 {
"pa_paq_mode",
"Sets the perceptual adaptive quantization mode",
OFFSET(pa_paq_mode),
AV_OPT_TYPE_INT, {.i64 = -1 }, -1, AMF_PA_PAQ_MODE_CAQ,
VE , .unit =
"paq_mode" },
143 {
"none",
"no perceptual adaptive quantization", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_PA_PAQ_MODE_NONE }, 0, 0,
VE, .unit =
"paq_mode" },
144 {
"caq",
"caq perceptual adaptive quantization", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_PA_PAQ_MODE_CAQ }, 0, 0,
VE, .unit =
"paq_mode" },
146 {
"pa_taq_mode",
"Sets the temporal adaptive quantization mode",
OFFSET(pa_taq_mode),
AV_OPT_TYPE_INT, {.i64 = -1 }, -1, AMF_PA_TAQ_MODE_2,
VE , .unit =
"taq_mode" },
147 {
"none",
"no temporal adaptive quantization", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_PA_TAQ_MODE_NONE }, 0, 0,
VE, .unit =
"taq_mode" },
148 {
"1",
"temporal adaptive quantization mode 1", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_PA_TAQ_MODE_1 }, 0, 0,
VE, .unit =
"taq_mode" },
149 {
"2",
"temporal adaptive quantization mode 2", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_PA_TAQ_MODE_2 }, 0, 0,
VE, .unit =
"taq_mode" },
151 {
"pa_high_motion_quality_boost_mode",
"Sets the PA high motion quality boost mode",
OFFSET(pa_high_motion_quality_boost_mode),
AV_OPT_TYPE_INT, {.i64 = -1 }, -1, AMF_PA_HIGH_MOTION_QUALITY_BOOST_MODE_AUTO,
VE , .unit =
"high_motion_quality_boost_mode" },
152 {
"none",
"no high motion quality boost", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_PA_HIGH_MOTION_QUALITY_BOOST_MODE_NONE }, 0, 0,
VE, .unit =
"high_motion_quality_boost_mode" },
153 {
"auto",
"auto high motion quality boost", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_PA_HIGH_MOTION_QUALITY_BOOST_MODE_AUTO }, 0, 0,
VE, .unit =
"high_motion_quality_boost_mode" },
160 AMF_RESULT res = AMF_OK;
162 AMFVariantStruct var = {0};
164 amf_int64 profile_level = 0;
168 AMFSize framesize = AMFConstructSize(avctx->
width, avctx->
height);
170 amf_int64 color_depth;
171 amf_int64 color_profile;
190 if (
ctx->usage != -1) {
191 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_USAGE,
ctx->usage);
194 AMF_ASSIGN_PROPERTY_SIZE(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_FRAMESIZE, framesize);
196 AMF_ASSIGN_PROPERTY_RATE(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_FRAMERATE,
framerate);
200 profile = AMF_VIDEO_ENCODER_HEVC_PROFILE_MAIN;
203 profile = AMF_VIDEO_ENCODER_HEVC_PROFILE_MAIN_10;
209 if (
ctx->profile != -1) {
215 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_PROFILE,
profile);
218 if (
ctx->tier != -1) {
219 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_TIER,
ctx->tier);
222 profile_level = avctx->
level;
224 profile_level =
ctx->level;
227 if (profile_level != 0) {
228 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_PROFILE_LEVEL, profile_level);
231 if (
ctx->quality != -1) {
232 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_QUALITY_PRESET,
ctx->quality);
236 if (avctx->
refs != -1) {
237 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_MAX_NUM_REFRAMES, avctx->
refs);
242 AMF_ASSIGN_PROPERTY_RATIO(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_ASPECT_RATIO, ratio);
246 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_OUTPUT_COLOR_PROFILE, color_profile);
250 color_depth = AMF_COLOR_BIT_DEPTH_8;
254 color_depth = AMF_COLOR_BIT_DEPTH_10;
256 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_COLOR_BIT_DEPTH, color_depth);
258 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_OUTPUT_TRANSFER_CHARACTERISTIC, avctx->
color_trc);
260 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_OUTPUT_COLOR_PRIMARIES, avctx->
color_primaries);
263 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_NUM_GOPS_PER_IDR,
ctx->gops_per_idr);
265 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_GOP_SIZE, avctx->
gop_size);
268 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_SLICES_PER_FRAME, avctx->
slices);
270 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_DE_BLOCKING_FILTER_DISABLE, !deblocking_filter);
272 if (
ctx->header_insertion_mode != -1) {
273 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_HEADER_INSERTION_MODE,
ctx->header_insertion_mode);
278 if (
ctx->rate_control_mode == AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_UNKNOWN) {
279 if (
ctx->min_qp_i != -1 ||
ctx->max_qp_i != -1 ||
280 ctx->min_qp_p != -1 ||
ctx->max_qp_p != -1 ||
281 ctx->qp_i !=-1 ||
ctx->qp_p != -1) {
282 ctx->rate_control_mode = AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_CONSTANT_QP;
285 ctx->rate_control_mode = AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_CBR;
288 ctx->rate_control_mode = AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_PEAK_CONSTRAINED_VBR;
294 if (
ctx->rate_control_mode == AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_CONSTANT_QP) {
295 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_PREENCODE_ENABLE, 0);
296 if (
ctx->preencode != -1) {
297 if (
ctx->preencode) {
298 av_log(
ctx,
AV_LOG_WARNING,
"Preencode is not supported by cqp Rate Control Method, automatically disabled\n");
303 if (
ctx->preencode != -1) {
304 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_PREENCODE_ENABLE,
ctx->preencode);
308 if (
ctx->rate_control_mode == AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_QUALITY_VBR) {
309 if (
ctx->qvbr_quality_level != -1) {
310 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_QVBR_QUALITY_LEVEL,
ctx->qvbr_quality_level);
314 if (
ctx->hw_high_motion_quality_boost != -1) {
315 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_HIGH_MOTION_QUALITY_BOOST_ENABLE, ((
ctx->hw_high_motion_quality_boost == 0) ?
false :
true));
318 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD,
ctx->rate_control_mode);
321 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_VBV_BUFFER_SIZE, avctx->
rc_buffer_size);
325 if (amf_buffer_fullness > 64)
326 amf_buffer_fullness = 64;
327 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_INITIAL_VBV_BUFFER_FULLNESS, amf_buffer_fullness);
331 if (
ctx->rate_control_mode == AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_CONSTANT_QP) {
332 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_ENABLE_VBAQ,
false);
333 if (
ctx->enable_vbaq)
336 if (
ctx->enable_vbaq != -1) {
337 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_ENABLE_VBAQ, !!
ctx->enable_vbaq);
341 if (
ctx->me_half_pel != -1) {
342 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_MOTION_HALF_PIXEL,
ctx->me_half_pel);
344 if (
ctx->me_quarter_pel != -1) {
345 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_MOTION_QUARTERPIXEL,
ctx->me_quarter_pel);
349 if (
ctx->enforce_hrd != -1) {
350 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_ENFORCE_HRD, ((
ctx->enforce_hrd == 0) ?
false :
true));
353 if (
ctx->filler_data != -1) {
354 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_FILLER_DATA_ENABLE, ((
ctx->filler_data == 0) ?
false :
true));
358 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_TARGET_BITRATE, avctx->
bit_rate);
361 if (
ctx->rate_control_mode == AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_CBR) {
363 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_PEAK_BITRATE, avctx->
bit_rate);
368 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_PEAK_BITRATE, avctx->
rc_max_rate);
369 }
else if (
ctx->rate_control_mode == AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_PEAK_CONSTRAINED_VBR) {
373 if (
ctx->latency != -1) {
374 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_LOWLATENCY_MODE, ((
ctx->latency == 0) ?
false :
true));
377 if (
ctx->preanalysis != -1) {
378 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_PRE_ANALYSIS_ENABLE, !!((
ctx->preanalysis == 0) ?
false :
true));
381 res =
ctx->encoder->pVtbl->GetProperty(
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_PRE_ANALYSIS_ENABLE, &var);
382 if ((
int)var.int64Value)
384 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_PRE_ANALYSIS_ENABLE,
true);
386 if (
ctx->pa_activity_type != -1) {
387 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_PA_ACTIVITY_TYPE,
ctx->pa_activity_type);
389 if (
ctx->pa_scene_change_detection != -1) {
390 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_PA_SCENE_CHANGE_DETECTION_ENABLE, ((
ctx->pa_scene_change_detection == 0) ?
false :
true));
392 if (
ctx->pa_scene_change_detection_sensitivity != -1) {
393 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_PA_SCENE_CHANGE_DETECTION_SENSITIVITY,
ctx->pa_scene_change_detection_sensitivity);
395 if (
ctx->pa_static_scene_detection != -1) {
396 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_PA_STATIC_SCENE_DETECTION_ENABLE, ((
ctx->pa_static_scene_detection == 0) ?
false :
true));
398 if (
ctx->pa_static_scene_detection_sensitivity != -1) {
399 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_PA_STATIC_SCENE_DETECTION_SENSITIVITY,
ctx->pa_static_scene_detection_sensitivity);
401 if (
ctx->pa_initial_qp != -1) {
402 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_PA_INITIAL_QP_AFTER_SCENE_CHANGE,
ctx->pa_initial_qp);
404 if (
ctx->pa_max_qp != -1) {
405 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_PA_MAX_QP_BEFORE_FORCE_SKIP,
ctx->pa_max_qp);
407 if (
ctx->pa_caq_strength != -1) {
408 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_PA_CAQ_STRENGTH,
ctx->pa_caq_strength);
410 if (
ctx->pa_frame_sad != -1) {
411 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_PA_FRAME_SAD_ENABLE, ((
ctx->pa_frame_sad == 0) ?
false :
true));
413 if (
ctx->pa_paq_mode != -1) {
414 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_PA_PAQ_MODE,
ctx->pa_paq_mode);
416 if (
ctx->pa_taq_mode != -1) {
417 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_PA_TAQ_MODE,
ctx->pa_taq_mode);
419 if (
ctx->pa_ltr != -1) {
420 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_PA_LTR_ENABLE, ((
ctx->pa_ltr == 0) ?
false :
true));
422 if (
ctx->pa_lookahead_buffer_depth != -1) {
423 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_PA_LOOKAHEAD_BUFFER_DEPTH,
ctx->pa_lookahead_buffer_depth);
425 if (
ctx->pa_high_motion_quality_boost_mode != -1) {
426 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_PA_HIGH_MOTION_QUALITY_BOOST_MODE,
ctx->pa_high_motion_quality_boost_mode);
431 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_QUERY_TIMEOUT, 1);
432 res =
ctx->encoder->pVtbl->GetProperty(
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_QUERY_TIMEOUT, &var);
433 ctx->query_timeout_supported = res == AMF_OK && var.int64Value;
440 if (
ctx->max_au_size != -1) {
441 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_MAX_AU_SIZE,
ctx->max_au_size);
444 if (
ctx->min_qp_i != -1) {
445 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_MIN_QP_I,
ctx->min_qp_i);
446 }
else if (avctx->
qmin != -1) {
447 int qval = avctx->
qmin > 51 ? 51 : avctx->
qmin;
448 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_MIN_QP_I, qval);
450 if (
ctx->max_qp_i != -1) {
451 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_MAX_QP_I,
ctx->max_qp_i);
452 }
else if (avctx->
qmax != -1) {
453 int qval = avctx->
qmax > 51 ? 51 : avctx->
qmax;
454 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_MAX_QP_I, qval);
456 if (
ctx->min_qp_p != -1) {
457 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_MIN_QP_P,
ctx->min_qp_p);
458 }
else if (avctx->
qmin != -1) {
459 int qval = avctx->
qmin > 51 ? 51 : avctx->
qmin;
460 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_MIN_QP_P, qval);
462 if (
ctx->max_qp_p != -1) {
463 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_MAX_QP_P,
ctx->max_qp_p);
464 }
else if (avctx->
qmax != -1) {
465 int qval = avctx->
qmax > 51 ? 51 : avctx->
qmax;
466 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_MAX_QP_P, qval);
469 if (
ctx->qp_p != -1) {
470 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_QP_P,
ctx->qp_p);
472 if (
ctx->qp_i != -1) {
473 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_QP_I,
ctx->qp_i);
475 if (
ctx->skip_frame != -1) {
476 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_SKIP_FRAME_ENABLE, ((
ctx->skip_frame == 0) ?
false :
true));
480 res = AMFVariantInit(&var);
483 res =
ctx->encoder->pVtbl->GetProperty(
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_EXTRADATA, &var);
487 guid = IID_AMFBuffer();
489 res = var.pInterface->pVtbl->QueryInterface(var.pInterface, &guid, (
void**)&
buffer);
491 var.pInterface->pVtbl->Release(var.pInterface);
499 var.pInterface->pVtbl->Release(var.pInterface);
505 var.pInterface->pVtbl->Release(var.pInterface);
528 .
p.
name =
"hevc_amf",
544 .p.wrapper_name =
"amf",