Recherche avancée

Médias (1)

Mot : - Tags -/censure

Autres articles (62)

Sur d’autres sites (10859)

  • FFmpeg - Memory leak using sws_scale

    12 décembre 2018, par AlexVestin

    I’m trying to read a video-file and extract RGB24 frames from this. The problem is when I use sw_scale, the program leaks 200MB/s, which isn’t ideal.

    A shortened version of the code I’m using is :

    static int decode_packet(uint8_t** data, int* frame_size){
       int ret = 0, dec_ret = 0;
       dec_ret = avcodec_send_packet(video_dec_ctx, &pkt);
       while(dec_ret >= 0) {
           dec_ret = avcodec_receive_frame(video_dec_ctx, frame);            
           if(dec_ret == AVERROR(EAGAIN) || dec_ret == AVERROR_EOF) {
               return decoded;
           }
           if(!image_inited && frame->format != -1) {
               sws_context = init_context();
               image_inited = true;
           }

           const int size = video_dec_ctx->width*video_dec_ctx->height*3;
           uint8_t* buffer = malloc(size);

           const int out_linesize[1] = { 3 * video_dec_ctx->width };
           sws_scale(
               sws_context,
               frame->data,
               frame->linesize,
               0,
               video_dec_ctx->height,
               (const uint8_t * const *)&buffer,
               out_linesize
           );

           *data = buffer;
       }
    }

    void get_next_frame(uint8_t* data) {
      int ret = av_read_frame(fmt_ctx, &pkt);
      AVPacket orig_pkt = pkt;
      ret = decode_packet(&data, &idummy);
      av_packet_unref(&orig_pkt);
      av_frame_unref(frame);
      return ret;
    }

    And called from a main (pseduocode) :

    int main(inr argc, char** argv) {
      while(frames_left) {
         uint8_t* f;
         get_next_frame(f);
         apply_frame(f);
         free(f);
      }
    }

    After a bit of debugging I found that this part :

      const int out_linesize[1] = { 3 * video_dec_ctx->width };
       sws_scale(
           sws_context,
           frame->data,
           frame->linesize,
           0,
           video_dec_ctx->height,
           (const uint8_t * const *)&buffer,
           out_linesize
       );

    was the culprit. If I comment this section out the program runs fine (or at least without 200MB memory leak ^^)

    I’ve tried freeing the sws_context after each call, freeing the av_frame after each call in get_next_frame but the memory leak is still there.

    Does anyone know how to fix the leak ?

  • avformat/aacdec : Fix leak in adts_aac_read_packet()

    25 novembre 2017, par Michael Niedermayer
    avformat/aacdec : Fix leak in adts_aac_read_packet()
    

    Fixes : chromium-773637/clusterfuzz-testcase-minimized-6418078673141760

    Found-by : ossfuzz/chromium
    Reviewed-by : James Almer <jamrial@gmail.com>
    Signed-off-by : Michael Niedermayer <michael@niedermayer.cc>

    • [DH] libavformat/aacdec.c
  • avfilter/vf_framerate : fix frame leak at uninit

    12 septembre 2015, par Paul B Mahol
    avfilter/vf_framerate : fix frame leak at uninit
    

    Reported-by : Andres Noetzli
    Signed-off-by : Paul B Mahol <onemda@gmail.com>

    • [DH] libavfilter/vf_framerate.c