Libavfilter RFC: problem with ffmpeg.c/ffplay.c integration
Hi all, I've spotted a problem with the ffmpeg.c integration using the command ffmpeg -vfilters fps=1 -i input.avi output.avi In the way the integration is done in ffmpeg.c (my fault, I know), the filter infrastructure expects one input frame for every output frame. But that is not right for all filters. FFplay is also affected by this problem (although it's harder to reproduce, I didn't found a test case), it has a video queue and a filter will not work properly if the queue is empty. The root of the problem is that in the way libavfilter is designed, libavfilter must ask ffmpeg.c/ffplay.c every time it wants a frame, no matter how (if any) frame was outputted by the filter chain. I've thought in a few solutions: Solution 1 (the closest to the actual code): In the patch in soc svn, a input filter is defined in ffmpeg.c. A solution would be to move the call to av_read_frame and avcodec_decode_video to the request_frame method of the input filter, so it'll decode a video frame from the file each time the filter asks for one. Problem: Messy, ugly to handle audio and -vcodec copy, makes ffmpeg.c even more complex than it is already, scare people away of using libavfilter in other applications. Solution 2 (threading and queuing): Make ffmpeg.c have a thread for audio decoding, another one for video and another for filtering. The video thread will add frames to a video queue and the filtering thread will sleep and wait for frames is the video queue is empty. Problem: May introduce bugs, big patch, gives the impression that it is impossible to use libavfilter in a single-threaded application. There may also be corner cases where the queues gets too big and uses gigs of ram. Solution 3 (change libavfilter): Allow avfilter_request_frame to give a positive value if it outputs a frame, a negative one if error or end of video and zero if it has no frame to output be may have one latter. Then make a small video queue and just make the request_frame of the input filter return 0 if the queue is empty. The advantage is that it'll be easier to use it as a library and will not increase too much the complexity of ffmpeg.c/ffplay.c. Problem: Every video filter will have to handle the case where the previous filter do not have a frame now but may have latter... What is your opinion on that? -Vitor
On Wed, Jan 02, 2008 at 12:49:24PM +0100, Vitor Sessak wrote:
Hi all,
I've spotted a problem with the ffmpeg.c integration using the command
ffmpeg -vfilters fps=1 -i input.avi output.avi
In the way the integration is done in ffmpeg.c (my fault, I know), the filter infrastructure expects one input frame for every output frame. But that is not right for all filters. FFplay is also affected by this problem (although it's harder to reproduce, I didn't found a test case), it has a video queue and a filter will not work properly if the queue is empty.
The root of the problem is that in the way libavfilter is designed, libavfilter must ask ffmpeg.c/ffplay.c every time it wants a frame, no matter how (if any) frame was outputted by the filter chain.
I've thought in a few solutions:
Solution 1 (the closest to the actual code):
In the patch in soc svn, a input filter is defined in ffmpeg.c. A solution would be to move the call to av_read_frame and avcodec_decode_video to the request_frame method of the input filter, so it'll decode a video frame from the file each time the filter asks for one.
Problem: Messy, ugly to handle audio and -vcodec copy, makes ffmpeg.c even more complex than it is already, scare people away of using libavfilter in other applications.
APIs aside, theres an additional problem the source can be from the network or a v4l card and av_read_frame() could just tell you "i dont have a frame yet, go and do something else usefull" aka EAGAIN (current ffmpeg.c doesnt support it but i think we shouldnt ignore it in the design ...) also its possible to have more than 1 video stream in a file and av_read_frame might return stuff for the "wrong" stream when asked for the next frame ...
Solution 2 (threading and queuing):
Make ffmpeg.c have a thread for audio decoding, another one for video and another for filtering. The video thread will add frames to a video queue and the filtering thread will sleep and wait for frames is the video queue is empty.
Problem: May introduce bugs, big patch, gives the impression that it is impossible to use libavfilter in a single-threaded application. There may also be corner cases where the queues gets too big and uses gigs of ram.
id like to keep threads optional, not mandatory if possible for core functionality [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Many that live deserve death. And some that die deserve life. Can you give it to them? Then do not be too eager to deal out death in judgement. For even the very wise cannot see all ends. -- Gandalf
Hello, On 02/01/2008, Michael Niedermayer <michaelni@gmx.at> wrote:
On Wed, Jan 02, 2008 at 12:49:24PM +0100, Vitor Sessak wrote:
I've thought in a few solutions:
Solution 1 (the closest to the actual code):
In the patch in soc svn, a input filter is defined in ffmpeg.c. A solution would be to move the call to av_read_frame and avcodec_decode_video to the request_frame method of the input filter, so it'll decode a video frame from the file each time the filter asks for one.
Problem: Messy, ugly to handle audio and -vcodec copy, makes ffmpeg.c even more complex than it is already, scare people away of using libavfilter in other applications.
APIs aside, theres an additional problem the source can be from the network or a v4l card and av_read_frame() could just tell you "i dont have a frame yet, go and do something else usefull" aka EAGAIN (current ffmpeg.c doesnt support it but i think we shouldnt ignore it in the design ...)
also its possible to have more than 1 video stream in a file and av_read_frame might return stuff for the "wrong" stream when asked for the next frame ...
Solution 2 (threading and queuing):
Make ffmpeg.c have a thread for audio decoding, another one for video and another for filtering. The video thread will add frames to a video queue and the filtering thread will sleep and wait for frames is the video queue is empty.
Problem: May introduce bugs, big patch, gives the impression that it is impossible to use libavfilter in a single-threaded application. There may also be corner cases where the queues gets too big and uses gigs of ram.
id like to keep threads optional, not mandatory if possible for core functionality
Is solution 3 not an option or do you just have no opinion on that at the moment? Regards, Rob
On Wed, Jan 02, 2008 at 02:27:43PM +0000, Robert Swain wrote:
Hello,
On 02/01/2008, Michael Niedermayer <michaelni@gmx.at> wrote:
On Wed, Jan 02, 2008 at 12:49:24PM +0100, Vitor Sessak wrote:
I've thought in a few solutions:
Solution 1 (the closest to the actual code):
In the patch in soc svn, a input filter is defined in ffmpeg.c. A solution would be to move the call to av_read_frame and avcodec_decode_video to the request_frame method of the input filter, so it'll decode a video frame from the file each time the filter asks for one.
Problem: Messy, ugly to handle audio and -vcodec copy, makes ffmpeg.c even more complex than it is already, scare people away of using libavfilter in other applications.
APIs aside, theres an additional problem the source can be from the network or a v4l card and av_read_frame() could just tell you "i dont have a frame yet, go and do something else usefull" aka EAGAIN (current ffmpeg.c doesnt support it but i think we shouldnt ignore it in the design ...)
also its possible to have more than 1 video stream in a file and av_read_frame might return stuff for the "wrong" stream when asked for the next frame ...
Solution 2 (threading and queuing):
Make ffmpeg.c have a thread for audio decoding, another one for video and another for filtering. The video thread will add frames to a video queue and the filtering thread will sleep and wait for frames is the video queue is empty.
Problem: May introduce bugs, big patch, gives the impression that it is impossible to use libavfilter in a single-threaded application. There may also be corner cases where the queues gets too big and uses gigs of ram.
id like to keep threads optional, not mandatory if possible for core functionality
Is solution 3 not an option or do you just have no opinion on that at the moment?
no opinion, as ive not investigated the effects of the proposed change fully ... [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Republics decline into democracies and democracies degenerate into despotisms. -- Aristotle
On Wed, 02 Jan 2008 12:49:24 +0100 Vitor Sessak <vitor1001@gmail.com> wrote:
Hi all,
I've spotted a problem with the ffmpeg.c integration using the command
ffmpeg -vfilters fps=1 -i input.avi output.avi
In the way the integration is done in ffmpeg.c (my fault, I know), the filter infrastructure expects one input frame for every output frame. But that is not right for all filters. FFplay is also affected by this problem (although it's harder to reproduce, I didn't found a test case), it has a video queue and a filter will not work properly if the queue is empty.
The root of the problem is that in the way libavfilter is designed, libavfilter must ask ffmpeg.c/ffplay.c every time it wants a frame, no matter how (if any) frame was outputted by the filter chain.
I've thought in a few solutions:
Solution 1 (the closest to the actual code):
In the patch in soc svn, a input filter is defined in ffmpeg.c. A solution would be to move the call to av_read_frame and avcodec_decode_video to the request_frame method of the input filter, so it'll decode a video frame from the file each time the filter asks for one.
Problem: Messy, ugly to handle audio and -vcodec copy, makes ffmpeg.c even more complex than it is already, scare people away of using libavfilter in other applications.
Solution 2 (threading and queuing):
Make ffmpeg.c have a thread for audio decoding, another one for video and another for filtering. The video thread will add frames to a video queue and the filtering thread will sleep and wait for frames is the video queue is empty.
Problem: May introduce bugs, big patch, gives the impression that it is impossible to use libavfilter in a single-threaded application. There may also be corner cases where the queues gets too big and uses gigs of ram.
Solution 3 (change libavfilter):
Allow avfilter_request_frame to give a positive value if it outputs a frame, a negative one if error or end of video and zero if it has no frame to output be may have one latter. Then make a small video queue and just make the request_frame of the input filter return 0 if the queue is empty. The advantage is that it'll be easier to use it as a library and will not increase too much the complexity of ffmpeg.c/ffplay.c.
Problem: Every video filter will have to handle the case where the previous filter do not have a frame now but may have latter...
What is your opinion on that?
I'll take a closer look at this tonight, but I think solution 3 sounds reasonable.
-Vitor
-- Bobby Bingham Never trust atoms. Or anything made of atoms. このメールは再利用されたバイトでできている。
On Wed, Jan 02, 2008 at 10:00:26AM -0500, Bobby Bingham wrote:
On Wed, 02 Jan 2008 12:49:24 +0100 Vitor Sessak <vitor1001@gmail.com> wrote:
Hi all,
I've spotted a problem with the ffmpeg.c integration using the command
ffmpeg -vfilters fps=1 -i input.avi output.avi
In the way the integration is done in ffmpeg.c (my fault, I know), the filter infrastructure expects one input frame for every output frame. But that is not right for all filters. FFplay is also affected by this problem (although it's harder to reproduce, I didn't found a test case), it has a video queue and a filter will not work properly if the queue is empty.
The root of the problem is that in the way libavfilter is designed, libavfilter must ask ffmpeg.c/ffplay.c every time it wants a frame, no matter how (if any) frame was outputted by the filter chain.
I've thought in a few solutions:
Solution 1 (the closest to the actual code):
In the patch in soc svn, a input filter is defined in ffmpeg.c. A solution would be to move the call to av_read_frame and avcodec_decode_video to the request_frame method of the input filter, so it'll decode a video frame from the file each time the filter asks for one.
Problem: Messy, ugly to handle audio and -vcodec copy, makes ffmpeg.c even more complex than it is already, scare people away of using libavfilter in other applications.
Solution 2 (threading and queuing):
Make ffmpeg.c have a thread for audio decoding, another one for video and another for filtering. The video thread will add frames to a video queue and the filtering thread will sleep and wait for frames is the video queue is empty.
Problem: May introduce bugs, big patch, gives the impression that it is impossible to use libavfilter in a single-threaded application. There may also be corner cases where the queues gets too big and uses gigs of ram.
Solution 3 (change libavfilter):
Allow avfilter_request_frame to give a positive value if it outputs a frame, a negative one if error or end of video and zero if it has no frame to output be may have one latter. Then make a small video queue and just make the request_frame of the input filter return 0 if the queue is empty. The advantage is that it'll be easier to use it as a library and will not increase too much the complexity of ffmpeg.c/ffplay.c.
Problem: Every video filter will have to handle the case where the previous filter do not have a frame now but may have latter...
What is your opinion on that?
I'll take a closer look at this tonight, but I think solution 3 sounds reasonable.
As nothing has been commited yet to solve this IIRC ... what about /** * Frame poll callback. This returns the number of immedeately available * frames. That is if it returns 1 or larger than the next request_frame() * is guranteed to return one frame (with no delay) * * Output video pads only. */ int (*poll_frame)(AVFilterLink *link); with that we could just check each output stream (there could be more than 1) if a frame could be output. And if yes run a request_frame() on that. If no stream has a >0 return for poll_frame() than another input packet could be demuxed and decoded (from a file which caused a poll()==0) and send it to one of the input vf_filo poll_frame() could have a trivial default implementation which just polls its input filters and returns that, this would be sufficient for 90% of filters. [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Everything should be made as simple as possible, but not simpler. -- Albert Einstein
On Mon, 7 Jan 2008 23:07:19 +0100 Michael Niedermayer <michaelni@gmx.at> wrote:
On Wed, Jan 02, 2008 at 10:00:26AM -0500, Bobby Bingham wrote:
On Wed, 02 Jan 2008 12:49:24 +0100 Vitor Sessak <vitor1001@gmail.com> wrote:
Hi all,
I've spotted a problem with the ffmpeg.c integration using the command
ffmpeg -vfilters fps=1 -i input.avi output.avi
In the way the integration is done in ffmpeg.c (my fault, I know), the filter infrastructure expects one input frame for every output frame. But that is not right for all filters. FFplay is also affected by this problem (although it's harder to reproduce, I didn't found a test case), it has a video queue and a filter will not work properly if the queue is empty.
The root of the problem is that in the way libavfilter is designed, libavfilter must ask ffmpeg.c/ffplay.c every time it wants a frame, no matter how (if any) frame was outputted by the filter chain.
I've thought in a few solutions:
Solution 1 (the closest to the actual code):
In the patch in soc svn, a input filter is defined in ffmpeg.c. A solution would be to move the call to av_read_frame and avcodec_decode_video to the request_frame method of the input filter, so it'll decode a video frame from the file each time the filter asks for one.
Problem: Messy, ugly to handle audio and -vcodec copy, makes ffmpeg.c even more complex than it is already, scare people away of using libavfilter in other applications.
Solution 2 (threading and queuing):
Make ffmpeg.c have a thread for audio decoding, another one for video and another for filtering. The video thread will add frames to a video queue and the filtering thread will sleep and wait for frames is the video queue is empty.
Problem: May introduce bugs, big patch, gives the impression that it is impossible to use libavfilter in a single-threaded application. There may also be corner cases where the queues gets too big and uses gigs of ram.
Solution 3 (change libavfilter):
Allow avfilter_request_frame to give a positive value if it outputs a frame, a negative one if error or end of video and zero if it has no frame to output be may have one latter. Then make a small video queue and just make the request_frame of the input filter return 0 if the queue is empty. The advantage is that it'll be easier to use it as a library and will not increase too much the complexity of ffmpeg.c/ffplay.c.
Problem: Every video filter will have to handle the case where the previous filter do not have a frame now but may have latter...
What is your opinion on that?
I'll take a closer look at this tonight, but I think solution 3 sounds reasonable.
As nothing has been commited yet to solve this IIRC ...
what about
/** * Frame poll callback. This returns the number of immedeately available * frames. That is if it returns 1 or larger than the next request_frame() * is guranteed to return one frame (with no delay) * * Output video pads only. */ int (*poll_frame)(AVFilterLink *link);
with that we could just check each output stream (there could be more than 1) if a frame could be output. And if yes run a request_frame() on that. If no stream has a >0 return for poll_frame() than another input packet could be demuxed and decoded (from a file which caused a poll()==0) and send it to one of the input vf_filo
poll_frame() could have a trivial default implementation which just polls its input filters and returns that, this would be sufficient for 90% of filters.
[...]
Consider a filter which needs to check the timestamp or such of the next frame to determine whether or not to output it. This will require it to request the frame in poll_frame and either drop it or buffer it until it's requested by the next filter, so you can't do slice rendering. The idea to use the return value of request_frame avoids this. -- Bobby Bingham Never trust atoms. Or anything made of atoms. このメールは再利用されたバイトでできている。
On Mon, Jan 07, 2008 at 11:56:32PM -0500, Bobby Bingham wrote:
On Mon, 7 Jan 2008 23:07:19 +0100 Michael Niedermayer <michaelni@gmx.at> wrote:
On Wed, Jan 02, 2008 at 10:00:26AM -0500, Bobby Bingham wrote:
On Wed, 02 Jan 2008 12:49:24 +0100 Vitor Sessak <vitor1001@gmail.com> wrote:
Hi all,
I've spotted a problem with the ffmpeg.c integration using the command
ffmpeg -vfilters fps=1 -i input.avi output.avi
In the way the integration is done in ffmpeg.c (my fault, I know), the filter infrastructure expects one input frame for every output frame. But that is not right for all filters. FFplay is also affected by this problem (although it's harder to reproduce, I didn't found a test case), it has a video queue and a filter will not work properly if the queue is empty.
The root of the problem is that in the way libavfilter is designed, libavfilter must ask ffmpeg.c/ffplay.c every time it wants a frame, no matter how (if any) frame was outputted by the filter chain.
I've thought in a few solutions:
Solution 1 (the closest to the actual code):
In the patch in soc svn, a input filter is defined in ffmpeg.c. A solution would be to move the call to av_read_frame and avcodec_decode_video to the request_frame method of the input filter, so it'll decode a video frame from the file each time the filter asks for one.
Problem: Messy, ugly to handle audio and -vcodec copy, makes ffmpeg.c even more complex than it is already, scare people away of using libavfilter in other applications.
Solution 2 (threading and queuing):
Make ffmpeg.c have a thread for audio decoding, another one for video and another for filtering. The video thread will add frames to a video queue and the filtering thread will sleep and wait for frames is the video queue is empty.
Problem: May introduce bugs, big patch, gives the impression that it is impossible to use libavfilter in a single-threaded application. There may also be corner cases where the queues gets too big and uses gigs of ram.
Solution 3 (change libavfilter):
Allow avfilter_request_frame to give a positive value if it outputs a frame, a negative one if error or end of video and zero if it has no frame to output be may have one latter. Then make a small video queue and just make the request_frame of the input filter return 0 if the queue is empty. The advantage is that it'll be easier to use it as a library and will not increase too much the complexity of ffmpeg.c/ffplay.c.
Problem: Every video filter will have to handle the case where the previous filter do not have a frame now but may have latter...
What is your opinion on that?
I'll take a closer look at this tonight, but I think solution 3 sounds reasonable.
As nothing has been commited yet to solve this IIRC ...
what about
/** * Frame poll callback. This returns the number of immedeately available * frames. That is if it returns 1 or larger than the next request_frame() * is guranteed to return one frame (with no delay) * * Output video pads only. */ int (*poll_frame)(AVFilterLink *link);
with that we could just check each output stream (there could be more than 1) if a frame could be output. And if yes run a request_frame() on that. If no stream has a >0 return for poll_frame() than another input packet could be demuxed and decoded (from a file which caused a poll()==0) and send it to one of the input vf_filo
poll_frame() could have a trivial default implementation which just polls its input filters and returns that, this would be sufficient for 90% of filters.
[...]
Consider a filter which needs to check the timestamp or such of the next frame to determine whether or not to output it. This will require it to request the frame in poll_frame and either drop it or buffer it until it's requested by the next filter, so you can't do slice rendering.
hmm, what about simply letting poll_frame() return the timestamps (or even more) of the available frames as well? This should work IMHO with the use case of having a vf_fifo on every input and an application pushing frames into them.
The idea to use the return value of request_frame avoids this.
no, think of a filter needing more than 1 frame where the first succeeds but the second fails requesting. This could be 2 frames from the same source or 2 frames from different sources, like in a "picture in picture" filter mixing 2 videos. This would also need some buffering in the filter ... Ironically poll_frame() would avoid that problem. Also theres another possible issue without poll_frame() but maybe iam missing something ... If you have several outputs, from which do you request a frame? Each in sequence? like 0,1,0,1,0,1, ... ? Imagine a single input, a simple split filter where each input frame from the single input is send to each of the 2 outputs, and then a frame drop filter droping every 2nd frame on one of these outputs. The naive 0,1,0,1, ... requesting will cause a problem in terms of buffer requirements. If you would instead use the timestamps, to decide, a filter changing timestamps (like to produce a slow motion effect) instead of droping frames would break that as well. [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB I know you won't believe me, but the highest form of Human Excellence is to question oneself and others. -- Socrates
Hi Michael Niedermayer wrote:
On Wed, Jan 02, 2008 at 10:00:26AM -0500, Bobby Bingham wrote:
On Wed, 02 Jan 2008 12:49:24 +0100 Vitor Sessak <vitor1001@gmail.com> wrote:
Hi all,
I've spotted a problem with the ffmpeg.c integration using the command
ffmpeg -vfilters fps=1 -i input.avi output.avi
[...]
What is your opinion on that?
I'll take a closer look at this tonight, but I think solution 3 sounds reasonable.
As nothing has been commited yet to solve this IIRC ...
what about
/** * Frame poll callback. This returns the number of immedeately available * frames. That is if it returns 1 or larger than the next request_frame() * is guranteed to return one frame (with no delay) * * Output video pads only. */ int (*poll_frame)(AVFilterLink *link);
with that we could just check each output stream (there could be more than 1) if a frame could be output. And if yes run a request_frame() on that. If no stream has a >0 return for poll_frame() than another input packet could be demuxed and decoded (from a file which caused a poll()==0) and send it to one of the input vf_filo
poll_frame() could have a trivial default implementation which just polls its input filters and returns that, this would be sufficient for 90% of filters.
Something like the following? -Vitor
On Fri, Feb 01, 2008 at 10:18:27PM +0100, Vitor Sessak wrote:
> Hi
>
> Michael Niedermayer wrote:
>> On Wed, Jan 02, 2008 at 10:00:26AM -0500, Bobby Bingham wrote:
>>> On Wed, 02 Jan 2008 12:49:24 +0100
>>> Vitor Sessak <vitor1001@gmail.com> wrote:
>>>
>>>> Hi all,
>>>>
>>>> I've spotted a problem with the ffmpeg.c integration using the command
>>>>
>>>> ffmpeg -vfilters fps=1 -i input.avi output.avi
>>>>
>
> [...]
>
>>>>
>>>> What is your opinion on that?
>>> I'll take a closer look at this tonight, but I think solution 3 sounds
>>> reasonable.
>> As nothing has been commited yet to solve this IIRC ...
>> what about
>> /**
>> * Frame poll callback. This returns the number of immedeately
>> available
>> * frames. That is if it returns 1 or larger than the next
>> request_frame()
>> * is guranteed to return one frame (with no delay)
>> *
>> * Output video pads only.
>> */
>> int (*poll_frame)(AVFilterLink *link);
>> with that we could just check each output stream (there could be more than
>> 1)
>> if a frame could be output. And if yes run a request_frame() on that. If
>> no
>> stream has a >0 return for poll_frame() than another input packet could be
>> demuxed and decoded (from a file which caused a poll()==0) and send it to
>> one
>> of the input vf_filo
>> poll_frame() could have a trivial default implementation which just polls
>> its input filters and returns that, this would be sufficient for 90% of
>> filters.
>
> Something like the following?
[...]
> +static int link_in_poll_frame(AVFilterLink *link)
> +{
> + AVFilterLink *link2 = get_extern_input_link(link);
> + if(!link2)
> + return -1;
> + return avfilter_poll_frame(link2);
> +}
> +
> static int link_in_config_props(AVFilterLink *link)
> {
> AVFilterLink *link2 = get_extern_input_link(link);
> @@ -236,6 +245,15 @@
> return -1;
> }
>
> +static int graph_out_poll_frame(AVFilterLink *link)
> +{
> + AVFilterLink *link2 = get_intern_output_link(link);
> +
> + if(link2)
> + return avfilter_poll_frame(link2);
> + return -1;
> +}
these 2 are inconsistant, with the retuen -1 and avfilter_poll_frame() order
[...]
> +static int poll_frame(AVFilterLink *link)
> +{
> + FPSContext *fps = link->src->priv;
> +
> + if (fps->has_frame)
> + return 1;
> +
> + if(avfilter_poll_frame(link->src->inputs[0]) &&
> + avfilter_request_frame(link->src->inputs[0])) {
> + fps->videoend = 1;
> + return 1;
> + }
> +
> + fps->has_frame = !!(fps->pic && fps->pic->pts >= fps->pts);
> + return fps->has_frame;
> +}
This should output values larger than 1 if its known that more can be
output from the available frame.
> +
> static void end_frame(AVFilterLink *link)
> {
> }
> @@ -71,14 +90,17 @@
> {
> FPSContext *fps = link->src->priv;
>
> - while(!fps->pic || fps->pic->pts < fps->pts)
> - if(avfilter_request_frame(link->src->inputs[0]))
> - return -1;
> + if (fps->videoend)
> + return -1;
>
> + fps->has_frame=0;
> avfilter_start_frame(link, avfilter_ref_pic(fps->pic, ~AV_PERM_WRITE));
> avfilter_draw_slice (link, 0, fps->pic->h);
> avfilter_end_frame (link);
>
> + avfilter_unref_pic(fps->pic);
> + fps->pic = NULL;
> +
> fps->pts += fps->timebase;
>
> return 0;
This does not look like it would work if poll_frame() isnt used.
I did not intent to make poll_frame() mandatory to be used, but rather
an option for cases like ffmpeg.c.
That is pure use of request_frame() is fine as long as your inputs are
guranteed to be able to handle it until EOF.
I think the extra complexity for supporting both cases is quite small
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
it is not once nor twice but times without number that the same ideas make
their appearance in the world. -- Aristotle
Hi, and thanks for reviewing
Michael Niedermayer wrote:
> On Fri, Feb 01, 2008 at 10:18:27PM +0100, Vitor Sessak wrote:
>> Hi
>>
>> Michael Niedermayer wrote:
>>> On Wed, Jan 02, 2008 at 10:00:26AM -0500, Bobby Bingham wrote:
>>>> On Wed, 02 Jan 2008 12:49:24 +0100
>>>> Vitor Sessak <vitor1001@gmail.com> wrote:
>>>>
>>>>> Hi all,
>>>>>
>>>>> I've spotted a problem with the ffmpeg.c integration using the command
>>>>>
>>>>> ffmpeg -vfilters fps=1 -i input.avi output.avi
>>>>>
>> [...]
>>
>>>>> What is your opinion on that?
>>>> I'll take a closer look at this tonight, but I think solution 3 sounds
>>>> reasonable.
>>> As nothing has been commited yet to solve this IIRC ...
>>> what about
>>> /**
>>> * Frame poll callback. This returns the number of immedeately
>>> available
>>> * frames. That is if it returns 1 or larger than the next
>>> request_frame()
>>> * is guranteed to return one frame (with no delay)
>>> *
>>> * Output video pads only.
>>> */
>>> int (*poll_frame)(AVFilterLink *link);
>>> with that we could just check each output stream (there could be more than
>>> 1)
>>> if a frame could be output. And if yes run a request_frame() on that. If
>>> no
>>> stream has a >0 return for poll_frame() than another input packet could be
>>> demuxed and decoded (from a file which caused a poll()==0) and send it to
>>> one
>>> of the input vf_filo
>>> poll_frame() could have a trivial default implementation which just polls
>>> its input filters and returns that, this would be sufficient for 90% of
>>> filters.
>> Something like the following?
>
> [...]
>> +static int link_in_poll_frame(AVFilterLink *link)
>> +{
>> + AVFilterLink *link2 = get_extern_input_link(link);
>> + if(!link2)
>> + return -1;
>> + return avfilter_poll_frame(link2);
>> +}
>> +
>> static int link_in_config_props(AVFilterLink *link)
>> {
>> AVFilterLink *link2 = get_extern_input_link(link);
>> @@ -236,6 +245,15 @@
>> return -1;
>> }
>>
>> +static int graph_out_poll_frame(AVFilterLink *link)
>> +{
>> + AVFilterLink *link2 = get_intern_output_link(link);
>> +
>> + if(link2)
>> + return avfilter_poll_frame(link2);
>> + return -1;
>> +}
>
> these 2 are inconsistant, with the retuen -1 and avfilter_poll_frame() order
Fixed.
>
>
> [...]
>> +static int poll_frame(AVFilterLink *link)
>> +{
>> + FPSContext *fps = link->src->priv;
>> +
>> + if (fps->has_frame)
>> + return 1;
>> +
>> + if(avfilter_poll_frame(link->src->inputs[0]) &&
>> + avfilter_request_frame(link->src->inputs[0])) {
>> + fps->videoend = 1;
>> + return 1;
>> + }
>> +
>> + fps->has_frame = !!(fps->pic && fps->pic->pts >= fps->pts);
>> + return fps->has_frame;
>> +}
>
> This should output values larger than 1 if its known that more can be
> output from the available frame.
The fps filter only support decreasing the fps (since it's first
version). All it does is to drop frames. It can't output more than one
frame then. Yes, I know, it probably is not ok for SVN like that, but my
priority is getting avfilter.* vf_crop.c and the ffmpeg.c in a good
enough shape to SVN. Then I could fix one filter at a time.
>
>
>> +
>> static void end_frame(AVFilterLink *link)
>> {
>> }
>> @@ -71,14 +90,17 @@
>> {
>> FPSContext *fps = link->src->priv;
>>
>> - while(!fps->pic || fps->pic->pts < fps->pts)
>> - if(avfilter_request_frame(link->src->inputs[0]))
>> - return -1;
>> + if (fps->videoend)
>> + return -1;
>>
>> + fps->has_frame=0;
>> avfilter_start_frame(link, avfilter_ref_pic(fps->pic, ~AV_PERM_WRITE));
>> avfilter_draw_slice (link, 0, fps->pic->h);
>> avfilter_end_frame (link);
>>
>> + avfilter_unref_pic(fps->pic);
>> + fps->pic = NULL;
>> +
>> fps->pts += fps->timebase;
>>
>> return 0;
>
> This does not look like it would work if poll_frame() isnt used.
> I did not intent to make poll_frame() mandatory to be used, but rather
> an option for cases like ffmpeg.c.
> That is pure use of request_frame() is fine as long as your inputs are
> guranteed to be able to handle it until EOF.
> I think the extra complexity for supporting both cases is quite small
Agreed. Changes made.
New version attached. Will commit in 24h if no one opposes to it or asks
more time for reviewing.
-Vitor
Vitor Sessak wrote:
Hi, and thanks for reviewing
[...]
This does not look like it would work if poll_frame() isnt used. I did not intent to make poll_frame() mandatory to be used, but rather an option for cases like ffmpeg.c. That is pure use of request_frame() is fine as long as your inputs are guranteed to be able to handle it until EOF. I think the extra complexity for supporting both cases is quite small
Agreed. Changes made.
New version attached. Will commit in 24h if no one opposes to it or asks more time for reviewing.
Commited. -Vitor
participants (4)
-
Bobby Bingham -
Michael Niedermayer -
Robert Swain -
Vitor Sessak