ffmpeg中ff_scale_image()内存泄露

版本:ffmpeg1.2


 
 
  int    ff_scale_image( uint8_t *dst_data[4], int dst_linesize[4],
                                         int dst_w, int dst_h, enum AVPixelFormat dst_pix_fmt,
                                          uint8_t * const src_data[4], int src_linesize[4],
                                        int src_w, int src_h, enum AVPixelFormat src_pix_fmt,
                                         void *log_ctx)
{
                             int ret;
                             SwsContext *sws_ctx = sws_getContext (src_w, src_h, src_pix_fmt,
                                                                                                     dst_w, dst_h, dst_pix_fmt,
                                                                                                           SWS_BILINEAR , NULL , NULL , NULL );
                              if (!sws_ctx) {
                                                       av_log(log_ctx, AV_LOG_ERROR,
                                                       "Impossible to create scale context for the conversion "
                                                       "fmt:%s s:%dx%d -> fmt:%s s:%dx%d\n",
                                                    av_get_pix_fmt_name(src_pix_fmt), src_w, src_h,
                                                    av_get_pix_fmt_name(dst_pix_fmt), dst_w, dst_h);
                                                       ret = AVERROR(EINVAL);
                                                   goto end;
                                             }

                      if ((ret = av_image_alloc(dst_data, dst_linesize, dst_w, dst_h, dst_pix_fmt, 16)) < 0)
                                   goto end;
                    ret = 0;
                       sws_scale(sws_ctx, ( const uint8_t * const*)src_data, src_linesize, 0, src_h, dst_data, dst_linesize);
       end:
                         sws_freeContext(sws_ctx);
                       return ret;
              }

我在使用这个函数进行像素转换的时候,如果反复进行调用就会出现内存泄露,不知道什么原因;

但是如果把这个函数分开使用,即

init()

{

、、、、、

struct SwsContext *sws_ctx = sws_getContext(src_w, src_h, src_pix_fmt,
                                                                             dst_w, dst_h, dst_pix_fmt,
                                                                              SWS_BILINEAR, NULL, NULL, NULL);

if ((ret = av_image_alloc(dst_data, dst_linesize, dst_w, dst_h, dst_pix_fmt, 16)) < 0)
                 release();

}


process()

{

、、、、、、、、

sws_scale(sws_ctx, (constuint8_t * const*)src_data, src_linesize, 0, src_h, dst_data, dst_linesize);

}


release()

{

、、、、、、、

sws_freeContext(sws_ctx);

}


这样的话就是正确的,不会出现内存泄露。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值