[FFmpeg-devel] [patch 3/3] Make timing calculations less dependant on start_time being defined.

Neil Brown neilb
Sat Aug 25 00:45:50 CEST 2007


On Friday August 24, michaelni at gmx.at wrote:
> > 
> > I'm having a hard time understanding the point of some of (well... all
> > of) the code in update_initial_timestamps.
> 
> its very simple, av_find_stream_info() analyses a input file/stream and
> buffers all packets which it had to read (so that theres no need to seek
> back after av_find_stream_info() which with pipes would be impossible)
> 
> update_initial_timestamps() updates the timestamps of these buffered
> packets in the case that the packets had no timestamp (that is libavformat
> used the framerate / AVPacket.duration to set timestamps starting from a
> arbitrary (=0) timestamt)

Ahhhh... I get it now.  All the time stamps are being offset by
   dts - st->cur_dts

That makes sense.  Thanks.

> 
> the first packet with a timestamp gets put in the buffer after 
> update_initial_timestamps() is called thus if theres nothing in the buffer
> the code to set start_time fails ...
> solution seems to be to pass pkt->pts in addition to dts into
> update_initial_timestamps() and then add an additional check to use that
> if no packet in the buffer had a pts value

So this patch maybe (which also appears to fix my problem).

Thanks for your patience.

NeilBrown

--------------------
If the first packet has a valid pts and dts, use the pts to initialise
start_time.

Index: utils.c
===================================================================
--- utils.c	(revision 10200)
+++ utils.c	(working copy)
@@ -589,7 +589,9 @@
     return 0;
 }
 
-static void update_initial_timestamps(AVFormatContext *s, int stream_index, int64_t dts){
+static void update_initial_timestamps(AVFormatContext *s, int stream_index,
+                                      int64_t dts, int64_t pts)
+{
     AVStream *st= s->streams[stream_index];
     AVPacketList *pktl= s->packet_buffer;
 
@@ -612,6 +614,8 @@
         if(st->start_time == AV_NOPTS_VALUE && pktl->pkt.pts != AV_NOPTS_VALUE)
             st->start_time= pktl->pkt.pts;
     }
+    if (st->start_time == AV_NOPTS_VALUE)
+        st->start_time = pts;
 }
 
 static void compute_pkt_fields(AVFormatContext *s, AVStream *st,
@@ -669,7 +673,7 @@
             /* PTS = presentation time stamp */
             if (pkt->dts == AV_NOPTS_VALUE)
                 pkt->dts = st->last_IP_pts;
-            update_initial_timestamps(s, pkt->stream_index, pkt->dts);
+            update_initial_timestamps(s, pkt->stream_index, pkt->dts, pkt->pts);
             if (pkt->dts == AV_NOPTS_VALUE)
                 pkt->dts = st->cur_dts;
 
@@ -695,7 +699,7 @@
             /* presentation is not delayed : PTS and DTS are the same */
             if(pkt->pts == AV_NOPTS_VALUE)
                 pkt->pts = pkt->dts;
-            update_initial_timestamps(s, pkt->stream_index, pkt->pts);
+            update_initial_timestamps(s, pkt->stream_index, pkt->pts, pkt->pts);
             if(pkt->pts == AV_NOPTS_VALUE)
                 pkt->pts = st->cur_dts;
             pkt->dts = pkt->pts;
@@ -712,7 +716,7 @@
         if(pkt->dts == AV_NOPTS_VALUE)
             pkt->dts= st->pts_buffer[0];
         if(delay>1){
-            update_initial_timestamps(s, pkt->stream_index, pkt->dts); // this should happen on the first packet
+            update_initial_timestamps(s, pkt->stream_index, pkt->dts, pkt->pts); // this should happen on the first packet
         }
         if(pkt->dts > st->cur_dts)
             st->cur_dts = pkt->dts;




More information about the ffmpeg-devel mailing list