[FFmpeg-devel] [PATCH] compute chapters end
Aurelien Jacobs
aurel
Sat May 24 23:45:20 CEST 2008
On Sat, 24 May 2008 17:21:20 +0200
Michael Niedermayer <michaelni at gmx.at> wrote:
> On Sat, May 24, 2008 at 04:13:17PM +0200, Aurelien Jacobs wrote:
> > On Sat, 24 May 2008 16:01:21 +0200
> > Aurelien Jacobs <aurel at gnuage.org> wrote:
> >
> > > Hi,
> > >
> > > Attached patch will compute the end of all chapters when end
> > > is not specified in the container.
> >
> > Oh, and here is a version which won't segfault when no chapters
> > are present.
> >
> > Aurel
>
> > Index: libavformat/utils.c
> > ===================================================================
> > --- libavformat/utils.c (revision 13280)
> > +++ libavformat/utils.c (working copy)
> > @@ -1805,6 +1805,20 @@
> > return CODEC_ID_NONE;
> > }
> >
> > +static void compute_chapters_end(AVFormatContext *s)
> > +{
> > + unsigned int i;
> > +
> > + for (i=0; i+1<s->nb_chapters; i++)
> > + if (s->chapters[i]->end == AV_NOPTS_VALUE)
> > + s->chapters[i]->end = s->chapters[i+1]->start;
> > +
> > + if (s->nb_chapters && s->chapters[i]->end == AV_NOPTS_VALUE)
> > + s->chapters[i]->end = av_rescale_q(s->start_time + s->duration,
> > + AV_TIME_BASE_Q,
> > + s->chapters[i]->time_base);
> > +}
>
> This needs a few asserts
> s->chapters[i]->start <= s->chapters[i+1]->start
> s->chapters[i]->time_base == s->chapters[i+1]->time_base
> s->start_time != AV_NOPTS_VALUE
> s->duration>0
>
> I assume these are guranteed to be true whenever end == AV_NOPTS_VALUE
> currently, the asserts() would ensure that future changes dont lead to
> hard to debug issues.
Good idea indeed.
Patch applied with asserts.
Aurel
More information about the ffmpeg-devel
mailing list