Android - What is the maximum file size that setMaxFileSize can be set to in respect to Androids mediarecorder? I know it's somewhere between 4147483650 and 5147483650. Why is there a limit in the first place?
I'm recording on to a SDCARD, detecting the size of the cards space before we run.
"ERROR/AuthorDriver(31): setParameter(max-filesize = 7270309850) failed with result -5"
"ERROR/AuthorDriver(31): Ln 903 handleSetParameters("max-filesize=7270309850") error"
"ERROR/AndroidRuntime(409): java.lang.RuntimeException: setMaxFileSize failed."
Why is there a limit in the first
place?
SD cards use the msdos (FAT16) filesystem, which has a file size limit. This is not an Android limitation, but a limitation of SD cards in general.
If you look in AuthorDriver.cpp, you'll see that it performs a check to see if the time value you passed in will fit into a 16bit int. There's a comment that reads "PV API expects this to fit in a uint16". So, yeah, there doesn't appear to be a way to get around this for now.
I have tried on GS5, Hauwei Y550, Note 3 and they all can't record files longer than 4096 MB (even with their official camera application). This limits 1080p videos to 35 minutes and 4K videos to less than 20 minutes. The reason is the one provided by Shane-Kirk (except it is 32bit).
I have opened an enhancement issue on Android source code with all details, if you are interested please consider starring it, the more we are the more likely they will make a patch to AuthorDriver.cpp.
https://code.google.com/p/android/issues/detail?id=145618&q=mediarecorder&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars
I'm working on an android recorder as well.
use StatFs and pass the path of the external storage directory to the constructor and you can call functions such as getAvailableBlocks() and getBlockSize() on the StatFs object.
So that way you know how much more space is available on the SD card.
Related
I'm curious if someone can point me to (or just describe) how, given that an Android application has an extremely limited memory space to play with (I think it's around 20 megs), a video player can load and play videos that are an order of magnitude or more larger in size. Is the app loading the video in some sort of chunks?
I ask because I have an app that has some video assets embedded and the app has grown to be about 80 megs and is just a total monster for compiling and debugging (without the assets the app would only be about 2 megs), and I was thinking that I should just remove the assets and have them download on the side and sit on the sdcard, rather than within the apk, but I'm worried that loading them and playing them at run time will bust through the app's memory allotment, and was hoping someone can shed some light on what my options are.
TIA
They buffer the video in manageable chunks, yes. Even if your videos are GBs in size, you won't hit a memory wall using standard video playing APIs. You can use the standard calls to setVideoURI or setVideoPath to point to the file and it will handle it from there. The same works for MediaPlayer in general if you're not using a VideoView
Downloading the videos outside the apk is still a good idea, though. If I had to download a new 80MB file for each incremental upgrade, I'd probably just uninstall instead. If you don't want to host them yourself, look into the supplemental apk option.
You can take your game into the native layer where you can bypass this limit. Take a look at a blog I wrote http://jnispot.blogspot.com/2012/10/jnindk-arrays-bitmaps-and-games-oh-my.html
I have no idea if this is what video apps do, but you can actually increase the memory beyond the normal limit by using malloc statements in native code. This bypasses the normal max of around 20 MB.
I have only used this for encryption on android devices where AES encryption needs rather karger amounts of memory when dealing with large encrypted files (even around 10MB files).
I'm developing an app that will download large files (mostly videos). What I need to know is this:
Is there a max singe file size imposed by either Android or iOS? All I've seen is the 4GB limit of a FAT filesystem. The max video size should come no where near that, but we want to be 100% sure that there isn't a lower limit
Is there a max amount of space allocated to a single app on either system? Google turned up nothing on this question, so I am going to assume there isn't a limit beyond available file space (which seems logical, but also far to free for an Apple-built system)
Is there a max number of individual files or directories for either system? Again, Google turned up nothing. I don't see why there would be here, but I want to cover all the bases here.
Thanks!
All answers here are for Android:
Is there a max singe file size imposed by either Android or iOS? All I've seen is the 4GB limit of a FAT filesystem.
I would not exceed 4GB.
Is there a max amount of space allocated to a single app on either system?
No, there is no per-app quota system at this time. That being said, try not to make users regret using your app. :-)
Is there a max number of individual files or directories for either system?
Yes, but since the counts should be in the millions, your app will grind to a halt long before you hit those limits.
Can't answer for iOS, but for Android, your APK can't exceed 50MB (if it does, you can include expansion files for your additional data).
Here is the link to the docs explaining all the details:
http://developer.android.com/guide/google/play/expansion-files.html
all
When I try to read some media file from sd card after the first time I insert to the device, the read performance is much worse than the second time, does anybody have any idea about this phenomena, and how can I avoid this problem, I tried open and fopen, but the results are the same, I just want read performance is the same, no matter when I insert SD card, thanks
Using O_DIRECT (see open(2)) when opening the file will bypass the buffer cache. This is often not a good idea, but I would expect it to be more consistent from run to run.
Keep in mind that using O_DIRECT requires that the memory read into be SC_PAGESIZE aligned and read in blocks which are multiples of SC_PAGESIZE.
Are you saying it's worse for the first read than subsequent reads before you remove the device? If so, this is normal - it's due to buffering. Basically the system is using the system RAM to speed up the perceived speed of the device.
If you remove the card after unmounting it and then put it back and remount it I would expect the first read would again be slower, then subsequent reads would appear to be faster again.
I wanted to know if there was a size limit to the data files an android app can use or a size limit depending on the SD card (or internal memory) filesystem ?
Cheers
Olivier
The file size limit is determined by the filesystem. FAT32, for instance, cannot handle files larger than 4GB. Unfortunately, it is fairly likely that your microSD card is formatted in FAT32.
For Android 2.2 and older, the internal file system is YAFFS. The author, Charles Manning, states in this mailing that the maximum file size is 512 MB. It has been announced that Android 2.3 will use ext4.
It might be possible to format your SD card to this format as well, but I haven't tried it. Bear in mind that you won't be able to read the contents under Windows or OS X.
See also the answers in this topic.
What is an effective way to determine how much free space is on the SD card?
If you just want to check it yourself, here are the steps to do it:
http://www.tech-recipes.com/rx/5641/android-how-to-check-available-internal-and-sd-card-memory-space/
UPDATE:
I just found that there is a better SO answer to this question:
How to Check available space on android device ? on SD card?
Here are some methods to get available space, these methods give you more control and you can get available space in different units bytes, kb, mb, gb.
How to Check available space on android device ? on SD card?
Usable since API level 9:
Environment.getExternalStorageDirectory().getUsableSpace();
http://developer.android.com/reference/java/io/File.html#getUsableSpace()
Here is a function that allows you to retrieve the amount of memory in the android device.
You can very easily find out the amount of memory that is left of you SD card via the phones device information. Please elaborate if your requirements are something else.
Create a file and write one byte at a time until you get an out of space exception.