Only do this when building for a recent VAAPI version - initial driver implementations were confused about the interpretation of the framerate field, but hopefully this will be consistent everywhere once 0.40.0 is released. (cherry picked from commit ff35aa8ca4069bf1543adeec4c28e51e4a012eee)
Unified · Split
| @@ -1116,6 +1116,7 @@ static av_cold int vaapi_encode_init_rate_control(AVCodecContext *avctx) · 1115 unmodified lines | ||
| 1116 | 1116 | int rc_window_size; |
| 1117 | 1117 | int hrd_buffer_size; |
| 1118 | 1118 | int hrd_initial_buffer_fullness; |
| 1119 | + int fr_num, fr_den; | |
| 1119 | 1120 | |
| 1120 | 1121 | if (avctx->bit_rate > INT32_MAX) { |
| 1121 | 1122 | av_log(avctx, AV_LOG_ERROR, "Target bitrate of 2^31 bps or " |
| @@ -1172,6 +1173,23 @@ static av_cold int vaapi_encode_init_rate_control(AVCodecContext *avctx) · 50 unmodified lines | ||
| 1172 | 1173 | ctx->global_params_size[ctx->nb_global_params++] = |
| 1173 | 1174 | sizeof(ctx->hrd_params); |
| 1174 | 1175 | |
| 1176 | + if (avctx->framerate.num > 0 && avctx->framerate.den > 0) | |
| 1177 | + av_reduce(&fr_num, &fr_den, | |
| 1178 | + avctx->framerate.num, avctx->framerate.den, 65535); | |
| 1179 | + else | |
| 1180 | + av_reduce(&fr_num, &fr_den, | |
| 1181 | + avctx->time_base.den, avctx->time_base.num, 65535); | |
| 1182 | + | |
| 1183 | + ctx->fr_params.misc.type = VAEncMiscParameterTypeFrameRate; | |
| 1184 | + ctx->fr_params.fr.framerate = (unsigned int)fr_den << 16 | fr_num; | |
| 1185 | + | |
| 1186 | +#if VA_CHECK_VERSION(0, 40, 0) | |
| 1187 | + ctx->global_params[ctx->nb_global_params] = | |
| 1188 | + &ctx->fr_params.misc; | |
| 1189 | + ctx->global_params_size[ctx->nb_global_params++] = | |
| 1190 | + sizeof(ctx->fr_params); | |
| 1191 | +#endif | |
| 1192 | + | |
| 1175 | 1193 | return 0; |
| 1176 | 1194 | } |
| 1177 | 1195 | |
| @@ -155,6 +155,10 @@ typedef struct VAAPIEncodeContext { · 154 unmodified lines | ||
| 155 | 155 | VAEncMiscParameterBuffer misc; |
| 156 | 156 | VAEncMiscParameterHRD hrd; |
| 157 | 157 | } hrd_params; |
| 158 | + struct { | |
| 159 | + VAEncMiscParameterBuffer misc; | |
| 160 | + VAEncMiscParameterFrameRate fr; | |
| 161 | + } fr_params; | |
| 158 | 162 | |
| 159 | 163 | // Per-sequence parameter structure (VAEncSequenceParameterBuffer*). |
| 160 | 164 | void *codec_sequence_params; |