lavfi: add a new function av_buffersrc_buffer().
ffmpeg | branch: master | Anton Khirnov <anton@khirnov.net> | Wed Dec 21 20:39:18 2011 +0100| [e1d9dbf2d465448028bf396d7b37dbb642794678] | committer: Anton Khirnov lavfi: add a new function av_buffersrc_buffer(). It can be used to directly pass a AVFilterBufferRef to lavfi, avoiding a memcpy.
http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e1d9dbf2d465448028...
libavfilter/Makefile | 2 +- libavfilter/buffersrc.h | 38 ++++++++++++++++++++++++++ libavfilter/vsrc_buffer.c | 66 ++++++++++++++++++++++---------------------- 3 files changed, 72 insertions(+), 34 deletions(-) diff --git a/libavfilter/Makefile b/libavfilter/Makefile index c269db5..78c4692 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -3,7 +3,7 @@ FFLIBS = avutil FFLIBS-$(CONFIG_MOVIE_FILTER) += avformat avcodec FFLIBS-$(CONFIG_SCALE_FILTER) += swscale -HEADERS = avfilter.h avfiltergraph.h vsrc_buffer.h +HEADERS = avfilter.h avfiltergraph.h buffersrc.h vsrc_buffer.h OBJS = allfilters.o \ avfilter.o \ diff --git a/libavfilter/buffersrc.h b/libavfilter/buffersrc.h new file mode 100644 index 0000000..bd82c06 --- /dev/null +++ b/libavfilter/buffersrc.h @@ -0,0 +1,38 @@ +/* + * + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVFILTER_BUFFERSRC_H +#define AVFILTER_BUFFERSRC_H + +/** + * @file + * Memory buffer source API. + */ + +#include "avfilter.h" + +/** + * Add a buffer to the filtergraph s. + * + * @param buf buffer containing frame data to be passed down the filtergraph. + * This function will take ownership of buf, the user must not free it. + */ +int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf); + +#endif /* AVFILTER_BUFFERSRC_H */ diff --git a/libavfilter/vsrc_buffer.c b/libavfilter/vsrc_buffer.c index 982fed5..7ef19a1 100644 --- a/libavfilter/vsrc_buffer.c +++ b/libavfilter/vsrc_buffer.c @@ -24,13 +24,12 @@ */ #include "avfilter.h" +#include "buffersrc.h" #include "vsrc_buffer.h" #include "libavutil/imgutils.h" typedef struct { - int64_t pts; - AVFrame frame; - int has_frame; + AVFilterBufferRef *buf; int h, w; enum PixelFormat pix_fmt; AVRational time_base; ///< time_base to set in the output link @@ -42,7 +41,7 @@ int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame, { BufferSourceContext *c = buffer_filter->priv; - if (c->has_frame) { + if (c->buf) { av_log(buffer_filter, AV_LOG_ERROR, "Buffering several frames is not supported. " "Please consume all available frames before adding a new one.\n" @@ -50,15 +49,31 @@ int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame, //return -1; } - memcpy(c->frame.data , frame->data , sizeof(frame->data)); - memcpy(c->frame.linesize, frame->linesize, sizeof(frame->linesize)); - c->frame.interlaced_frame= frame->interlaced_frame; - c->frame.top_field_first = frame->top_field_first; - c->frame.key_frame = frame->key_frame; - c->frame.pict_type = frame->pict_type; - c->pts = pts; - c->pixel_aspect = pixel_aspect; - c->has_frame = 1; + c->buf = avfilter_get_video_buffer(buffer_filter->outputs[0], AV_PERM_WRITE, + c->w, c->h); + av_image_copy(c->buf->data, c->buf->linesize, frame->data, frame->linesize, + c->pix_fmt, c->w, c->h); + + avfilter_copy_frame_props(c->buf, frame); + c->buf->pts = pts; + c->buf->video->pixel_aspect = pixel_aspect; + + return 0; +} + +int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf) +{ + BufferSourceContext *c = s->priv; + + if (c->buf) { + av_log(s, AV_LOG_ERROR, + "Buffering several frames is not supported. " + "Please consume all available frames before adding a new one.\n" + ); + return AVERROR(EINVAL); + } + + c->buf = buf; return 0; } @@ -113,33 +128,18 @@ static int config_props(AVFilterLink *link) static int request_frame(AVFilterLink *link) { BufferSourceContext *c = link->src->priv; - AVFilterBufferRef *picref; - if (!c->has_frame) { + if (!c->buf) { av_log(link->src, AV_LOG_ERROR, "request_frame() called with no available frame!\n"); //return -1; } - /* This picture will be needed unmodified later for decoding the next - * frame */ - picref = avfilter_get_video_buffer(link, AV_PERM_WRITE | AV_PERM_PRESERVE | - AV_PERM_REUSE2, - link->w, link->h); - - av_image_copy(picref->data, picref->linesize, - c->frame.data, c->frame.linesize, - picref->format, link->w, link->h); - - avfilter_copy_frame_props(picref, &c->frame); - picref->pts = c->pts; - picref->video->pixel_aspect = c->pixel_aspect; - avfilter_start_frame(link, avfilter_ref_buffer(picref, ~0)); + avfilter_start_frame(link, avfilter_ref_buffer(c->buf, ~0)); avfilter_draw_slice(link, 0, link->h, 1); avfilter_end_frame(link); - avfilter_unref_buffer(picref); - - c->has_frame = 0; + avfilter_unref_buffer(c->buf); + c->buf = NULL; return 0; } @@ -147,7 +147,7 @@ static int request_frame(AVFilterLink *link) static int poll_frame(AVFilterLink *link) { BufferSourceContext *c = link->src->priv; - return !!(c->has_frame); + return !!(c->buf); } AVFilter avfilter_vsrc_buffer = {
On Mon, Dec 26, 2011 at 04:14:01AM +0100, Anton Khirnov wrote:
ffmpeg | branch: master | Anton Khirnov <anton@khirnov.net> | Wed Dec 21 20:39:18 2011 +0100| [e1d9dbf2d465448028bf396d7b37dbb642794678] | committer: Anton Khirnov
lavfi: add a new function av_buffersrc_buffer().
It can be used to directly pass a AVFilterBufferRef to lavfi, avoiding a memcpy.
http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e1d9dbf2d465448028...
This commit introduces a massive memleak when using avfilter with -ss after -i (it really looks like decoded frames that are not encoded are not freed). Command to reproduce: ffmpeg -i hd_sources_makes_it_more_obvious.ext -ss 120 -vf scale=720:528 /dev/null The code have changed since, and I didn't find my way to make a fix. Can someone fix it? Regards.
On Thu, May 17, 2012 at 11:52:29AM +0200, Etienne Buira wrote:
On Mon, Dec 26, 2011 at 04:14:01AM +0100, Anton Khirnov wrote:
ffmpeg | branch: master | Anton Khirnov <anton@khirnov.net> | Wed Dec 21 20:39:18 2011 +0100| [e1d9dbf2d465448028bf396d7b37dbb642794678] | committer: Anton Khirnov
lavfi: add a new function av_buffersrc_buffer().
It can be used to directly pass a AVFilterBufferRef to lavfi, avoiding a memcpy.
http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e1d9dbf2d465448028...
This commit introduces a massive memleak when using avfilter with -ss after -i (it really looks like decoded frames that are not encoded are not freed).
Command to reproduce: ffmpeg -i hd_sources_makes_it_more_obvious.ext -ss 120 -vf scale=720:528 /dev/null
The code have changed since, and I didn't find my way to make a fix. Can someone fix it?
I tried to reproduce but had no luck there where alot of changes and bugfixes in teh last few days Is this still reproducable ? if yes please explain how to reproduce it exactly [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Many things microsoft did are stupid, but not doing something just because microsoft did it is even more stupid. If everything ms did were stupid they would be bankrupt already.
On Mon, May 21, 2012 at 03:25:30AM +0200, Michael Niedermayer wrote:
On Thu, May 17, 2012 at 11:52:29AM +0200, Etienne Buira wrote:
On Mon, Dec 26, 2011 at 04:14:01AM +0100, Anton Khirnov wrote:
ffmpeg | branch: master | Anton Khirnov <anton@khirnov.net> | Wed Dec 21 20:39:18 2011 +0100| [e1d9dbf2d465448028bf396d7b37dbb642794678] | committer: Anton Khirnov
lavfi: add a new function av_buffersrc_buffer().
It can be used to directly pass a AVFilterBufferRef to lavfi, avoiding a memcpy.
http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e1d9dbf2d465448028...
This commit introduces a massive memleak when using avfilter with -ss after -i (it really looks like decoded frames that are not encoded are not freed).
Command to reproduce: ffmpeg -i hd_sources_makes_it_more_obvious.ext -ss 120 -vf scale=720:528 /dev/null
The code have changed since, and I didn't find my way to make a fix. Can someone fix it?
I tried to reproduce but had no luck there where alot of changes and bugfixes in teh last few days Is this still reproducable ? if yes please explain how to reproduce it exactly
Hi Michael, It has been fixed in 01e98b1b006c67ab0948f3c1de65a94609fe79cf, thanks.
participants (3)
-
Etienne Buira -
git@videolan.org -
Michael Niedermayer