[FFmpeg-devel] [PATCH] Support for variable frame duration

Henrik Gulbrandsen henrik
Sat Apr 26 09:21:04 CEST 2008


On Wed, 2008-04-23 at 00:19 +0200, Baptiste Coudurier wrote:
> Hi,
> 
> Henrik Gulbrandsen wrote:
> > [...]
> > 
> > Index: libavformat/mov.c
> > ===================================================================
> > --- libavformat/mov.c	(revision 12920)
> > +++ libavformat/mov.c	(working copy)
> > @@ -1729,6 +1729,8 @@ static int mov_read_packet(AVFormatConte
> >      MOVStreamContext *sc = 0;
> >      AVIndexEntry *sample = 0;
> >      int64_t best_dts = INT64_MAX;
> > +    int64_t next_dts = 0;
> > +    int next_index;
> >      int i;
> >   retry:
> >      for (i = 0; i < s->nb_streams; i++) {
> > @@ -1747,6 +1749,10 @@ static int mov_read_packet(AVFormatConte
> >                  sample = current_sample;
> >                  best_dts = dts;
> >                  sc = msc;
> > +
> > +                next_index = msc->current_sample + 1;
> > +                next_dts = (next_index < msc->sample_count)?
> > +                    st->index_entries[next_index].timestamp : st->duration;
> >              }
> >          }
> >      }
> > @@ -1790,6 +1796,7 @@ static int mov_read_packet(AVFormatConte
> >          }
> >      } else {
> >          pkt->pts = pkt->dts;
> > +        pkt->duration = next_dts - pkt->dts;
> >      }
> >      pkt->flags |= sample->flags & AVINDEX_KEYFRAME ? PKT_FLAG_KEY : 0;
> >      pkt->pos = sample->pos;
> > 
> 
> Better to get duration at the end when needed, thus removing computation
> from the loop. Besides idea is ok.

I think I may be missing your point. The only loop here iterates over
about two streams, so it's not like there is a performance issue, and
the next_dts computation is where it is because that's where sample is
determined in the first place. As far as I can see, there's no AVStream
reference in MOVStreamContext, so I would have to save st in order to
perform the computation outside the loop. Wouldn't this just introduce
an unneeded variable and make the code harder to read?

/Henrik

-------------- next part --------------
A non-text attachment was scrubbed...
Name: video_duration_mov_2.patch
Type: text/x-patch
Size: 1108 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20080426/ca2e6c51/attachment.bin>



More information about the ffmpeg-devel mailing list