[FFmpeg-devel] [PATCH] Base parser frame_offset on correct packet pos.
Reimar Döffinger
Reimar.Doeffinger at gmx.de
Sun Apr 10 01:25:20 CEST 2011
The current code only works if the next buffer starts directly
after the previous one in the file. For formats with some sort
of framing that is not necessarily the case.
Without this change, GENERIC_INDEX with needs_parsing and framing
that causes the stream to be non-consecutive results in a broken
index being generated.
This is probably also a bug in the generic index code, it probably
should ignore the parser output and instead always seek to some
pkt->pos, or at the very least only use it when full parsing is requested.
---
libavcodec/parser.c | 8 ++++++++
tests/ref/seek/lavf_asf | 12 ++++++------
2 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/libavcodec/parser.c b/libavcodec/parser.c
index 34659b7..7507f76 100644
--- a/libavcodec/parser.c
+++ b/libavcodec/parser.c
@@ -157,6 +157,8 @@ int av_parser_parse2(AVCodecParserContext *s,
s->cur_offset = pos;
s->flags |= PARSER_FLAG_FETCHED_OFFSET;
}
+ if (s->cur_offset == -1)
+ s->cur_offset = pos;
if (buf_size == 0) {
/* padding is always necessary even if EOF, so we add it here */
@@ -197,6 +199,12 @@ int av_parser_parse2(AVCodecParserContext *s,
if (index < 0)
index = 0;
s->cur_offset += index;
+ // next frame offsets are based next packet start
+ if (buf_size && index == buf_size) {
+ s->cur_offset = -1;
+ if (*poutbuf_size)
+ s->flags &= ~PARSER_FLAG_FETCHED_OFFSET;
+ }
return index;
}
diff --git a/tests/ref/seek/lavf_asf b/tests/ref/seek/lavf_asf
index 757fd0e..8756052 100644
--- a/tests/ref/seek/lavf_asf
+++ b/tests/ref/seek/lavf_asf
@@ -1,6 +1,6 @@
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 575 size: 28487
ret: 0 st:-1 flags:0 ts:-1.000000
-ret: 0 st: 1 flags:1 dts: 0.444000 pts: 0.444000 pos: 147775 size: 209
+ret: 0 st: 1 flags:1 dts: 0.480000 pts: 0.480000 pos: -1 size: 209
ret: 0 st:-1 flags:1 ts: 1.894167
ret: 0 st: 1 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size: 209
ret: 0 st: 0 flags:0 ts: 0.788000
@@ -10,7 +10,7 @@ ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 575 size: 28487
ret:-1 st: 1 flags:0 ts: 2.577000
ret:-1 st: 1 flags:1 ts: 1.471000
ret: 0 st:-1 flags:0 ts: 0.365002
-ret: 0 st: 1 flags:1 dts: 0.444000 pts: 0.444000 pos: 147775 size: 209
+ret: 0 st: 1 flags:1 dts: 0.480000 pts: 0.480000 pos: -1 size: 209
ret: 0 st:-1 flags:1 ts:-0.740831
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 575 size: 28487
ret: 0 st: 0 flags:0 ts: 2.153000
@@ -18,19 +18,19 @@ ret: 0 st: 1 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size: 209
ret: 0 st: 0 flags:1 ts: 1.048000
ret: 0 st: 1 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size: 209
ret: 0 st: 1 flags:0 ts:-0.058000
-ret: 0 st: 1 flags:1 dts: 0.000000 pts: 0.000000 pos: 29375 size: 208
+ret: 0 st: 1 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size: 208
ret:-1 st: 1 flags:1 ts: 2.836000
ret: 0 st:-1 flags:0 ts: 1.730004
ret: 0 st: 1 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size: 209
ret: 0 st:-1 flags:1 ts: 0.624171
-ret: 0 st: 1 flags:1 dts: 0.444000 pts: 0.444000 pos: 147775 size: 209
+ret: 0 st: 1 flags:1 dts: 0.480000 pts: 0.480000 pos: -1 size: 209
ret: 0 st: 0 flags:0 ts:-0.482000
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 575 size: 28487
ret: 0 st: 0 flags:1 ts: 2.413000
ret: 0 st: 1 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size: 209
ret:-1 st: 1 flags:0 ts: 1.307000
ret: 0 st: 1 flags:1 ts: 0.201000
-ret: 0 st: 1 flags:1 dts: 0.183000 pts: 0.183000 pos: 70975 size: 209
+ret: 0 st: 1 flags:1 dts: 0.183000 pts: 0.183000 pos: -1 size: 209
ret: 0 st:-1 flags:0 ts:-0.904994
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 575 size: 28487
ret: 0 st:-1 flags:1 ts: 1.989173
@@ -42,6 +42,6 @@ ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 575 size: 28487
ret:-1 st: 1 flags:0 ts: 2.672000
ret:-1 st: 1 flags:1 ts: 1.566000
ret: 0 st:-1 flags:0 ts: 0.460008
-ret: 0 st: 1 flags:1 dts: 0.444000 pts: 0.444000 pos: 147775 size: 209
+ret: 0 st: 1 flags:1 dts: 0.480000 pts: 0.480000 pos: -1 size: 209
ret: 0 st:-1 flags:1 ts:-0.645825
ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 575 size: 28487
--
1.7.4.1
More information about the ffmpeg-devel
mailing list