also subtract preroll when reading ASF simple index object

Message ID 4D83145D.5060309@gmail.com
State Committed
Headers show

Commit Message

Vladimir Pantelic March 18, 2011, 8:14 a.m.
Anton Khirnov wrote:

>>  -            av_log(s, AV_LOG_DEBUG, "pktnum:%d, pktct:%d\n", pktnum, pktct);
>>  +            av_log(s, AV_LOG_DEBUG, "pktnum:%d, pktct:%d  pts: %lld\n", pktnum, pktct, index_pts);
>
> %lld ->  PRId64 ?

yep

Comments

Vladimir Pantelic March 22, 2011, 9:34 a.m. | #1
> From: Vladimir Pantelic<vladoman@gmail.com>
> Date: Thu, 17 Mar 2011 22:34:52 +0100
> Subject: [PATCH] also subtract preroll when reading ASF simple index object
>
> this was missed when ASF was changed to return timestamps
> without preroll.
> ---
>   libavformat/asfdec.c |    4 ++--
>   1 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/libavformat/asfdec.c b/libavformat/asfdec.c
> index 79b3bcb..9f460dd 100644
> --- a/libavformat/asfdec.c
> +++ b/libavformat/asfdec.c
> @@ -1218,10 +1218,10 @@ static void asf_build_simple_index(AVFormatContext *s, int stream_index)
>               int pktnum=avio_rl32(s->pb);
>               int pktct =avio_rl16(s->pb);
>               int64_t pos      = s->data_offset + s->packet_size*(int64_t)pktnum;
> -            int64_t index_pts= av_rescale(itime, i, 10000);
> +            int64_t index_pts= FFMAX(av_rescale(itime, i, 10000) - asf->hdr.preroll, 0);
>
>               if(pos != last_pos){
> -            av_log(s, AV_LOG_DEBUG, "pktnum:%d, pktct:%d\n", pktnum, pktct);
> +            av_log(s, AV_LOG_DEBUG, "pktnum:%d, pktct:%d  pts: %"PRId64"\n", pktnum, pktct, index_pts);
>               av_add_index_entry(s->streams[stream_index], pos, index_pts, s->packet_size, 0, AVINDEX_KEYFRAME);
>               last_pos=pos;
>               }

ping
Mans Rullgard March 22, 2011, 11:20 a.m. | #2
Vladimir Pantelic <vladoman@gmail.com> writes:

> Anton Khirnov wrote:
>
>>>  -            av_log(s, AV_LOG_DEBUG, "pktnum:%d, pktct:%d\n", pktnum, pktct);
>>>  +            av_log(s, AV_LOG_DEBUG, "pktnum:%d, pktct:%d  pts: %lld\n", pktnum, pktct, index_pts);
>>
>> %lld ->  PRId64 ?
>
> yep
>
>
> From 057af717394ec2352d52fa8c1d96f66262da423c Mon Sep 17 00:00:00 2001
> From: Vladimir Pantelic <vladoman@gmail.com>
> Date: Thu, 17 Mar 2011 22:34:52 +0100
> Subject: [PATCH] also subtract preroll when reading ASF simple index object
>
> this was missed when ASF was changed to return timestamps
> without preroll.
> ---
>  libavformat/asfdec.c |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/libavformat/asfdec.c b/libavformat/asfdec.c
> index 79b3bcb..9f460dd 100644
> --- a/libavformat/asfdec.c
> +++ b/libavformat/asfdec.c
> @@ -1218,10 +1218,10 @@ static void asf_build_simple_index(AVFormatContext *s, int stream_index)
>              int pktnum=avio_rl32(s->pb);
>              int pktct =avio_rl16(s->pb);
>              int64_t pos      = s->data_offset + s->packet_size*(int64_t)pktnum;
> -            int64_t index_pts= av_rescale(itime, i, 10000);
> +            int64_t index_pts= FFMAX(av_rescale(itime, i, 10000) - asf->hdr.preroll, 0);

