[FFmpeg-devel] Writing filters

Clément Bœsch u at pkh.me
Wed Jun 11 15:15:07 CEST 2014


On Wed, Jun 11, 2014 at 03:02:46PM +0200, James Darnley wrote:
> While I appreciate the effort someone put into doc/writing_filters.txt
> it still doesn't go far enough for me to understand enough for what I
> want to do, namely an A->V filter.
> 
> It (doc/writing_filters.txt) is based on a one-in-one-out video filter
> (edgedetect) so it doesn't need to explain some of the more
> "interesting" functions.  It only has to explain filter_frame which, I
> think, is fairly simple in concept: it is called by the previous filter
> and itself calls the next filter's filter_frame, indirectly though
> ff_filter_frame (I think).
> 
> While looking at some of the vsrc and other avf filters, I see that some
> use filter_frame, some use request_frame, and some use both.
> 

Yes, request_frame() is still a bit magic to me so I didn't feel
comfortable explaining it.

> I believe request frame works in the other direction: it gets called
> from the next filter, does whatever it needs to and then "returns".  I'm
> sure you can see that I don't understand this quite as well.  Its use in
> mandelbrot is obvious, it draws the picture then calls ff_filter_frame
> to send the image along the chain.
> 
> What I don't understand is: why some filters use both; how they use both
> and how data gets from the input to the output; and when I (or another
> user) should use both.
> 
> I see that request_frame in showwaves and showspectrum run request_frame
> in a loop until "something" happens (they actually set a var in their
> context) but, their flow is obscured by an inline push_frame function
> which calls ff_filter_frame.  This looks like it should result in the
> same frame going to the next filter twice over.
> 
> What adds to my confusion is that avectorscope doesn't use both, it uses
> only filter_frame.
> 

It's important to note that the API evolved quite a bit since the
beginning. I *think* we can avoid request_frame in various cases nowadays
with the help of FF_LINK_FLAG_REQUEST_LOOP.

Nicolas or Stefano can probably give more insight.

Also look at doc/filter_design.txt. It's definitely outdated but the
request_frame() part might give you some insight.

> I guess my ultimate questions are:
> 
> Is my understanding how filter_frame and request_frame correct?
> 
> If necessary, can someone explain in more detail the difference between
> filter_frame and request_frame?
> 
> Why do some filters, particularly showwaves and showspectrum, use both
> filter_frame and request_frame?  Why does avectorscope not?
> 
> How do frames flow though showwaves and showspectrum?
> 
> If not already explained, when should a filter use both or not use both
> filter_frame and request_frame?
> 

> I appreciate any insights people can give.  Anything I learn, I will try
> to add to existing docs.

I'd love that :)

> 
> One final thought, I hope my problems aren't coming from how I am trying
> to run the filter:
> > ffmpeg -f lavfi -i 'amovie=temp.flac,asplit[out0],jd=rate=60[out1]' -y tempabc.mkv

You could use ffmpeg -i temp.flac -filter_complex 'asplit ...'

... but it's good to test with amovie as well, because the request/push
behaviour is kind of different iirc.

[...]

-- 
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140611/079c6715/attachment.asc>


More information about the ffmpeg-devel mailing list