[FFmpeg-devel] [PATCH] avformat/wavdec: More accurate duration

Danivy 755793225 at qq.com
Wed Jul 28 17:26:56 EEST 2021


Using data size and nAvgBytesPerSec to calculate the duration will be more accurate
---
 libavformat/wavdec.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c
index d2fb81ca7f..50b1f81e62 100644
--- a/libavformat/wavdec.c
+++ b/libavformat/wavdec.c
@@ -185,7 +185,8 @@ static int wav_parse_fmt_tag(AVFormatContext *s, int64_t size, AVStream *st)
 
     st->internal->need_parsing = AVSTREAM_PARSE_FULL_RAW;
 
-    avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
+    uint64_t nAvgBytesPerSec = st->codecpar->bit_rate / 8;
+    avpriv_set_pts_info(st, 64, 1, nAvgBytesPerSec);
 
     return 0;
 }
@@ -637,7 +638,9 @@ break_loop:
                                   /
                 (st->codecpar->channels * (uint64_t)av_get_bits_per_sample(st->codecpar->codec_id));
 
-    if (sample_count)
+    if (data_size)
+        st->duration = data_size;
+    else if (sample_count)
         st->duration = sample_count;
 
     if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S32LE &&
-- 
2.17.2 (Apple Git-113)



More information about the ffmpeg-devel mailing list