Under what circumstances does this become negative without the FFMAX?
Vladimir Pantelic March 22, 2011, 12:46 p.m. | #3
Måns Rullgård wrote:
> Vladimir Pantelic<vladoman@gmail.com>  writes:

>>   From 057af717394ec2352d52fa8c1d96f66262da423c Mon Sep 17 00:00:00 2001
>>  From: Vladimir Pantelic<vladoman@gmail.com>
>>  Date: Thu, 17 Mar 2011 22:34:52 +0100
>>  Subject: [PATCH] also subtract preroll when reading ASF simple index object
>>
>>  this was missed when ASF was changed to return timestamps
>>  without preroll.
>>  ---
>>   libavformat/asfdec.c |    4 ++--
>>   1 files changed, 2 insertions(+), 2 deletions(-)
>>
>>  diff --git a/libavformat/asfdec.c b/libavformat/asfdec.c
>>  index 79b3bcb..9f460dd 100644
>>  --- a/libavformat/asfdec.c
>>  +++ b/libavformat/asfdec.c
>>  @@ -1218,10 +1218,10 @@ static void asf_build_simple_index(AVFormatContext *s, int stream_index)
>>               int pktnum=avio_rl32(s->pb);
>>               int pktct =avio_rl16(s->pb);
>>               int64_t pos      = s->data_offset + s->packet_size*(int64_t)pktnum;
>>  -            int64_t index_pts= av_rescale(itime, i, 10000);
>>  +            int64_t index_pts= FFMAX(av_rescale(itime, i, 10000) - asf->hdr.preroll, 0);
>
> Under what circumstances does this become negative without the FFMAX?

the simple index starts at 0, so with a preroll of e.g. 3000ms the 1st 4 index entries
(0ms, 1000ms, 2000ms, 3000ms) all point to the same packet with timestamp 3000ms.

since we subtract the preroll, we need to do that for the index time too and thus the 1st
entries all map to 0
Vladimir Pantelic March 23, 2011, 10:39 a.m. | #4
ping

Vladimir Pantelic wrote:
> Måns Rullgård wrote:
>>  Vladimir Pantelic<vladoman@gmail.com>   writes:
>
>>>     From 057af717394ec2352d52fa8c1d96f66262da423c Mon Sep 17 00:00:00 2001
>>>   From: Vladimir Pantelic<vladoman@gmail.com>
>>>   Date: Thu, 17 Mar 2011 22:34:52 +0100
>>>   Subject: [PATCH] also subtract preroll when reading ASF simple index object
>>>
>>>   this was missed when ASF was changed to return timestamps
>>>   without preroll.
>>>   ---
>>>    libavformat/asfdec.c |    4 ++--
>>>    1 files changed, 2 insertions(+), 2 deletions(-)
>>>
>>>   diff --git a/libavformat/asfdec.c b/libavformat/asfdec.c
>>>   index 79b3bcb..9f460dd 100644
>>>   --- a/libavformat/asfdec.c
>>>   +++ b/libavformat/asfdec.c
>>>   @@ -1218,10 +1218,10 @@ static void asf_build_simple_index(AVFormatContext *s, int stream_index)
>>>                int pktnum=avio_rl32(s->pb);
>>>                int pktct =avio_rl16(s->pb);
>>>                int64_t pos      = s->data_offset + s->packet_size*(int64_t)pktnum;
>>>   -            int64_t index_pts= av_rescale(itime, i, 10000);
>>>   +            int64_t index_pts= FFMAX(av_rescale(itime, i, 10000) - asf->hdr.preroll, 0);
>>
>>  Under what circumstances does this become negative without the FFMAX?
>
> the simple index starts at 0, so with a preroll of e.g. 3000ms the 1st 4 index entries
> (0ms, 1000ms, 2000ms, 3000ms) all point to the same packet with timestamp 3000ms.
>
> since we subtract the preroll, we need to do that for the index time too and thus the 1st
> entries all map to 0
>
>
>
Mans Rullgard March 23, 2011, 11:11 a.m. | #5
Vladimir Pantelic <vladoman@gmail.com> writes:

