[FFmpeg-devel] [PATCH] oggdec get start_time

Reimar Döffinger Reimar.Doeffinger
Tue Oct 13 18:46:59 CEST 2009


Hello,
this is obviously broken since it depends on luck that the first and
last packets it finds are from the same stream, so obviously someone
should better implement something proper.
Still this fixes the issue with the file that can be found here:
http://code.google.com/p/gnome-mplayer/issues/detail?id=300
so that FFmpeg indicates the duration correctly as 58 seconds instead of
13 hours.
Index: libavformat/oggdec.c
===================================================================
--- libavformat/oggdec.c        (revision 20212)
+++ libavformat/oggdec.c        (working copy)
@@ -453,6 +453,20 @@
     end = size > MAX_PAGE_SIZE? size - MAX_PAGE_SIZE: 0;
 
     ogg_save (s);
+    url_fseek (s->pb, 0, SEEK_SET);
+    while (!ogg_read_page (s, &i)){
+        if (ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0 &&
+            ogg->streams[i].codec)
+            idx = i;
+    }
+    if (idx != -1){
+        s->streams[idx]->start_time =
+            ogg_gptopts (s, idx, ogg->streams[idx].granule);
+    }
+
+    ogg_restore (s, 0);
+    ogg_save (s);
+
     url_fseek (s->pb, end, SEEK_SET);
 
     while (!ogg_read_page (s, &i)){
@@ -464,6 +478,8 @@
     if (idx != -1){
         s->streams[idx]->duration =
             ogg_gptopts (s, idx, ogg->streams[idx].granule);
+        if (s->streams[idx]->start_time != AV_NOPTS_VALUE)
+            s->streams[idx]->duration -= s->streams[idx]->start_time;
     }
 
     ogg->size = size;




More information about the ffmpeg-devel mailing list