[FFmpeg-devel] avformat/mpegts: index only keyframes to ensure accurate seeks

Submitted by Michael Niedermayer on May 8, 2019, 4:13 p.m.

Details

Message ID 20190508161337.GU3501@michaelspb
State New
Headers show

Commit Message

Michael Niedermayer May 8, 2019, 4:13 p.m.
On Mon, May 06, 2019 at 08:26:23PM -0700, Aman Gupta wrote:
> From: Aman Gupta <aman@tmm1.net>
> 
> Signed-off-by: Aman Gupta <aman@tmm1.net>
> ---
>  libavformat/mpegts.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
> index 8a84e5cc19..49e282903c 100644
> --- a/libavformat/mpegts.c
> +++ b/libavformat/mpegts.c
> @@ -3198,9 +3198,9 @@ static int64_t mpegts_get_dts(AVFormatContext *s, int stream_index,
>          ret = av_read_frame(s, &pkt);
>          if (ret < 0)
>              return AV_NOPTS_VALUE;
> -        if (pkt.dts != AV_NOPTS_VALUE && pkt.pos >= 0) {
> +        if (pkt.dts != AV_NOPTS_VALUE && pkt.pos >= 0 && (pkt.flags & AV_PKT_FLAG_KEY)) {
>              ff_reduce_index(s, pkt.stream_index);
> -            av_add_index_entry(s->streams[pkt.stream_index], pkt.pos, pkt.dts, 0, 0, AVINDEX_KEYFRAME /* FIXME keyframe? */);
> +            av_add_index_entry(s->streams[pkt.stream_index], pkt.pos, pkt.dts, 0, 0, AVINDEX_KEYFRAME);
>              if (pkt.stream_index == stream_index && pkt.pos >= *ppos) {

What happens with streams that have no keyframes but use more dispersed intra refresh ?

also breaks fate-seek-lavf-ts
Test seek-lavf-ts failed. Look at tests/data/fate/seek-lavf-ts.err for details.
make: *** [fate-seek-lavf-ts] Error 1

[...]

Patch hide | download patch | download mbox

--- ./tests/ref/seek/lavf-ts	2019-04-22 01:06:36.162990906 +0200
+++ tests/data/fate/seek-lavf-ts	2019-05-08 18:07:40.290602734 +0200
@@ -16,7 +16,7 @@ 
 ret: 0         st:-1 flags:1  ts:-0.740831
 ret: 0         st: 0 flags:1 dts: 1.400000 pts: 1.440000 pos:    564 size: 24801
 ret: 0         st: 0 flags:0  ts: 2.153333
-ret: 0         st: 1 flags:1 dts: 1.794811 pts: 1.794811 pos: 322608 size:   209
+ret: 0         st: 1 flags:1 dts: 2.160522 pts: 2.160522 pos: 404576 size:   209
 ret: 0         st: 0 flags:1  ts: 1.047500
 ret: 0         st: 0 flags:1 dts: 1.400000 pts: 1.440000 pos:    564 size: 24801
 ret: 0         st: 1 flags:0  ts:-0.058333
@@ -24,7 +24,7 @@ 
 ret: 0         st: 1 flags:1  ts: 2.835833
 ret: 0         st: 1 flags:1 dts: 2.160522 pts: 2.160522 pos: 404576 size:   209
 ret: 0         st:-1 flags:0  ts: 1.730004
-ret: 0         st: 1 flags:1 dts: 1.429089 pts: 1.429089 pos: 159988 size:   208
+ret: 0         st: 0 flags:1 dts: 1.880000 pts: 1.920000 pos: 189692 size: 24786
 ret: 0         st:-1 flags:1  ts: 0.624171
 ret: 0         st: 0 flags:1 dts: 1.400000 pts: 1.440000 pos:    564 size: 24801
 ret: 0         st: 0 flags:0  ts:-0.481667
@@ -38,7 +38,7 @@ 
 ret: 0         st:-1 flags:0  ts:-0.904994
 ret: 0         st: 0 flags:1 dts: 1.400000 pts: 1.440000 pos:    564 size: 24801
 ret: 0         st:-1 flags:1  ts: 1.989173
-ret: 0         st: 0 flags:0 dts: 1.960000 pts: 2.000000 pos: 235000 size: 15019
+ret: 0         st: 0 flags:1 dts: 1.880000 pts: 1.920000 pos: 189692 size: 24786
 ret: 0         st: 0 flags:0  ts: 0.883344
 ret: 0         st: 0 flags:1 dts: 1.400000 pts: 1.440000 pos:    564 size: 24801
 ret: 0         st: 0 flags:1  ts:-0.222489