[FFmpeg-user] hevc_nvenc pts < dts error on some time_bases
Louis Letourneau
lletourn49 at gmail.com
Tue Jan 14 04:33:15 EET 2025
Using
ffmpeg version 7.0.2 Copyright (c) 2000-2024 the FFmpeg developers
I keep getting this error:
[mp4 @ 0x60f656ba95c0] pts (1000) < dts (1997) in stream 0
If in my C++ code I try to encode images in timebase 1/60000, framerate
60000/1001 or 60000/1000
I modified the doc/examples/mux.c to force hevc_nvenc and timebases (patch
attached)
If I use 1/60 timbase and 60/1 frame_rate, it all works fine.
ffmpeg command line seems to be able to do it at 59.94 with -vf fps or
forcing with -r
Using libx264 or libx265 works fine.
Any ideas?
Thanks
Louis
-------------- next part --------------
--- ../f/ffmpeg-7.0.2/doc/examples/mux.c 2024-08-02 18:55:25.000000000 -0400
+++ doc/examples/mux.c 2025-01-13 21:25:46.914932469 -0500
@@ -44,7 +44,6 @@
#include <libswresample/swresample.h>
#define STREAM_DURATION 10.0
-#define STREAM_FRAME_RATE 25 /* 25 images/s */
#define STREAM_PIX_FMT AV_PIX_FMT_YUV420P /* default pix_fmt */
#define SCALE_FLAGS SWS_BICUBIC
@@ -131,6 +130,10 @@
/* find the encoder */
*codec = avcodec_find_encoder(codec_id);
+ if((*codec)->type == AVMEDIA_TYPE_VIDEO) {
+ *codec = avcodec_find_encoder_by_name("hevc_nvenc");
+ codec_id = (*codec)->id;
+ }
if (!(*codec)) {
fprintf(stderr, "Could not find encoder for '%s'\n",
avcodec_get_name(codec_id));
@@ -184,7 +187,7 @@
* of which frame timestamps are represented. For fixed-fps content,
* timebase should be 1/framerate and timestamp increments should be
* identical to 1. */
- ost->st->time_base = (AVRational){ 1, STREAM_FRAME_RATE };
+ ost->st->time_base = (AVRational){ 1, 60000 };
c->time_base = ost->st->time_base;
c->gop_size = 12; /* emit one intra frame every twelve frames at most */
@@ -504,7 +507,8 @@
fill_yuv_image(ost->frame, ost->next_pts, c->width, c->height);
}
- ost->frame->pts = ost->next_pts++;
+ ost->frame->pts = ost->next_pts;
+ ost->next_pts += 1001;
return ost->frame;
}
More information about the ffmpeg-user
mailing list