[FFmpeg-cvslog] hls: Store first_timestamp in units of AV_TIME_BASE

Martin Storsjö git at videolan.org
Tue Jul 30 10:08:37 CEST 2013


ffmpeg | branch: master | Martin Storsjö <martin at martin.st> | Mon Jul 29 10:09:02 2013 +0300| [e1d5b244761cf69db655ad7ece1dbf2c13dd4fce] | committer: Martin Storsjö

hls: Store first_timestamp in units of AV_TIME_BASE

When first_timestamp was stored as-is, its actual time base
wasn't known later in the seek function.

Additionally, the logic (from 795d9594cfa) for scaling it
based on stream_index is flawed - stream_index in the seek
function only specifies which stream the seek timestamp refers
to, but obviously doesn't say anything about which stream
first_timestamp belongs to.

In the cases where stream_index was >= 0 and all streams had the
same time base, this didn't matter in practice.

Seeking taking first_timestamp into account is problematic
when one variant is mpegts (with real timestamps) and one variant
is raw ADTS (with timestamps only being accumulated packet
duration), where the variants start at totally different timestamps.

Signed-off-by: Martin Storsjö <martin at martin.st>

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

 libavformat/hls.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/libavformat/hls.c b/libavformat/hls.c
index b01dd3e..5eb98c5 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -627,8 +627,11 @@ start:
                     reset_packet(&var->pkt);
                     break;
                 } else {
-                    if (c->first_timestamp == AV_NOPTS_VALUE)
-                        c->first_timestamp = var->pkt.dts;
+                    if (c->first_timestamp == AV_NOPTS_VALUE &&
+                        var->pkt.dts       != AV_NOPTS_VALUE)
+                        c->first_timestamp = av_rescale_q(var->pkt.dts,
+                            var->ctx->streams[var->pkt.stream_index]->time_base,
+                            AV_TIME_BASE_Q);
                 }
 
                 if (c->seek_timestamp == AV_NOPTS_VALUE)
@@ -728,8 +731,7 @@ static int hls_read_seek(AVFormatContext *s, int stream_index,
         /* Reset reading */
         struct variant *var = c->variants[i];
         int64_t pos = c->first_timestamp == AV_NOPTS_VALUE ? 0 :
-                      av_rescale_rnd(c->first_timestamp, 1,
-                          stream_index >= 0 ? s->streams[stream_index]->time_base.den : AV_TIME_BASE,
+                      av_rescale_rnd(c->first_timestamp, 1, AV_TIME_BASE,
                           flags & AVSEEK_FLAG_BACKWARD ? AV_ROUND_DOWN : AV_ROUND_UP);
         if (var->input) {
             ffurl_close(var->input);



More information about the ffmpeg-cvslog mailing list