ffmpeg | branch: release/4.2 | Zachariah Brown <[email protected]> | 
Thu May 14 14:15:33 2020 -0400| [393eff8917b0fe1e26667cc4599aeb16ace5728c] | 
committer: Timo Rothenpieler

avcodec/nvenc: use framerate if available

The h264_nvenc and hevc_nvenc encoders aren't respecting the framerate in the 
codec context.
Instead it was using the timebase which in our use-case was 1/1000 so the 
encoder was behaving
as if we wanted 1000fps. This resulted in poor encoding results due to an 
extremely low bitrate.

Both the amf and qsv encoders already contain similar logic to first check the 
framerate before
falling back to the timebase.

Signed-off-by: Zachariah Brown <[email protected]>
Signed-off-by: Timo Rothenpieler <[email protected]>

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

 libavcodec/nvenc.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index 38095e7fa1..5fa44b1819 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -1164,8 +1164,13 @@ static av_cold int nvenc_setup_encoder(AVCodecContext 
*avctx)
     ctx->init_encode_params.darHeight = dh;
     ctx->init_encode_params.darWidth = dw;
 
-    ctx->init_encode_params.frameRateNum = avctx->time_base.den;
-    ctx->init_encode_params.frameRateDen = avctx->time_base.num * 
avctx->ticks_per_frame;
+    if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
+        ctx->init_encode_params.frameRateNum = avctx->framerate.num;
+        ctx->init_encode_params.frameRateDen = avctx->framerate.den;
+    } else {
+        ctx->init_encode_params.frameRateNum = avctx->time_base.den;
+        ctx->init_encode_params.frameRateDen = avctx->time_base.num * 
avctx->ticks_per_frame;
+    }
 
     ctx->init_encode_params.enableEncodeAsync = 0;
     ctx->init_encode_params.enablePTD = 1;

_______________________________________________
ffmpeg-cvslog mailing list
[email protected]
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
[email protected] with subject "unsubscribe".

Reply via email to