> Måns Rullgård wrote:
>> Vladimir Pantelic<vladoman@gmail.com>  writes:
>
>>>   From 057af717394ec2352d52fa8c1d96f66262da423c Mon Sep 17 00:00:00 2001
>>>  From: Vladimir Pantelic<vladoman@gmail.com>
>>>  Date: Thu, 17 Mar 2011 22:34:52 +0100
>>>  Subject: [PATCH] also subtract preroll when reading ASF simple index object
>>>
>>>  this was missed when ASF was changed to return timestamps
>>>  without preroll.
>>>  ---
>>>   libavformat/asfdec.c |    4 ++--
>>>   1 files changed, 2 insertions(+), 2 deletions(-)
>>>
>>>  diff --git a/libavformat/asfdec.c b/libavformat/asfdec.c
>>>  index 79b3bcb..9f460dd 100644
>>>  --- a/libavformat/asfdec.c
>>>  +++ b/libavformat/asfdec.c
>>>  @@ -1218,10 +1218,10 @@ static void asf_build_simple_index(AVFormatContext *s, int stream_index)
>>>               int pktnum=avio_rl32(s->pb);
>>>               int pktct =avio_rl16(s->pb);
>>>               int64_t pos      = s->data_offset + s->packet_size*(int64_t)pktnum;
>>>  -            int64_t index_pts= av_rescale(itime, i, 10000);
>>>  +            int64_t index_pts= FFMAX(av_rescale(itime, i, 10000) - asf->hdr.preroll, 0);
>>
>> Under what circumstances does this become negative without the FFMAX?
>
> the simple index starts at 0, so with a preroll of e.g. 3000ms the 1st
> 4 index entries (0ms, 1000ms, 2000ms, 3000ms) all point to the same
> packet with timestamp 3000ms.
>
> since we subtract the preroll, we need to do that for the index time
> too and thus the 1st entries all map to 0

Is this intentional and correct?  I sounds totally weird to me.
Vladimir Pantelic March 23, 2011, 11:36 a.m. | #6
Måns Rullgård wrote:
> Vladimir Pantelic<vladoman@gmail.com>  writes:
>
>>  Måns Rullgård wrote:
>>>  Vladimir Pantelic<vladoman@gmail.com>   writes:
>>
>>>>     From 057af717394ec2352d52fa8c1d96f66262da423c Mon Sep 17 00:00:00 2001
>>>>   From: Vladimir Pantelic<vladoman@gmail.com>
>>>>   Date: Thu, 17 Mar 2011 22:34:52 +0100
>>>>   Subject: [PATCH] also subtract preroll when reading ASF simple index object
>>>>
>>>>   this was missed when ASF was changed to return timestamps
>>>>   without preroll.
>>>>   ---
>>>>    libavformat/asfdec.c |    4 ++--
>>>>    1 files changed, 2 insertions(+), 2 deletions(-)
>>>>
>>>>   diff --git a/libavformat/asfdec.c b/libavformat/asfdec.c
>>>>   index 79b3bcb..9f460dd 100644
>>>>   --- a/libavformat/asfdec.c
>>>>   +++ b/libavformat/asfdec.c
>>>>   @@ -1218,10 +1218,10 @@ static void asf_build_simple_index(AVFormatContext *s, int stream_index)
>>>>                int pktnum=avio_rl32(s->pb);
>>>>                int pktct =avio_rl16(s->pb);
>>>>                int64_t pos      = s->data_offset + s->packet_size*(int64_t)pktnum;
>>>>   -            int64_t index_pts= av_rescale(itime, i, 10000);
>>>>   +            int64_t index_pts= FFMAX(av_rescale(itime, i, 10000) - asf->hdr.preroll, 0);
>>>
>>>  Under what circumstances does this become negative without the FFMAX?
>>
>>  the simple index starts at 0, so with a preroll of e.g. 3000ms the 1st
>>  4 index entries (0ms, 1000ms, 2000ms, 3000ms) all point to the same
>>  packet with timestamp 3000ms.
>>
>>  since we subtract the preroll, we need to do that for the index time
>>  too and thus the 1st entries all map to 0
>
> Is this intentional and correct?  I sounds totally weird to me.
>

