diff mbox series

[FFmpeg-devel] avcodec/nvenc: Update the encoder to use the framerate (if available) in the codec context

Message ID 20200514181533.2010-1-zachariah@renewedvision.com
State Accepted
Commit b18fd2b95b2fea10f0b5381333a1b4c032f010bc
Headers show
Series [FFmpeg-devel] avcodec/nvenc: Update the encoder to use the framerate (if available) in the codec context | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Zachariah Brown May 14, 2020, 6:15 p.m. UTC
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 <zachariah@renewedvision.com>
---
 libavcodec/nvenc.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Derek Buitenhuis May 14, 2020, 7:27 p.m. UTC | #1
On 14/05/2020 19:15, Zachariah Brown wrote:
> 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 <zachariah@renewedvision.com>
> ---
>  libavcodec/nvenc.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)

Every other encoder does this, so looks OK.

- Derek
Timo Rothenpieler May 14, 2020, 10:53 p.m. UTC | #2
applied, thanks
diff mbox series

Patch

diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index 068d469ae6..cbdddd33f9 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -1209,8 +1209,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;