Memory Leak when using ffmpeg Video Writer (Patch #775)


Added by Chav Reddy about 14 years ago. Updated almost 12 years ago.


Status:Cancelled Start date:
Priority:Normal Due date:
Assignee:Alexander Reshetnikov % Done:

0%

Category:highgui-video
Target version:2.4.0
Affected version: Operating System:
Difficulty: HW Platform:
Pull request:

Description

In function CvVideoWriter_FFMPEG::open()- > icv_add_video_stream_FFMPEG() -> av_new_stream() memory is allocated for stream->info.

When closing the CvVideoWriter this memory should be free'd.

cvcap_ffmpeg:1169

/* free the streams */
for(i = 0; i < oc->nb_streams; i++) {
av_freep(&oc->streams[i]->codec);
+++ av_freep(&oc->streams[i]->info);
av_freep(&oc->streams[i]);
}

I have noticed this bug in version 2.1. In 2.2 it appears in the code, but I have not tested it.


Related issues

related to Bug #3206: VideoWriter.open Leak Done 2013-08-08

Associated revisions

Revision a2d27429
Added by Andrey Kamaev almost 12 years ago

Merge pull request #775 from bitwangyaoyao:2.4_fixerr

History

Updated by Chav Reddy about 14 years ago

Also:
cvcap_ffmpeg:1185

+++ av_metadata_free(&oc->metadata);

/* free the stream */
av_free(oc);

Replying to chav:

In function CvVideoWriter_FFMPEG::open()- > icv_add_video_stream_FFMPEG() -> av_new_stream() memory is allocated for stream->info.

When closing the CvVideoWriter this memory should be free'd.

cvcap_ffmpeg:1169

/* free the streams */
for(i = 0; i < oc->nb_streams; i++) {
av_freep(&oc->streams[i]->codec);
+++ av_freep(&oc->streams[i]->info);
av_freep(&oc->streams[i]);
}

I have noticed this bug in version 2.1. In 2.2 it appears in the code, but I have not tested it.

Updated by Alexander Shishkov about 13 years ago

  • Description changed from In function [[CvVideoWriter]]_FFMPEG::open()- > icv_add_video_stream_FFMPE... to In function CvVideoWriter_FFMPEG::open()- > icv_add_video_stream_FFMPEG() ... More

Updated by Alexander Shishkov almost 13 years ago

  • Tracker changed from Bug to Patch
  • Target version deleted ()

Updated by Alexander Shishkov almost 13 years ago

  • Priority changed from Normal to High

Updated by Alexander Reshetnikov almost 13 years ago

  • Status changed from Open to Cancelled
  • Priority changed from High to Normal
  • Assignee set to Alexander Reshetnikov

Updated by Alexander Shishkov almost 13 years ago

  • Target version set to 2.4.0

Updated by Andrey Kamaev over 12 years ago

  • Category changed from highgui-images to highgui-video

Updated by sebastien wybo about 12 years ago

In version 2.43 there still seems to be a 20kB memory leak when deleting a cv::videoWriter using ffmpeg
The proposed patch no longer applies as AV_Stream struct has been changed since
Is a patch underway or is it considered a ffmpeg related bug? or a non important bug?

Updated by Ugo Galassi almost 12 years ago

In opencv there is a memory leak when releasing a video stream. It is still present in 2.4.5

This patch for me worked:

in void CvVideoWriter_FFMPEG::close()
you have to substitute

-----------------------
/* free the streams */
for(i = 0; i < oc->nb_streams; i++) {
av_freep(&oc->streams[i]->codec);
av_freep(&oc->streams[i]);
}
-----------------------

and

-----------------------
av_free(oc);
-----------------------

with

================
avformat_free_context(oc);

================

Also available in: Atom PDF