file: asf_with_chapters.wmv (muxed using M$ tools)

index with old behaviour:

[asf @ 0x8c3d6d0] pktnum:0, pktct:2  pts: 0
[asf @ 0x8c3d6d0] pktnum:0, pktct:2  pts: 1000
[asf @ 0x8c3d6d0] pktnum:0, pktct:2  pts: 2000
[asf @ 0x8c3d6d0] pktnum:0, pktct:2  pts: 3000
[asf @ 0x8c3d6d0] pktnum:1, pktct:5  pts: 4000
[asf @ 0x8c3d6d0] pktnum:1, pktct:5  pts: 5000
[asf @ 0x8c3d6d0] pktnum:122, pktct:5  pts: 6000
[asf @ 0x8c3d6d0] pktnum:122, pktct:5  pts: 7000
[asf @ 0x8c3d6d0] pktnum:257, pktct:6  pts: 8000
[asf @ 0x8c3d6d0] pktnum:257, pktct:6  pts: 9000
...
...

The 1st 4 index entries all point to the same packet
and thus to the same 1st key frame (at 3000ms)

since they all point to the same packet/position,
3 of them are suppressed due to:

     if(pos != last_pos){
         ...
     }


new behaviour:

[asf @ 0x8c3d6d0] pktnum:0, pktct:2  pts: 0
     Last message repeated 3 times
[asf @ 0x8c3d6d0] pktnum:1, pktct:5  pts: 1000
[asf @ 0x8c3d6d0] pktnum:1, pktct:5  pts: 2000
[asf @ 0x8c3d6d0] pktnum:122, pktct:5  pts: 3000
[asf @ 0x8c3d6d0] pktnum:122, pktct:5  pts: 4000
[asf @ 0x8c3d6d0] pktnum:257, pktct:6  pts: 5000
[asf @ 0x8c3d6d0] pktnum:257, pktct:6  pts: 6000
...
...

again, 3 are suppressed.
Mans Rullgard March 23, 2011, 12:51 p.m. | #7
Vladimir Pantelic <vladoman@gmail.com> writes:

> Måns Rullgård wrote:
>> Vladimir Pantelic<vladoman@gmail.com>  writes:
>>
>>>  Måns Rullgård wrote:
>>>>  Vladimir Pantelic<vladoman@gmail.com>   writes:
>>>
>>>>>     From 057af717394ec2352d52fa8c1d96f66262da423c Mon Sep 17 00:00:00 2001
>>>>>   From: Vladimir Pantelic<vladoman@gmail.com>
>>>>>   Date: Thu, 17 Mar 2011 22:34:52 +0100
>>>>>   Subject: [PATCH] also subtract preroll when reading ASF simple index object
>>>>>
>>>>>   this was missed when ASF was changed to return timestamps
>>>>>   without preroll.
>>>>>   ---
>>>>>    libavformat/asfdec.c |    4 ++--
>>>>>    1 files changed, 2 insertions(+), 2 deletions(-)
>>>>>
>>>>>   diff --git a/libavformat/asfdec.c b/libavformat/asfdec.c
>>>>>   index 79b3bcb..9f460dd 100644
>>>>>   --- a/libavformat/asfdec.c
>>>>>   +++ b/libavformat/asfdec.c
>>>>>   @@ -1218,10 +1218,10 @@ static void asf_build_simple_index(AVFormatContext *s, int stream_index)
>>>>>                int pktnum=avio_rl32(s->pb);
>>>>>                int pktct =avio_rl16(s->pb);
>>>>>                int64_t pos      = s->data_offset + s->packet_size*(int64_t)pktnum;
>>>>>   -            int64_t index_pts= av_rescale(itime, i, 10000);
>>>>>   +            int64_t index_pts= FFMAX(av_rescale(itime, i, 10000) - asf->hdr.preroll, 0);
>>>>
>>>>  Under what circumstances does this become negative without the FFMAX?
>>>
>>>  the simple index starts at 0, so with a preroll of e.g. 3000ms the 1st
>>>  4 index entries (0ms, 1000ms, 2000ms, 3000ms) all point to the same
>>>  packet with timestamp 3000ms.
>>>
>>>  since we subtract the preroll, we need to do that for the index time
>>>  too and thus the 1st entries all map to 0
>>
>> Is this intentional and correct?  I sounds totally weird to me.
>>
>
> file: asf_with_chapters.wmv (muxed using M$ tools)
>
> index with old behaviour:
>
> [asf @ 0x8c3d6d0] pktnum:0, pktct:2  pts: 0
> [asf @ 0x8c3d6d0] pktnum:0, pktct:2  pts: 1000
> [asf @ 0x8c3d6d0] pktnum:0, pktct:2  pts: 2000
> [asf @ 0x8c3d6d0] pktnum:0, pktct:2  pts: 3000
> [asf @ 0x8c3d6d0] pktnum:1, pktct:5  pts: 4000
> [asf @ 0x8c3d6d0] pktnum:1, pktct:5  pts: 5000
> [asf @ 0x8c3d6d0] pktnum:122, pktct:5  pts: 6000
> [asf @ 0x8c3d6d0] pktnum:122, pktct:5  pts: 7000
> [asf @ 0x8c3d6d0] pktnum:257, pktct:6  pts: 8000
> [asf @ 0x8c3d6d0] pktnum:257, pktct:6  pts: 9000
> ...
> ...
>
> The 1st 4 index entries all point to the same packet
> and thus to the same 1st key frame (at 3000ms)

