You set up an old Android phone as an offline security camera, put a cheap 32 GB microSD card in it, and left it recording all night. In the morning there is one video file. It is a little under 4 GB, and it ends hours before you woke up.
Nothing crashed. The card is not full. You ran into one of the oldest limits in personal computing: a FAT32 file system cannot hold a single file of 4 GB or more. Most small SD cards ship formatted FAT32, and Android's own video writer knows about the limit and stops before it.
This article explains where the limit comes from, which cards it affects, what Android's MP4 recorder does when it gets close, how long that takes at common video bitrates, and how to set up a no-cloud, local-only phone camera so that it records all night without hitting the wall. Quoted lines below come from the SD Association, Microsoft's file system documentation, Android's MediaRecorder reference, and the Android Open Source Project (AOSP) source code, all read on the day this was written.
Why does my phone camera recording stop at almost 4 GB?
Short answer: your SD card is very likely formatted FAT32, and FAT32 stores each file's size in a 32-bit number. The biggest number that fits is 4,294,967,295 bytes, which is 4 GiB minus one byte. A file cannot grow past that. Android's MP4 writer checks the file system's limit when a recording starts and caps the recording below it, so the recording ends a little before 4 GB instead of corrupting.
If the card is FAT32, this will happen with any recording app that writes one long file. It is not a fault in the phone, the card or the app. The fix is to either write many smaller files (segments), lower the bitrate so each file covers more time, or use a card formatted exFAT, which does not have this limit.
Where the 4 GB limit comes from
Microsoft's description of how FAT works says it plainly: "The largest possible file for a FAT32 volume is 4 GB minus 1 byte." The same page's limits table writes it as 2^32 bytes minus 1 byte, which is the largest number a 32-bit size field can hold: FAT32 records each file's length in 32 bits. exFAT was designed with a much wider size field, and in practice it has no file size limit you will ever reach with a camera.
So the limit belongs to the file system, not to the card's capacity. A 32 GB FAT32 card can hold eight 3.9 GB files. It cannot hold one 5 GB file.
Which SD cards are FAT32?
The SD Association, which writes the SD card standards, defines the file system by card capacity:
| Card type | Capacity | Standard file system |
|---|---|---|
| SD | up to 2 GB | FAT12 / FAT16 |
| SDHC | over 2 GB up to 32 GB | FAT32 |
| SDXC | over 32 GB up to 2 TB | exFAT |
| SDUC | over 2 TB up to 128 TB | exFAT |
The logo on the card tells you which one you have. Every SDHC card (4, 8, 16, 32 GB) is FAT32 by the standard. Those are exactly the cards people buy for a budget camera phone, because they are cheap and old phones often have small internal storage.
An SDXC card (64 GB and up) arrives as exFAT, but it does not always stay that way. See the next section.
What happens when you format the card in the phone
When you tap "Format" on an SD card in Android's storage settings, the work is done by a system component called vold. An AOSP change titled "Use exFAT for SDXC cards" explains the rule. When the phone supports both file systems, it picks by size: the code comment reads "use exfat for SDXC (>~32GiB) cards", and anything at or below that threshold gets FAT32 (the code calls it vfat).
The important words are "when both are supported". exFAT support depends on the phone's software. In that same code, if the phone only supports vfat, an automatic format uses FAT32 whatever the card's size. So on some older or very cheap phones, formatting a 64 GB card in the phone can leave you with a FAT32 card, and the 4 GB limit comes back.
That gives you two simple rules:
- A card of 32 GB or less is FAT32. Plan around the limit.
- A bigger card is only exFAT if it was formatted by something that supports exFAT. Check it before you trust it.
How Android's video recorder handles the limit
Most Android camera apps record MP4 files through Android's media framework. The public MediaRecorder API lets an app set a size limit with setMaxFileSize(). The reference says that after a recording reaches that size, the app's listener gets MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED "and recording will be stopped".
The interesting part is what happens when an app does not set a limit. In the current AOSP MP4 writer (MPEG4Writer.cpp), the start() method asks the operating system how many bits the file system uses for file sizes (fpathconf with _PC_FILESIZEBITS). It then works out the largest file size that allows and, if the app left the limit at zero, sets it anyway. The log line in the source says it directly: "File size limit set to … bytes implicitly".
On a file system that reports 32 bits, that implicit limit is 2^32 − 1 bytes, the FAT32 maximum. An older AOSP commit made the same point years ago when it raised the recorder's cap to "4GB (more precisely 2^32-1 bytes -- FAT32 max file size)".
The writer does not wait until the last byte. Its size check is deliberately cautious. The source comment says: "Be conservative in the estimate: do not exceed 95% of the target file limit." It also sends an early warning, MEDIA_RECORDER_INFO_MAX_FILESIZE_APPROACHING, at 90%. For a 4 GiB limit, 95% is about 3.8 GiB, which is why the file you find is "a little under 4 GB" rather than exactly 4 GB.
Two honest caveats:
- Not every app uses
MediaRecorder. Apps that useMediaMuxeror their own writer handle this in their own way. But none of them can make FAT32 store a 4 GB file. - On newer Android versions, apps reach the SD card through a system layer, so what
fpathconfreports may differ by device. The file system's own rule does not change: on FAT32, writing past 4 GiB − 1 byte fails.
How long until you hit the limit?
The time depends only on the video bitrate (how many bits per second the encoder writes), not on resolution as such. Here is the arithmetic for a single file on FAT32, using the full 4,294,967,295 bytes and the writer's 95% stop point:
| Video bitrate | Time to full 4 GiB | Time to 95% (~3.8 GiB) |
|---|---|---|
| 2 Mbps | 286 min (4 h 46 min) | 272 min |
| 4 Mbps | 143 min (2 h 23 min) | 136 min |
| 8 Mbps | 72 min | 68 min |
| 12 Mbps | 48 min | 45 min |
| 16 Mbps | 36 min | 34 min |
Audio adds a little more. So if a 1080p recording at around 8 Mbps "always stops after about an hour", the FAT32 limit is the first thing to suspect. The same table also tells you something about the card itself: at 8 Mbps a phone writes about 86 GB per day, so a 32 GB card fills in well under half a day unless old files are deleted.
How to record all night without hitting the 4 GB limit
1. Record in segments instead of one long file
This is the best fix, and it also protects you against other failures. A camera that writes one file every 10, 15 or 30 minutes never gets close to 4 GB, and if power is cut, you lose only the current segment instead of the whole night. MP4 files need a final index (the moov box) written at the end, so an interrupted single file is often unplayable. I covered that in detail in Why an Interrupted Android Recording Won't Play, and the Android API for switching files without dropping frames (setNextOutputFile()) in Storage, Not Heat, Is the Real Limit on 24/7 Android Recording.
Whatever app you use, look for a setting called segment length, clip length, file split or loop recording.
2. Test the app on your card before you rely on it
Do not trust a setting name. Do this once:
- Put in the card you will actually use.
- Start a recording and leave it for longer than the time in the table above for your quality setting (for 1080p, give it two hours).
- Stop it and look at the files. Several files of similar size, all playable, means you are safe. One file just under 4 GB that ends early means you hit the limit.
This test takes one evening and saves you from finding out on the night something happens.
3. Use exFAT on a bigger card, if your phone supports it
A 64 GB or larger SDXC card, formatted exFAT, removes the per-file limit. To check the format, put the card in a Windows computer, right-click the drive, choose Properties and read File system. If it says FAT32 and you want exFAT, back up anything on it first, because formatting erases the card. Then insert it in the phone and check that the phone can read and write it. If the phone cannot use exFAT, it will ask to format the card, and a format done by a phone without exFAT support will produce FAT32 again.
4. Lower the bitrate if you do not need the detail
For a shop counter or a doorway, 720p at a lower bitrate often shows everything you need and doubles the time per file. It also doubles how many hours fit on the card.
5. Be careful with "format as internal storage"
Android can format an SD card as internal storage (adoptable storage). That replaces FAT32 with an encrypted file system tied to that one phone, which removes the 4 GB limit but means you can no longer pull the card and read it on a laptop. There are other trade-offs too. Read Should You Format the SD Card as Internal Storage on an Old Phone Security Camera? before choosing this.
6. Remember FAT32's other weakness
FAT32 also has no journal, so a power cut during a write can damage the card's file table, not just the last file. That is another reason to keep segments short. More on how cards fail in The microSD Card Is the Weakest Part of a 24/7 Phone Camera.
Where Background Camera RemoteStream fits
I build Background Camera RemoteStream, an Android app that turns a phone into a camera that records with the screen off, stores everything on the phone (no cloud account, no subscription), lets you watch live from another device on the same Wi-Fi through its built-in web server, and can stream to YouTube Live when you want an off-device copy. It works without internet for local recording and LAN viewing.
None of that changes the FAT32 rule, and I will not pretend it does. If you use it with an SDHC card, run the two-hour test from step 2 on your own phone and card, the same way you would for any other app. The table above tells you how long to wait.
- Google Play: https://play.google.com/store/apps/details?id=com.superfunicular.digicam
- Website: https://superfunicular.com
Quick checklist
- [ ] Card of 32 GB or less? It is FAT32. One file cannot reach 4 GB.
- [ ] Recording stops near 3.8–4 GB and ends early? That is the FAT32 limit, not a crash.
- [ ] Turn on segment or clip recording if your app has it.
- [ ] Run a two-hour test recording on the real card.
- [ ] Bigger card? Check the file system on a computer; exFAT has no practical file limit.
- [ ] Do the storage math: at 8 Mbps the phone writes about 86 GB a day.
Sources
- SD Association, "Capacity (SD/SDHC/SDXC/SDUC)": https://www.sdcard.org/developers/sd-standard-overview/capacity-sd-sdhc-sdxc-sduc/
- Microsoft, "How FAT Works": https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2003/cc776720(v=ws.10)
- Android Developers,
MediaRecorderreference: https://developer.android.com/reference/android/media/MediaRecorder - AOSP,
MPEG4Writer.cpp: https://android.googlesource.com/platform/frameworks/av/+/master/media/libstagefright/MPEG4Writer.cpp - AOSP vold change "Use exFAT for SDXC cards" (mirror): https://gerrit.omnirom.org/plugins/gitiles/android_system_vold/+/4cff06d45faa4cf62f471f56550006e5f0a2d7db%5E%21
- AOSP commit "Increased recorded MP4 max file size to 4GB" (mirror): https://gitlab.e.foundation/e/os/android_frameworks_av/-/commit/f622e2c78407b50806a53a06a89b2b6546420f55
Top comments (0)