[FFmpeg-devel] [PATCH] libavfilter-soc: Make overlay handle still images

Martin Storsjö martin
Thu May 7 21:45:53 CEST 2009

Hi Vitor,

On Wed, 6 May 2009, Vitor Sessak wrote:

> Just a question: how are you testing those changes?

I'm testing it with the following command line:

ffplay in.mov -vfilters "movie=0:png:overlay.png, scale=0:0 [over1], [in] [over1] overlay=10:10 [out]"

and similarly with ffmpeg.

> > +        oldpts = over->pics[idx][1]->pts;
> >          if(avfilter_request_frame(link->src->inputs[idx]))
> >              return -1;
> > +        if(over->pics[idx][1]->pts == oldpts) {
> > +            /* no new pts, we're probably at eof, pull a frame
> > +               from the other queue to keep it moving */
> The correct way to know if the video is over is to check if request_frame()
> returned -1.

That was my initial guess, too, but the movie source filter provides the 
last frame repeatedly instead of returning -1.

This can easily be fixed by the first attached patch. (It contains checks 
both before and after movie_get_frame, to avoid unnecessary calls to the 
underlying layers after reaching eof.)

When this is applied, the eof handling in the overlay filter can be fixed 
in a few other ways, named -overlay-eof2 and 4.

The first one, -eof2, alters the frame pulling logic only slightly. The 
request_frame function returns -1 when unable to pull frames from both 
streams. Since a stream may contain only one frame, it requires the image 
copying to try to check over->pics[idx][1] if over->pics[idx][0] is null.

The second way of solving it, -eof4, moves the last frame from 
over->pics[idx][1] into over->pics[idx][0] by a 
start_frame(link->src->inputs[idx], NULL) if there still is a frame in 
over->pics[idx][1]. This way, all input frames should be output too. (In 
the original overlay filter logic, the last input frame wouldn't be 

Do these look sensible?

This doesn't really address all issues in the overlay filter, but is at 
least a step in the right direction, and fixes the eof issue for me.

// Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: libavfilter-soc-movie-eof.patch
Type: text/x-diff
Size: 498 bytes
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090507/a9fbd958/attachment.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: libavfilter-soc-overlay-eof2.patch
Type: text/x-diff
Size: 3198 bytes
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090507/a9fbd958/attachment-0001.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: libavfilter-soc-overlay-eof4.patch
Type: text/x-diff
Size: 2254 bytes
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090507/a9fbd958/attachment-0002.patch>

More information about the ffmpeg-devel mailing list