Skip to content

Commit 0791102

Browse files
lucenticusOvchinnikovDmitrii
authored andcommitted
avcodec/amfenc: add smart access video option
This commit adds option for enabling SmartAccess Video (SAV) in AMF encoders. SAV is an AMD hardware-specific feature which enables the parallelization of encode and decode streams across multiple Video Codec Engine (VCN) hardware instances.
1 parent 5b460bd commit 0791102

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

libavcodec/amfenc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ typedef struct AMFEncoderContext {
7272
int b_frame_delta_qp;
7373
int ref_b_frame_delta_qp;
7474
int bit_depth;
75+
int smart_access_video;
7576

7677
// Dynamic options, can be set after Init() call
7778

libavcodec/amfenc_av1.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ static const AVOption options[] = {
133133
{ "1080p", "", 0, AV_OPT_TYPE_CONST, {.i64 = AMF_VIDEO_ENCODER_AV1_ALIGNMENT_MODE_64X16_1080P_CODED_1082 }, 0, 0, VE, .unit = "align" },
134134
{ "none", "", 0, AV_OPT_TYPE_CONST, {.i64 = AMF_VIDEO_ENCODER_AV1_ALIGNMENT_MODE_NO_RESTRICTIONS }, 0, 0, VE, .unit = "align" },
135135

136+
{ "smart_access_video", "Enable Smart Access Video to enhance performance by utilizing both APU and dGPU memory access", OFFSET(smart_access_video), AV_OPT_TYPE_BOOL, {.i64 = -1 }, -1, 1, VE},
137+
136138
//Pre Analysis options
137139
{ "preanalysis", "Enable preanalysis", OFFSET(preanalysis), AV_OPT_TYPE_BOOL, {.i64 = -1 }, -1, 1, VE },
138140

@@ -326,6 +328,21 @@ FF_ENABLE_DEPRECATION_WARNINGS
326328
av_log(ctx, AV_LOG_DEBUG, "Rate control turned to Peak VBR\n");
327329
}
328330
}
331+
if (ctx->smart_access_video != -1) {
332+
AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, AMF_VIDEO_ENCODER_AV1_ENABLE_SMART_ACCESS_VIDEO, ctx->smart_access_video != 0);
333+
if (res != AMF_OK) {
334+
av_log(avctx, AV_LOG_ERROR, "The Smart Access Video is not supported by AMF.\n");
335+
if (ctx->smart_access_video != 0)
336+
return AVERROR(ENOSYS);
337+
} else {
338+
av_log(avctx, AV_LOG_INFO, "The Smart Access Video (%d) is set.\n", ctx->smart_access_video);
339+
// Set low latency mode if Smart Access Video is enabled
340+
if (ctx->smart_access_video != 0) {
341+
AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, AMF_VIDEO_ENCODER_AV1_ENCODING_LATENCY_MODE, AMF_VIDEO_ENCODER_AV1_ENCODING_LATENCY_MODE_LOWEST_LATENCY);
342+
av_log(avctx, AV_LOG_INFO, "The Smart Access Video set low latency mode.\n");
343+
}
344+
}
345+
}
329346

