Record until SD card is full == ERROR_UNKNOWN

14 views
Skip to first unread message
Assigned to leoh...@google.com by charco...@google.com

Tobias Tharaldsen

unread,
Aug 18, 2025, 4:20:16 AMAug 18
to Android CameraX Discussion Group
Hi. 
I see that when I record to SD card and there is no space left on SD card the error type is ERROR_UNKNOWN, and just wanted to mention it here, in case that is an error you want to (and can) classify a bit more, the "cause" message is this: java.lang.IllegalStateException: writeSampleData returned an error.
The video file ended up corrupt which was expected because no storage to place the moov atom or other finalizing data.

It is no problem for me in my app, because I record to internal storage (and check for remaining available storage continuously), which brings me to a couple of questions regarding video recording on filesystems.

1. What happens if I record on FAT16 filesystem and reach the filesystems max file size limit of 2GB (or FAT32 and 4GB)? Will the file be corrupt, or it will finalize the file correctly?
(My micro SD card had only 1GB so I have ordered a bigger one to test on real SD card, but can't test myself right now unfortunately)

2. Can devices running API 31+ still come with and use FAT32? That might be up to the manufacturer and not possible to answer being 100% sure? It seems at least that using internal storage on API 31+ should not meet the 4GB max file size limit.

Leo Huang

unread,
Aug 18, 2025, 9:16:30 AMAug 18
to Tobias Tharaldsen, Android CameraX Discussion Group
Hi,
 
> I see that when I record to SD card and there is no space left on SD card the error type is ERROR_UNKNOWN, and just wanted to mention it here, in case that is an error you want to (and can) classify a bit more, the "cause" message is this: java.lang.IllegalStateException: writeSampleData returned an error. It is no problem for me in my app, because I record to internal storage (and check for remaining available storage continuously),

Thanks for the feedback, we have noticed this exception before. In CameraX versions 1.5.0-alpha02 and newer, there's an improved feature that automatically stops a recording when the available storage drops below a certain threshold (~50MB). When this happens, the recording is finalized with the error code ERROR_INSUFFICIENT_STORAGE. This helps prevent file corruption. However, this feature does not apply to FileDescriptorOutputOptions because there is no information about the output destination.
May I know which CameraX version and which OutputOptions (i.e. FileOutputOptions, MediaStoreOutputOptions and FileDescriptorOutputOptions) you are using?

> It is no problem for me in my app, because I record to internal storage (and check for remaining available storage continuously)

I'm curious why you didn't take the same approach when recording to a SD card?

> 1. What happens if I record on FAT16 filesystem and reach the filesystems max file size limit of 2GB (or FAT32 and 4GB)? Will the file be corrupt, or it will finalize the file correctly? (My micro SD card had only 1GB so I have ordered a bigger one to test on real SD card, but can't test myself right now unfortunately)

The video file will likely be corrupt. The behavior is similar to running out of storage space.
We are working on a new feature that will attempt to preserve the video file even if the recording is terminated unexpectedly. This feature could potentially help in these situations. You can follow this issue.

> 2. Can devices running API 31+ still come with and use FAT32? That might be up to the manufacturer and not possible to answer being 100% sure? It seems at least that using internal storage on API 31+ should not meet the 4GB max file size limit.

I'm not sure about this, but I guess for compatibility with other devices it can be.

Tobias Tharaldsen <tobb...@gmail.com> 於 2025年8月18日 週一 下午4:20寫道:
--
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/ded7c392-787d-4dea-bd8e-578e3c7de9f1n%40android.com.

Tobias Tharaldsen

unread,
Aug 18, 2025, 9:53:14 AMAug 18
to Android CameraX Discussion Group, leoh...@google.com, Android CameraX Discussion Group, Tobias Tharaldsen
Hi.
Thanks for answering, then it sounds like an even better solution is on its way that you mentioned about saving recordings being stopped abruptly, which is great! :)

Of course, what I used for testing was:
- CameraX version: 1.5.0-rc01
- Device: Sony Xperia 10 II (since my S22 don't have micro SD card slot)
- SD card filesystem: FAT16

Testing reaching full storage on SD card was not an important test for me, since I use internal storage (and is why I didn't set up any handling of observing the remaining available space on the SD card), but I quickly got to test it by getting some help from AI to set it up like this:
val resolver = application.contentResolver
val volumes = MediaStore.getExternalVolumeNames(application)

val sdCardVolume = volumes.find { it != "external_primary" }
val targetUri = if (sdCardVolume != null) {
MediaStore.Video.Media.getContentUri(sdCardVolume)
} else {
MediaStore.Video.Media.EXTERNAL_CONTENT_URI
}

val filename = "VID_${System.currentTimeMillis()}"
val contentValues = ContentValues().apply {
put(MediaStore.Video.Media.DISPLAY_NAME, filename)
put(MediaStore.Video.Media.MIME_TYPE, "video/mp4")
}

val outputOptions = MediaStoreOutputOptions.Builder(resolver, targetUri)
.setContentValues(contentValues)
.build()

activeRecording = videoCapture?.output
?.prepareRecording(application, outputOptions)
?.withAudioEnabled()
?.start(ContextCompat.getMainExecutor(application)) { event ->
Reply all
Reply to author
Forward
0 new messages