Search code examples
androidandroid-cameraandroid-camera2android-mediarecorder

File size limit on using android's mediaRecorder?


I have made a custom video camera using android's media Recorder. The problem I am facing is that it stops recording when the file size reaches 3.80 GB.

  • I know this is not a file system problem as my sdcards has ntfs (my phone supports it -Honor 6X)
  • I have enough space on my sd card.
  • I am not even using the MediaRecorder.setMaxFileSize().
  • The inbuilt camera app in my phone has no problem taking videos which cross 3.80 GB.

So what exactly is the problem here? I know in some android devices, the camera app has a embedded file size restriction, irrespective of the file system. But this shouldn't be a problem while making a custom video recording app right?

Edit: Posted the solution below.


Solution

  • Okay I found the solution, The problem was that I wasn't using MediaRecorder.setMaxFileSize(), so by default the limit was set to 4GB. Even when using MediaRecorder.setMaxFileSize(-ve or 0), which apparently disables the file size limit according to it's reference page, still sets the file size limit internally as 4GB (If anyone has more info on this, please do share). The solution was that, I found the free space in my internal storage using StatFS and set that as the parameter for setMaxFileSize(), this worked beautifully. I was able to cross the 4GB file limit finally. This works for all file systems supporting file size greater than 4GB.