When B frames >= 1, there'll be a invalid dts/pts warning during encoding like:

[mp4 @ 000000000034cba0] Invalid DTS: 1024 PTS: 512 in output stream 0:0, replacing by guess [mp4 @ 000000000034cba0] Invalid DTS: 1536 PTS: 1024 in output stream 0:0, replacing by guess
Set a -1 offset to dts to prevent dts>pts case.

From: agathah <a...@nvidia.com>
---
 libavcodec/nvenc.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index 345fb78..19a3ec8 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -657,9 +657,14 @@ static av_cold int nvenc_encode_init(AVCodecContext *avctx)
     }

     if (ctx->gobpattern >= 0) {
-        ctx->encode_config.frameIntervalP = 1;
+           ctx->encode_config.frameIntervalP = ctx->gobpattern;
     }

+    // when there're b frames, set dts offset
+    if (ctx->encode_config.frameIntervalP >= 2) {
+        ctx->last_dts = -2;
+    }
+

ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.colourDescriptionPresentFlag = 1;

ctx->encode_config.encodeCodecConfig.h264Config.h264VUIParameters.videoSignalTypePresentFlag = 1;

@@ -905,6 +910,10 @@ static int process_output_surface(AVCodecContext *avctx, AVPacket *pkt, AVFrame
     pkt->pts = lock_params.outputTimeStamp;
     pkt->dts = timestamp_queue_dequeue(&ctx->timestamp_list);

+    // when there're b frame(s), set dts offset
+    if (ctx->encode_config.frameIntervalP >= 2)
+        pkt->dts -= 1;
+
     if (pkt->dts > pkt->pts)
         pkt->dts = pkt->pts;

--
1.9.5.github.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to