Opened 5 years ago

Closed 5 years ago

#3338 closed defect (needs_more_info)

Memory leak playing ogv videos

Reported by: romain145 Owned by:
Priority: normal Component: undetermined
Version: unspecified Keywords: leak
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Hello,

using the ffmpeg library as part of an SDL application to play ogv video files, I face memory leaks at the end of the video. Ogv videos are generated with ffmpeg2theora.

$ ffmpeg2theora
ffmpeg2theora 0.27 - Xiph.Org libtheora 1.1 20090822 (Thusnelda)

FFmpeg version :

$ ffmpeg
ffmpeg version N-59766-ge11983b Copyright (c) 2000-2014 the FFmpeg developers
 built on Jan 11 2014 17:06:41 with gcc 4.7 (Debian 4.7.2-5)
 configuration: --disable-optimizations
 libavutil      52. 62.100 / 52. 62.100
 libavcodec     55. 47.101 / 55. 47.101
 libavformat    55. 22.103 / 55. 22.103
 libavdevice    55.  5.102 / 55.  5.102
 libavfilter     4.  1.100 /  4.  1.100
 libswscale      2.  5.101 /  2.  5.101
 libswresample   0. 17.104 /  0. 17.104
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Commands called at the end of each frame decoding :

av_free_packet(&packet);
SDL_DestroyTexture(bmpTex1);
av_free(pFrame);
av_free(pFrame_YUV420P);
av_free(buffer_YUV420P);

At the end of the video :

av_free_packet(&packet);
avcodec_close(pCodecCtx);
av_close_input_file(pFormatCtx);

Using the same code, playing an avi video file it doesn't show any memory leak.

Video files details :
gears2.ogv file is 2.1MB

$ ffmpeg -i gears2.ogv
[...]
Input #0, ogg, from 'gear2.ogv':
 Duration: 00:00:02.08, start: 0.000000, bitrate: 8167 kb/s
   Stream #0:0: Video: theora, yuv420p, 1024x768 [SAR 3:4 DAR 1:1], 25 tbr, 25 tbn, 25 tbc
   Metadata:
     MAJOR_BRAND     : MSNV
     MINOR_VERSION   : 16786688
     COMPATIBLE_BRANDS: MSNVisommp42
     CREATION_TIME   : 2013-11-14 14:37:55
     ENCODER         : Lavf54.6.100

2.avi file is 144MB

$ ffmpeg -i 2.avi
[...]
Input #0, avi, from '2.avi':
 Duration: 00:00:02.03, start: 0.000000, bitrate: 566614 kb/s
   Stream #0:0: Video: rawvideo, bgr24, 1024x768, 30 tbr, 30 tbn, 30 tbc

Attachments (2)

test_video.zip (371.2 KB) - added by romain145 5 years ago.
video.cpp (3.0 KB) - added by romain145 5 years ago.
Updated render

Download all attachments as: .zip

Change History (7)

comment:1 Changed 5 years ago by cehoyos

  • Component changed from FFmpeg to undetermined
  • Keywords memory ogv avi removed

Please provide the complete valgrind output and / or provide the sample that allows to reproduce the leak.

Changed 5 years ago by romain145

comment:2 Changed 5 years ago by romain145

Sample attached with a couple of videos.

comment:3 Changed 5 years ago by gjdfgh

From the zip:

  AVFrame           *pFrame_YUV420P = avcodec_alloc_frame();
  if(pFrame_YUV420P == NULL) 
  {
    fprintf(stderr, "Could not allocate pFrame_YUV420P\n");
  }
  
  uint8_t           *buffer_YUV420P = (uint8_t *)av_malloc(avpicture_get_size(PIX_FMT_YUV420P,pCodecCtx->width, pCodecCtx->height));  
  avpicture_fill((AVPicture *)pFrame_YUV420P, buffer_YUV420P,PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height);


This is 100% broken. You can't use AVFrame this way. Besides, the decoder allocates the frames for you.

Changed 5 years ago by romain145

Updated render

comment:4 Changed 5 years ago by romain145

Attached a new implementation following explanations on this thread : https://forums.libsdl.org/viewtopic.php?t=9898
Still showing the memory leak.

If still incorrect, please update with the link to the manual part/tutorial referring to this.
Thanks.

comment:5 Changed 5 years ago by cehoyos

  • Resolution set to needs_more_info
  • Status changed from new to closed

If you believe there is a bug in FFmpeg, please provide the complete valgrind output and reopen this ticket.

If you need support, please read http://ffmpeg.org/contact.html

Note: See TracTickets for help on using tickets.