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 {
"async_depth",
"Set maximum encoding parallelism. Higher values increase output latency.",
OFFSET(hwsurfaces_in_queue_max),
AV_OPT_TYPE_INT, {.i64 = 16 }, 1, 16,
VE },
88 {
"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 },
89 {
"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 },
94 {
"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},
95 {
"min_qp_i",
"min quantization parameter for I-frame",
OFFSET(min_qp_i),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 51,
VE },
96 {
"max_qp_i",
"max quantization parameter for I-frame",
OFFSET(max_qp_i),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 51,
VE },
97 {
"min_qp_p",
"min quantization parameter for P-frame",
OFFSET(min_qp_p),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 51,
VE },
98 {
"max_qp_p",
"max quantization parameter for P-frame",
OFFSET(max_qp_p),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 51,
VE },
109 {
"log_to_dbg",
"Enable AMF logging to debug output",
OFFSET(log_to_dbg),
AV_OPT_TYPE_BOOL,{ .i64 = 0 }, 0, 1,
VE },
114 {
"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" },
115 {
"y",
"activity y", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_PA_ACTIVITY_Y }, 0, 0,
VE, .unit =
"activity_type" },
116 {
"yuv",
"activity yuv", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_PA_ACTIVITY_YUV }, 0, 0,
VE, .unit =
"activity_type" },
118 {
"pa_scene_change_detection_enable",
"Enable scene change detection",
OFFSET(pa_scene_change_detection),
AV_OPT_TYPE_BOOL, {.i64 = -1 }, -1, 1,
VE },
120 {
"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" },
121 {
"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" },
122 {
"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" },
123 {
"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" },
125 {
"pa_static_scene_detection_enable",
"Enable static scene detection",
OFFSET(pa_static_scene_detection),
AV_OPT_TYPE_BOOL, {.i64 = -1 }, -1, 1,
VE },
127 {
"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" },
128 {
"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" },
129 {
"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" },
130 {
"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" },
132 {
"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 },
133 {
"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 },
135 {
"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" },
136 {
"low",
"low Content Adaptive Quantization strength", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_PA_CAQ_STRENGTH_LOW }, 0, 0,
VE, .unit =
"caq_strength" },
137 {
"medium",
"medium Content Adaptive Quantization strength", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_PA_CAQ_STRENGTH_MEDIUM }, 0, 0,
VE, .unit =
"caq_strength" },
138 {
"high",
"high Content Adaptive Quantization strength", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_PA_CAQ_STRENGTH_HIGH }, 0, 0,
VE, .unit =
"caq_strength" },
140 {
"pa_frame_sad_enable",
"Enable Frame SAD algorithm",
OFFSET(pa_frame_sad),
AV_OPT_TYPE_BOOL, {.i64 = -1 }, -1, 1,
VE },
141 {
"pa_ltr_enable",
"Enable long term reference frame management",
OFFSET(pa_ltr),
AV_OPT_TYPE_BOOL, {.i64 = -1 }, -1, 1,
VE },
144 {
"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" },
145 {
"none",
"no perceptual adaptive quantization", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_PA_PAQ_MODE_NONE }, 0, 0,
VE, .unit =
"paq_mode" },
146 {
"caq",
"caq perceptual adaptive quantization", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_PA_PAQ_MODE_CAQ }, 0, 0,
VE, .unit =
"paq_mode" },
148 {
"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" },
149 {
"none",
"no temporal adaptive quantization", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_PA_TAQ_MODE_NONE }, 0, 0,
VE, .unit =
"taq_mode" },
150 {
"1",
"temporal adaptive quantization mode 1", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_PA_TAQ_MODE_1 }, 0, 0,
VE, .unit =
"taq_mode" },
151 {
"2",
"temporal adaptive quantization mode 2", 0,
AV_OPT_TYPE_CONST, {.i64 = AMF_PA_TAQ_MODE_2 }, 0, 0,
VE, .unit =
"taq_mode" },
153 {
"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" },
154 {
"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" },
155 {
"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" },
162 AMF_RESULT res = AMF_OK;
164 AMFVariantStruct var = {0};
166 amf_int64 profile_level = 0;
170 AMFSize framesize = AMFConstructSize(avctx->
width, avctx->
height);
172 amf_int64 color_depth;
173 amf_int64 color_profile;
192 if (
ctx->usage != -1) {
193 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_USAGE,
ctx->usage);
196 AMF_ASSIGN_PROPERTY_SIZE(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_FRAMESIZE, framesize);
198 AMF_ASSIGN_PROPERTY_RATE(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_FRAMERATE,
framerate);
202 profile = AMF_VIDEO_ENCODER_HEVC_PROFILE_MAIN;
205 profile = AMF_VIDEO_ENCODER_HEVC_PROFILE_MAIN_10;
211 if (
ctx->profile != -1) {
217 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_PROFILE,
profile);
220 if (
ctx->tier != -1) {
221 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_TIER,
ctx->tier);
224 profile_level = avctx->
level;
226 profile_level =
ctx->level;
229 if (profile_level != 0) {
230 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_PROFILE_LEVEL, profile_level);
233 if (
ctx->quality != -1) {
234 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_QUALITY_PRESET,
ctx->quality);
238 if (avctx->
refs != -1) {
239 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_MAX_NUM_REFRAMES, avctx->
refs);
244 AMF_ASSIGN_PROPERTY_RATIO(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_ASPECT_RATIO, ratio);
248 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_OUTPUT_COLOR_PROFILE, color_profile);
252 color_depth = AMF_COLOR_BIT_DEPTH_8;
256 color_depth = AMF_COLOR_BIT_DEPTH_10;
258 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_COLOR_BIT_DEPTH, color_depth);
260 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_OUTPUT_TRANSFER_CHARACTERISTIC, avctx->
color_trc);
262 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_OUTPUT_COLOR_PRIMARIES, avctx->
color_primaries);
265 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_NUM_GOPS_PER_IDR,
ctx->gops_per_idr);
267 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_GOP_SIZE, avctx->
gop_size);
270 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_SLICES_PER_FRAME, avctx->
slices);
272 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_DE_BLOCKING_FILTER_DISABLE, !deblocking_filter);
274 if (
ctx->header_insertion_mode != -1) {
275 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_HEADER_INSERTION_MODE,
ctx->header_insertion_mode);
280 if (
ctx->rate_control_mode == AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_UNKNOWN) {
281 if (
ctx->min_qp_i != -1 ||
ctx->max_qp_i != -1 ||
282 ctx->min_qp_p != -1 ||
ctx->max_qp_p != -1 ||
283 ctx->qp_i !=-1 ||
ctx->qp_p != -1) {
284 ctx->rate_control_mode = AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_CONSTANT_QP;
287 ctx->rate_control_mode = AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_CBR;
290 ctx->rate_control_mode = AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_PEAK_CONSTRAINED_VBR;
296 if (
ctx->rate_control_mode == AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_CONSTANT_QP) {
297 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_PREENCODE_ENABLE, 0);
298 if (
ctx->preencode != -1) {
299 if (
ctx->preencode) {
300 av_log(
ctx,
AV_LOG_WARNING,
"Preencode is not supported by cqp Rate Control Method, automatically disabled\n");
305 if (
ctx->preencode != -1) {
306 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_PREENCODE_ENABLE,
ctx->preencode);
310 if (
ctx->rate_control_mode == AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_QUALITY_VBR) {
311 if (
ctx->qvbr_quality_level != -1) {
312 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_QVBR_QUALITY_LEVEL,
ctx->qvbr_quality_level);
316 if (
ctx->hw_high_motion_quality_boost != -1) {
317 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));
320 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD,
ctx->rate_control_mode);
323 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_VBV_BUFFER_SIZE, avctx->
rc_buffer_size);
327 if (amf_buffer_fullness > 64)
328 amf_buffer_fullness = 64;
329 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_INITIAL_VBV_BUFFER_FULLNESS, amf_buffer_fullness);
333 if (
ctx->rate_control_mode == AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_CONSTANT_QP) {
334 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_ENABLE_VBAQ,
false);
335 if (
ctx->enable_vbaq)
338 if (
ctx->enable_vbaq != -1) {
339 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_ENABLE_VBAQ, !!
ctx->enable_vbaq);
343 if (
ctx->me_half_pel != -1) {
344 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_MOTION_HALF_PIXEL,
ctx->me_half_pel);
346 if (
ctx->me_quarter_pel != -1) {
347 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_MOTION_QUARTERPIXEL,
ctx->me_quarter_pel);
351 if (
ctx->enforce_hrd != -1) {
352 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_ENFORCE_HRD, ((
ctx->enforce_hrd == 0) ?
false :
true));
355 if (
ctx->filler_data != -1) {
356 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_FILLER_DATA_ENABLE, ((
ctx->filler_data == 0) ?
false :
true));
360 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_TARGET_BITRATE, avctx->
bit_rate);
363 if (
ctx->rate_control_mode == AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_CBR) {
365 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_PEAK_BITRATE, avctx->
bit_rate);
370 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_PEAK_BITRATE, avctx->
rc_max_rate);
371 }
else if (
ctx->rate_control_mode == AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_PEAK_CONSTRAINED_VBR) {
375 if (
ctx->latency != -1) {
376 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_LOWLATENCY_MODE, ((
ctx->latency == 0) ?
false :
true));
379 if (
ctx->preanalysis != -1) {
380 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_PRE_ANALYSIS_ENABLE, !!((
ctx->preanalysis == 0) ?
false :
true));
383 res =
ctx->encoder->pVtbl->GetProperty(
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_PRE_ANALYSIS_ENABLE, &var);
384 if ((
int)var.int64Value)
386 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_PRE_ANALYSIS_ENABLE,
true);
388 if (
ctx->pa_activity_type != -1) {
389 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_PA_ACTIVITY_TYPE,
ctx->pa_activity_type);
391 if (
ctx->pa_scene_change_detection != -1) {
392 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_PA_SCENE_CHANGE_DETECTION_ENABLE, ((
ctx->pa_scene_change_detection == 0) ?
false :
true));
394 if (
ctx->pa_scene_change_detection_sensitivity != -1) {
395 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_PA_SCENE_CHANGE_DETECTION_SENSITIVITY,
ctx->pa_scene_change_detection_sensitivity);
397 if (
ctx->pa_static_scene_detection != -1) {
398 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_PA_STATIC_SCENE_DETECTION_ENABLE, ((
ctx->pa_static_scene_detection == 0) ?
false :
true));
400 if (
ctx->pa_static_scene_detection_sensitivity != -1) {
401 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_PA_STATIC_SCENE_DETECTION_SENSITIVITY,
ctx->pa_static_scene_detection_sensitivity);
403 if (
ctx->pa_initial_qp != -1) {
404 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_PA_INITIAL_QP_AFTER_SCENE_CHANGE,
ctx->pa_initial_qp);
406 if (
ctx->pa_max_qp != -1) {
407 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_PA_MAX_QP_BEFORE_FORCE_SKIP,
ctx->pa_max_qp);
409 if (
ctx->pa_caq_strength != -1) {
410 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_PA_CAQ_STRENGTH,
ctx->pa_caq_strength);
412 if (
ctx->pa_frame_sad != -1) {
413 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_PA_FRAME_SAD_ENABLE, ((
ctx->pa_frame_sad == 0) ?
false :
true));
415 if (
ctx->pa_paq_mode != -1) {
416 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_PA_PAQ_MODE,
ctx->pa_paq_mode);
418 if (
ctx->pa_taq_mode != -1) {
419 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_PA_TAQ_MODE,
ctx->pa_taq_mode);
421 if (
ctx->pa_ltr != -1) {
422 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_PA_LTR_ENABLE, ((
ctx->pa_ltr == 0) ?
false :
true));
424 if (
ctx->pa_lookahead_buffer_depth != -1) {
425 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_PA_LOOKAHEAD_BUFFER_DEPTH,
ctx->pa_lookahead_buffer_depth);
427 if (
ctx->pa_high_motion_quality_boost_mode != -1) {
428 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_PA_HIGH_MOTION_QUALITY_BOOST_MODE,
ctx->pa_high_motion_quality_boost_mode);
433 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_QUERY_TIMEOUT, 1);
434 res =
ctx->encoder->pVtbl->GetProperty(
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_QUERY_TIMEOUT, &var);
435 ctx->query_timeout_supported = res == AMF_OK && var.int64Value;
442 if (
ctx->max_au_size != -1) {
443 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_MAX_AU_SIZE,
ctx->max_au_size);
446 if (
ctx->min_qp_i != -1) {
447 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_MIN_QP_I,
ctx->min_qp_i);
448 }
else if (avctx->
qmin != -1) {
449 int qval = avctx->
qmin > 51 ? 51 : avctx->
qmin;
450 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_MIN_QP_I, qval);
452 if (
ctx->max_qp_i != -1) {
453 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_MAX_QP_I,
ctx->max_qp_i);
454 }
else if (avctx->
qmax != -1) {
455 int qval = avctx->
qmax > 51 ? 51 : avctx->
qmax;
456 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_MAX_QP_I, qval);
458 if (
ctx->min_qp_p != -1) {
459 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_MIN_QP_P,
ctx->min_qp_p);
460 }
else if (avctx->
qmin != -1) {
461 int qval = avctx->
qmin > 51 ? 51 : avctx->
qmin;
462 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_MIN_QP_P, qval);
464 if (
ctx->max_qp_p != -1) {
465 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_MAX_QP_P,
ctx->max_qp_p);
466 }
else if (avctx->
qmax != -1) {
467 int qval = avctx->
qmax > 51 ? 51 : avctx->
qmax;
468 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_MAX_QP_P, qval);
471 if (
ctx->qp_p != -1) {
472 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_QP_P,
ctx->qp_p);
474 if (
ctx->qp_i != -1) {
475 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_QP_I,
ctx->qp_i);
477 if (
ctx->skip_frame != -1) {
478 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_SKIP_FRAME_ENABLE, ((
ctx->skip_frame == 0) ?
false :
true));
482 res = AMFVariantInit(&var);
485 res =
ctx->encoder->pVtbl->GetProperty(
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_EXTRADATA, &var);
489 guid = IID_AMFBuffer();
491 res = var.pInterface->pVtbl->QueryInterface(var.pInterface, &guid, (
void**)&
buffer);
493 var.pInterface->pVtbl->Release(var.pInterface);
501 var.pInterface->pVtbl->Release(var.pInterface);
507 var.pInterface->pVtbl->Release(var.pInterface);
530 .
p.
name =
"hevc_amf",
546 .p.wrapper_name =
"amf",