OutOfMemory while recording 4K video to low class SD card

43 views
Skip to first unread message

Eugene B

unread,
Dec 3, 2025, 12:40:32 PMDec 3
to Android CameraX Discussion Group
When recording 4K video to a low-class (e.g., Class 4) SD card, the video stream continuously fills the internal buffer faster than the data can be written to the slow storage medium. This quickly leads to a system-level low memory condition. To maintain overall OS functionality, Android's process management then terminates all background and, eventually, foreground processes, including the camera app.

The SD card specification does not provide a standardized way to query the card's speed class directly. Therefore, the application cannot retrieve this information reliably. While we could theoretically perform a write speed test ourselves, implementing such a feature seems out of scope for a core Camera application.

I have reviewed the CameraX API but could not find a method to obtain the size of the VideoRecorder's internal buffer. The VideoRecordEvent.RecordingStats only provides information about the number of bytes written.

Question: Is there any way to access or determine the size of the VideoRecorder buffer in CameraX?

13:21:54.723   300   300 I lowmemorykiller: Kill 'com.some.store:AppMetrica' (19951), uid 10029, oom_score_adj 945 to free 31888kB rss, 55172kB swap; reason: min watermark is breached and thrashing (109%)
13:21:55.264   300   300 I lowmemorykiller: Kill 'com.some.browser:AppMetrica' (20255), uid 10062, oom_score_adj 935 to free 28300kB rss, 60048kB swap; reason: min watermark is breached and thrashing (97%)
13:21:55.294   300   300 I lowmemorykiller: Kill 'com.android.externalstorage' (20190), uid 10026, oom_score_adj 925 to free 29096kB rss, 43668kB swap; reason: min watermark is breached even after kill
13:21:55.313   300   300 I lowmemorykiller: Kill 'android.process.media' (20359), uid 10017, oom_score_adj 915 to free 29816kB rss, 44084kB swap; reason: min watermark is breached even after kill
13:21:55.330   300   300 I lowmemorykiller: Kill 'com.some.browser' (20208), uid 10062, oom_score_adj 905 to free 32088kB rss, 60924kB swap; reason: min watermark is breached even after kill
13:21:55.445   300   300 W lowmemorykiller: Failed to open /proc/20255/oom_score_adj; errno=2: process 20255 might have been killed
13:21:55.805   300   300 I lowmemorykiller: Kill 'tech.nda.packageupdateservice' (19861), uid 10077, oom_score_adj 800 to free 29388kB rss, 44916kB swap; reason: low watermark is breached and thrashing (85%)
13:21:56.333   300   300 I lowmemorykiller: Kill 'com.some.store' (19889), uid 10029, oom_score_adj 500 to free 34428kB rss, 64752kB swap; reason: min watermark is breached and thrashing (86%)
13:21:56.358   300   300 I lowmemorykiller: Kill 'tech.nda.keyboard' (20106), uid 10050, oom_score_adj 200 to free 33636kB rss, 263024kB swap; reason: min watermark is breached even after kill
13:21:56.669   630 21208 I DropBoxManagerService: add tag=system_server_lowmem isTagEnabled=true flags=0x6
13:21:58.050   300   300 I lowmemorykiller: Kill 'com.android.launcher3' (15014), uid 10081, oom_score_adj 100 to free 45836kB rss, 71900kB swap; reason: min watermark is breached and thrashing (208%)
13:21:59.122   300   300 I lowmemorykiller: Kill 'android.ext.services' (15151), uid 10096, oom_score_adj 100 to free 28972kB rss, 45024kB swap; reason: min watermark is breached and thrashing (209%)
13:21:59.144   300   300 I lowmemorykiller: Kill 'com.android.smspush' (15396), uid 10088, oom_score_adj 100 to free 26464kB rss, 44012kB swap; reason: min watermark is breached even after kill
13:21:59.151   300   300 I lowmemorykiller: Kill 'tech.nda.camera' (20888), uid 10086, oom_score_adj 0 to free 360160kB rss, 242184kB swap; reason: min watermark is breached even after kill
13:21:59.253   300   300 I lowmemorykiller: Kill '<pre-initialized>' (21209), uid 10077, oom_score_adj 0 to free 23544kB rss, 43688kB swap; reason: min watermark is breached even after kill
13:22:02.134   300   300 I lowmemorykiller: Kill '<pre-initialized>' (21227), uid 10081, oom_score_adj 0 to free 29096kB rss, 39216kB swap; reason: min watermark is breached and thrashing (489%)
13:22:06.907   300   300 I lowmemorykiller: Kill 'com.android.launcher3' (21243), uid 10081, oom_score_adj 0 to free 38240kB rss, 38804kB swap; reason: min watermark is breached and thrashing (209%)
13:22:07.781   300   300 I lowmemorykiller: Kill 'com.some.store' (21260), uid 10029, oom_score_adj 0 to free 32868kB rss, 37636kB swap; reason: min watermark is breached and thrashing (201%)

