[FFmpeg-devel] [PATCH] ivfdec/ivfenc: Match behaviour of libvpx and chromium

Calvin Walton calvin.walton at kepstin.ca
Tue Oct 1 21:43:02 EEST 2019


On Tue, 2019-10-01 at 15:26 -0300, James Almer wrote:
> On 10/1/2019 2:56 PM, Calvin Walton wrote:
> >  libavformat/ivfdec.c |  3 ++-
> >  libavformat/ivfenc.c | 11 ++++-------
> >  2 files changed, 6 insertions(+), 8 deletions(-)
> > 
> > diff --git a/libavformat/ivfdec.c b/libavformat/ivfdec.c
> > index 40ae464b76..2eaa5164ff 100644
> > --- a/libavformat/ivfdec.c
> > +++ b/libavformat/ivfdec.c
> > @@ -53,7 +53,8 @@ static int read_header(AVFormatContext *s)
> >      st->codecpar->height     = avio_rl16(s->pb);
> >      time_base.den         = avio_rl32(s->pb);
> >      time_base.num         = avio_rl32(s->pb);
> > -    st->duration          = avio_rl64(s->pb);
> > +    st->nb_frames         = avio_rl32(s->pb);
> 
> The demuxer will report N/A as duration after this.

This is intentional, as the container format doesn't have a duration
field, only a frame count. I suppose it might be possible to estimate a
duration by probing the file to guess the average framerate, and then
dividing the frame count by the framerate - but I'm not familiar with
how that could be done in the demuxer

> >          size_t end = avio_tell(pb);
> >  
> >          avio_seek(pb, 24, SEEK_SET);
> > -        avio_wl64(pb, ctx->frame_cnt * ctx->sum_delta_pts / (ctx-
> > >frame_cnt - 1));
> > +        avio_wl32(pb, ctx->frame_cnt);
> >          avio_seek(pb, end, SEEK_SET);
> >      }
> 
> Similarly, old versions of the ivf demuxer will read bogus duration
> values after this change.

Old versions of the ivf demuxer read bogus duration values for files
generated by vpxenc in the case where the timebase is something other
than 1/framerate (i think this can happen if a timebase is manually set
or if a fractional framerate is used) or if the file is vfr (I'm not
sure if vpxenc can generate vfr files).


-- 
Calvin Walton <calvin.walton at kepstin.ca>



More information about the ffmpeg-devel mailing list