1

How to programmatically calculate how much memory I can use for recording a video before starting video recording in android. Can any one give me some spark to go forward. Thanks.

wilson
  • 35
  • 6

1 Answers1

4

You can estimate how much video you can record with the available space by using the CamcorderProfile class to find the audio & video bitrates. You need to specify which profile you are using though. Here is some code to get the bitrate for 1080p video if available or "high quality" video if not:

int quality = CamcorderProfile.QUALITY_HIGH;
if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_1080P))
    quality = CamcorderProfile.QUALITY_1080P;
CamcorderProfile profile = CamcorderProfile.get(quality);
int bitrate = profile.videoBitRate + profile.audioBitRate;

Then if you know how many bytes of storage you have available you can estimate how many seconds of video you can record by calculating

seconds left = bytes left / (bitrate / 8)

I'm not sure whether the device would let you keep recording until you completely ran out of storage space however.

samgak
  • 23,944
  • 4
  • 60
  • 82
  • Hi I think this answer have some spark and thanks a lot samgak I will try and let you know. thanks once again. – wilson Mar 27 '15 at 05:05
  • Awesome man samgak it works like a charm...thanks a lot for your timely help and support. – wilson Mar 27 '15 at 09:12
  • Hi samgak can you please help me the same to calculate " how many photos can be taken with the available space in android"..? – wilson Mar 31 '15 at 08:52
  • Please ask that as a new question – samgak Mar 31 '15 at 08:53
  • ya pls check this "http://stackoverflow.com/questions/29364532/calulate-space-for-photo-capture-in-android" – wilson Mar 31 '15 at 08:58
  • Dear Samgak did u got any solution for my second question.. I am waiting for ur reply.. – wilson Apr 01 '15 at 04:43
  • I don't really know the answer to your second question sorry, I was hoping someone else would be able to answer it – samgak Apr 01 '15 at 04:49