Scott Nien

unread,
Dec 4, 2025, 4:09:34 AMDec 4
to Eugene B, Android CameraX Discussion Group
Hi there, 
This seems something we can improve. 

Can you share more information to us? 
1) What devices are you using 
2) What is the purpose of recording 4K videos on a sd card? Is this a key user journey in your app or is it reported by your app users?

--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.
To view this discussion visit https://groups.google.com/a/android.com/d/msgid/camerax-developers/3165185d-cff8-4281-8175-0d6dd66ea87an%40android.com.

Eugene B

unread,
Dec 4, 2025, 7:49:07 AMDec 4
to Scott Nien, Android CameraX Discussion Group
Hi Scott,

This is not a device issue. Even if a device doesn’t have an SD card slot, AOSP supports USB hubs, which in turn support SD cards. AOSP also supports other external storage media.
In our Camera app, we give the user the option to choose which storage to use for saving media. We want the Camera app to behave reliably, regardless of whether the user understands the variety of SD cards and other external storage options.
If the storage turns out to be too slow, the app will stop recording video and notify the user that this storage does not support 4K recording.

Scott Nien

unread,
Dec 4, 2025, 10:49:28 AMDec 4
to Eugene B, Android CameraX Discussion Group

Thanks for the information. This makes sense. Let me double check,  so what CameraX can improve is to 
Avoid the OutOfMemory crash by 
1) adjust the internal buffer size properly 
2) provide a way to detect if the speed is fast enough for 4K recording, if not trigger an error to warn the app user. 

Is it correct?  

And do you think this SD cards / other USB storage case is very important for 4K recording as it needs large amount of disk space?  

Eugene B

unread,
Dec 4, 2025, 11:05:20 AMDec 4
to Android CameraX Discussion Group, scot...@google.com, Android CameraX Discussion Group, Eugene B
Ideally, the CameraX API would automatically stop recording video if the accumulated buffer grows too quickly, for example with the too_slow_storage error—this would be a unified approach, as for other cases.

Regarding the second point, I don't see a quick way to determine the write speed of the selected storage. I developed a utility class for measuring speed and discovered the following:
Measurements revealed that when recording a file smaller than 25 megabytes, the measured write speed is significantly underestimated and does not reflect the actual speed.

For example, when recording a 10-20 MB file:
A low-class SD card shows a write speed of 2-3 MB/s.
A class 10 SD card shows 2.5-3.5 MB/s.
Internal storage shows 50-70 MB/s.

When recording a 25 MB file, the calculated speed is more realistic:
Low-class SD card: 2-3 MB/s.
Class 10 SD card: 5-8 MB/s.
Internal storage: 120-160 MB/s.

I don't think the Camera API should be responsible for determining the speed of the storage device itself.

Professional cameras supports 4K video recording to an SD card. I see no reason to limit the user. After all, we all strive to make our products better.
четверг, 4 декабря 2025 г. в 18:49:28 UTC+3, scot...@google.com:
Reply all
Reply to author
Forward
0 new messages