diff mbox series

[FFmpeg-devel] avformat/flvdec: fix mismatch on timestamp wrap point

Message ID tencent_79D72D449AA640019A799F99AB7E4E3F7008@qq.com
State New
Headers show
Series [FFmpeg-devel] avformat/flvdec: fix mismatch on timestamp wrap point | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_armv7_RPi4 success Make finished
andriy/make_fate_armv7_RPi4 success Make fate finished
andriy/make_aarch64_jetson success Make finished
andriy/make_fate_aarch64_jetson success Make fate finished

Commit Message

Zhao Zhili March 9, 2022, 11:15 a.m. UTC
Change the wrap point to 2^31 to match flvenc muxer. For other flv
muxers which treat timestamp as uint32_t, it should be handled by
wrap_timestamp(). For muxers which treat timestamp as int32_t and
create negative timestamp, they are broken before the patch.
---
 libavformat/flvdec.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
index b9e36b3ff1..ff5e6eabb4 100644
--- a/libavformat/flvdec.c
+++ b/libavformat/flvdec.c
@@ -184,7 +184,7 @@  static AVStream *create_stream(AVFormatContext *s, int codec_type)
     }
 
 
-    avpriv_set_pts_info(st, 32, 1, 1000); /* 32 bit pts in ms */
+    avpriv_set_pts_info(st, 31, 1, 1000); /* 31 bit pts in ms */
     flv->last_keyframe_stream_index = s->nb_streams - 1;
     add_keyframes_index(s);
     return st;
@@ -1033,7 +1033,11 @@  retry:
     size = avio_rb24(s->pb);
     flv->sum_flv_tag_size += size + 11;
     dts  = avio_rb24(s->pb);
-    dts |= (unsigned)avio_r8(s->pb) << 24;
+    /* FLV timestamps are 32 bits signed, flvenc.c doesn't use the 32 msb, but
+     * other muxer may treat timestamp as uint32_t. We ignore the 32 bit and
+     * handle the wrap by avpriv_set_pts_info().
+     */
+    dts |= ((unsigned)avio_r8(s->pb) & 0x7F) << 24;
     av_log(s, AV_LOG_TRACE, "type:%d, size:%d, last:%d, dts:%"PRId64" pos:%"PRId64"\n", type, size, last, dts, avio_tell(s->pb));
     if (avio_feof(s->pb))
         return AVERROR_EOF;