330347
// Pre-Pass, Pre-Analysis, Two-Pass
331348
if (ctx->rate_control_mode == AMF_VIDEO_ENCODER_AV1_RATE_CONTROL_METHOD_CONSTANT_QP) {

libavcodec/amfenc_h264.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ static const AVOption options[] = {
139139
{ "forced_idr", "Force I frames to be IDR frames", OFFSET(forced_idr) , AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
140140
{ "aud", "Inserts AU Delimiter NAL unit", OFFSET(aud) , AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE },
141141

142+
{ "smart_access_video", "Enable Smart Access Video to enhance performance by utilizing both APU and dGPU memory access", OFFSET(smart_access_video), AV_OPT_TYPE_BOOL, {.i64 = -1 }, -1, 1, VE},
143+
142144
//Pre Analysis options
143145
{ "preanalysis", "Enable preanalysis", OFFSET(preanalysis), AV_OPT_TYPE_BOOL, {.i64 = -1 }, -1, 1, VE },
144146

@@ -399,6 +401,22 @@ FF_ENABLE_DEPRECATION_WARNINGS
399401
AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, AMF_VIDEO_ENCODER_LOWLATENCY_MODE, ((ctx->latency == 0) ? false : true));
400402
}
401403

404+
if (ctx->smart_access_video != -1) {
405+
AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, AMF_VIDEO_ENCODER_ENABLE_SMART_ACCESS_VIDEO, ctx->smart_access_video != 0);
406+
if (res != AMF_OK) {
407+
av_log(avctx, AV_LOG_ERROR, "The Smart Access Video is not supported by AMF.\n");
408+
if (ctx->smart_access_video != 0)
409+
return AVERROR(ENOSYS);
410+
} else {
411+
av_log(avctx, AV_LOG_INFO, "The Smart Access Video (%d) is set.\n", ctx->smart_access_video);
412+
// Set low latency mode if Smart Access Video is enabled
413+
if (ctx->smart_access_video != 0) {
414+
AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, AMF_VIDEO_ENCODER_LOWLATENCY_MODE, true);
415+
av_log(avctx, AV_LOG_INFO, "The Smart Access Video set low latency mode.\n");
416+
}
417+
}
418+
}
419+
402420
if (ctx->preanalysis != -1) {
403421
AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, AMF_VIDEO_ENCODER_PRE_ANALYSIS_ENABLE, !!((ctx->preanalysis == 0) ? false : true));
404422
}

libavcodec/amfenc_hevc.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ static const AVOption options[] = {
109109
{ "forced_idr", "Force I frames to be IDR frames", OFFSET(forced_idr) ,AV_OPT_TYPE_BOOL,{ .i64 = 0 }, 0, 1, VE },
110110
{ "aud", "Inserts AU Delimiter NAL unit", OFFSET(aud) ,AV_OPT_TYPE_BOOL,{ .i64 = -1 }, -1, 1, VE },
111111

112+
{ "smart_access_video", "Enable Smart Access Video to enhance performance by utilizing both APU and dGPU memory access", OFFSET(smart_access_video), AV_OPT_TYPE_BOOL, {.i64 = -1 }, -1, 1, VE},
113+
112114
//Pre Analysis options
113115
{ "preanalysis", "Enable preanalysis", OFFSET(preanalysis), AV_OPT_TYPE_BOOL, {.i64 = -1 }, -1, 1, VE },
114116

@@ -309,6 +311,22 @@ FF_ENABLE_DEPRECATION_WARNINGS
309311
}
310312
}
311313

314+
if (ctx->smart_access_video != -1) {
315+
AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, AMF_VIDEO_ENCODER_HEVC_ENABLE_SMART_ACCESS_VIDEO, ctx->smart_access_video != 0);
316+
if (res != AMF_OK) {
317+
av_log(avctx, AV_LOG_ERROR, "The Smart Access Video is not supported by AMF.\n");
318+
if (ctx->smart_access_video != 0)
319+
return AVERROR(ENOSYS);
320+
} else {
321+
av_log(avctx, AV_LOG_INFO, "The Smart Access Video (%d) is set.\n", ctx->smart_access_video);
322+
// Set low latency mode if Smart Access Video is enabled
323+
if (ctx->smart_access_video != 0) {
324+
AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, AMF_VIDEO_ENCODER_HEVC_LOWLATENCY_MODE, true);
325+
av_log(avctx, AV_LOG_INFO, "The Smart Access Video set low latency mode.\n");
326+
}
327+
}
328+
}
329+
312330
// Pre-Pass, Pre-Analysis, Two-Pass
313331
if (ctx->rate_control_mode == AMF_VIDEO_ENCODER_HEVC_RATE_CONTROL_METHOD_CONSTANT_QP) {
314332
AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_HEVC_PREENCODE_ENABLE, 0);

0 commit comments

Comments
 (0)