Use AVCodecContext.compression_level rather than a private option, replacing the H.264-specific quality option (which stays only for compatibility). This now works with the H.265 encoder in the i965 driver, as well as the existing cases with the H.264 encoder.tags/n4.0
@@ -948,7 +948,13 @@ The following standard libavcodec options are used: | |||||
@item | @item | ||||
@option{rc_init_occupancy} / @option{rc_initial_buffer_occupancy} | @option{rc_init_occupancy} / @option{rc_initial_buffer_occupancy} | ||||
@item | @item | ||||
@option{compression_level} | |||||
Speed / quality tradeoff: higher values are faster / worse quality. | |||||
@item | |||||
@option{q} / @option{global_quality} | @option{q} / @option{global_quality} | ||||
Size / quality tradeoff: higher values are smaller / worse quality. | |||||
@item | @item | ||||
@option{qmin} | @option{qmin} | ||||
(only: @option{qmax} is not supported) | (only: @option{qmax} is not supported) | ||||
@@ -969,9 +975,6 @@ The following standard libavcodec options are used: | |||||
@option{level} sets the value of @emph{level_idc}. | @option{level} sets the value of @emph{level_idc}. | ||||
@table @option | @table @option | ||||
@item quality | |||||
Set the local encoding quality/speed tradeoff (range 1-8, higher values are faster; not all | |||||
systems implement all levels). | |||||
@item low_power | @item low_power | ||||
Use low-power encoding mode. | Use low-power encoding mode. | ||||
@end table | @end table | ||||
@@ -1423,6 +1423,41 @@ av_cold int ff_vaapi_encode_init(AVCodecContext *avctx) | |||||
goto fail; | goto fail; | ||||
} | } | ||||
if (avctx->compression_level >= 0) { | |||||
#if VA_CHECK_VERSION(0, 36, 0) | |||||
VAConfigAttrib attr = { VAConfigAttribEncQualityRange }; | |||||
vas = vaGetConfigAttributes(ctx->hwctx->display, | |||||
ctx->va_profile, | |||||
ctx->va_entrypoint, | |||||
&attr, 1); | |||||
if (vas != VA_STATUS_SUCCESS) { | |||||
av_log(avctx, AV_LOG_WARNING, "Failed to query quality " | |||||
"attribute: will use default compression level.\n"); | |||||
} else { | |||||
if (avctx->compression_level > attr.value) { | |||||
av_log(avctx, AV_LOG_WARNING, "Invalid compression " | |||||
"level: valid range is 0-%d, using %d.\n", | |||||
attr.value, attr.value); | |||||
avctx->compression_level = attr.value; | |||||
} | |||||
ctx->quality_params.misc.type = | |||||
VAEncMiscParameterTypeQualityLevel; | |||||
ctx->quality_params.quality.quality_level = | |||||
avctx->compression_level; | |||||
ctx->global_params[ctx->nb_global_params] = | |||||
&ctx->quality_params.misc; | |||||
ctx->global_params_size[ctx->nb_global_params++] = | |||||
sizeof(ctx->quality_params); | |||||
} | |||||
#else | |||||
av_log(avctx, AV_LOG_WARNING, "The encode compression level " | |||||
"option is not supported with this VAAPI version.\n"); | |||||
#endif | |||||
} | |||||
ctx->input_order = 0; | ctx->input_order = 0; | ||||
ctx->output_delay = avctx->max_b_frames; | ctx->output_delay = avctx->max_b_frames; | ||||
ctx->decode_delay = 1; | ctx->decode_delay = 1; | ||||
@@ -159,6 +159,12 @@ typedef struct VAAPIEncodeContext { | |||||
VAEncMiscParameterBuffer misc; | VAEncMiscParameterBuffer misc; | ||||
VAEncMiscParameterFrameRate fr; | VAEncMiscParameterFrameRate fr; | ||||
} fr_params; | } fr_params; | ||||
#if VA_CHECK_VERSION(0, 36, 0) | |||||
struct { | |||||
VAEncMiscParameterBuffer misc; | |||||
VAEncMiscParameterBufferQualityLevel quality; | |||||
} quality_params; | |||||
#endif | |||||
// Per-sequence parameter structure (VAEncSequenceParameterBuffer*). | // Per-sequence parameter structure (VAEncSequenceParameterBuffer*). | ||||
void *codec_sequence_params; | void *codec_sequence_params; | ||||
@@ -154,14 +154,6 @@ typedef struct VAAPIEncodeH264Context { | |||||
// Rate control configuration. | // Rate control configuration. | ||||
int send_timing_sei; | int send_timing_sei; | ||||
#if VA_CHECK_VERSION(0, 36, 0) | |||||
// Speed-quality tradeoff setting. | |||||
struct { | |||||
VAEncMiscParameterBuffer misc; | |||||
VAEncMiscParameterBufferQualityLevel quality; | |||||
} quality_params; | |||||
#endif | |||||
} VAAPIEncodeH264Context; | } VAAPIEncodeH264Context; | ||||
typedef struct VAAPIEncodeH264Options { | typedef struct VAAPIEncodeH264Options { | ||||
@@ -1141,21 +1133,8 @@ static av_cold int vaapi_encode_h264_configure(AVCodecContext *avctx) | |||||
av_assert0(0 && "Invalid RC mode."); | av_assert0(0 && "Invalid RC mode."); | ||||
} | } | ||||
if (opt->quality > 0) { | |||||
#if VA_CHECK_VERSION(0, 36, 0) | |||||
priv->quality_params.misc.type = | |||||
VAEncMiscParameterTypeQualityLevel; | |||||
priv->quality_params.quality.quality_level = opt->quality; | |||||
ctx->global_params[ctx->nb_global_params] = | |||||
&priv->quality_params.misc; | |||||
ctx->global_params_size[ctx->nb_global_params++] = | |||||
sizeof(priv->quality_params); | |||||
#else | |||||
av_log(avctx, AV_LOG_WARNING, "The encode quality option is not " | |||||
"supported with this VAAPI version.\n"); | |||||
#endif | |||||
} | |||||
if (avctx->compression_level == FF_COMPRESSION_DEFAULT) | |||||
avctx->compression_level = opt->quality; | |||||
return 0; | return 0; | ||||
} | } | ||||