[FFmpeg-cvslog] vaapi_encode: Pass framerate parameters to driver

Mark Thompson git at videolan.org
Wed Feb 8 23:01:16 EET 2017


ffmpeg | branch: master | Mark Thompson <sw at jkqxz.net> | Tue Nov 29 22:12:46 2016 +0000| [be6546a4ff592785d039df6cbdd7659781d30b2c] | committer: Mark Thompson

vaapi_encode: Pass framerate parameters to driver

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)

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=be6546a4ff592785d039df6cbdd7659781d30b2c
---

 libavcodec/vaapi_encode.c | 18 ++++++++++++++++++
 libavcodec/vaapi_encode.h |  4 ++++
 2 files changed, 22 insertions(+)

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index e491b3c..070ff5f 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -1116,6 +1116,7 @@ static av_cold int vaapi_encode_init_rate_control(AVCodecContext *avctx)
     int rc_window_size;
     int hrd_buffer_size;
     int hrd_initial_buffer_fullness;
+    int fr_num, fr_den;
 
     if (avctx->bit_rate > INT32_MAX) {
         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)
     ctx->global_params_size[ctx->nb_global_params++] =
         sizeof(ctx->hrd_params);
 
+    if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
+        av_reduce(&fr_num, &fr_den,
+                  avctx->framerate.num, avctx->framerate.den, 65535);
+    else
+        av_reduce(&fr_num, &fr_den,
+                  avctx->time_base.den, avctx->time_base.num, 65535);
+
+    ctx->fr_params.misc.type = VAEncMiscParameterTypeFrameRate;
+    ctx->fr_params.fr.framerate = (unsigned int)fr_den << 16 | fr_num;
+
+#if VA_CHECK_VERSION(0, 40, 0)
+    ctx->global_params[ctx->nb_global_params] =
+        &ctx->fr_params.misc;
+    ctx->global_params_size[ctx->nb_global_params++] =
+        sizeof(ctx->fr_params);
+#endif
+
     return 0;
 }
 
diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h
index 2c1b7cf..0edf27e 100644
--- a/libavcodec/vaapi_encode.h
+++ b/libavcodec/vaapi_encode.h
@@ -155,6 +155,10 @@ typedef struct VAAPIEncodeContext {
         VAEncMiscParameterBuffer misc;
         VAEncMiscParameterHRD hrd;
     } hrd_params;
+    struct {
+        VAEncMiscParameterBuffer misc;
+        VAEncMiscParameterFrameRate fr;
+    } fr_params;
 
     // Per-sequence parameter structure (VAEncSequenceParameterBuffer*).
     void           *codec_sequence_params;



More information about the ffmpeg-cvslog mailing list