diff mbox

[FFmpeg-devel,v2,2/2] avformat/hls: fix start time seek error

Message ID 1514951087-9400-1-git-send-email-mymoeyard@gmail.com
State New
Headers show

Commit Message

mymoeyard@gmail.com Jan. 3, 2018, 3:44 a.m. UTC
From: Wu Zhiqiang <mymoeyard@gmail.com>

Calculate first_timestamp based on first packet timestamp.
Some m3u8 have streams that second one has smaller timestamp
in first packet of this stream.
Start/seek from start time may fail due to EIO error.
It should be based on start_time of AvFormatContext.

Signed-off-by: Wu Zhiqiang <mymoeyard@gmail.com>
---
 libavformat/hls.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Comments

wm4 Jan. 3, 2018, 8:40 a.m. UTC | #1
On Tue,  2 Jan 2018 22:44:47 -0500
mymoeyard@gmail.com wrote:

> From: Wu Zhiqiang <mymoeyard@gmail.com>
> 
> Calculate first_timestamp based on first packet timestamp.
> Some m3u8 have streams that second one has smaller timestamp
> in first packet of this stream.
> Start/seek from start time may fail due to EIO error.
> It should be based on start_time of AvFormatContext.
> 
> Signed-off-by: Wu Zhiqiang <mymoeyard@gmail.com>
> ---
>  libavformat/hls.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/libavformat/hls.c b/libavformat/hls.c
> index 069e7b06e9..125f68ca4e 100644
> --- a/libavformat/hls.c
> +++ b/libavformat/hls.c
> @@ -2110,10 +2110,8 @@ static int hls_read_packet(AVFormatContext *s, AVPacket *pkt)
>                          pkt_ts = AV_NOPTS_VALUE;
>  
>  
> -                    if (c->first_timestamp == AV_NOPTS_VALUE &&
> -                        pkt_ts       != AV_NOPTS_VALUE)
> -                        c->first_timestamp = av_rescale_q(pkt_ts,
> -                            get_timebase(pls), AV_TIME_BASE_Q);
> +                    c->first_timestamp = s->start_time != AV_NOPTS_VALUE ? s->start_time : 0;
> +
>                  }
>  
>                  if (pls->seek_timestamp == AV_NOPTS_VALUE)

Not sure if I agree with this. AFAIK start_time is set by
avformat_find_stream_info(), so calling that would be required. But
that call also adds a lot of startup latency.
diff mbox

Patch

diff --git a/libavformat/hls.c b/libavformat/hls.c
index 069e7b06e9..125f68ca4e 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -2110,10 +2110,8 @@  static int hls_read_packet(AVFormatContext *s, AVPacket *pkt)
                         pkt_ts = AV_NOPTS_VALUE;
 
 
-                    if (c->first_timestamp == AV_NOPTS_VALUE &&
-                        pkt_ts       != AV_NOPTS_VALUE)
-                        c->first_timestamp = av_rescale_q(pkt_ts,
-                            get_timebase(pls), AV_TIME_BASE_Q);
+                    c->first_timestamp = s->start_time != AV_NOPTS_VALUE ? s->start_time : 0;
+
                 }
 
                 if (pls->seek_timestamp == AV_NOPTS_VALUE)