Problems rendering video [Android]

40 views
Skip to first unread message

matie...@gmail.com

unread,
Aug 22, 2013, 4:44:00 PM8/22/13
to jav...@googlegroups.com
I am doing an application that creates a video using a set of photos saved in the sd-card. The problem I am trying to fix is that the application crashes when I create some videos. The crashes depends of the resolution of the source picture files. For example, I can render a video using 400 images with a resolution of 320x480 but I can only do a 25-frames video using images with a resolution of 2500x3200.

I am doing the coding process in background using Asynctask (for providing a feedback to the user and maintain it informed of the coding process). When the coding process crashes no warnings/errors/etc are captured in the logcat. Using the DDMS for examining the memory usage I can not view any memory leak (I also do not recieve any memory warning on the logcat).  For this reasons I supose that it may be a problem related with the ffmpeg libraries (but I have no idea).

I have testet different codecs defined on avcodec.java, like:  

AV_CODEC_ID_MPEG1VIDEO = 1,
AV_CODEC_ID_MPEG2VIDEO = 2,
      AV_CODEC_ID_H263 = 5,
      AV_CODEC_ID_MJPEG = 8,

etc

Trying with lossless video codecs seems not doing effect. 

I am running my application on a Sony Ericsson Xperia Arc (1ghz cpu, 320mb intern memory). 



Any suggestion would be appreciated I have no idea how can I fix that.


Thank you.
 

matie...@gmail.com

unread,
Aug 26, 2013, 2:28:39 PM8/26/13
to jav...@googlegroups.com

Ok, finally I have found the solution, but not the originating problem.

To create the video I was using a sort of code like:

    FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(name,width,heigth);
    recorder.start()

    while(imagesinfolder){

    IplImage img = highgui.cvLoadImage("/path/to/image[i].jpg")
    recorder.record(img)
    i++;
    }

It seems to create a memory problem, maybe because IplImage is not cleaned by the garbage collector.

My solution is use, instead of highgui.cvLoadImage, the method: opencv_core.cvLoadImage(img); and then, opencv_core.cvReleaseImage(img); in every iteration.

FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(name,width,heigth);
recorder.start()

while(imagesinfolder){

IplImage img = opencv_core.cvLoadImage("/path/to/image[i].jpg")
recorder.record(img)
img.cvReleaseImage();
i++;
}

Using it, all the poblems have disappeared and I can render long videos witout any issues.

Samuel Audet

unread,
Aug 31, 2013, 9:01:26 PM8/31/13
to jav...@googlegroups.com
Hello,


On 08/27/2013 03:28 AM, matie...@gmail.com wrote:

Ok, finally I have found the solution, but not the originating problem.

To create the video I was using a sort of code like:

    FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(name,width,heigth);
    recorder.start()

    while(imagesinfolder){

    IplImage img = highgui.cvLoadImage("/path/to/image[i].jpg")
    recorder.record(img)
    i++;
    }

It seems to create a memory problem, maybe because IplImage is not cleaned by the garbage collector.

That's correct, it isn't. As per the README.txt file, cvLoadImage() is a normal C function, and as such we need to call cvReleaseImage(img) to release native memory.

Samuel
Reply all
Reply to author
Forward
0 new messages