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)
... | ... |
@@ -1116,6 +1116,7 @@ static av_cold int vaapi_encode_init_rate_control(AVCodecContext *avctx) |
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) |
1172 | 1172 |
ctx->global_params_size[ctx->nb_global_params++] = |
1173 | 1173 |
sizeof(ctx->hrd_params); |
1174 | 1174 |
|
1175 |
+ if (avctx->framerate.num > 0 && avctx->framerate.den > 0) |
|
1176 |
+ av_reduce(&fr_num, &fr_den, |
|
1177 |
+ avctx->framerate.num, avctx->framerate.den, 65535); |
|
1178 |
+ else |
|
1179 |
+ av_reduce(&fr_num, &fr_den, |
|
1180 |
+ avctx->time_base.den, avctx->time_base.num, 65535); |
|
1181 |
+ |
|
1182 |
+ ctx->fr_params.misc.type = VAEncMiscParameterTypeFrameRate; |
|
1183 |
+ ctx->fr_params.fr.framerate = (unsigned int)fr_den << 16 | fr_num; |
|
1184 |
+ |
|
1185 |
+#if VA_CHECK_VERSION(0, 40, 0) |
|
1186 |
+ ctx->global_params[ctx->nb_global_params] = |
|
1187 |
+ &ctx->fr_params.misc; |
|
1188 |
+ ctx->global_params_size[ctx->nb_global_params++] = |
|
1189 |
+ sizeof(ctx->fr_params); |
|
1190 |
+#endif |
|
1191 |
+ |
|
1175 | 1192 |
return 0; |
1176 | 1193 |
} |
1177 | 1194 |
|
... | ... |
@@ -155,6 +155,10 @@ typedef struct VAAPIEncodeContext { |
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; |