[FFmpeg-devel] [PATCH] Only using st->parser->pos when doing repacking in the parser.

Reimar Döffinger Reimar.Doeffinger at gmx.de
Mon Apr 25 00:34:12 CEST 2011


On Sun, Apr 24, 2011 at 11:50:15PM +0200, Reimar Döffinger wrote:
> On Sun, Apr 24, 2011 at 11:28:42PM +0200, Michael Niedermayer wrote:
> > On Sun, Apr 24, 2011 at 06:17:14PM +0200, Reimar Döffinger wrote:
> > > ---
> > >  libavformat/utils.c |    6 +++++-
> > >  1 files changed, 5 insertions(+), 1 deletions(-)
> > > 
> > > diff --git a/libavformat/utils.c b/libavformat/utils.c
> > > index e7ce911..d2b8fc2 100644
> > > --- a/libavformat/utils.c
> > > +++ b/libavformat/utils.c
> > > @@ -1069,7 +1069,11 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt)
> > >                      pkt->stream_index = st->index;
> > >                      pkt->pts = st->parser->pts;
> > >                      pkt->dts = st->parser->dts;
> > > -                    pkt->pos = st->parser->pos;
> > > +                    // When not repacking, using parser pos can at best break
> > > +                    // things since parsers are not designed to handle the
> > > +                    // case where current packet pos + size < next packet pos
> > > +                    if (st->needs_parsing == AVSTREAM_PARSE_FULL)
> > > +                        pkt->pos = st->parser->pos;
> > 
> > i think this should also check for AVSTREAM_PARSE_TIMESTAMPS
> 
> Hm, I think it might make most sense to check for
> st->parser->flags & PARSER_FLAG_COMPLETE_FRAMES

Doesn't work, causes the pos to be too far ahead for
DNXHD.
Below seems to work for using generic index with
electronicarts demuxer while not changing any
of the regression tests.
Does it look sensible?
It basically ensures that the whole delay etc. logic
e.g. when switching to/from PARSER_FLAG_COMPLETE_FRAMES
is still used, but it also ensures that for the complete
frames case we only ever use exact packet start/end positions,
even if they are not consecutive.
diff --git a/libavcodec/parser.c b/libavcodec/parser.c
index c1c8ce2..10d3a69 100644
--- a/libavcodec/parser.c
+++ b/libavcodec/parser.c
@@ -115,7 +115,8 @@ int av_parser_parse2(AVCodecParserContext *s,
     int index, i;
     uint8_t dummy_buf[FF_INPUT_BUFFER_PADDING_SIZE];
 
-    if(!(s->flags & PARSER_FLAG_FETCHED_OFFSET)) {
+    if(!(s->flags & PARSER_FLAG_FETCHED_OFFSET) ||
+       s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
         s->next_frame_offset =
         s->cur_offset        = pos;
         s->flags |= PARSER_FLAG_FETCHED_OFFSET;


More information about the ffmpeg-devel mailing list