What is the point of having 4 index entries for the same packet?

> again, 3 are suppressed.

I'm not doubting that, but I am questioning the correctness of that
behaviour in the first place.  Are those index entries really supposed
to indicate the same packet, or is that libavformat f*cking up?
Vladimir Pantelic March 23, 2011, 1:26 p.m. | #8
Måns Rullgård wrote:
> Vladimir Pantelic<vladoman@gmail.com>  writes:
>
>>  Måns Rullgård wrote:
>>>  Vladimir Pantelic<vladoman@gmail.com>   writes:
>>>
>>>>   Måns Rullgård wrote:
>>>>>   Vladimir Pantelic<vladoman@gmail.com>    writes:
>>>>
>>>>>>       From 057af717394ec2352d52fa8c1d96f66262da423c Mon Sep 17 00:00:00 2001
>>>>>>    From: Vladimir Pantelic<vladoman@gmail.com>
>>>>>>    Date: Thu, 17 Mar 2011 22:34:52 +0100
>>>>>>    Subject: [PATCH] also subtract preroll when reading ASF simple index object
>>>>>>
>>>>>>    this was missed when ASF was changed to return timestamps
>>>>>>    without preroll.
>>>>>>    ---
>>>>>>     libavformat/asfdec.c |    4 ++--
>>>>>>     1 files changed, 2 insertions(+), 2 deletions(-)
>>>>>>
>>>>>>    diff --git a/libavformat/asfdec.c b/libavformat/asfdec.c
>>>>>>    index 79b3bcb..9f460dd 100644
>>>>>>    --- a/libavformat/asfdec.c
>>>>>>    +++ b/libavformat/asfdec.c
>>>>>>    @@ -1218,10 +1218,10 @@ static void asf_build_simple_index(AVFormatContext *s, int stream_index)
>>>>>>                 int pktnum=avio_rl32(s->pb);
>>>>>>                 int pktct =avio_rl16(s->pb);
>>>>>>                 int64_t pos      = s->data_offset + s->packet_size*(int64_t)pktnum;
>>>>>>    -            int64_t index_pts= av_rescale(itime, i, 10000);
>>>>>>    +            int64_t index_pts= FFMAX(av_rescale(itime, i, 10000) - asf->hdr.preroll, 0);
>>>>>
>>>>>   Under what circumstances does this become negative without the FFMAX?
>>>>
>>>>   the simple index starts at 0, so with a preroll of e.g. 3000ms the 1st
>>>>   4 index entries (0ms, 1000ms, 2000ms, 3000ms) all point to the same
>>>>   packet with timestamp 3000ms.
>>>>
>>>>   since we subtract the preroll, we need to do that for the index time
>>>>   too and thus the 1st entries all map to 0
>>>
>>>  Is this intentional and correct?  I sounds totally weird to me.
>>>
>>
>>  file: asf_with_chapters.wmv (muxed using M$ tools)
>>
>>  index with old behaviour:
>>
>>  [asf @ 0x8c3d6d0] pktnum:0, pktct:2  pts: 0
>>  [asf @ 0x8c3d6d0] pktnum:0, pktct:2  pts: 1000
>>  [asf @ 0x8c3d6d0] pktnum:0, pktct:2  pts: 2000
>>  [asf @ 0x8c3d6d0] pktnum:0, pktct:2  pts: 3000
>>  [asf @ 0x8c3d6d0] pktnum:1, pktct:5  pts: 4000
>>  [asf @ 0x8c3d6d0] pktnum:1, pktct:5  pts: 5000
>>  [asf @ 0x8c3d6d0] pktnum:122, pktct:5  pts: 6000
>>  [asf @ 0x8c3d6d0] pktnum:122, pktct:5  pts: 7000
>>  [asf @ 0x8c3d6d0] pktnum:257, pktct:6  pts: 8000
>>  [asf @ 0x8c3d6d0] pktnum:257, pktct:6  pts: 9000
>>  ...
>>  ...
>>
>>  The 1st 4 index entries all point to the same packet
>>  and thus to the same 1st key frame (at 3000ms)
>
> What is the point of having 4 index entries for the same packet?

