diff mbox series

[FFmpeg-devel,2/3] lavc/encode: generalize a check for setting dts=pts

Message ID 20220928093213.947-2-anton@khirnov.net
State Accepted
Commit 8789720d28f55ed72721cb4fe4c20c73e73114fc
Headers show
Series [FFmpeg-devel,1/3] lavc/encode: make sure frame timebase matches encoder, when set | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov Sept. 28, 2022, 9:32 a.m. UTC
DTS may be different from PTS only if both of these are true:
- the codec supports reordering
- the encoder has delay
---
 libavcodec/encode.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index 0f78012747..fb3ab0db3c 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -211,7 +211,7 @@  int ff_encode_encode_cb(AVCodecContext *avctx, AVPacket *avpkt,
 
         if (avctx->codec->type == AVMEDIA_TYPE_VIDEO &&
             !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY))
-            avpkt->pts = avpkt->dts = frame->pts;
+            avpkt->pts = frame->pts;
         if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY)) {
             if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
                 if (avpkt->pts == AV_NOPTS_VALUE)
@@ -221,9 +221,12 @@  int ff_encode_encode_cb(AVCodecContext *avctx, AVPacket *avpkt,
                                                               frame->nb_samples);
             }
         }
-        if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
+
+        // dts equals pts unless there is reordering
+        // there can be no reordering if there is no encoder delay
+        if (!(avctx->codec_descriptor->props & AV_CODEC_PROP_REORDER) ||
+            !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY))
             avpkt->dts = avpkt->pts;
-        }
     } else {
 unref:
         av_packet_unref(avpkt);