[FFmpeg-devel] [PATCH v2, 1/2] avformat/hls: fix seek accuracy problem

2018-01-02 Thread mymoeyard
From: Wu Zhiqiang 

HLS demuxer seeking use dts instead of pts.
Demuxer skip some frame when dts is before pts in special case.
And it is impossible to re-seek back to start time after playing.
---
 libavformat/hls.c | 18 ++
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/libavformat/hls.c b/libavformat/hls.c
index 950cc4c3bd..069e7b06e9 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -2086,6 +2086,7 @@ static int hls_read_packet(AVFormatContext *s, AVPacket 
*pkt)
  * stream */
 if (pls->needed && !pls->pkt.data) {
 while (1) {
+int64_t pkt_ts;
 int64_t ts_diff;
 AVRational tb;
 ret = av_read_frame(pls->ctx, >pkt);
@@ -2101,9 +2102,17 @@ static int hls_read_packet(AVFormatContext *s, AVPacket 
*pkt)
 fill_timing_for_id3_timestamped_stream(pls);
 }
 
+if (pls->pkt.pts != AV_NOPTS_VALUE)
+pkt_ts =  pls->pkt.pts;
+else if (pls->pkt.dts != AV_NOPTS_VALUE)
+pkt_ts =  pls->pkt.dts;
+else
+pkt_ts = AV_NOPTS_VALUE;
+
+
 if (c->first_timestamp == AV_NOPTS_VALUE &&
-pls->pkt.dts   != AV_NOPTS_VALUE)
-c->first_timestamp = av_rescale_q(pls->pkt.dts,
+pkt_ts   != AV_NOPTS_VALUE)
+c->first_timestamp = av_rescale_q(pkt_ts,
 get_timebase(pls), AV_TIME_BASE_Q);
 }
 