don't ask me, ask M$

but see here: http://imagebin.org/144532

this is the M$ ASF viewer showing this file that was created with M$ tools.
(it was remuxed by me from an AVI)

>>  again, 3 are suppressed.
>
> I'm not doubting that, but I am questioning the correctness of that
> behaviour in the first place.  Are those index entries really supposed
> to indicate the same packet, or is that libavformat f*cking up?

no, they are like that in the original ASF file. see above.
Mans Rullgard March 23, 2011, 1:45 p.m. | #9
Vladimir Pantelic <vladoman@gmail.com> writes:

> Måns Rullgård wrote:
>> Vladimir Pantelic<vladoman@gmail.com>  writes:
>>
>>>  Måns Rullgård wrote:
>>>>  Vladimir Pantelic<vladoman@gmail.com>   writes:
>>>>
>>>>>   Måns Rullgård wrote:
>>>>>>   Vladimir Pantelic<vladoman@gmail.com>    writes:
>>>>>
>>>>>>>       From 057af717394ec2352d52fa8c1d96f66262da423c Mon Sep 17 00:00:00 2001
>>>>>>>    From: Vladimir Pantelic<vladoman@gmail.com>
>>>>>>>    Date: Thu, 17 Mar 2011 22:34:52 +0100
>>>>>>>    Subject: [PATCH] also subtract preroll when reading ASF simple index object
>>>>>>>
>>>>>>>    this was missed when ASF was changed to return timestamps
>>>>>>>    without preroll.
>>>>>>>    ---
>>>>>>>     libavformat/asfdec.c |    4 ++--
>>>>>>>     1 files changed, 2 insertions(+), 2 deletions(-)
>>>>>>>
>>>>>>>    diff --git a/libavformat/asfdec.c b/libavformat/asfdec.c
>>>>>>>    index 79b3bcb..9f460dd 100644
>>>>>>>    --- a/libavformat/asfdec.c
>>>>>>>    +++ b/libavformat/asfdec.c
>>>>>>>    @@ -1218,10 +1218,10 @@ static void asf_build_simple_index(AVFormatContext *s, int stream_index)
>>>>>>>                 int pktnum=avio_rl32(s->pb);
>>>>>>>                 int pktct =avio_rl16(s->pb);
>>>>>>>                 int64_t pos      = s->data_offset + s->packet_size*(int64_t)pktnum;
>>>>>>>    -            int64_t index_pts= av_rescale(itime, i, 10000);
>>>>>>>    +            int64_t index_pts= FFMAX(av_rescale(itime, i, 10000) - asf->hdr.preroll, 0);
>>>>>>
>>>>>>   Under what circumstances does this become negative without the FFMAX?
>>>>>
>>>>>   the simple index starts at 0, so with a preroll of e.g. 3000ms the 1st
>>>>>   4 index entries (0ms, 1000ms, 2000ms, 3000ms) all point to the same
>>>>>   packet with timestamp 3000ms.
>>>>>
>>>>>   since we subtract the preroll, we need to do that for the index time
>>>>>   too and thus the 1st entries all map to 0
>>>>
>>>>  Is this intentional and correct?  I sounds totally weird to me.
>>>>
>>>
>>>  file: asf_with_chapters.wmv (muxed using M$ tools)
>>>
>>>  index with old behaviour:
>>>
>>>  [asf @ 0x8c3d6d0] pktnum:0, pktct:2  pts: 0
>>>  [asf @ 0x8c3d6d0] pktnum:0, pktct:2  pts: 1000
>>>  [asf @ 0x8c3d6d0] pktnum:0, pktct:2  pts: 2000
>>>  [asf @ 0x8c3d6d0] pktnum:0, pktct:2  pts: 3000
>>>  [asf @ 0x8c3d6d0] pktnum:1, pktct:5  pts: 4000
>>>  [asf @ 0x8c3d6d0] pktnum:1, pktct:5  pts: 5000
>>>  [asf @ 0x8c3d6d0] pktnum:122, pktct:5  pts: 6000
>>>  [asf @ 0x8c3d6d0] pktnum:122, pktct:5  pts: 7000
>>>  [asf @ 0x8c3d6d0] pktnum:257, pktct:6  pts: 8000
>>>  [asf @ 0x8c3d6d0] pktnum:257, pktct:6  pts: 9000
>>>  ...
>>>  ...
>>>
>>>  The 1st 4 index entries all point to the same packet
>>>  and thus to the same 1st key frame (at 3000ms)
>>
>> What is the point of having 4 index entries for the same packet?
>
> don't ask me, ask M$
>
> but see here: http://imagebin.org/144532
>
> this is the M$ ASF viewer showing this file that was created with M$ tools.
> (it was remuxed by me from an AVI)

