[FFmpeg-devel] [PATCH 1/3] avcodec/decode: set best_effort_timestamp on output frames for all decoders

James Almer jamrial at gmail.com
Sun Dec 13 05:15:22 EET 2020


Fixes a decoding regression introduced by e9a2a87773, and as a side effect also
fixes bogus values set to certain audio frames that had some samples discarded,
where the offsets added to pts, pkt_dts and pkt_duration were not reflected in
best_effort_timestamp.

Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavcodec/decode.c                | 11 ++++-------
 tests/ref/fate/exif-image-embedded |  4 ++--
 tests/ref/fate/gaplessinfo-itunes1 |  2 +-
 tests/ref/fate/gaplessinfo-itunes2 |  2 +-
 4 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 5a1849f944..d804b0bed0 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -372,10 +372,6 @@ static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame,
     if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) {
         if (frame->flags & AV_FRAME_FLAG_DISCARD)
             got_frame = 0;
-        if (got_frame)
-            frame->best_effort_timestamp = guess_correct_pts(avctx,
-                                                             frame->pts,
-                                                             frame->pkt_dts);
     } else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
         uint8_t *side;
         int side_size;
@@ -384,9 +380,6 @@ static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame,
         uint8_t discard_reason = 0;
 
         if (ret >= 0 && got_frame) {
-            frame->best_effort_timestamp = guess_correct_pts(avctx,
-                                                             frame->pts,
-                                                             frame->pkt_dts);
             if (frame->format == AV_SAMPLE_FMT_NONE)
                 frame->format = avctx->sample_fmt;
             if (!frame->channel_layout)
@@ -579,6 +572,10 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
         avci->draining_done = 1;
 
     if (!ret) {
+        frame->best_effort_timestamp = guess_correct_pts(avctx,
+                                                         frame->pts,
+                                                         frame->pkt_dts);
+
         /* the only case where decode data is not set should be decoders
          * that do not call ff_get_buffer() */
         av_assert0((frame->private_ref && frame->private_ref->size == sizeof(FrameDecodeData)) ||
diff --git a/tests/ref/fate/exif-image-embedded b/tests/ref/fate/exif-image-embedded
index 392c145efb..d9239b3c83 100644
--- a/tests/ref/fate/exif-image-embedded
+++ b/tests/ref/fate/exif-image-embedded
@@ -44,8 +44,8 @@ pkt_pts=353600
 pkt_pts_time=0.025057
 pkt_dts=353600
 pkt_dts_time=0.025057
-best_effort_timestamp=0
-best_effort_timestamp_time=0.000000
+best_effort_timestamp=353600
+best_effort_timestamp_time=0.025057
 pkt_duration=15040
 pkt_duration_time=0.001066
 pkt_pos=16292
diff --git a/tests/ref/fate/gaplessinfo-itunes1 b/tests/ref/fate/gaplessinfo-itunes1
index bb5c09ad34..c10e4cccfd 100644
--- a/tests/ref/fate/gaplessinfo-itunes1
+++ b/tests/ref/fate/gaplessinfo-itunes1
@@ -24,7 +24,7 @@ packet|pts=1291264|dts=1291264|duration=1024|flags=K_
 packet|pts=1292288|dts=1292288|duration=1024|flags=K_
 packet|pts=1293312|dts=1293312|duration=1024|flags=K_
 stream|nb_read_packets=1264
-frame|pkt_pts=2112|pkt_dts=2112|best_effort_timestamp=2048|pkt_duration=960|nb_samples=960
+frame|pkt_pts=2112|pkt_dts=2112|best_effort_timestamp=2112|pkt_duration=960|nb_samples=960
 frame|pkt_pts=3072|pkt_dts=3072|best_effort_timestamp=3072|pkt_duration=1024|nb_samples=1024
 frame|pkt_pts=4096|pkt_dts=4096|best_effort_timestamp=4096|pkt_duration=1024|nb_samples=1024
 frame|pkt_pts=5120|pkt_dts=5120|best_effort_timestamp=5120|pkt_duration=1024|nb_samples=1024
diff --git a/tests/ref/fate/gaplessinfo-itunes2 b/tests/ref/fate/gaplessinfo-itunes2
index 0603ba8bf2..752b953197 100644
--- a/tests/ref/fate/gaplessinfo-itunes2
+++ b/tests/ref/fate/gaplessinfo-itunes2
@@ -24,7 +24,7 @@ packet|pts=102400|dts=102400|duration=1024|flags=K_
 packet|pts=103424|dts=103424|duration=1024|flags=K_
 packet|pts=104448|dts=104448|duration=1024|flags=K_
 stream|nb_read_packets=103
-frame|pkt_pts=2112|pkt_dts=2112|best_effort_timestamp=2048|pkt_duration=960|nb_samples=960
+frame|pkt_pts=2112|pkt_dts=2112|best_effort_timestamp=2112|pkt_duration=960|nb_samples=960
 frame|pkt_pts=3072|pkt_dts=3072|best_effort_timestamp=3072|pkt_duration=1024|nb_samples=1024
 frame|pkt_pts=4096|pkt_dts=4096|best_effort_timestamp=4096|pkt_duration=1024|nb_samples=1024
 frame|pkt_pts=5120|pkt_dts=5120|best_effort_timestamp=5120|pkt_duration=1024|nb_samples=1024
-- 
2.29.2



More information about the ffmpeg-devel mailing list