@@ -2113,15 +2122,16 @@ static int hls_read_packet(AVFormatContext *s, AVPacket 
*pkt)
 if (pls->seek_stream_index < 0 ||
 pls->seek_stream_index == pls->pkt.stream_index) {
 
-if (pls->pkt.dts == AV_NOPTS_VALUE) {
+if (pkt_ts == AV_NOPTS_VALUE) {
 pls->seek_timestamp = AV_NOPTS_VALUE;
 break;
 }
 
 tb = get_timebase(pls);
-ts_diff = av_rescale_rnd(pls->pkt.dts, AV_TIME_BASE,
+ts_diff = av_rescale_rnd(pkt_ts, AV_TIME_BASE,
 tb.den, AV_ROUND_DOWN) -
 pls->seek_timestamp;
+
 if (ts_diff >= 0 && (pls->seek_flags  & AVSEEK_FLAG_ANY ||
 pls->pkt.flags & AV_PKT_FLAG_KEY)) {
 pls->seek_timestamp = AV_NOPTS_VALUE;
-- 
2.15.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


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

2018-01-02 Thread mymoeyard
From: Wu Zhiqiang 

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 
---
 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)
-- 
2.15.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] avformat/hls: fix seek accuracy problem

2018-01-02 Thread mymoeyard
From: Wu Zhiqiang 

HLS demuxer seeking use dts instead of pts.
Demuxer skip some frame when dts is before pts in special case.
And it is impossible to re-seek back to start time after playing.
---
 libavformat/hls.c | 18 ++
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/libavformat/hls.c b/libavformat/hls.c
index 950cc4c3bd..069e7b06e9 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -2086,6 +2086,7 @@ static int hls_read_packet(AVFormatContext *s, AVPacket 
*pkt)
  * stream */
 if (pls->needed && !pls->pkt.data) {
 while (1) {
+int64_t pkt_ts;
 int64_t ts_diff;
 AVRational tb;
 ret = av_read_frame(pls->ctx, >pkt);
@@ -2101,9 +2102,17 @@ static int hls_read_packet(AVFormatContext *s, AVPacket 
*pkt)
 fill_timing_for_id3_timestamped_stream(pls);
 }
 
+if (pls->pkt.pts != AV_NOPTS_VALUE)
+pkt_ts =  pls->pkt.pts;
+else if (pls->pkt.dts != AV_NOPTS_VALUE)
+pkt_ts =  pls->pkt.dts;
+else
+pkt_ts = AV_NOPTS_VALUE;
+
+
 if (c->first_timestamp == AV_NOPTS_VALUE &&
-pls->pkt.dts   != AV_NOPTS_VALUE)
-c->first_timestamp = av_rescale_q(pls->pkt.dts,
+pkt_ts   != AV_NOPTS_VALUE)
+c->first_timestamp = av_rescale_q(pkt_ts,
 get_timebase(pls), AV_TIME_BASE_Q);
 }
 
@@ -2113,15 +2122,16 @@ static int hls_read_packet(AVFormatContext *s, AVPacket 
*pkt)
 if (pls->seek_stream_index < 0 ||
 pls->seek_stream_index == pls->pkt.stream_index) {
 
-if (pls->pkt.dts == AV_NOPTS_VALUE) {
+if (pkt_ts == AV_NOPTS_VALUE) {
 pls->seek_timestamp = AV_NOPTS_VALUE;
 break;
 }
 
 tb = get_timebase(pls);
-ts_diff = av_rescale_rnd(pls->pkt.dts, AV_TIME_BASE,
+ts_diff = av_rescale_rnd(pkt_ts, AV_TIME_BASE,
 tb.den, AV_ROUND_DOWN) -
 pls->seek_timestamp;
+
 if (ts_diff >= 0 && (pls->seek_flags  & AVSEEK_FLAG_ANY ||
 pls->pkt.flags & AV_PKT_FLAG_KEY)) {
 pls->seek_timestamp = AV_NOPTS_VALUE;
-- 
2.15.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH, V3] avformat/concat: Fix wrong wrapped timestamp

2017-12-29 Thread mymoeyard
From: Wu Zhiqiang 

When using concat protocol, start from middle of file will generate non-zero 
wrap reference.
If seek to time before the wrap reference, wrap control will generate wrong 
wrapped timestamp.
Copy wrap related stream properties when reading header can fix this problem.

Signed-off-by: Wu Zhiqiang 
---
 libavformat/concatdec.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
index 0e189012ad..8ea9c2b02d 100644
--- a/libavformat/concatdec.c
+++ b/libavformat/concatdec.c
@@ -188,6 +188,12 @@ static int copy_stream_props(AVStream *st, AVStream 
*source_st)
 st->time_base   = source_st->time_base;
 st->sample_aspect_ratio = source_st->sample_aspect_ratio;
 
+/* Fix wrap control problem */
+avpriv_set_pts_info(st, source_st->pts_wrap_bits, source_st->time_base.num,
+source_st->time_base.den);
+st->pts_wrap_behavior   = source_st->pts_wrap_behavior;
+st->pts_wrap_reference  = source_st->pts_wrap_reference;
+
 av_dict_copy(>metadata, source_st->metadata, 0);
 return 0;
 }
-- 
2.15.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH, V2] avformat/concat: Fix wrong wrapped timestamp

2017-12-14 Thread mymoeyard
From: Wu Zhiqiang 

When using concat protocol, start from middle of file will generate non-zero 
wrap reference.
If seek to time before the wrap reference, wrap control will generate wrong 
wrapped timestamp.
Copy wrap related stream properties when reading header can fix this problem.

Signed-off-by: Wu Zhiqiang 
---
 libavformat/concatdec.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
index 0e189012ad..8dae2737df 100644
--- a/libavformat/concatdec.c
+++ b/libavformat/concatdec.c
@@ -188,6 +188,11 @@ static int copy_stream_props(AVStream *st, AVStream 
*source_st)
 st->time_base   = source_st->time_base;
 st->sample_aspect_ratio = source_st->sample_aspect_ratio;
 
+/* Fix wrap control problem */
+avpriv_set_pts_info(st, source_st->pts_wrap_bits, 
source_st->time_base.num, source_st->time_base.den);
+st->pts_wrap_behavior   = source_st->pts_wrap_behavior;
+st->pts_wrap_reference  = source_st->pts_wrap_reference;
+
 av_dict_copy(>metadata, source_st->metadata, 0);
 return 0;
 }
-- 
2.15.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] avformat/concat: Fix wrong wrapped timestamp

2017-12-14 Thread mymoeyard
From: wu zhiqiang 

When using concat protocal, start from middle of file will generate non-zero 
wrap reference. If seek to time less than the wrap reference, wrap control will 
be triggered and generate wrong wrapped timestamp.
Copy wrap related stream properties when reading header can fix this problem.

Signed-off-by: wu zhiqiang 
---
 libavformat/concatdec.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
index 0e189012ad..e933888661 100644
--- a/libavformat/concatdec.c
+++ b/libavformat/concatdec.c
@@ -188,6 +188,11 @@ static int copy_stream_props(AVStream *st, AVStream 
*source_st)
 st->time_base   = source_st->time_base;
 st->sample_aspect_ratio = source_st->sample_aspect_ratio;
 
+/* Fix wrap control problem */
+st->pts_wrap_bits   = source_st->pts_wrap_bits;
+st->pts_wrap_behavior   = source_st->pts_wrap_behavior;
+st->pts_wrap_reference  = source_st->pts_wrap_reference;
+
 av_dict_copy(>metadata, source_st->metadata, 0);
 return 0;
 }
-- 
2.15.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel