IMX462 stream with VLC fills up memory resulting in OOM trigger

I’m running a libcamera-vid stream from my IMX462 on a Raspberry PI model 3A+
Stream is fed into cvlc with the following command:

/usr/local/bin/libcamera-vid -t 0 -n --inline --framerate 25 --width 640 --height 480 -o - | /usr/bin/cvlc -vvv stream:///dev/stdin --sout ‘#rtp{sdp=rtsp://:8554/stream}’ :demux=h264

I noticed that this stream will only run for a few hours since the memory is slowly filling up.
At a certain moment the OOM becomes activated and kills the vlc process:

Jan 21 06:43:31 raspberrypi kernel: [26493.401437] oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),cpuset=/,mems_allowed=0,global_oom,task_memcg=/,task=vlc,pid=450,uid=0
Jan 21 06:43:31 raspberrypi kernel: [26493.401554] Out of memory: Killed process 450 (vlc) total-vm:99032kB, anon-rss:0kB, file-rss:0kB, shmem-rss:0kB, UID:0 pgtables:78kB oom_score_adj:0
Jan 21 06:43:31 raspberrypi kernel: [26493.432645] oom_reaper: reaped process 450 (vlc), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB

My question is how I can prevent this from happening? Is there a better way to stream libcamera-vid stream into rtsp so I can receive it on my Synology Surveillance station?

Not sure if it’s a problem with libcamera-vid, can you try the following commands? :

/usr/local/bin/libcamera-vid -t 0 -n --inline --framerate 25 --width 640 --height 480 -o /dev/null

It discards the output of libcamera-vid instead of sending it to vlc, which we can use to confirm if there is a problem running libcamera-vid alone.

Ok thanks for the suggestion, I started that 4 hours ago. This is the result. First thuis is what I get if I start the command you suggested:

[email protected]:~ $ /usr/local/bin/libcamera-vid -t 0 -n --inline --framerate 25 --width 640 --height 480 -o /dev/null
[0:01:24.931432831] [645] INFO Camera camera_manager.cpp:293 libcamera v0.0.0
[0:01:24.947840956] [649] WARN CameraSensor camera_sensor.cpp:197 ‘arducam-pivariety 10-000c’: Recommended V4L2 control 0x009a0922 not supported
[0:01:24.967335800] [649] WARN CameraSensor camera_sensor.cpp:249 ‘arducam-pivariety 10-000c’: The sensor kernel driver needs to be fixed
[0:01:24.967484133] [649] WARN CameraSensor camera_sensor.cpp:251 ‘arducam-pivariety 10-000c’: See Documentation/sensor_driver_requirements.rst in the libcamera s ources for more information
[0:01:24.979573091] [649] WARN CameraSensorProperties camera_sensor_properties.cpp:141 No static properties available for ‘arducam-pivariety’
[0:01:24.979763664] [649] WARN CameraSensorProperties camera_sensor_properties.cpp:143 Please consider updating the camera sensor properties database
[0:01:24.979891997] [649] WARN CameraSensor camera_sensor.cpp:414 ‘arducam-pivariety 10-000c’: Failed to retrieve the camera location
[0:01:25.453759810] [649] ERROR IPAProxy ipa_proxy.cpp:149 Configuration file ‘arducam-pivariety.json’ not found for IPA module ‘raspberrypi’
[0:01:25.865176997] [649] ERROR DelayedControls delayed_controls.cpp:87 Delay request for control id 0x009a090a but control is not exposed by device /dev/video0
[0:01:25.876318976] [645] INFO Camera camera.cpp:937 configuring streams: (0) 640x480-YUV420
[0:01:25.877951424] [649] INFO RPI raspberrypi.cpp:122 Mode: 1920x1080 fmt RG10 Score: 2136.67 (best 2136.67)
[0:01:25.878231216] [649] INFO RPI raspberrypi.cpp:122 Mode: 1920x1080 fmt pRAA Score: 1636.67 (best 1636.67)
[0:01:25.955287153] [649] INFO RPI raspberrypi.cpp:624 Sensor: /base/soc/i2c0mux/[email protected]/[email protected] - Selected mode: 1920x1080-pRAA
[0:01:26.016309028] [653] INFO IPARPI raspberrypi.cpp:654 Request ctrl: Sharpness = 1.000000
[0:01:26.016970903] [653] INFO IPARPI raspberrypi.cpp:654 Request ctrl: Saturation = 1.000000
[0:01:26.017327726] [653] INFO IPARPI raspberrypi.cpp:654 Request ctrl: Contrast = 1.000000
[0:01:26.017644185] [653] INFO IPARPI raspberrypi.cpp:654 Request ctrl: Brightness = 0.000000
[0:01:26.017931216] [653] INFO IPARPI raspberrypi.cpp:654 Request ctrl: FrameDurationLimits = [ 40000, 40000 ]
[0:01:26.018351112] [653] INFO IPARPI raspberrypi.cpp:654 Request ctrl: NoiseReductionMode = 1
[0:01:26.018855122] [653] INFO IPARPI raspberrypi.cpp:654 Request ctrl: AeMeteringMode = 0
[0:01:26.019403143] [653] INFO IPARPI raspberrypi.cpp:654 Request ctrl: AeExposureMode = 0
[0:01:26.019719237] [653] INFO IPARPI raspberrypi.cpp:654 Request ctrl: ExposureValue = 0.000000
[0:01:26.020130747] [653] INFO IPARPI raspberrypi.cpp:654 Request ctrl: AwbMode = 0
[0:01:26.029171997] [649] INFO RPISTREAM rpi_stream.cpp:122 No buffers available for ISP Output0
[0:01:26.029310955] [649] INFO RPISTREAM rpi_stream.cpp:122 No buffers available for ISP Output0
[0:01:26.489383507] [649] INFO RPI raspberrypi.cpp:1732 Dropping frame at the request of the IPA (7 left)
[0:01:26.522529080] [649] INFO RPI raspberrypi.cpp:1732 Dropping frame at the request of the IPA (6 left)
[0:01:26.560109914] [649] INFO RPI raspberrypi.cpp:1732 Dropping frame at the request of the IPA (5 left)
[0:01:26.595718664] [649] INFO RPI raspberrypi.cpp:1732 Dropping frame at the request of the IPA (4 left)
[0:01:26.629947726] [649] INFO RPI raspberrypi.cpp:1732 Dropping frame at the request of the IPA (3 left)
[0:01:26.665778351] [649] INFO RPI raspberrypi.cpp:1732 Dropping frame at the request of the IPA (2 left)
[0:01:26.699376372] [649] INFO RPI raspberrypi.cpp:1732 Dropping frame at the request of the IPA (1 left)
[0:01:26.732945747] [649] INFO RPI raspberrypi.cpp:1732 Dropping frame at the request of the IPA (0 left)

Then I did a free -m command after I started it:

free -m
total used free shared buff/cache available
Mem: 428 98 166 3 163 277
Swap: 99 0 99

Now after 4 hours:

[email protected]:~ $ free -m
total used free shared buff/cache available
Mem: 428 171 93 3 164 204
Swap: 99 0 99

As you can see the amount of free memory has decreased already significantly in 4 hours.
I did not start any other processes in between, just let it run.

Hope this helps.

And this is the result after about 14 hours where the system is now using swap memory::

[email protected]:~ $ free -m
total used free shared buff/cache available
Mem: 428 344 60 1 23 47
Swap: 99 8 91

Thank you very much for your information,
I will go to the github of libcamera-apps to check if any memory related bugs have been fixed recently

Thanks Wong, maybe it’s a problem specific for the Rasppberry PI model 3A+?
It only has 512MB memory while the 3B+has 1GB.

Are there any other people maybe using the IMX462 on a RPI 3A+?

BTW I’m running the recommended OS version:
[email protected]:~ $ uname -a
Linux raspberrypi 5.10.17-v7+ #1403 SMP Mon Feb 22 11:29:51 GMT 2021 armv7l GNU/Linux

I’m not very sure, I’ll do some testing.
Thanks again for your information.

Hi Wong,

do you happen to have any update or suggestion for me?

thanks

We tested it on Pi4 for about 14 hours,
The free memory has changed from 432 to 351. I plan to upgrade libcamera to the new version first and run the test again.

log:
out.txt (197.3 KB)

Hi Wong,

thanks for the first feedback. Good to see you also see a gradually increase of memory usage over time. Since PI4 has larger memory it will take longer but most likely at some point you will face the same issue as I saw on the RPI Model 3A+. Appreciate if you could try the latest version and could share your findings.

Update some test results:

Install the official image and use the built-in libcamera (for testing IMX477):
https://downloads.raspberrypi.org/raspios_full_armhf/images/raspios_full_armhf-2021-11-08/

System Info:

[email protected]:~ $ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 11 (bullseye)"
NAME="Raspbian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

Kernel Version:

[email protected]:~ $ uname -a
Linux raspberrypi 5.10.63-v7l+ #1459 SMP Wed Oct 6 16:41:57 BST 2021 armv7l GNU/Linux

Test command

libcamera-vid -t 0 -n --inline --framerate 25 --width 640 --height 480 -o /dev/null

Tested module
imx477

Test for two days:
free memory from 7211 to 7095

Looks like no problem.

The next step will be testing with our modified libcamera.

log:
imx477_libcamera_test.txt (900.1 KB)