zoukankan      html  css  js  c++  java
  • 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 ",
                                                        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);

    }


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

  • 相关阅读:
    第十章 系统级I/O
    第九章 虚拟内存
    第六章 存储器层次结构
    第八章 异常控制流(下)
    第八章 异常控制流(上)
    第三章 机器的程序级表示(下)
    第三章 机器的程序级表示(中)
    第三章 机器的程序级表示(上)
    python学习之列表的定义以及增删改查
    Python学习之字符串中的下标和切片以及逆序
  • 原文地址:https://www.cnblogs.com/dyllove98/p/3198894.html
Copyright © 2011-2022 走看看