Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

memory leak with VideoWriter

I have a problem writing a video in iOS.

I have double checked my code, the problem is just in :

            _videoWriter->write(frame);

each time I call this function, i lose some memory ; it seems to me that the memory is not realeased even after _videoWriter->release() ( only a very little portion )

as i should register long videos, I wanted to try to save the video now and then, but if i close the file i had created (through method release() ) and try to reopen it , i get an error ( in general, it seems to me that if the file i'm trying to open already exists, the function fail, i can only create new video files )

this is the method that adds a frame:

            Mat frame = [MainViewController cvMatWithImage:image];

            _videoWriter->write(frame);

            _nframeswritten++;
            NSLog(@"frames %d/%d", _nframeswritten, _nframes);

this is how i open the video:

    _videoWriter = new VideoWriter();
    _videoWriter->open([_videoPath UTF8String],
                                       CV_FOURCC('M','J','P','G'),
                                       //CV_FOURCC('X','V','I','D'),
                                       //CV_FOURCC('F','L','V','1'),
                                       //CV_FOURCC('U','2','6','3'),
                                       //CV_FOURCC('P','I','M','1'),
                                       VIDEO_FPS,
                                       cvSize(288,352));

at the time i manage to record a video about 2 minutes lenght before it crashes on an iphone4s ( 10 fps, 288x352 )

click to hide/show revision 2
No.2 Revision

updated 2013-03-24 05:23:08 -0600

berak gravatar image

memory leak with VideoWriter

I have a problem writing a video in iOS.

I have double checked my code, the problem is just in :

            _videoWriter->write(frame);

each time I call this function, i lose some memory ; it seems to me that the memory is not realeased even after _videoWriter->release() ( only a very little portion )

as i should register long videos, I wanted to try to save the video now and then, but if i close the file i had created (through method release() ) and try to reopen it , i get an error ( in general, it seems to me that if the file i'm trying to open already exists, the function fail, i can only create new video files )

this is the method that adds a frame:

            Mat frame = [MainViewController cvMatWithImage:image];

            _videoWriter->write(frame);

            _nframeswritten++;
            NSLog(@"frames %d/%d", _nframeswritten, _nframes);

this is how i open the video:

    _videoWriter = new VideoWriter();
    _videoWriter->open([_videoPath UTF8String],
                                       CV_FOURCC('M','J','P','G'),
                                       //CV_FOURCC('X','V','I','D'),
                                       //CV_FOURCC('F','L','V','1'),
                                       //CV_FOURCC('U','2','6','3'),
                                       //CV_FOURCC('P','I','M','1'),
                                       VIDEO_FPS,
                                       cvSize(288,352));

at the time i manage to record a video about 2 minutes lenght before it crashes on an iphone4s ( 10 fps, 288x352 )