OK, I'm convinced.  This just sounds so stupid I had to make sure.

Patch OK.

Patch

From 057af717394ec2352d52fa8c1d96f66262da423c Mon Sep 17 00:00:00 2001
From: Vladimir Pantelic <vladoman@gmail.com>
Date: Thu, 17 Mar 2011 22:34:52 +0100
Subject: [PATCH] also subtract preroll when reading ASF simple index object

this was missed when ASF was changed to return timestamps
without preroll.
---
 libavformat/asfdec.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/asfdec.c b/libavformat/asfdec.c
index 79b3bcb..9f460dd 100644
--- a/libavformat/asfdec.c
+++ b/libavformat/asfdec.c
@@ -1218,10 +1218,10 @@  static void asf_build_simple_index(AVFormatContext *s, int stream_index)
             int pktnum=avio_rl32(s->pb);
             int pktct =avio_rl16(s->pb);
             int64_t pos      = s->data_offset + s->packet_size*(int64_t)pktnum;
-            int64_t index_pts= av_rescale(itime, i, 10000);
+            int64_t index_pts= FFMAX(av_rescale(itime, i, 10000) - asf->hdr.preroll, 0);
 
             if(pos != last_pos){
-            av_log(s, AV_LOG_DEBUG, "pktnum:%d, pktct:%d\n", pktnum, pktct);
+            av_log(s, AV_LOG_DEBUG, "pktnum:%d, pktct:%d  pts: %"PRId64"\n", pktnum, pktct, index_pts);
             av_add_index_entry(s->streams[stream_index], pos, index_pts, s->packet_size, 0, AVINDEX_KEYFRAME);
             last_pos=pos;
             }
-- 
1.6.0.2