[FFmpeg-devel] [PATCH] lavfi: add duration field to AVFilterBufferRef

Stefano Sabatini stefasab at gmail.com
Thu Aug 2 12:17:48 CEST 2012


On date Tuesday 2012-07-31 15:53:19 +0200, Michael Niedermayer encoded:
> On Mon, Jul 30, 2012 at 07:20:32PM +0200, Nicolas George wrote:
> > Le tridi 13 thermidor, an CCXX, Stefano Sabatini a écrit :
> > > ---
> > >  libavfilter/audio.c       |    1 +
> > >  libavfilter/avcodec.c     |    2 ++
> > >  libavfilter/avfilter.h    |    7 +++++++
> > >  libavfilter/buffer.c      |    1 +
> > >  libavfilter/f_settb.c     |   10 ++++++----
> > >  libavfilter/vf_showinfo.c |    6 ++++--
> > >  6 files changed, 21 insertions(+), 6 deletions(-)
> > 
> > I must say, after some thought since last time it was suggested, I am not
> > completely sure it is such a good idea.
> 
> duration is neccessary for low latency frame rate changing filters.
> i think the filter framework would be a joke if it couldnt do that.
> 
> 
> > 
> > What happens with filters such as select? Is it supposed to wait for the
> > next accepted frame in order to adjust the duration?
> 
> not really relevant.
> select can set duration = N/A, thats just what it does ATM
> improving select beyond that becomes possible if duration is available
> also its easy to add a flag to inputs that says need_duration and let
> the avfilter core then buffer one frame to get the duration if its
> not available
> 
> 
> > 
> > And what if the duration and the next timestamp are inconsistent?
> 
> undefined behavior and there could be a filter that corrects such
> inconsistencies in a consistent way
> 
> 
> > 
> > This is not an easy issue.
> 
> no but IMHO not adding information because its too hard to use it in all
> cases is the worse.
> A filter can alway just not look at a field if it doesnt want to

OK, so trying to resume all the answers:

- we should add a duration field to AVFilterBufferRef
- it should be a common field, that is it should be used by
  audio/video/subtitles
- it should accept a value of 0

My main problem right now is how to propagate this information
lavc<->lavfi, or in other words from AVFrame to AVFilterBufferRef.

Currently the only *explicit* duration information in AVFrame is the
one contained in pkt_duration, which makes sense only for video frames
(and possibly subtitles?), and for which a value of 0 means
"undefined".

Now this field is meaningless for audio frames, so when I need to move
the information from AVFrame->AVFilterBufferRef I could simply use
the nb_samples information and compute:
duration = av_rescale_q(nb_samples, (AVRational){1, sample_rate}, time_base);

the problem is that *time_base information is not available in
AVFrame*. Indeed when we copy the information from AVFrame ->
AVFilterBufferRef we assume that AVFrame.pts is expressed with the
same timebase as AVFilterBufferRef.pts.

The other problem with this approach is that we lost the audio
duration information again when we do AVFilterBufferRef -> AVFrame.

So my proposal is to extend AVFrame with a duration field, expressed
as a number of units in the assumed time_base, and accepting the value
0, and unspecified is AV_NOVALUE_PTS.
-- 
FFmpeg = Funny & Friendly Mysterious Perfectionist Evangelical Gospel


More information about the ffmpeg-devel mailing list