mirror of
https://mirror.skon.top/https://github.com/FFmpeg/FFmpeg
synced 2026-04-20 21:00:41 +08:00
avfilter/vf_libopencv: fix memleak
Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
This commit is contained in:
@@ -36,9 +36,9 @@
|
||||
#include "formats.h"
|
||||
#include "video.h"
|
||||
|
||||
static void fill_iplimage_from_frame(IplImage *img, const AVFrame *frame, enum AVPixelFormat pixfmt)
|
||||
static void fill_iplimage_from_frame(IplImage **_img, const AVFrame *frame, enum AVPixelFormat pixfmt)
|
||||
{
|
||||
IplImage *tmpimg;
|
||||
IplImage *img;
|
||||
int depth, channels_nb;
|
||||
|
||||
if (pixfmt == AV_PIX_FMT_GRAY8) { depth = IPL_DEPTH_8U; channels_nb = 1; }
|
||||
@@ -46,8 +46,7 @@ static void fill_iplimage_from_frame(IplImage *img, const AVFrame *frame, enum A
|
||||
else if (pixfmt == AV_PIX_FMT_BGR24) { depth = IPL_DEPTH_8U; channels_nb = 3; }
|
||||
else return;
|
||||
|
||||
tmpimg = cvCreateImageHeader((CvSize){frame->width, frame->height}, depth, channels_nb);
|
||||
*img = *tmpimg;
|
||||
*_img = img = cvCreateImageHeader((CvSize){frame->width, frame->height}, depth, channels_nb);
|
||||
img->imageData = img->imageDataOrigin = frame->data[0];
|
||||
img->dataOrder = IPL_DATA_ORDER_PIXEL;
|
||||
img->origin = IPL_ORIGIN_TL;
|
||||
@@ -366,7 +365,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
|
||||
OCVContext *s = ctx->priv;
|
||||
AVFilterLink *outlink= inlink->dst->outputs[0];
|
||||
AVFrame *out;
|
||||
IplImage inimg, outimg;
|
||||
IplImage *inimg, *outimg;
|
||||
|
||||
out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
|
||||
if (!out) {
|
||||
@@ -377,10 +376,12 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
|
||||
|
||||
fill_iplimage_from_frame(&inimg , in , inlink->format);
|
||||
fill_iplimage_from_frame(&outimg, out, inlink->format);
|
||||
s->end_frame_filter(ctx, &inimg, &outimg);
|
||||
fill_frame_from_iplimage(out, &outimg, inlink->format);
|
||||
s->end_frame_filter(ctx, inimg, outimg);
|
||||
fill_frame_from_iplimage(out, outimg, inlink->format);
|
||||
|
||||
av_frame_free(&in);
|
||||
cvReleaseImageHeader(&inimg);
|
||||
cvReleaseImageHeader(&outimg);
|
||||
|
||||
return ff_filter_frame(outlink, out);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user