[FFmpeg-cvslog] avformat/oggparseopus: calculate pts/dts for initial packets after seeking

Michael Niedermayer git at videolan.org
Thu Sep 11 23:51:29 CEST 2014


ffmpeg | branch: release/2.1 | Michael Niedermayer <michaelni at gmx.at> | Thu Sep 11 23:50:35 2014 +0200| [64908f70e4362d140e288c9ee227249ef5228510] | committer: Carl Eugen Hoyos

avformat/oggparseopus: calculate pts/dts for initial packets after seeking

based on code from oggparsevorbis
Fixes Ticket3124
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
(cherry picked from commit 7f39352a1b661771cf471986059027acd8e0e31f)

Fixes ticket #3943.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=64908f70e4362d140e288c9ee227249ef5228510
---

 libavformat/oggparseopus.c |   30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/libavformat/oggparseopus.c b/libavformat/oggparseopus.c
index 5a80314..6e6adcd 100644
--- a/libavformat/oggparseopus.c
+++ b/libavformat/oggparseopus.c
@@ -112,6 +112,36 @@ static int opus_packet(AVFormatContext *avf, int idx)
     if (!os->psize)
         return AVERROR_INVALIDDATA;
 
+    if ((!os->lastpts || os->lastpts == AV_NOPTS_VALUE) && !(os->flags & OGG_FLAG_EOS)) {
+        int seg, d;
+        int duration;
+        uint8_t *last_pkt  = os->buf + os->pstart;
+        uint8_t *next_pkt  = last_pkt;
+
+        duration = 0;
+        seg = os->segp;
+        d = opus_duration(last_pkt, os->psize);
+        if (d < 0) {
+            os->pflags |= AV_PKT_FLAG_CORRUPT;
+            return 0;
+        }
+        duration += d;
+        last_pkt = next_pkt =  next_pkt + os->psize;
+        for (; seg < os->nsegs; seg++) {
+            if (os->segments[seg] < 255) {
+                int d = opus_duration(last_pkt, os->segments[seg]);
+                if (d < 0) {
+                    duration = os->granule;
+                    break;
+                }
+                duration += d;
+                last_pkt  = next_pkt + os->segments[seg];
+            }
+            next_pkt += os->segments[seg];
+        }
+        os->lastpts                 =
+        os->lastdts                 = os->granule - duration;
+    }
 
     os->pduration = opus_duration(packet, os->psize);
     if (os->lastpts != AV_NOPTS_VALUE) {



More information about the ffmpeg-cvslog mailing list