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);
257 if (color_depth == AMF_COLOR_BIT_DEPTH_8) {
259 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_OUTPUT_TRANSFER_CHARACTERISTIC, AMF_COLOR_TRANSFER_CHARACTERISTIC_BT709);
261 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_OUTPUT_COLOR_PRIMARIES, AMF_COLOR_PRIMARIES_BT709);
263 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_OUTPUT_TRANSFER_CHARACTERISTIC, AMF_COLOR_TRANSFER_CHARACTERISTIC_SMPTE2084);
264 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_OUTPUT_COLOR_PRIMARIES, AMF_COLOR_PRIMARIES_BT2020);
268 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_NUM_GOPS_PER_IDR,
ctx->gops_per_idr);
269 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_GOP_SIZE, avctx->
gop_size);
271 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_SLICES_PER_FRAME, avctx->
slices);
273 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_DE_BLOCKING_FILTER_DISABLE, !deblocking_filter);
275 if (
ctx->header_insertion_mode != -1) {
276 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_HEADER_INSERTION_MODE,
ctx->header_insertion_mode);
281 if (
ctx->rate_control_mode == AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_UNKNOWN) {
282 if (
ctx->min_qp_i != -1 ||
ctx->max_qp_i != -1 ||
283 ctx->min_qp_p != -1 ||
ctx->max_qp_p != -1 ||
284 ctx->qp_i !=-1 ||
ctx->qp_p != -1) {
285 ctx->rate_control_mode = AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_CONSTANT_QP;
288 ctx->rate_control_mode = AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_CBR;
291 ctx->rate_control_mode = AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_PEAK_CONSTRAINED_VBR;
297 if (
ctx->rate_control_mode == AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_CONSTANT_QP) {
298 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_PREENCODE_ENABLE, 0);
299 if (
ctx->preencode != -1) {
300 if (
ctx->preencode) {
301 av_log(
ctx,
AV_LOG_WARNING,
"Preencode is not supported by cqp Rate Control Method, automatically disabled\n");
306 if (
ctx->preencode != -1) {
307 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_PREENCODE_ENABLE,
ctx->preencode);
311 if (
ctx->rate_control_mode == AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_QUALITY_VBR) {
312 if (
ctx->qvbr_quality_level != -1) {
313 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_QVBR_QUALITY_LEVEL,
ctx->qvbr_quality_level);
317 if (
ctx->hw_high_motion_quality_boost != -1) {
318 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));
321 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD,
ctx->rate_control_mode);
324 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_VBV_BUFFER_SIZE, avctx->
rc_buffer_size);
328 if (amf_buffer_fullness > 64)
329 amf_buffer_fullness = 64;
330 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_INITIAL_VBV_BUFFER_FULLNESS, amf_buffer_fullness);
334 if (
ctx->rate_control_mode == AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_CONSTANT_QP) {
335 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_ENABLE_VBAQ,
false);
336 if (
ctx->enable_vbaq)
339 if (
ctx->enable_vbaq != -1) {
340 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_ENABLE_VBAQ, !!
ctx->enable_vbaq);
344 if (
ctx->me_half_pel != -1) {
345 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_MOTION_HALF_PIXEL,
ctx->me_half_pel);
347 if (
ctx->me_quarter_pel != -1) {
348 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_MOTION_QUARTERPIXEL,
ctx->me_quarter_pel);
352 if (
ctx->enforce_hrd != -1) {
353 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_ENFORCE_HRD, ((
ctx->enforce_hrd == 0) ?
false :
true));
356 if (
ctx->filler_data != -1) {
357 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_FILLER_DATA_ENABLE, ((
ctx->filler_data == 0) ?
false :
true));
361 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_TARGET_BITRATE, avctx->
bit_rate);
364 if (
ctx->rate_control_mode == AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_CBR) {
366 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_PEAK_BITRATE, avctx->
bit_rate);
371 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_PEAK_BITRATE, avctx->
rc_max_rate);
372 }
else if (
ctx->rate_control_mode == AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_PEAK_CONSTRAINED_VBR) {
376 if (
ctx->latency != -1) {
377 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_LOWLATENCY_MODE, ((
ctx->latency == 0) ?
false :
true));
380 if (
ctx->preanalysis != -1) {
381 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_PRE_ANALYSIS_ENABLE, !!((
ctx->preanalysis == 0) ?
false :
true));
384 res =
ctx->encoder->pVtbl->GetProperty(
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_PRE_ANALYSIS_ENABLE, &var);
385 if ((
int)var.int64Value)
387 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_PRE_ANALYSIS_ENABLE,
true);
389 if (
ctx->pa_activity_type != -1) {
390 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_PA_ACTIVITY_TYPE,
ctx->pa_activity_type);
392 if (
ctx->pa_scene_change_detection != -1) {
393 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_PA_SCENE_CHANGE_DETECTION_ENABLE, ((
ctx->pa_scene_change_detection == 0) ?
false :
true));
395 if (
ctx->pa_scene_change_detection_sensitivity != -1) {
396 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_PA_SCENE_CHANGE_DETECTION_SENSITIVITY,
ctx->pa_scene_change_detection_sensitivity);
398 if (
ctx->pa_static_scene_detection != -1) {
399 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_PA_STATIC_SCENE_DETECTION_ENABLE, ((
ctx->pa_static_scene_detection == 0) ?
false :
true));
401 if (
ctx->pa_static_scene_detection_sensitivity != -1) {
402 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_PA_STATIC_SCENE_DETECTION_SENSITIVITY,
ctx->pa_static_scene_detection_sensitivity);
404 if (
ctx->pa_initial_qp != -1) {
405 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_PA_INITIAL_QP_AFTER_SCENE_CHANGE,
ctx->pa_initial_qp);
407 if (
ctx->pa_max_qp != -1) {
408 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_PA_MAX_QP_BEFORE_FORCE_SKIP,
ctx->pa_max_qp);
410 if (
ctx->pa_caq_strength != -1) {
411 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_PA_CAQ_STRENGTH,
ctx->pa_caq_strength);
413 if (
ctx->pa_frame_sad != -1) {
414 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_PA_FRAME_SAD_ENABLE, ((
ctx->pa_frame_sad == 0) ?
false :
true));
416 if (
ctx->pa_paq_mode != -1) {
417 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_PA_PAQ_MODE,
ctx->pa_paq_mode);
419 if (
ctx->pa_taq_mode != -1) {
420 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_PA_TAQ_MODE,
ctx->pa_taq_mode);
422 if (
ctx->pa_ltr != -1) {
423 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_PA_LTR_ENABLE, ((
ctx->pa_ltr == 0) ?
false :
true));
425 if (
ctx->pa_lookahead_buffer_depth != -1) {
426 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_PA_LOOKAHEAD_BUFFER_DEPTH,
ctx->pa_lookahead_buffer_depth);
428 if (
ctx->pa_high_motion_quality_boost_mode != -1) {
429 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_PA_HIGH_MOTION_QUALITY_BOOST_MODE,
ctx->pa_high_motion_quality_boost_mode);
438 if (
ctx->max_au_size != -1) {
439 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_MAX_AU_SIZE,
ctx->max_au_size);
442 if (
ctx->min_qp_i != -1) {
443 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_MIN_QP_I,
ctx->min_qp_i);
444 }
else if (avctx->
qmin != -1) {
445 int qval = avctx->
qmin > 51 ? 51 : avctx->
qmin;
446 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_MIN_QP_I, qval);
448 if (
ctx->max_qp_i != -1) {
449 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_MAX_QP_I,
ctx->max_qp_i);
450 }
else if (avctx->
qmax != -1) {
451 int qval = avctx->
qmax > 51 ? 51 : avctx->
qmax;
452 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_MAX_QP_I, qval);
454 if (
ctx->min_qp_p != -1) {
455 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_MIN_QP_P,
ctx->min_qp_p);
456 }
else if (avctx->
qmin != -1) {
457 int qval = avctx->
qmin > 51 ? 51 : avctx->
qmin;
458 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_MIN_QP_P, qval);
460 if (
ctx->max_qp_p != -1) {
461 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_MAX_QP_P,
ctx->max_qp_p);
462 }
else if (avctx->
qmax != -1) {
463 int qval = avctx->
qmax > 51 ? 51 : avctx->
qmax;
464 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_MAX_QP_P, qval);
467 if (
ctx->qp_p != -1) {
468 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_QP_P,
ctx->qp_p);
470 if (
ctx->qp_i != -1) {
471 AMF_ASSIGN_PROPERTY_INT64(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_QP_I,
ctx->qp_i);
473 if (
ctx->skip_frame != -1) {
474 AMF_ASSIGN_PROPERTY_BOOL(res,
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_SKIP_FRAME_ENABLE, ((
ctx->skip_frame == 0) ?
false :
true));
478 res = AMFVariantInit(&var);
481 res =
ctx->encoder->pVtbl->GetProperty(
ctx->encoder, AMF_VIDEO_ENCODER_HEVC_EXTRADATA, &var);
485 guid = IID_AMFBuffer();
487 res = var.pInterface->pVtbl->QueryInterface(var.pInterface, &guid, (
void**)&
buffer);
489 var.pInterface->pVtbl->Release(var.pInterface);
497 var.pInterface->pVtbl->Release(var.pInterface);
503 var.pInterface->pVtbl->Release(var.pInterface);
526 .
p.
name =
"hevc_amf",
542 .p.wrapper_name =
"amf",