[FFmpeg-cvslog] r20844 - trunk/libavformat/utils.c

michael subversion
Sun Dec 13 23:56:59 CET 2009


Author: michael
Date: Sun Dec 13 23:56:59 2009
New Revision: 20844

Log:
Try to simplify av_estimate_timings_from_pts() like in ffmbc.
Note if this breaks for some file, report it please!

Modified:
   trunk/libavformat/utils.c

Modified: trunk/libavformat/utils.c
==============================================================================
--- trunk/libavformat/utils.c	Sun Dec 13 23:31:29 2009	(r20843)
+++ trunk/libavformat/utils.c	Sun Dec 13 23:56:59 2009	(r20844)
@@ -1758,7 +1758,7 @@ static void av_estimate_timings_from_pts
     AVPacket pkt1, *pkt = &pkt1;
     AVStream *st;
     int read_size, i, ret;
-    int64_t end_time;
+    int64_t end_time, start_time[MAX_STREAMS];
     int64_t filesize, offset, duration;
 
     ic->cur_st = NULL;
@@ -1768,6 +1768,13 @@ static void av_estimate_timings_from_pts
 
     for(i=0;i<ic->nb_streams;i++) {
         st = ic->streams[i];
+        if(st->start_time != AV_NOPTS_VALUE){
+            start_time[i]= st->start_time;
+        }else if(st->first_dts != AV_NOPTS_VALUE){
+            start_time[i]= st->first_dts;
+        }else
+            av_log(st->codec, AV_LOG_WARNING, "start time is not set in av_estimate_timings_from_pts\n");
+
         if (st->parser) {
             av_parser_close(st->parser);
             st->parser= NULL;
@@ -1775,36 +1782,6 @@ static void av_estimate_timings_from_pts
         }
     }
 
-    /* we read the first packets to get the first PTS (not fully
-       accurate, but it is enough now) */
-    url_fseek(ic->pb, 0, SEEK_SET);
-    read_size = 0;
-    for(;;) {
-        if (read_size >= DURATION_MAX_READ_SIZE)
-            break;
-        /* if all info is available, we can stop */
-        for(i = 0;i < ic->nb_streams; i++) {
-            st = ic->streams[i];
-            if (st->start_time == AV_NOPTS_VALUE)
-                break;
-        }
-        if (i == ic->nb_streams)
-            break;
-
-        do{
-            ret = av_read_packet(ic, pkt);
-        }while(ret == AVERROR(EAGAIN));
-        if (ret != 0)
-            break;
-        read_size += pkt->size;
-        st = ic->streams[pkt->stream_index];
-        if (pkt->pts != AV_NOPTS_VALUE) {
-            if (st->start_time == AV_NOPTS_VALUE)
-                st->start_time = pkt->pts;
-        }
-        av_free_packet(pkt);
-    }
-
     /* estimate the end time (duration) */
     /* XXX: may need to support wrapping */
     filesize = ic->file_size;
@@ -1826,9 +1803,9 @@ static void av_estimate_timings_from_pts
         read_size += pkt->size;
         st = ic->streams[pkt->stream_index];
         if (pkt->pts != AV_NOPTS_VALUE &&
-            st->start_time != AV_NOPTS_VALUE) {
+            start_time[pkt->stream_index] != AV_NOPTS_VALUE) {
             end_time = pkt->pts;
-            duration = end_time - st->start_time;
+            duration = end_time - start_time[pkt->stream_index];
             if (duration > 0) {
                 if (st->duration == AV_NOPTS_VALUE ||
                     st->duration < duration)



More information about the ffmpeg-cvslog mailing list