1

I upgraded my RPI2 to use Raspbian Jessie. (NOOBS 1.9.0) I also installed OpenCV 2.4.9.1 package. (It is the default package from apt-get install)

Now, I have a problem while recording video with OpenCV in my C/C++ program. I'm writing a AVI (DIVX) file with the cvVideoWriter/cvWriteFrame functions.

I received the following error on the console and OpenCV stops writing the video:

[mpeg4 @ 0x21d9580] get_buffer() failed (-12 (nil))

No matters what I do, It always happens after around 30 to 60 minutes of video recording.

What is causing this error ? Is it coming from ffmpeg or gstreamer or something else ?

How could I trap this error and handle it in my C/C++ program ?

2 Answers 2

2

The source lines that are printing the error are here in libav

Digging further, you can see that -12 corresponds to ENOMEM, returned here in lavfilters-ffmpeg i.e. it practically does if (!buffer) return AVERROR(ENOMEM)

Given this happens after 30 to 60 minutes and you're executing this on a Pi, is it possible you are actually running out of memory? What do you see if you run top while streaming?

What is causing this error ? Is it coming from ffmpeg or gstreamer or something else ?

How could I trap this error and handle it in my C/C++ program ?

To answer all three questions let's go one level deeper and see the definition of av_malloc() in FFmpeg. It appears to be doing plain memory allocation, not allocating some more obscure video memory via ION nor mmap() nor dmabuf.

Because this is plain C code and not throwing exceptions you cannot easily trap it as an exception. However, I imagine you could make your program monitor the amount of available memory and adapt things (stop the stream and restart if necessary) to prevent this ENOMEM from happening.

0

If you are using the app from the root user, my best guess is that you are running out of space. Did you expand the file system? If not, then that is your most likely suspect.

HomeBoy Out

4
  • I'm running my program as root. I'm writing the file to an external USB dongle. What do you mean by expand the file system ? Why is running it as root different that the default pi user.
    – ssinfod
    Commented Mar 24, 2016 at 12:08
  • Take a look over on the Foundation's sitehere... Seems to be exactly the problem you have. Running the raspi-config provides access to fixing the size problem. Run raspi-config and select theexpand_rootfs option. Reboot. This should fix your problem. Commented Mar 24, 2016 at 15:02
  • Does this apply to a USB dongle ? Can you give me the link to the foundation website since It is not in your comment above.
    – ssinfod
    Commented Apr 15, 2016 at 4:13
  • There's a ton of info as to the why of the rootfs. I am not on the know however :). Sorry the linl did not come through in my first post. A quick search at the foundation site returned this results. I am sure you can fine the exact answer you need. duckduckgo.com/?q=Expand+root+site%3Araspberrypi.org Commented Apr 16, 2016 at 1:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.